Skip to content

fix: gas optimizations for progress-tracker and learn-token (#131, #132, #133) - #170

Merged
DeFiVC merged 4 commits into
ChainLearnOfficial:mainfrom
Ojukwu-Chinedu:fix/gas-optimization-issues
Jul 29, 2026
Merged

fix: gas optimizations for progress-tracker and learn-token (#131, #132, #133)#170
DeFiVC merged 4 commits into
ChainLearnOfficial:mainfrom
Ojukwu-Chinedu:fix/gas-optimization-issues

Conversation

@Ojukwu-Chinedu

Copy link
Copy Markdown
Contributor

Summary:

Resolve three gas optimization issues:

  • closes count_completed_modules #131 count_completed_modules: Replace O(n) storage iteration with modules_completed_bitmap.count_ones() (O(1) popcount). The bitmap already tracks completed module indices, so the count is derived directly without any persistent storage reads.
  • closes average_quiz_score #132 average_quiz_score: Document that the function already uses O(1) running sums (total_quiz_score and quizzes_submitted) maintained in ProgressInfo — no Vec iteration.
  • closes claim_reward #133 claim_reward: Replace ProgressTrackerClient::new() with env.invoke_contract() to avoid the non-trivial gas cost of client instantiation on every reward claim.

…odules

Replace O(n) storage iteration in count_completed_modules with
modules_completed_bitmap.count_ones(). The bitmap already tracks
completed module indices, so popcount gives the same result in O(1)
without any persistent storage reads.

Simplify calculate_progress and is_eligible_for_credential signatures
to remove parameters that are no longer needed.

Closes ChainLearnOfficial#131
average_quiz_score already uses the running sum (total_quiz_score)
and count (quizzes_submitted) maintained in ProgressInfo, making it
O(1) with no Vec iteration. Add documentation making this explicit.

Closes ChainLearnOfficial#132
Replace ProgressTrackerClient::new() with env.invoke_contract() in
claim_reward. Client instantiation has non-trivial gas cost and is
wasted when only a single cross-contract call is needed.

Closes ChainLearnOfficial#133
@drips-wave

drips-wave Bot commented Jul 29, 2026

Copy link
Copy Markdown

@Ojukwu-Chinedu Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@DeFiVC
DeFiVC merged commit 6071b85 into ChainLearnOfficial:main Jul 29, 2026
@grantfox-oss grantfox-oss Bot mentioned this pull request Jul 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

claim_reward average_quiz_score count_completed_modules

2 participants