Skip to content

Conversation

@arad-starkware
Copy link
Collaborator

@arad-starkware arad-starkware commented Nov 27, 2025

This change is Reviewable


Note

Implements consensus block rewards based on average block duration with configurable bounds, integrates caching in staking, adds RewardSupplier EIC, and updates docs/tests accordingly.

  • Contracts – Reward Supplier:
    • Add update_current_epoch_block_rewards returning per-block STRK/BTC rewards using yearly mint and measured avg block duration (avg_block_duration).
    • Track timing via block_snapshot and clamp with BlockDurationConfig; expose get_block_duration_config and set_block_duration_config (app governor only).
    • New storage/consts: avg_block_duration, block_snapshot, block_duration_config, BLOCK_DURATION_SCALE, DEFAULT_*, use shared SECONDS_IN_YEAR.
    • New EIC RewardSupplierEIC initializing avg/min/max block duration with validation.
    • New errors: BLOCK_DURATION_OVERFLOW, INVALID_{BLOCK_NUMBER,BLOCK_TIMESTAMP,MIN_MAX_BLOCK_DURATION,AVG_BLOCK_DURATION}.
  • Contracts – Staking:
    • Compute per-epoch block rewards via Reward Supplier; cache in block_rewards with last_calculated_epoch.
    • On set_consensus_rewards_first_epoch, pre-initialize block rewards; update_rewards now uses cached per-block rewards.
  • Docs:
    • Document new Reward Supplier APIs (update_current_epoch_block_rewards, get_block_duration_config, set_block_duration_config), new error INVALID_MIN_MAX_BLOCK_DURATION, and struct BlockDurationConfig; clarify calculate_current_epoch_rewards usage.
  • Tests/Utils:
    • Extensive tests for block-reward path, config validation, EIC upgrade, mixed token pools, epoch/block timing, migration flows.
    • Test helpers for advancing blocks/time, reward calculations with avg block duration, and EIC declarations.
  • Deps:
    • Bump starkware_utils/testing git revs.

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

Copy link
Collaborator Author

arad-starkware commented Nov 27, 2025

@arad-starkware arad-starkware self-assigned this Nov 27, 2025
@arad-starkware arad-starkware force-pushed the arad/test_add_update_rewards_old_delegator_flow branch from 8114c54 to f4d55a7 Compare November 27, 2025 15:12
@arad-starkware arad-starkware marked this pull request as ready for review November 27, 2025 15:13
@arad-starkware arad-starkware force-pushed the arad/test_add_update_rewards_transition_with_balance_change_flow branch from 11dc7bf to 2e31872 Compare November 27, 2025 15:28
@arad-starkware arad-starkware force-pushed the arad/test_add_update_rewards_old_delegator_flow branch 2 times, most recently from 2fdc3f1 to eb07598 Compare November 27, 2025 17:11
@arad-starkware arad-starkware force-pushed the arad/test_add_update_rewards_transition_with_balance_change_flow branch from 2e31872 to fa6010f Compare November 27, 2025 17:11
Copy link
Collaborator

@noa-starkware noa-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 3 files reviewed, 2 unresolved discussions (waiting on @arad-starkware)


src/flow_test/flows.cairo line 9103 at r1 (raw file):

        system.stake(:staker, amount: stake_amount, pool_enabled: true, :commission);
        let pool = system.staking.get_pool(:staker);
        system.delegate(:delegator, :pool, amount: delegated_amount);

Add BTC delegate if version is V2 and test his rewards


src/flow_test/flows.cairo line 9124 at r1 (raw file):

        let delegated_amount = self.delegated_amount.unwrap();
        let pool = self.pool.unwrap();

Do we want add one attest here?

@arad-starkware arad-starkware force-pushed the arad/test_add_update_rewards_old_delegator_flow branch from eb07598 to 3b2272c Compare November 28, 2025 09:44
@arad-starkware arad-starkware force-pushed the arad/test_add_update_rewards_transition_with_balance_change_flow branch 2 times, most recently from 6eab75d to 74cbcfc Compare December 1, 2025 13:20
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