@@ -94,9 +94,8 @@ get_inflation_num_slots( fd_exec_slot_ctx_t * slot_ctx,
94
94
/* https://github.com/anza-xyz/agave/blob/7117ed9653ce19e8b2dea108eff1f3eb6a3378a7/runtime/src/bank.rs#L2121 */
95
95
static double
96
96
slot_in_year_for_inflation ( fd_exec_slot_ctx_t * slot_ctx ) {
97
- fd_epoch_schedule_t const * epoch_schedule = fd_bank_epoch_schedule_query ( slot_ctx -> bank );
98
-
99
- ulong num_slots = get_inflation_num_slots ( slot_ctx , epoch_schedule , slot_ctx -> slot );
97
+ fd_epoch_schedule_t epoch_schedule = fd_sysvar_epoch_schedule_read_nofail ( slot_ctx -> sysvar_cache );
98
+ ulong num_slots = get_inflation_num_slots ( slot_ctx , & epoch_schedule , slot_ctx -> slot );
100
99
return (double )num_slots / (double )fd_bank_slots_per_year_get ( slot_ctx -> bank );
101
100
}
102
101
@@ -278,7 +277,8 @@ get_slots_in_epoch( ulong epoch,
278
277
static double
279
278
epoch_duration_in_years ( fd_exec_slot_ctx_t * slot_ctx ,
280
279
ulong prev_epoch ) {
281
- ulong slots_in_epoch = get_slots_in_epoch ( prev_epoch , fd_bank_epoch_schedule_query ( slot_ctx -> bank ) );
280
+ fd_epoch_schedule_t epoch_schedule = fd_sysvar_epoch_schedule_read_nofail ( slot_ctx -> sysvar_cache );
281
+ ulong slots_in_epoch = get_slots_in_epoch ( prev_epoch , & epoch_schedule );
282
282
return (double )slots_in_epoch / (double )fd_bank_slots_per_year_get ( slot_ctx -> bank );
283
283
}
284
284
@@ -377,8 +377,7 @@ calculate_reward_points_partitioned( fd_exec_slot_ctx_t * slot_ctx,
377
377
ulong rewards ,
378
378
fd_point_value_t * result ,
379
379
fd_tpool_t * tpool ,
380
- fd_epoch_info_t * temp_info ,
381
- fd_spad_t * runtime_spad ) {
380
+ fd_epoch_info_t * temp_info ) {
382
381
383
382
uint128 points = 0 ;
384
383
ulong minimum_stake_delegation = get_minimum_stake_delegation ( slot_ctx );
@@ -387,13 +386,12 @@ calculate_reward_points_partitioned( fd_exec_slot_ctx_t * slot_ctx,
387
386
int _err [1 ];
388
387
ulong new_warmup_cooldown_rate_epoch_val = 0UL ;
389
388
ulong * new_warmup_cooldown_rate_epoch = & new_warmup_cooldown_rate_epoch_val ;
390
- int is_some = fd_new_warmup_cooldown_rate_epoch ( slot_ctx -> slot ,
391
- slot_ctx -> funk ,
392
- slot_ctx -> funk_txn ,
393
- runtime_spad ,
394
- fd_bank_features_query ( slot_ctx -> bank ),
395
- new_warmup_cooldown_rate_epoch ,
396
- _err );
389
+ int is_some = fd_new_warmup_cooldown_rate_epoch (
390
+ slot_ctx -> sysvar_cache ,
391
+ fd_bank_features_query ( slot_ctx -> bank ),
392
+ slot_ctx -> slot ,
393
+ new_warmup_cooldown_rate_epoch ,
394
+ _err );
397
395
if ( FD_UNLIKELY ( !is_some ) ) {
398
396
new_warmup_cooldown_rate_epoch = NULL ;
399
397
}
@@ -605,13 +603,12 @@ calculate_stake_vote_rewards( fd_exec_slot_ctx_t * slot_ct
605
603
int _err [1 ];
606
604
ulong new_warmup_cooldown_rate_epoch_val = 0UL ;
607
605
ulong * new_warmup_cooldown_rate_epoch = & new_warmup_cooldown_rate_epoch_val ;
608
- int is_some = fd_new_warmup_cooldown_rate_epoch ( slot_ctx -> slot ,
609
- slot_ctx -> funk ,
610
- slot_ctx -> funk_txn ,
611
- runtime_spad ,
612
- fd_bank_features_query ( slot_ctx -> bank ),
613
- new_warmup_cooldown_rate_epoch ,
614
- _err );
606
+ int is_some = fd_new_warmup_cooldown_rate_epoch (
607
+ slot_ctx -> sysvar_cache ,
608
+ fd_bank_features_query ( slot_ctx -> bank ),
609
+ slot_ctx -> slot ,
610
+ new_warmup_cooldown_rate_epoch ,
611
+ _err );
615
612
if ( FD_UNLIKELY ( !is_some ) ) {
616
613
new_warmup_cooldown_rate_epoch = NULL ;
617
614
}
@@ -699,8 +696,10 @@ calculate_validator_rewards( fd_exec_slot_ctx_t * slot_ctx,
699
696
fd_spad_t * * exec_spads ,
700
697
ulong exec_spad_cnt ,
701
698
fd_spad_t * runtime_spad ) {
702
- /* https://github.com/firedancer-io/solana/blob/dab3da8e7b667d7527565bddbdbecf7ec1fb868e/runtime/src/bank.rs#L2759-L2786 */
703
- fd_stake_history_t const * stake_history = fd_sysvar_stake_history_read ( slot_ctx -> funk , slot_ctx -> funk_txn , runtime_spad );
699
+ /* FIXME the reflinks here heavily diverged from upstream Agave */
700
+
701
+ /* https://github.com/firedancer-io/solana/blob/dab3da8e7b667d7527565bddbdbecf7ec1fb868e/runtime/src/bank.rs#L2759-L2786 */
702
+ fd_stake_history_t const * stake_history = fd_sysvar_stake_history_join_const ( slot_ctx -> sysvar_cache );
704
703
if ( FD_UNLIKELY ( !stake_history ) ) {
705
704
FD_LOG_ERR (( "Unable to read and decode stake history sysvar" ));
706
705
}
@@ -711,8 +710,7 @@ calculate_validator_rewards( fd_exec_slot_ctx_t * slot_ctx,
711
710
rewards ,
712
711
& result -> point_value ,
713
712
tpool ,
714
- temp_info ,
715
- runtime_spad );
713
+ temp_info );
716
714
717
715
/* Calculate the stake and vote rewards for each account */
718
716
calculate_stake_vote_rewards ( slot_ctx ,
@@ -725,6 +723,8 @@ calculate_validator_rewards( fd_exec_slot_ctx_t * slot_ctx,
725
723
exec_spads ,
726
724
exec_spad_cnt ,
727
725
runtime_spad );
726
+
727
+ fd_sysvar_stake_history_leave_const ( slot_ctx -> sysvar_cache , stake_history );
728
728
}
729
729
730
730
/* Calculate the number of blocks required to distribute rewards to all stake accounts.
@@ -837,10 +837,10 @@ calculate_rewards_for_partitioning( fd_exec_slot_ctx_t * slot_
837
837
runtime_spad );
838
838
839
839
fd_stake_reward_calculation_t * stake_reward_calculation = & validator_result -> calculate_stake_vote_rewards_result .stake_reward_calculation ;
840
- fd_epoch_schedule_t const * epoch_schedule = fd_bank_epoch_schedule_query ( slot_ctx -> bank );
841
- ulong num_partitions = get_reward_distribution_num_blocks ( epoch_schedule ,
842
- slot_ctx -> slot ,
843
- stake_reward_calculation -> stake_rewards_len );
840
+ fd_epoch_schedule_t const epoch_schedule = fd_sysvar_epoch_schedule_read_nofail ( slot_ctx -> sysvar_cache );
841
+
842
+ ulong num_partitions = get_reward_distribution_num_blocks (
843
+ & epoch_schedule , slot_ctx -> slot , stake_reward_calculation -> stake_rewards_len );
844
844
hash_rewards_into_partitions ( stake_reward_calculation ,
845
845
parent_blockhash ,
846
846
num_partitions ,
@@ -1036,8 +1036,7 @@ set_epoch_reward_status_active( fd_exec_slot_ctx_t * slot_ctx,
1036
1036
static void
1037
1037
distribute_epoch_rewards_in_partition ( fd_partitioned_stake_rewards_dlist_t * partition ,
1038
1038
fd_stake_reward_t * pool ,
1039
- fd_exec_slot_ctx_t * slot_ctx ,
1040
- fd_spad_t * runtime_spad ) {
1039
+ fd_exec_slot_ctx_t * slot_ctx ) {
1041
1040
1042
1041
ulong lamports_distributed = 0UL ;
1043
1042
ulong lamports_burned = 0UL ;
@@ -1059,8 +1058,7 @@ distribute_epoch_rewards_in_partition( fd_partitioned_stake_rewards_dlist_t * pa
1059
1058
1060
1059
/* Update the epoch rewards sysvar with the amount distributed and burnt */
1061
1060
fd_sysvar_epoch_rewards_distribute ( slot_ctx ,
1062
- lamports_distributed + lamports_burned ,
1063
- runtime_spad );
1061
+ lamports_distributed + lamports_burned );
1064
1062
1065
1063
FD_LOG_DEBUG (( "lamports burned: %lu, lamports distributed: %lu" , lamports_burned , lamports_distributed ));
1066
1064
@@ -1071,15 +1069,7 @@ distribute_epoch_rewards_in_partition( fd_partitioned_stake_rewards_dlist_t * pa
1071
1069
1072
1070
https://github.com/anza-xyz/agave/blob/cbc8320d35358da14d79ebcada4dfb6756ffac79/runtime/src/bank/partitioned_epoch_rewards/distribution.rs#L42 */
1073
1071
void
1074
- fd_distribute_partitioned_epoch_rewards ( fd_exec_slot_ctx_t * slot_ctx ,
1075
- fd_tpool_t * tpool ,
1076
- fd_spad_t * * exec_spads ,
1077
- ulong exec_spad_cnt ,
1078
- fd_spad_t * runtime_spad ) {
1079
-
1080
- (void )tpool ;
1081
- (void )exec_spads ;
1082
- (void )exec_spad_cnt ;
1072
+ fd_distribute_partitioned_epoch_rewards ( fd_exec_slot_ctx_t * slot_ctx ) {
1083
1073
1084
1074
fd_epoch_reward_status_global_t const * epoch_reward_status = fd_bank_epoch_reward_status_locking_query ( slot_ctx -> bank );
1085
1075
@@ -1102,27 +1092,26 @@ fd_distribute_partitioned_epoch_rewards( fd_exec_slot_ctx_t * slot_ctx,
1102
1092
ulong distribution_starting_block_height = status -> distribution_starting_block_height ;
1103
1093
ulong distribution_end_exclusive = distribution_starting_block_height + status -> partitioned_stake_rewards .partitions_len ;
1104
1094
1105
- fd_epoch_schedule_t const * epoch_schedule = fd_bank_epoch_schedule_query ( slot_ctx -> bank );
1106
- ulong epoch = fd_slot_to_epoch ( epoch_schedule , slot_ctx -> slot , NULL );
1095
+ fd_epoch_schedule_t epoch_schedule = fd_sysvar_epoch_schedule_read_nofail ( slot_ctx -> sysvar_cache );
1096
+ ulong epoch = fd_slot_to_epoch ( & epoch_schedule , slot_ctx -> slot , NULL );
1107
1097
1108
- if ( FD_UNLIKELY ( get_slots_in_epoch ( epoch , epoch_schedule ) <= status -> partitioned_stake_rewards .partitions_len ) ) {
1098
+ if ( FD_UNLIKELY ( get_slots_in_epoch ( epoch , & epoch_schedule ) <= status -> partitioned_stake_rewards .partitions_len ) ) {
1109
1099
FD_LOG_ERR (( "Should not be distributing rewards" ));
1110
1100
}
1111
1101
1112
1102
if ( (height >=distribution_starting_block_height ) && (height < distribution_end_exclusive ) ) {
1113
1103
ulong partition_index = height - distribution_starting_block_height ;
1114
1104
distribute_epoch_rewards_in_partition ( & partitions [ partition_index ],
1115
1105
pool ,
1116
- slot_ctx ,
1117
- runtime_spad );
1106
+ slot_ctx );
1118
1107
}
1119
1108
1120
1109
fd_bank_epoch_reward_status_end_locking_query ( slot_ctx -> bank );
1121
1110
1122
1111
/* If we have finished distributing rewards, set the status to inactive */
1123
1112
if ( fd_ulong_sat_add ( height , 1UL ) >= distribution_end_exclusive ) {
1124
1113
set_epoch_reward_status_inactive ( slot_ctx );
1125
- fd_sysvar_epoch_rewards_set_inactive ( slot_ctx , runtime_spad );
1114
+ fd_sysvar_epoch_rewards_set_inactive ( slot_ctx );
1126
1115
}
1127
1116
}
1128
1117
@@ -1181,8 +1170,9 @@ fd_rewards_recalculate_partitioned_rewards( fd_exec_slot_ctx_t * slot_ctx,
1181
1170
fd_spad_t * * exec_spads ,
1182
1171
ulong exec_spad_cnt ,
1183
1172
fd_spad_t * runtime_spad ) {
1184
- fd_sysvar_epoch_rewards_t * epoch_rewards = fd_sysvar_epoch_rewards_read ( slot_ctx -> funk , slot_ctx -> funk_txn , runtime_spad );
1185
- if ( FD_UNLIKELY ( epoch_rewards == NULL ) ) {
1173
+ fd_sysvar_epoch_rewards_t epoch_rewards_ ;
1174
+ fd_sysvar_epoch_rewards_t const * epoch_rewards = fd_sysvar_epoch_rewards_read ( slot_ctx -> sysvar_cache , & epoch_rewards_ );
1175
+ if ( FD_UNLIKELY ( !epoch_rewards ) ) {
1186
1176
FD_LOG_NOTICE (( "Failed to read or decode epoch rewards sysvar - may not have been created yet" ));
1187
1177
set_epoch_reward_status_inactive ( slot_ctx );
1188
1178
return ;
@@ -1204,24 +1194,23 @@ fd_rewards_recalculate_partitioned_rewards( fd_exec_slot_ctx_t * slot_ctx,
1204
1194
https://github.com/anza-xyz/agave/blob/2316fea4c0852e59c071f72d72db020017ffd7d0/runtime/src/bank/partitioned_epoch_rewards/calculation.rs#L566 */
1205
1195
FD_LOG_NOTICE (( "epoch rewards is active" ));
1206
1196
1207
- fd_epoch_schedule_t const * epoch_schedule = fd_bank_epoch_schedule_query ( slot_ctx -> bank );
1208
- ulong epoch = fd_slot_to_epoch ( epoch_schedule , slot_ctx -> slot , NULL );
1197
+ fd_epoch_schedule_t epoch_schedule = fd_sysvar_epoch_schedule_read_nofail ( slot_ctx -> sysvar_cache );
1198
+ ulong epoch = fd_slot_to_epoch ( & epoch_schedule , slot_ctx -> slot , NULL );
1209
1199
ulong rewarded_epoch = fd_ulong_sat_sub ( epoch , 1UL );
1210
1200
1211
1201
int _err [1 ] = {0 };
1212
- ulong * new_warmup_cooldown_rate_epoch = fd_spad_alloc ( runtime_spad , alignof(ulong ), sizeof (ulong ) );
1213
- int is_some = fd_new_warmup_cooldown_rate_epoch ( slot_ctx -> slot ,
1214
- slot_ctx -> funk ,
1215
- slot_ctx -> funk_txn ,
1216
- runtime_spad ,
1202
+ ulong new_warmup_cooldown_rate_epoch_ ;
1203
+ ulong * new_warmup_cooldown_rate_epoch = & new_warmup_cooldown_rate_epoch_ ;
1204
+ int is_some = fd_new_warmup_cooldown_rate_epoch ( slot_ctx -> sysvar_cache ,
1217
1205
fd_bank_features_query ( slot_ctx -> bank ),
1206
+ slot_ctx -> slot ,
1218
1207
new_warmup_cooldown_rate_epoch ,
1219
1208
_err );
1220
1209
if ( FD_UNLIKELY ( !is_some ) ) {
1221
1210
new_warmup_cooldown_rate_epoch = NULL ;
1222
1211
}
1223
1212
1224
- fd_stake_history_t const * stake_history = fd_sysvar_stake_history_read ( slot_ctx -> funk , slot_ctx -> funk_txn , runtime_spad );
1213
+ fd_stake_history_t const * stake_history = fd_sysvar_stake_history_join_const ( slot_ctx -> sysvar_cache );
1225
1214
if ( FD_UNLIKELY ( !stake_history ) ) {
1226
1215
FD_LOG_ERR (( "Unable to read and decode stake history sysvar" ));
1227
1216
}
0 commit comments