diff --git a/src/discof/backup/fd_ssmanifest_encoder.c b/src/discof/backup/fd_ssmanifest_encoder.c index 07a121fe648..b457e89899a 100644 --- a/src/discof/backup/fd_ssmanifest_encoder.c +++ b/src/discof/backup/fd_ssmanifest_encoder.c @@ -189,7 +189,6 @@ ENCODE_FN { ulong ec_cnt = 0UL; fd_epoch_credits_t const * ec = NULL; - ulong ag_marker_idx = ULONG_MAX; fd_vote_stakes_t * vote_stakes = fd_bank_vote_stakes( bank ); ulong fork_id = bank->vote_stakes_fork_id; @@ -203,13 +202,6 @@ ENCODE_FN { ec = find_epoch_credits( enc->bank, &ele->pubkey ); FD_TEST( ec ); ec_cnt = ec->cnt; - if( FD_UNLIKELY( ec->has_ag_migration_marker ) ) { - ulong ag_migration_slot = bank->f.alpenglow_migration_slot; - FD_TEST( ag_migration_slot!=ULONG_MAX ); - ulong ag_migration_epoch = fd_slot_to_epoch( &bank->f.epoch_schedule, ag_migration_slot, NULL ); - ag_marker_idx = fd_epoch_credits_ag_marker_idx( ec, ag_migration_epoch ); - ec_cnt++; - } } /* SIMD-0232 collectors. t-3..t-5 collectors are never consulted on @@ -260,15 +252,10 @@ ENCODE_FN { .accumulated_lamports_len = (uint)( ec_cnt-ec_skip ) }; memcpy( v5.bls_pubkey_compressed, ele->bls_key, FD_BLS_PUB_COMPRESSED_SZ ); - for( ulong k=0UL, j=0UL; k=ec_skip ) v5.accumulated_lamports[ k-ec_skip ] = (fd_vote_epoch_credits_t){ ULONG_MAX, ULONG_MAX, ULONG_MAX }; - continue; - } - if( k>=ec_skip ) v5.accumulated_lamports[ k-ec_skip ] = (fd_vote_epoch_credits_t){ (ulong)ec->epoch[j], - ec->base_credits + (ulong)ec->credits_delta[j], - ec->base_credits + (ulong)ec->prev_credits_delta[j] }; - j++; + for( ulong j=ec_skip; jepoch[j], + ec->base_credits + (ulong)ec->credits_delta[j], + ec->base_credits + (ulong)ec->prev_credits_delta[j] }; } typedef struct { uchar b[ FD_VOTE_STATE_V5_PAD_SZ ]; } v5_tail_t; PUSH_VAL( uint, fd_vote_state_versioned_enum_v5 ); @@ -297,17 +284,10 @@ ENCODE_FN { /* Epoch credits */ PUSH_VAL( ulong, ec_cnt ); - for( ulong k=0UL, j=0UL; kepoch[j] ); PUSH_VAL( ulong, ec->base_credits + (ulong)ec->credits_delta[j] ); PUSH_VAL( ulong, ec->base_credits + (ulong)ec->prev_credits_delta[j] ); - j++; } PUSH_VAL( ulong, 0UL ); /* last_timestamp_slot */ diff --git a/src/discof/backup/fd_ssmanifest_writer.c b/src/discof/backup/fd_ssmanifest_writer.c index 55b599c036b..3e52b7f2480 100644 --- a/src/discof/backup/fd_ssmanifest_writer.c +++ b/src/discof/backup/fd_ssmanifest_writer.c @@ -1,6 +1,5 @@ #include "fd_ssmanifest_writer.h" #include "../../flamenco/runtime/fd_system_ids.h" -#include "../../flamenco/runtime/sysvar/fd_sysvar_epoch_schedule.h" #include "../../flamenco/runtime/program/vote/fd_vote_state_versioned.h" #include "../../ballet/bls/fd_bls.h" diff --git a/src/discof/backup/test_snap_roundtrip.c b/src/discof/backup/test_snap_roundtrip.c index 02a2531dcde..0945ffc71c0 100644 --- a/src/discof/backup/test_snap_roundtrip.c +++ b/src/discof/backup/test_snap_roundtrip.c @@ -10,7 +10,6 @@ #include "../../flamenco/runtime/fd_txncache.h" #include "../../flamenco/runtime/fd_txncache_shmem.h" #include "../../flamenco/runtime/fd_txncache_private.h" -#include "../../flamenco/runtime/sysvar/fd_sysvar_epoch_schedule.h" #include "../../flamenco/runtime/sysvar/fd_sysvar_slot_history.h" #if FD_HAS_RACESAN #include "../../util/racesan/fd_racesan.h" @@ -73,13 +72,11 @@ seed_epoch_credits( fd_bank_t * bank ) { FD_TEST( fd_epoch_credits_view_init( view, fd_bank_epoch_credits( bank ), bank->epoch_credits_fork_id ) ); FD_TEST( view->len==VALIDATOR_CNT ); FD_TEST( EPOCH_CREDITS_CNT<=FD_EPOCH_CREDITS_MAX ); - bank->f.alpenglow_migration_slot = fd_epoch_slot0( &bank->f.epoch_schedule, EPOCH_CREDITS_CNT ); for( ulong i=0UL; ilen; i++ ) { - fd_epoch_credits_t * ec = &view->credits[ i ]; - ec->cnt = EPOCH_CREDITS_CNT; - ec->commission = (ushort)( 4321U + i ); - ec->base_credits = 10000UL + 1000UL*i; - ec->has_ag_migration_marker = i==1UL; + fd_epoch_credits_t * ec = &view->credits[ i ]; + ec->cnt = EPOCH_CREDITS_CNT; + ec->commission = (ushort)( 4321U + i ); + ec->base_credits = 10000UL + 1000UL*i; for( ulong j=0UL; jepoch[ j ] = (ushort)( j+1UL ); ec->prev_credits_delta[ j ] = (uint)( 100UL*j + 7UL*i ); @@ -101,19 +98,11 @@ check_epoch_credits( fd_bank_t * bank, } FD_TEST( ec ); FD_TEST( ec->cnt==EPOCH_CREDITS_CNT ); - ulong ag_marker_idx = ec->has_ag_migration_marker ? EPOCH_CREDITS_CNT-1UL : ULONG_MAX; - FD_TEST( vs->epoch_credits_history_len==ec->cnt+(ulong)ec->has_ag_migration_marker ); - for( ulong k=0UL, j=0UL; kepoch_credits_history_len; k++ ) { - if( k==ag_marker_idx ) { - FD_TEST( vs->epoch_credits[k].epoch ==ULONG_MAX ); - FD_TEST( vs->epoch_credits[k].credits ==ULONG_MAX ); - FD_TEST( vs->epoch_credits[k].prev_credits==ULONG_MAX ); - continue; - } - FD_TEST( vs->epoch_credits[k].epoch ==(ulong)ec->epoch[j] ); - FD_TEST( vs->epoch_credits[k].credits ==ec->base_credits+(ulong)ec->credits_delta[j] ); - FD_TEST( vs->epoch_credits[k].prev_credits==ec->base_credits+(ulong)ec->prev_credits_delta[j] ); - j++; + FD_TEST( vs->epoch_credits_history_len==ec->cnt ); + for( ulong j=0UL; jcnt; j++ ) { + FD_TEST( vs->epoch_credits[j].epoch ==(ulong)ec->epoch[j] ); + FD_TEST( vs->epoch_credits[j].credits ==ec->base_credits+(ulong)ec->credits_delta[j] ); + FD_TEST( vs->epoch_credits[j].prev_credits==ec->base_credits+(ulong)ec->prev_credits_delta[j] ); } fd_epoch_credits_view_fini( view ); } diff --git a/src/discof/restore/utils/fd_ssload.c b/src/discof/restore/utils/fd_ssload.c index 5193cc86dd0..b89c80bbeb4 100644 --- a/src/discof/restore/utils/fd_ssload.c +++ b/src/discof/restore/utils/fd_ssload.c @@ -501,14 +501,10 @@ fd_ssload_recover_apply( fd_snapshot_manifest_t * manifest, fd_epoch_credits_t * ec = &epoch_credits_view->credits[epoch_credits_len]; fd_memcpy( ec->pubkey, elem->vote, 32UL ); - ulong cnt = 0UL; - ec->base_credits = 0UL; - ec->has_ag_migration_marker = 0; + ulong cnt = 0UL; + ec->base_credits = 0UL; for( ulong j=0UL; jepoch_credits_history_len; j++ ) { - if( FD_UNLIKELY( fd_epoch_credits_is_alpenglow_marker( &elem->epoch_credits[ j ] ) ) ) { - ec->has_ag_migration_marker = 1; - continue; - } + if( FD_UNLIKELY( fd_epoch_credits_is_alpenglow_marker( &elem->epoch_credits[ j ] ) ) ) continue; if( FD_UNLIKELY( !cnt ) ) ec->base_credits = elem->epoch_credits[ j ].prev_credits; ec->epoch[ cnt ] = (ushort)elem->epoch_credits[ j ].epoch; ec->credits_delta[ cnt ] = elem->epoch_credits[ j ].credits - ec->base_credits; diff --git a/src/flamenco/fd_flamenco_base.h b/src/flamenco/fd_flamenco_base.h index 9d59b2c1787..a55600ab2e0 100644 --- a/src/flamenco/fd_flamenco_base.h +++ b/src/flamenco/fd_flamenco_base.h @@ -146,7 +146,6 @@ struct fd_epoch_credits { ulong credits_delta [ FD_EPOCH_CREDITS_MAX ]; ulong prev_credits_delta[ FD_EPOCH_CREDITS_MAX ]; ushort commission; - /* cnt does not include the Alpenglow marker entry */ uchar cnt; uchar fast_path_ok; /* True if the entries satisfy the boundary fast path prerequisites: (1) initial[n]<=final[n], (2) initial[n]==final[n-1], and (3) @@ -154,74 +153,12 @@ struct fd_epoch_credits { by vote programs. Points calculation takes the fast paths only when true and the slow reference implementation otherwise. So synthetic fuzzer inputs fall back gracefully. */ - /* has_ag_migration_marker is 1 if the Alpenglow migration marker - is present in the vote account's epoch credits, and 0 otherwise. - This is only needed to correctly pay out rewards earnt during the - Alpenglow migration epoch. - - The Alpenglow migration changes what epoch credit entries - represent. Entries from before the migration are Tower credits, - and entries from after are Alpenglow credits. - - During the migration epoch, vote accounts can earn both Tower - credits before the migration slot and Alpenglow credits after. - This means there can be two entries for the migration epoch, and - if there is only one entry we don't know if it represents Tower - credits or Alpenglow credits. The marker is used to disambiguate: - entries from epochs before the marker are Tower credits, and - entries at/after the marker are Alpenglow credits. - - It is also true that: - - At most one entry per epoch is written in non-migration epochs. - - At most one entry per epoch is written for Tower credits during - the migration epoch. - - At most one entry per epoch is written for Alpenglow credits - during the migration epoch. - - The marker is only written during the migration epoch, whilst - crediting any Alpenglow credits earnt. If the vote account did - not earn any Alpenglow credits during the migration epoch, - there will never be a marker in its epoch credits. - - Therefore, we know that: - - If the marker is not present and there is only 1 entry for the - migration epoch, that entry must represent Tower credits - - If the marker is present and there is only 1 entry for the - migration epoch, that entry must represent Alpenglow credits - - If the marker is present and there are 2 entries for the - migration epoch, the first represents Tower credits and the - second represents Alpenglow credits - - https://github.com/anza-xyz/agave/blob/v4.3.0/runtime/src/block_component_processor/vote_reward.rs#L532-L596 */ - uchar has_ag_migration_marker; }; typedef struct fd_epoch_credits fd_epoch_credits_t; FD_STATIC_ASSERT( (ulong)UCHAR_MAX>=FD_EPOCH_CREDITS_MAX, cnt_width ); FD_STATIC_ASSERT( sizeof(fd_epoch_credits_t)==1200UL, fd_epoch_credits ); -/* fd_epoch_credits_ag_marker_idx returns the index of the Alpenglow - migration marker in the on-chain epoch credits state, given the - epoch_credits and the migration epoch. This is so that our - serialized epoch credits are Agave-compatible. */ - -static inline ulong -fd_epoch_credits_ag_marker_idx( fd_epoch_credits_t const * epoch_credits, - ulong ag_migration_epoch ) { - if( FD_LIKELY( !epoch_credits->has_ag_migration_marker ) ) return ULONG_MAX; - - /* Find the last entry for the migration epoch - the marker goes - immediately before this entry. */ - for( ulong i=epoch_credits->cnt; i; i-- ) { - if( FD_UNLIKELY ((ulong)epoch_credits->epoch[ i-1UL ]==ag_migration_epoch )) { - return i-1UL; - } - } - - /* If there is no entry for the migration epoch, the marker is the - last entry. */ - return epoch_credits->cnt; -} - static inline uchar fd_epoch_credits_fast_path_ok( fd_epoch_credits_t const * epoch_credits ) { for( ulong i=0UL; icnt; i++ ) { diff --git a/src/flamenco/rewards/fd_rewards.c b/src/flamenco/rewards/fd_rewards.c index bf7543b36cf..fc58eaf4ace 100644 --- a/src/flamenco/rewards/fd_rewards.c +++ b/src/flamenco/rewards/fd_rewards.c @@ -441,15 +441,10 @@ calculate_stake_points_and_credits( fd_epoch_credits_t const * epoch_credits int coalesce_eligible = stake_epochs_are_normal( stake ) && epoch_credits->fast_path_ok; - /* Calculate the points for each Tower epoch credit. - If the Alpenglow migration marker is present, then the last entry - is the Alpenglow credits earnt during the migration epoch, which - we should skip. - https://github.com/anza-xyz/agave/blob/v4.3.0/runtime/src/inflation_rewards/points.rs#L183-L234 */ - ulong tower_entries = fd_ulong_sat_sub( (ulong)epoch_credits->cnt, (ulong)epoch_credits->has_ag_migration_marker ); + /* Calculate the points for each epoch credit */ uint128 points = 0; ulong new_credits_observed = credits_in_stake; - for( ulong i=0UL; icnt; i++ ) { ulong final_epoch_credits = base + epoch_credits->credits_delta[ i ]; ulong initial_epoch_credits = base + epoch_credits->prev_credits_delta[ i ]; @@ -482,7 +477,7 @@ calculate_stake_points_and_credits( fd_epoch_credits_t const * epoch_credits /* Multi-term Cases 1 and 2. Note that deactivation_epoch!=USHORT_MAX is implied since epoch[ i ] is also a ushort. */ - new_credits_observed = base + epoch_credits->credits_delta[ tower_entries-1UL ]; + new_credits_observed = credits_in_vote; break; } @@ -614,11 +609,11 @@ fd_rewards_inflation_collector( fd_bank_t * bank, and the migration slot (and for the epoch that ended at the activation boundary) stake rewards are still computed the tower way. - The migration epoch itself is a mixed Tower+Alpenglow epoch, where - credits earned before the migration slot are Tower credits and - credits earned after the migration slot are Alpenglow credits. + See https://github.com/anza-xyz/agave/blob/ef22c39d51b90c1f4cfccfe1f9fde94471c6242a/runtime/src/alpenglow_epoch_type.rs#L154 - See https://github.com/anza-xyz/agave/blob/ef22c39d51b90c1f4cfccfe1f9fde94471c6242a/runtime/src/alpenglow_epoch_type.rs#L154 */ + Note that the migration epoch itself is a mixed Tower+Alpenglow + epoch. We do not support correctly paying out rewards for this + epoch. */ static int rewarded_epoch_is_alpenglow( fd_bank_t * bank, @@ -629,28 +624,8 @@ rewarded_epoch_is_alpenglow( fd_bank_t * bank, return fd_slot_to_epoch( &bank->f.epoch_schedule, migration_slot, NULL )<=rewarded_epoch; } -/* https://github.com/anza-xyz/agave/blob/v4.3.0/runtime/src/alpenglow_epoch_type.rs#L197-L223 */ -static int -rewarded_epoch_is_alpenglow_migration( fd_bank_t * bank, - fd_accdb_t * accdb, - ulong rewarded_epoch ) { - ulong migration_slot = fd_alpenglow_migration_slot( bank, accdb ); - if( FD_LIKELY( migration_slot==ULONG_MAX ) ) return 0; - return fd_slot_to_epoch( &bank->f.epoch_schedule, migration_slot, NULL )==rewarded_epoch; -} - -/* https://github.com/anza-xyz/agave/blob/v4.3.0/runtime/src/alpenglow_epoch_type.rs#L198-L202 */ -static ulong -migration_num_tower_slots( fd_bank_t * bank, - fd_accdb_t * accdb, - ulong rewarded_epoch ) { - ulong migration_slot = fd_alpenglow_migration_slot( bank, accdb ); - /* +1 because the migration slot is counted as a Tower slot */ - return migration_slot - fd_epoch_slot0( &bank->f.epoch_schedule, rewarded_epoch ) + 1UL; -} - /* https://github.com/anza-xyz/agave/blob/cbc8320d35358da14d79ebcada4dfb6756ffac79/programs/stake/src/rewards.rs#L33 - https://github.com/anza-xyz/agave/blob/v4.3.0/runtime/src/inflation_rewards/mod.rs#L204-L372 */ + https://github.com/anza-xyz/agave/blob/v4.3.0-beta.0/runtime/src/inflation_rewards/mod.rs#L204-L371 */ static int redeem_rewards( fd_stake_delegation_t const * stake, ulong vote_state_idx, @@ -658,12 +633,8 @@ redeem_rewards( fd_stake_delegation_t const * stake, ulong total_rewards, uint128 total_points, int alpenglow_enabled, - int alpenglow_migration, - ulong num_tower_slots, - ulong slots_in_epoch, fd_runtime_stack_t * runtime_stack, fd_calculated_stake_points_t * stake_points_result, - uint128 ag_migration_points, fd_calculated_stake_rewards_t * result ) { /* The firedancer implementation of redeem_rewards inlines a lot of @@ -683,11 +654,7 @@ redeem_rewards( fd_stake_delegation_t const * stake, result->new_credits_observed = stake_points_result->new_credits_observed; return 0; } - /* https://github.com/anza-xyz/agave/blob/v4.3.0/runtime/src/inflation_rewards/mod.rs#L312-L322 */ - int zero_points = alpenglow_migration ? - ( ( stake_points_result->points.ud==0 && ag_migration_points==0 ) || ( ag_migration_points==0 && total_points==0 ) ) : - ( stake_points_result->points.ud==0 || (!alpenglow_enabled && total_points==0) ); - if( zero_points ) { + if( stake_points_result->points.ud==0 || (!alpenglow_enabled && total_points==0) ) { if( alpenglow_enabled && stake_points_result->new_credits_observed!=stake->credits_observed ) { /* Don't update credits_observed if the delegation is inactive. @@ -707,24 +674,13 @@ redeem_rewards( fd_stake_delegation_t const * stake, } uint128 rewards_u128 = stake_points_result->points.ud; - if( !alpenglow_enabled || alpenglow_migration ) { + if( !alpenglow_enabled ) { if( FD_UNLIKELY( __builtin_mul_overflow( rewards_u128, (uint128)(total_rewards), &rewards_u128 ) ) ) { FD_LOG_ERR(( "Rewards intermediate calculation should fit within u128" )); } FD_TEST( total_points ); rewards_u128 /= (uint128)total_points; } - if( alpenglow_migration ) { - /* https://github.com/anza-xyz/agave/blob/v4.3.0/runtime/src/inflation_rewards/mod.rs#L322-L332 */ - if( FD_UNLIKELY( __builtin_mul_overflow( rewards_u128, (uint128)num_tower_slots, &rewards_u128 ) ) ) { - FD_LOG_ERR(( "migration epoch tower rewards should fit within u128" )); - } - /* https://github.com/anza-xyz/agave/blob/v4.3.0/runtime/src/inflation_rewards/mod.rs#L331-L333 */ - rewards_u128 /= (uint128)slots_in_epoch; - if( FD_UNLIKELY( __builtin_add_overflow( rewards_u128, ag_migration_points, &rewards_u128 ) ) ) { - FD_LOG_ERR(( "migration epoch rewards intermediate calculation should fit within u128" )); - } - } if( FD_UNLIKELY( rewards_u128>(uint128)ULONG_MAX ) ) { FD_LOG_ERR(( "Rewards should fit within u64" )); @@ -732,9 +688,7 @@ redeem_rewards( fd_stake_delegation_t const * stake, ulong rewards = (ulong)rewards_u128; if( rewards == 0 ) { - if( alpenglow_enabled && - stake_points_result->new_credits_observed!=stake->credits_observed && - !stake_points_result->inactive ) { + if( alpenglow_enabled && stake_points_result->new_credits_observed!=stake->credits_observed ) { result->staker_rewards = 0UL; result->voter_rewards = 0UL; result->new_credits_observed = stake_points_result->new_credits_observed; @@ -852,10 +806,7 @@ calculate_stake_points_fast( fd_epoch_credits_t * epoch_credits, return; } - /* If the Alpenglow migration marker is present, then the last entry - is the Alpenglow credits earnt during the migration epoch, which - we should skip. */ - ulong cnt = fd_ulong_sat_sub( (ulong)epoch_credits->cnt, (ulong)epoch_credits->has_ag_migration_marker ); + ulong cnt = epoch_credits->cnt; if( FD_LIKELY( epoch_credits->fast_path_ok && cnt ) ) { ulong base = epoch_credits->base_credits; ulong credits_in_stake = stake->credits_observed; @@ -972,73 +923,8 @@ calculate_alpenglow_points( fd_epoch_credits_t const * epoch_credits, (uint128)validator_reward_epoch_stake; } -/* calculate_ag_migration_points is our implementation of Agave's - calculate_migration_points. - - https://github.com/anza-xyz/agave/blob/v4.3.0/runtime/src/inflation_rewards/points.rs#L314-L352 */ -static uint128 -calculate_ag_migration_points( fd_epoch_credits_t * epoch_credits, - fd_stake_history_t const * stake_history, - fd_stake_delegation_t const * stake, - ulong * new_rate_activation_epoch, - int use_fixed_point_stake_math, - ulong rewarded_epoch, - ulong tower_fast_path_epoch, - ulong validator_reward_epoch_stake, - fd_calculated_stake_points_t * result ) { - uint128 ag_migration_points = 0; - calculate_stake_points_fast( epoch_credits, stake_history, stake, new_rate_activation_epoch, use_fixed_point_stake_math, tower_fast_path_epoch, result ); - - ulong credits_in_stake = stake->credits_observed; - ulong cnt = epoch_credits->cnt; - ulong base = epoch_credits->base_credits; - ulong credits_in_vote = cnt ? base+epoch_credits->credits_delta[ cnt-1UL ] : 0UL; - - /* https://github.com/anza-xyz/agave/blob/v4.3.0/runtime/src/inflation_rewards/points.rs#L368-L398 */ - if( credits_in_vote<=credits_in_stake ) return 0; - - fd_stake_history_entry_t status; - int have_status = 0; - ulong ag_new_credits_observed = credits_in_stake; - ulong idx = fd_ulong_sat_sub( cnt, (ulong)epoch_credits->has_ag_migration_marker ); - if( idxepoch[ idx ]==rewarded_epoch ) { - ulong final_epoch_credits = base+epoch_credits->credits_delta [ idx ]; - ulong initial_epoch_credits = base+epoch_credits->prev_credits_delta[ idx ]; - ulong earned_credits = 0UL; - if( credits_in_stakepoints.ud = 0; - result->new_credits_observed = ag_new_credits_observed; - result->force_credits_update_with_skipped_reward = 1; - return ag_migration_points; - } - ag_migration_points = (uint128)earned_credits * - (uint128)status.effective / - (uint128)validator_reward_epoch_stake; - } - } - - result->new_credits_observed = fd_ulong_max( result->new_credits_observed, ag_new_credits_observed ); - if( result->new_credits_observed!=credits_in_stake ) { - if( !have_status ) status = fd_stake_delegation_activation_status( stake, rewarded_epoch, stake_history, new_rate_activation_epoch, use_fixed_point_stake_math ); - result->inactive = (uchar)( !status.effective && !status.activating ); - } - return ag_migration_points; -} - static inline void calculate_stake_points_for_reward( int alpenglow_enabled, - int alpenglow_migration, fd_runtime_stack_t * runtime_stack, fd_epoch_credits_t * epoch_credits, fd_stake_history_t const * stake_history, @@ -1047,8 +933,7 @@ calculate_stake_points_for_reward( int alpenglow_enab int use_fixed_point_stake_math, ulong rewarded_epoch, ulong tower_fast_path_epoch, - fd_calculated_stake_points_t * result, - uint128 * ag_migration_points ) { + fd_calculated_stake_points_t * result ) { if( FD_UNLIKELY( alpenglow_enabled ) ) { ulong validator_reward_epoch_stake = 0UL; fd_stake_accum_t const * accumulated = fd_stake_accum_map_ele_query_const( @@ -1057,26 +942,14 @@ calculate_stake_points_for_reward( int alpenglow_enab NULL, runtime_stack->stakes.stake_accum ); if( accumulated ) validator_reward_epoch_stake = accumulated->reward_stake; - if( FD_UNLIKELY( alpenglow_migration ) ) { - *ag_migration_points = calculate_ag_migration_points( epoch_credits, - stake_history, - stake, - new_rate_activation_epoch, - use_fixed_point_stake_math, - rewarded_epoch, - tower_fast_path_epoch, - validator_reward_epoch_stake, - result ); - } else { - calculate_alpenglow_points( epoch_credits, - stake_history, - stake, - new_rate_activation_epoch, - use_fixed_point_stake_math, - rewarded_epoch, - validator_reward_epoch_stake, - result ); - } + calculate_alpenglow_points( epoch_credits, + stake_history, + stake, + new_rate_activation_epoch, + use_fixed_point_stake_math, + rewarded_epoch, + validator_reward_epoch_stake, + result ); } else { calculate_stake_points_fast( epoch_credits, stake_history, @@ -1098,9 +971,8 @@ calculate_reward_points_partitioned( fd_bank_t * bank, ulong rewarded_epoch, fd_runtime_stack_t * runtime_stack ) { /* Calculate the points for each stake delegation */ - uint128 total_points = 0; - int alpenglow_enabled = rewarded_epoch_is_alpenglow( bank, accdb, rewarded_epoch ); - int alpenglow_migration = rewarded_epoch_is_alpenglow_migration( bank, accdb, rewarded_epoch ); + uint128 total_points = 0; + int alpenglow_enabled = rewarded_epoch_is_alpenglow( bank, accdb, rewarded_epoch ); fd_vote_rewards_t * vote_ele = runtime_stack->stakes.vote_ele; fd_vote_rewards_map_t * vote_ele_map = runtime_stack->stakes.vote_map; @@ -1149,14 +1021,7 @@ calculate_reward_points_partitioned( fd_bank_t * bank, fd_epoch_credits_t * epoch_credits = &epoch_credits_arr[ idx ]; - /* In the migration epoch, the total_points is only used to scale - the Tower rewards, so we calculate them here as if we were in a - Tower-only epoch. This mirrors Agave's structure. - - https://github.com/anza-xyz/agave/blob/v4.3.0/runtime/src/inflation_rewards/points.rs#L124-L144 */ - uint128 ag_migration_points = 0; - calculate_stake_points_for_reward( alpenglow_enabled && !alpenglow_migration, - 0, + calculate_stake_points_for_reward( alpenglow_enabled, runtime_stack, epoch_credits, stake_history, @@ -1165,11 +1030,9 @@ calculate_reward_points_partitioned( fd_bank_t * bank, FD_FEATURE_ACTIVE_BANK( bank, upgrade_bpf_stake_program_to_v5_1 ), rewarded_epoch, rewarded_epoch, - stake_points_result, - &ag_migration_points ); + stake_points_result ); - /* https://github.com/anza-xyz/agave/blob/v4.3.0/runtime/src/bank/partitioned_epoch_rewards/calculation.rs#L972-L1003 */ - if( FD_LIKELY( !alpenglow_enabled || alpenglow_migration ) ) { + if( FD_LIKELY( !alpenglow_enabled ) ) { total_points += stake_points_result->points.ud; } } @@ -1271,11 +1134,8 @@ calculate_stake_vote_rewards( fd_bank_t * bank, runtime_stack->stakes.stake_rewards_cnt = 0UL; - int alpenglow_enabled = rewarded_epoch_is_alpenglow( bank, accdb, rewarded_epoch ); - int alpenglow_migration = rewarded_epoch_is_alpenglow_migration( bank, accdb, rewarded_epoch ); - ulong num_tower_slots = alpenglow_migration ? migration_num_tower_slots( bank, accdb, rewarded_epoch ) : 0UL; - ulong slots_in_epoch = fd_epoch_slot_cnt( &bank->f.epoch_schedule, rewarded_epoch ); - int block_revenue_sharing = FD_FEATURE_ACTIVE_BANK( bank, block_revenue_sharing ); + int alpenglow_enabled = rewarded_epoch_is_alpenglow( bank, accdb, rewarded_epoch ); + int block_revenue_sharing = FD_FEATURE_ACTIVE_BANK( bank, block_revenue_sharing ); fd_calculated_stake_rewards_t calculated_stake_rewards_[1]; fd_epoch_credits_view_t epoch_credits_view[1]; @@ -1313,14 +1173,7 @@ calculate_stake_vote_rewards( fd_bank_t * bank, /* https://github.com/anza-xyz/agave/blob/v4.4.0-alpha.5/runtime/src/bank/partitioned_epoch_rewards/calculation.rs#L856-L867 */ ulong block_reward = block_revenue_sharing ? calculate_block_reward( bank, runtime_stack, stake_history, stake_delegation, rewarded_epoch ) : 0UL; - /* For the Alpenglow migration, we re-calculate the points for all - stake delegations because we haven't calculated the Alpenglow - points yet. Agave has the same semantics. We could compute and - cache the Alpenglow points in the first pass, but it would mean - bloating the cache for a one-off event. */ - int cached = !is_recalculation && - stake_delegation_idxmax_stake_accounts && - !alpenglow_migration; + int cached = !is_recalculation && stake_delegation_idxmax_stake_accounts; uint idx; if( FD_LIKELY( cached ) ) { idx = runtime_stack->stakes.stake_points_result[ stake_delegation_idx ].vote_idx; @@ -1362,7 +1215,6 @@ calculate_stake_vote_rewards( fd_bank_t * bank, fd_calculated_stake_points_t stake_points_result_[1]; fd_calculated_stake_points_t * stake_points_result; - uint128 ag_migration_points = 0; if( FD_LIKELY( cached ) ) { stake_points_result = &runtime_stack->stakes.stake_points_result[ stake_delegation_idx ]; } else { @@ -1372,7 +1224,6 @@ calculate_stake_vote_rewards( fd_bank_t * bank, stake rewards so we need to recalculate them. ULONG_MAX disables the tag fast path. */ calculate_stake_points_for_reward( alpenglow_enabled, - alpenglow_migration, runtime_stack, epoch_credits, stake_history, @@ -1381,8 +1232,7 @@ calculate_stake_vote_rewards( fd_bank_t * bank, FD_FEATURE_ACTIVE_BANK( bank, upgrade_bpf_stake_program_to_v5_1 ), rewarded_epoch, ULONG_MAX, - stake_points_result_, - &ag_migration_points ); + stake_points_result_ ); stake_points_result = stake_points_result_; } @@ -1396,12 +1246,8 @@ calculate_stake_vote_rewards( fd_bank_t * bank, total_rewards, total_points, alpenglow_enabled, - alpenglow_migration, - num_tower_slots, - slots_in_epoch, runtime_stack, stake_points_result, - ag_migration_points, calculated_stake_rewards ); if( FD_UNLIKELY( err!=0 ) ) { @@ -1464,11 +1310,8 @@ setup_stake_partitions( fd_bank_t * bank, ulong total_rewards, uint128 total_points ) { - int alpenglow_enabled = rewarded_epoch_is_alpenglow( bank, accdb, rewarded_epoch ); - int alpenglow_migration = rewarded_epoch_is_alpenglow_migration( bank, accdb, rewarded_epoch ); - ulong num_tower_slots = alpenglow_migration ? migration_num_tower_slots( bank, accdb, rewarded_epoch ) : 0UL; - ulong slots_in_epoch = fd_epoch_slot_cnt( &bank->f.epoch_schedule, rewarded_epoch ); - int block_revenue_sharing = FD_FEATURE_ACTIVE_BANK( bank, block_revenue_sharing ); + int alpenglow_enabled = rewarded_epoch_is_alpenglow( bank, accdb, rewarded_epoch ); + int block_revenue_sharing = FD_FEATURE_ACTIVE_BANK( bank, block_revenue_sharing ); fd_stake_rewards_t * stake_rewards = fd_bank_stake_rewards_modify( bank ); fd_epoch_credits_view_t epoch_credits_view[1]; @@ -1522,9 +1365,7 @@ setup_stake_partitions( fd_bank_t * bank, fd_epoch_credits_t * epoch_credits = &epoch_credits_arr[ idx ]; fd_calculated_stake_points_t stake_points_result[1]; - uint128 ag_migration_points = 0; calculate_stake_points_for_reward( alpenglow_enabled, - alpenglow_migration, runtime_stack, epoch_credits, stake_history, @@ -1533,8 +1374,7 @@ setup_stake_partitions( fd_bank_t * bank, FD_FEATURE_ACTIVE_BANK( bank, upgrade_bpf_stake_program_to_v5_1 ), rewarded_epoch, ULONG_MAX, - stake_points_result, - &ag_migration_points ); + stake_points_result ); /* redeem_rewards is actually just responsible for calculating the vote and stake rewards for each stake account. It does not do @@ -1546,12 +1386,8 @@ setup_stake_partitions( fd_bank_t * bank, total_rewards, total_points, alpenglow_enabled, - alpenglow_migration, - num_tower_slots, - slots_in_epoch, runtime_stack, stake_points_result, - ag_migration_points, calculated_stake_rewards ); if( FD_UNLIKELY( err!=0 ) ) { @@ -1619,14 +1455,10 @@ calculate_validator_rewards( fd_bank_t * bank, rewarded_epoch, runtime_stack ); - /* In a Tower or migration epoch, if there have been no Tower points - then no rewards are paid out (even Alpenglow rewards). - https://github.com/anza-xyz/agave/blob/v4.3.0-beta.3/runtime/src/bank/partitioned_epoch_rewards/calculation.rs#L959-L968 + /* https://github.com/anza-xyz/agave/blob/v4.3.0-beta.3/runtime/src/bank/partitioned_epoch_rewards/calculation.rs#L959-L968 https://github.com/anza-xyz/agave/blob/v4.3.0-beta.3/runtime/src/bank/partitioned_epoch_rewards/calculation.rs#L1005-L1008 https://github.com/anza-xyz/agave/blob/v4.3.0-beta.3/runtime/src/bank/partitioned_epoch_rewards/calculation.rs#L502-L518 */ - int skip_rewards = ( !rewarded_epoch_is_alpenglow( bank, accdb, rewarded_epoch ) || - rewarded_epoch_is_alpenglow_migration( bank, accdb, rewarded_epoch ) ) && - !total_points; + int skip_rewards = !rewarded_epoch_is_alpenglow( bank, accdb, rewarded_epoch ) && !total_points; if( FD_UNLIKELY( skip_rewards ) ) { *rewards_out = 0UL; runtime_stack->stakes.stake_rewards_cnt = 0UL; @@ -2489,8 +2321,7 @@ recalculate_partitioned_rewards( fd_bank_t * bank, fd_reward_epoch_stakes_restore( bank, accdb, rewarded_epoch, runtime_stack ); } - int const is_migration = rewarded_epoch_is_alpenglow_migration( bank, accdb, rewarded_epoch ); - int const skip_rewards = ( !is_alpenglow || is_migration ) && !epoch_rewards_sysvar->total_points.ud; + int const skip_rewards = !is_alpenglow && !epoch_rewards_sysvar->total_points.ud; if( FD_UNLIKELY( skip_rewards ) ) { runtime_stack->stakes.stake_rewards_cnt = 0UL; } diff --git a/src/flamenco/runtime/tests/fd_block_harness.c b/src/flamenco/runtime/tests/fd_block_harness.c index e9d094d792a..fad17f97777 100644 --- a/src/flamenco/runtime/tests/fd_block_harness.c +++ b/src/flamenco/runtime/tests/fd_block_harness.c @@ -326,15 +326,11 @@ fd_solfuzz_pb_block_ctx_create( fd_solfuzz_runner_t * runner, base_credits comes from the first real entry (subtracting a ULONG_MAX base would underflow every delta) and cnt counts only real entries. Mirrors fd_ssload.c / get_vote_credits(). */ - ulong cnt = 0UL; - ec->base_credits = 0UL; - ec->has_ag_migration_marker = 0; + ulong cnt = 0UL; + ec->base_credits = 0UL; for( ulong j=0UL; jepoch_credits_count; j++ ) { fd_exec_test_epoch_credit_t const * epc = &prev_vote_accs->epoch_credits[j]; - if( FD_UNLIKELY( fd_solfuzz_epoch_credit_is_alpenglow_marker( epc ) ) ) { - ec->has_ag_migration_marker = 1; - continue; - } + if( FD_UNLIKELY( fd_solfuzz_epoch_credit_is_alpenglow_marker( epc ) ) ) continue; if( FD_UNLIKELY( !cnt ) ) ec->base_credits = epc->prev_credits; ec->epoch[ cnt ] = (ushort)epc->epoch; ec->credits_delta[ cnt ] = epc->credits - ec->base_credits; diff --git a/src/flamenco/runtime/tests/fd_dump_pb.c b/src/flamenco/runtime/tests/fd_dump_pb.c index 539672f2b3e..79e540d9aaf 100644 --- a/src/flamenco/runtime/tests/fd_dump_pb.c +++ b/src/flamenco/runtime/tests/fd_dump_pb.c @@ -8,7 +8,6 @@ #include "../fd_bank.h" #include "../fd_runtime.h" #include "../fd_alut.h" -#include "../sysvar/fd_sysvar_epoch_schedule.h" #include "../program/fd_precompiles.h" #include "../../../third_party/nanopb/pb_encode.h" #include "../fd_runtime_stack_tmpl.h" @@ -737,8 +736,6 @@ create_block_context_protobuf_from_block( fd_block_dump_ctx_t * dump_ctx, reward calculation). Needed for the harness to correctly recalculate partitioned epoch rewards. */ fd_vote_rewards_map_t * vote_ele_map = runtime_stack->stakes.vote_map; - ulong ag_migration_slot = fd_alpenglow_migration_slot( parent_bank, accdb ); - ulong ag_migration_epoch = fd_slot_to_epoch( &parent_bank->f.epoch_schedule, ag_migration_slot, NULL ); fd_epoch_credits_view_t epoch_credits_view[1]; FD_TEST( fd_epoch_credits_view_init( epoch_credits_view, fd_bank_epoch_credits( parent_bank ), parent_bank->epoch_credits_fork_id ) ); for( pb_size_t i=0U; istakes.vote_ele ); if( idx==UINT_MAX ) continue; fd_epoch_credits_t const * ec = &epoch_credits_view->credits[idx]; - ulong base = ec->base_credits; - int has_ag_marker = ec->has_ag_migration_marker; - ulong ag_marker_idx = fd_epoch_credits_ag_marker_idx( ec, ag_migration_epoch ); - ulong cnt = (ulong)ec->cnt + (ulong)has_ag_marker; + ulong cnt = ec->cnt; + ulong base = ec->base_credits; va_t1[i].epoch_credits_count = (pb_size_t)cnt; va_t1[i].epoch_credits = fd_spad_alloc( spad, alignof(fd_exec_test_epoch_credit_t), cnt * sizeof(fd_exec_test_epoch_credit_t) ); - for( ulong k=0UL, j=0UL; kepoch[j]; - va_t1[i].epoch_credits[k].credits = base + ec->credits_delta[j]; - va_t1[i].epoch_credits[k].prev_credits = base + ec->prev_credits_delta[j]; - j++; + for( ulong j=0; jepoch[j]; + va_t1[i].epoch_credits[j].credits = base + ec->credits_delta[j]; + va_t1[i].epoch_credits[j].prev_credits = base + ec->prev_credits_delta[j]; } } fd_epoch_credits_view_fini( epoch_credits_view ); diff --git a/src/flamenco/runtime/tests/fd_svm_mini.c b/src/flamenco/runtime/tests/fd_svm_mini.c index e0b7138fa06..2d4593a2407 100644 --- a/src/flamenco/runtime/tests/fd_svm_mini.c +++ b/src/flamenco/runtime/tests/fd_svm_mini.c @@ -429,9 +429,8 @@ fd_svm_mini_init_mock_validators( fd_svm_mini_t * mini, fd_epoch_credits_t * epoch_credits = &epoch_credits_view->credits[ i ]; fd_memcpy( epoch_credits->pubkey, &vote_key, sizeof(fd_pubkey_t) ); - epoch_credits->cnt = 0UL; - epoch_credits->base_credits = 0UL; - epoch_credits->has_ag_migration_marker = 0; + epoch_credits->cnt = 0UL; + epoch_credits->base_credits = 0UL; fd_stake_delegations_root_update( stake_delegations, &stake_key, &vote_key, diff --git a/src/flamenco/runtime/tests/run_backtest_all.sh b/src/flamenco/runtime/tests/run_backtest_all.sh index fc07ac7e55c..afb09f3896d 100755 --- a/src/flamenco/runtime/tests/run_backtest_all.sh +++ b/src/flamenco/runtime/tests/run_backtest_all.sh @@ -9,13 +9,3 @@ src/flamenco/runtime/tests/run_ledger_backtest.sh -l alpenglow-legacy-vote-ixs - src/flamenco/runtime/tests/run_ledger_backtest.sh -l alpenglow-deactivated-stake -m 2000000 -e 810 src/flamenco/runtime/tests/run_ledger_backtest.sh -l alpenglow-leader-credits -m 2000000 -e 3915 src/flamenco/runtime/tests/run_ledger_backtest.sh -l alpenglow-alpenclock-lamports -m 2000000 -e 280 -src/flamenco/runtime/tests/run_ledger_backtest.sh -l alpenglow-migration-rewards -m 2000000 -e 1086 --zst -src/flamenco/runtime/tests/run_ledger_backtest.sh -l alpenglow-migration-epoch-end -m 2000000 -e 1087 --zst -src/flamenco/runtime/tests/run_ledger_backtest.sh -l alpenglow-migration-no-ag-credits -m 2000000 -e 1087 --zst -src/flamenco/runtime/tests/run_ledger_backtest.sh -l alpenglow-migration-epoch-start -m 2000000 -e 1599 --zst -src/flamenco/runtime/tests/run_ledger_backtest.sh -l alpenglow-migration-ag-only-voter -m 2000000 -e 1087 --zst -src/flamenco/runtime/tests/run_ledger_backtest.sh -l alpenglow-migration-no-tower-points -m 2000000 -e 1125 --zst -src/flamenco/runtime/tests/run_ledger_backtest.sh -l alpenglow-migration-vote-recreate -m 2000000 -e 1637 --zst -src/flamenco/runtime/tests/run_ledger_backtest.sh -l alpenglow-migration-validators -m 2000000 -e 2112 --zst -src/flamenco/runtime/tests/run_ledger_backtest.sh -l alpenglow-migration-validators-boundary-snap -m 2000000 -e 1600 --zst -src/flamenco/runtime/tests/run_ledger_backtest.sh -l alpenglow-migration-validators-mid-payout -m 2000000 -e 1600 --zst diff --git a/src/flamenco/runtime/tests/run_backtest_ci.sh b/src/flamenco/runtime/tests/run_backtest_ci.sh index a738dc67665..95aabae0710 100755 --- a/src/flamenco/runtime/tests/run_backtest_ci.sh +++ b/src/flamenco/runtime/tests/run_backtest_ci.sh @@ -6,15 +6,6 @@ src/flamenco/runtime/tests/run_ledger_backtest.sh -l alpenglow-legacy-vote-ixs - src/flamenco/runtime/tests/run_ledger_backtest.sh -l alpenglow-deactivated-stake -m 2000000 -e 810 src/flamenco/runtime/tests/run_ledger_backtest.sh -l alpenglow-leader-credits -m 2000000 -e 3915 src/flamenco/runtime/tests/run_ledger_backtest.sh -l alpenglow-alpenclock-lamports -m 2000000 -e 280 -src/flamenco/runtime/tests/run_ledger_backtest.sh -l alpenglow-migration-epoch-end -m 2000000 -e 1087 --zst -src/flamenco/runtime/tests/run_ledger_backtest.sh -l alpenglow-migration-no-ag-credits -m 2000000 -e 1087 --zst -src/flamenco/runtime/tests/run_ledger_backtest.sh -l alpenglow-migration-epoch-start -m 2000000 -e 1599 --zst -src/flamenco/runtime/tests/run_ledger_backtest.sh -l alpenglow-migration-ag-only-voter -m 2000000 -e 1087 --zst -src/flamenco/runtime/tests/run_ledger_backtest.sh -l alpenglow-migration-no-tower-points -m 2000000 -e 1125 --zst -src/flamenco/runtime/tests/run_ledger_backtest.sh -l alpenglow-migration-vote-recreate -m 2000000 -e 1637 --zst -src/flamenco/runtime/tests/run_ledger_backtest.sh -l alpenglow-migration-validators -m 2000000 -e 2112 --zst -src/flamenco/runtime/tests/run_ledger_backtest.sh -l alpenglow-migration-validators-boundary-snap -m 2000000 -e 1600 --zst -src/flamenco/runtime/tests/run_ledger_backtest.sh -l alpenglow-migration-validators-mid-payout -m 2000000 -e 1600 --zst src/flamenco/runtime/tests/run_ledger_backtest.sh -l alpenglow-block-revenue-sharing-agave-v4.4-57a35916-pr15795 -m 2000000 -e 1400 src/flamenco/runtime/tests/run_ledger_backtest.sh -l alpenglow-remove-inactive-stakes-agave-v4.4-6afe9919 -m 2000000 -e 1100 src/flamenco/runtime/tests/run_ledger_backtest.sh -l alpenglow-block-revenue-sharing-remove-inactive-stakes-agave-v4.4-57a35916-pr15795 -m 2000000 -e 1400 diff --git a/src/flamenco/runtime/tests/test_inflation_rewards.c b/src/flamenco/runtime/tests/test_inflation_rewards.c index b1c89b68242..4b1a98744d2 100644 --- a/src/flamenco/runtime/tests/test_inflation_rewards.c +++ b/src/flamenco/runtime/tests/test_inflation_rewards.c @@ -1139,190 +1139,6 @@ test_alpenglow_preserves_commission_remainder( fd_svm_mini_t * mini ) { FD_LOG_NOTICE(( "test_alpenglow_preserves_commission_remainder: PASSED" )); } -static void -set_vote_epoch_credits( fd_svm_mini_t * mini, - ulong root_idx, - fd_pubkey_t const * vote_key, - uchar commission, - fd_vote_epoch_credits_t const * entries, - ulong entry_cnt ) { - fd_accdb_fork_id_t root_fk = fd_svm_mini_fork_id( mini, root_idx ); - - fd_acc_t acc = fd_accdb_read_one( mini->runtime->accdb, root_fk, vote_key->key ); - FD_TEST( acc.lamports > 0UL ); - ulong data_sz = acc.data_len; - FD_TEST( data_sz<=FD_VOTE_STATE_V4_SZ ); - uchar data_copy[ FD_VOTE_STATE_V4_SZ ]; - memcpy( data_copy, acc.data, data_sz ); - uchar owner_copy[32]; memcpy( owner_copy, acc.owner, 32 ); - ulong lamports_copy = acc.lamports; - int exec_copy = acc.executable; - fd_accdb_unread_one( mini->runtime->accdb, &acc ); - - fd_vote_state_versioned_t versioned[1]; - FD_TEST( fd_vote_state_versioned_deserialize( versioned, data_copy, data_sz ) ); - fd_vsv_set_commission( versioned, commission, 0UL ); - fd_vote_epoch_credits_t * epoch_credits = fd_vsv_get_epoch_credits_mutable( versioned ); - deq_fd_vote_epoch_credits_t_remove_all( epoch_credits ); - for( ulong i=0UL; ikind==fd_vote_state_versioned_enum_v4 ? FD_VOTE_STATE_V4_SZ : FD_VOTE_STATE_V3_SZ; - FD_TEST( !fd_vote_state_versioned_serialize( versioned, new_data, new_data_sz ) ); - - fd_acc_t new_acc = {0}; - memcpy( new_acc.pubkey, vote_key->key, 32 ); - memcpy( new_acc.owner, owner_copy, 32 ); - new_acc.lamports = lamports_copy; - new_acc.executable = exec_copy; - new_acc.data_len = new_data_sz; - new_acc.data = new_data; - fd_svm_mini_put_account_rooted( mini, &new_acc ); -} - -static void -patch_stake_credits_observed( fd_svm_mini_t * mini, - ulong root_idx, - fd_pubkey_t const * stake_key, - fd_pubkey_t const * vote_key, - ulong credits_observed ); - -#define TEST_AG_MARKER ((fd_vote_epoch_credits_t){ .epoch=ULONG_MAX, .credits=ULONG_MAX, .prev_credits=ULONG_MAX }) - -static void -test_migration_epoch_prorates_tower_and_alpenglow( fd_svm_mini_t * mini ) { - fd_svm_mini_params_t params[1]; - fd_svm_mini_params_default( params ); - params->slots_per_epoch = TEST_SLOTS_PER_EPOCH; - params->root_slot = TEST_ROOT_SLOT; - params->mock_validator_cnt = 3UL; - ulong root_idx = fd_svm_mini_reset( mini, params ); - - activate_alpenglow( mini ); - set_alpenglow_migration( mini, 4UL ); - init_epoch_inflation_account( mini, 0UL ); - - fd_pubkey_t identity[3], vote[3], stake[3]; - for( ulong i=0UL; i<3UL; i++ ) mock_validator_keys_idx( params->hash_seed, i, &identity[i], &vote[i], &stake[i] ); - - fd_vote_epoch_credits_t const credits_a[3] = { - { .epoch=0UL, .credits=1000UL, .prev_credits= 0UL }, - TEST_AG_MARKER, - { .epoch=0UL, .credits=1500UL, .prev_credits=1000UL } }; - set_vote_epoch_credits( mini, root_idx, &vote[0], 7U, credits_a, 3UL ); - - fd_vote_epoch_credits_t const credits_b[1] = { - { .epoch=0UL, .credits=2000UL, .prev_credits=0UL } }; - set_vote_epoch_credits( mini, root_idx, &vote[1], 0U, credits_b, 1UL ); - - fd_vote_epoch_credits_t const credits_c[3] = { - { .epoch=0UL, .credits=1000UL, .prev_credits= 0UL }, - TEST_AG_MARKER, - { .epoch=0UL, .credits=1800UL, .prev_credits=1000UL } }; - set_vote_epoch_credits( mini, root_idx, &vote[2], 0U, credits_c, 3UL ); - patch_stake_credits_observed( mini, root_idx, &stake[2], &vote[2], 1200UL ); - - fd_bank_t * root_bank = fd_svm_mini_bank( mini, root_idx ); - ulong vat = fd_slot_params_at_slot( root_bank, TEST_EPOCH_BOUNDARY ).vat_to_burn_per_epoch; - fd_accdb_fork_id_t root_fk = fd_svm_mini_fork_id( mini, root_idx ); - ulong vote_before [3]; - ulong stake_before[3]; - for( ulong i=0UL; i<3UL; i++ ) { - set_account_lamports( mini, root_idx, &vote[i], read_lamports( mini, root_fk, &vote[i] )+vat ); - vote_before [i] = read_lamports( mini, root_fk, &vote[i] ); - stake_before[i] = read_lamports( mini, root_fk, &stake[i] ); - } - - ulong const staker_reward[3] = { 97339UL, 208333UL, 600UL }; - ulong const voter_reward [3] = { 7327UL, 0UL, 0UL }; - ulong const credits_after[3] = { 1500UL, 2000UL, 1800UL }; - - ulong epoch_idx = fd_svm_mini_attach_child( mini, root_idx, TEST_EPOCH_BOUNDARY ); - fd_bank_t * epoch_bank = fd_svm_mini_bank( mini, epoch_idx ); - fd_accdb_fork_id_t epoch_fk = fd_svm_mini_fork_id( mini, epoch_idx ); - - fd_sysvar_epoch_rewards_t er[1]; - FD_TEST( fd_sysvar_epoch_rewards_read( mini->runtime->accdb, epoch_fk, er ) ); - FD_TEST( er->active ); - FD_TEST( er->total_points.ud==(uint128)3000000000000UL ); - - for( ulong i=0UL; i<3UL; i++ ) { - FD_TEST( read_lamports( mini, epoch_fk, &vote[i] )==vote_before[i]-vat+voter_reward[i] ); - } - - fd_stake_rewards_t * stake_rewards = fd_bank_stake_rewards_modify( epoch_bank ); - ulong const total_staker_reward = staker_reward[0]+staker_reward[1]+staker_reward[2]; - FD_TEST( fd_stake_rewards_total_rewards( stake_rewards, epoch_bank->stake_rewards_fork_id )==total_staker_reward ); - - fd_stake_rewards_clear( stake_rewards ); - epoch_bank->stake_rewards_fork_id = USHORT_MAX; - fd_rewards_recalculate_partitioned_rewards( epoch_bank, mini->runtime->accdb, mini->runtime_stack, NULL ); - FD_TEST( fd_stake_rewards_total_rewards( fd_bank_stake_rewards_modify( epoch_bank ), - epoch_bank->stake_rewards_fork_id )==total_staker_reward ); - - fd_svm_mini_freeze( mini, epoch_idx ); - ulong distrib_idx = fd_svm_mini_attach_child( mini, epoch_idx, TEST_DISTRIB_SLOT ); - fd_accdb_fork_id_t distrib_fk = fd_svm_mini_fork_id( mini, distrib_idx ); - - for( ulong i=0UL; i<3UL; i++ ) { - FD_TEST( read_lamports( mini, distrib_fk, &stake[i] )==stake_before[i]+staker_reward[i] ); - FD_TEST( read_stake( mini, distrib_fk, &stake[i] ).credits_observed==credits_after[i] ); - } - - FD_LOG_NOTICE(( "test_migration_epoch_prorates_tower_and_alpenglow: PASSED" )); -} - -static void -test_migration_epoch_without_tower_points_skips_rewards( fd_svm_mini_t * mini ) { - fd_svm_mini_params_t params[1]; - fd_svm_mini_params_default( params ); - params->slots_per_epoch = TEST_SLOTS_PER_EPOCH; - params->root_slot = TEST_ROOT_SLOT; - params->mock_validator_cnt = 1UL; - ulong root_idx = fd_svm_mini_reset( mini, params ); - - activate_alpenglow( mini ); - set_alpenglow_migration( mini, 0UL ); - init_epoch_inflation_account( mini, 0UL ); - - fd_pubkey_t identity_key, vote_key, stake_key; - mock_validator_keys( params->hash_seed, &identity_key, &vote_key, &stake_key ); - fd_vote_epoch_credits_t const credits[2] = { - TEST_AG_MARKER, - { .epoch=0UL, .credits=500UL, .prev_credits=0UL } }; - set_vote_epoch_credits( mini, root_idx, &vote_key, 0U, credits, 2UL ); - - fd_bank_t * root_bank = fd_svm_mini_bank( mini, root_idx ); - ulong vat = fd_slot_params_at_slot( root_bank, TEST_EPOCH_BOUNDARY ).vat_to_burn_per_epoch; - fd_accdb_fork_id_t root_fk = fd_svm_mini_fork_id( mini, root_idx ); - set_account_lamports( mini, root_idx, &vote_key, read_lamports( mini, root_fk, &vote_key )+vat ); - ulong vote_before = read_lamports( mini, root_fk, &vote_key ); - ulong stake_before = read_lamports( mini, root_fk, &stake_key ); - - ulong epoch_idx = fd_svm_mini_attach_child( mini, root_idx, TEST_EPOCH_BOUNDARY ); - fd_bank_t * epoch_bank = fd_svm_mini_bank( mini, epoch_idx ); - fd_accdb_fork_id_t epoch_fk = fd_svm_mini_fork_id( mini, epoch_idx ); - - FD_TEST( read_lamports( mini, epoch_fk, &vote_key )==vote_before-vat ); - FD_TEST( fd_stake_rewards_total_rewards( fd_bank_stake_rewards_modify( epoch_bank ), - epoch_bank->stake_rewards_fork_id )==0UL ); - - fd_sysvar_epoch_rewards_t er[1]; - FD_TEST( fd_sysvar_epoch_rewards_read( mini->runtime->accdb, epoch_fk, er ) ); - FD_TEST( er->total_points.ud==0 ); - - fd_svm_mini_freeze( mini, epoch_idx ); - ulong distrib_idx = fd_svm_mini_attach_child( mini, epoch_idx, TEST_DISTRIB_SLOT ); - fd_accdb_fork_id_t distrib_fk = fd_svm_mini_fork_id( mini, distrib_idx ); - - FD_TEST( read_lamports( mini, distrib_fk, &stake_key )==stake_before ); - FD_TEST( read_stake( mini, distrib_fk, &stake_key ).credits_observed==0UL ); - - FD_LOG_NOTICE(( "test_migration_epoch_without_tower_points_skips_rewards: PASSED" )); -} - static void test_no_credits_no_reward( fd_svm_mini_t * mini ) { fd_svm_mini_params_t params[1]; @@ -4378,8 +4194,6 @@ main( int argc, test_finalize_verifies_footer( mini ); test_alpenglow_reward_uses_vote_credits( mini ); test_alpenglow_preserves_commission_remainder( mini ); - test_migration_epoch_prorates_tower_and_alpenglow( mini ); - test_migration_epoch_without_tower_points_skips_rewards( mini ); test_no_credits_no_reward( mini ); test_credits_staker_reward( mini ); test_evicted_reward_window_recalculated( mini ); diff --git a/src/flamenco/stakes/fd_stakes.c b/src/flamenco/stakes/fd_stakes.c index f022d751fc5..9bd41ffa67d 100644 --- a/src/flamenco/stakes/fd_stakes.c +++ b/src/flamenco/stakes/fd_stakes.c @@ -503,16 +503,12 @@ get_vote_credits( uchar const * account_data, FD_TEST( cnt<=FD_EPOCH_CREDITS_MAX ); epoch_credits->commission = commission; - ulong n = 0UL; - ulong base = 0UL; - uchar has_ag_marker = 0; + ulong n = 0UL; + ulong base = 0UL; for( ulong i=0UL; iprev_credits; FD_TEST( ele->epoch<=USHORT_MAX ); /* Epoch should fit. */ @@ -526,10 +522,9 @@ get_vote_credits( uchar const * account_data, n++; } - epoch_credits->cnt = (uchar)n; - epoch_credits->base_credits = base; - epoch_credits->has_ag_migration_marker = has_ag_marker; - epoch_credits->fast_path_ok = fd_epoch_credits_fast_path_ok( epoch_credits ); + epoch_credits->cnt = (uchar)n; + epoch_credits->base_credits = base; + epoch_credits->fast_path_ok = fd_epoch_credits_fast_path_ok( epoch_credits ); } int