Skip to content

Conversation

@noa-starkware
Copy link
Collaborator

@noa-starkware noa-starkware commented Nov 25, 2025

This change is Reviewable


Note

Introduce update_current_epoch_block_rewards with average block duration tracking and supporting errors/constants; update tests and docs accordingly.

  • Reward Supplier:
    • Add update_current_epoch_block_rewards() to compute per-epoch block rewards (STRK/BTC); staking-only.
    • Track block timing via new storage: avg_block_duration, block_snapshot; initialize avg_block_duration in constructor.
    • Add internal set_avg_block_duration() with sanity checks; use BLOCK_DURATION_SCALE and SECONDS_IN_YEAR in rewards calc.
    • Extend interface (IRewardSupplier) and use mul_wide_and_div for precise math.
  • Errors:
    • Add internal errors: INVALID_BLOCK_NUMBER, INVALID_BLOCK_TIMESTAMP.
    • Add reward supplier error: BLOCK_DURATION_OVERFLOW.
  • Constants/Utils:
    • Add SECONDS_IN_YEAR (shared); introduce BLOCK_DURATION_SCALE, DEFAULT_AVG_BLOCK_DURATION.
    • Rename test constant AVG_BLOCK_TIME -> AVG_BLOCK_DURATION; update time advancement helpers accordingly.
  • Docs:
    • Update spec to document update_current_epoch_block_rewards and clarify calculate_current_epoch_rewards usage.
  • Tests:
    • Add tests for block rewards flow and assertion cases; adjust helpers to use AVG_BLOCK_DURATION.

Written by Cursor Bugbot for commit a2c750f. This will update automatically on new commits. Configure here.

@codecov
Copy link

codecov bot commented Nov 25, 2025

Codecov Report

❌ Patch coverage is 95.19231% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 95.74%. Comparing base (9734730) to head (a2c750f).

Files with missing lines Patch % Lines
src/reward_supplier/reward_supplier.cairo 82.75% 5 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #63      +/-   ##
==========================================
- Coverage   95.77%   95.74%   -0.03%     
==========================================
  Files          42       42              
  Lines       10102    10203     +101     
==========================================
+ Hits         9675     9769      +94     
- Misses        427      434       +7     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@noa-starkware noa-starkware force-pushed the noa/staking/v3/update_current_epoch_block_rewards branch from 6d2dd72 to deb5f00 Compare November 25, 2025 12:44
Copy link
Collaborator

@NirLevi-starkware NirLevi-starkware left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 0 of 10 files reviewed, 1 unresolved discussion (waiting on @noa-starkware)


src/reward_supplier/reward_supplier.cairo line 141 at r2 (raw file):

    #[abi(embed_v0)]
    impl RewardSupplierImpl of IRewardSupplier<ContractState> {
        fn calculate_current_epoch_rewards(self: @ContractState) -> (Amount, Amount) {

Can't we use the code here? it looks the same. maybe we need to split the update function? to calculate_current_block_rewards and a setter to the block avg, WDYT?
This happend only once during epoch, so preformance is not an issue.

@noa-starkware noa-starkware force-pushed the noa/staking/v3/update_current_epoch_block_rewards branch from deb5f00 to 6fda82c Compare November 27, 2025 20:50
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.

3 participants