@@ -960,21 +960,23 @@ calculate_rewards_and_distribute_vote_rewards( fd_bank_t *
960
960
961
961
/* Distributes a single partitioned reward to a single stake account */
962
962
static int
963
- distribute_epoch_reward_to_stake_acc ( fd_exec_slot_ctx_t * slot_ctx ,
963
+ distribute_epoch_reward_to_stake_acc ( fd_bank_t * bank ,
964
+ fd_funk_t * funk ,
965
+ fd_funk_txn_t * funk_txn ,
964
966
fd_pubkey_t * stake_pubkey ,
965
967
ulong reward_lamports ,
966
968
ulong new_credits_observed ) {
967
969
FD_TXN_ACCOUNT_DECL ( stake_acc_rec );
968
970
if ( FD_UNLIKELY ( fd_txn_account_init_from_funk_mutable ( stake_acc_rec ,
969
971
stake_pubkey ,
970
- slot_ctx -> funk ,
971
- slot_ctx -> funk_txn ,
972
+ funk ,
973
+ funk_txn ,
972
974
0 ,
973
975
0UL ) != FD_ACC_MGR_SUCCESS ) ) {
974
976
FD_LOG_ERR (( "Unable to modify stake account" ));
975
977
}
976
978
977
- stake_acc_rec -> vt -> set_slot ( stake_acc_rec , slot_ctx -> slot );
979
+ stake_acc_rec -> vt -> set_slot ( stake_acc_rec , bank -> slot );
978
980
979
981
fd_stake_state_v2_t stake_state [1 ] = {0 };
980
982
if ( fd_stake_get_state ( stake_acc_rec , stake_state ) != 0 ) {
@@ -1000,20 +1002,20 @@ distribute_epoch_reward_to_stake_acc( fd_exec_slot_ctx_t * slot_ctx,
1000
1002
FD_LOG_ERR (( "write_stake_state failed" ));
1001
1003
}
1002
1004
1003
- fd_txn_account_mutable_fini ( stake_acc_rec , slot_ctx -> funk , slot_ctx -> funk_txn );
1005
+ fd_txn_account_mutable_fini ( stake_acc_rec , funk , funk_txn );
1004
1006
1005
1007
return 0 ;
1006
1008
}
1007
1009
1008
1010
/* Sets the epoch reward status to inactive, and destroys any allocated state associated with the active state. */
1009
1011
static void
1010
- set_epoch_reward_status_inactive ( fd_exec_slot_ctx_t * slot_ctx ) {
1011
- fd_epoch_reward_status_global_t * epoch_reward_status = fd_bank_epoch_reward_status_locking_modify ( slot_ctx -> bank );
1012
+ set_epoch_reward_status_inactive ( fd_bank_t * bank ) {
1013
+ fd_epoch_reward_status_global_t * epoch_reward_status = fd_bank_epoch_reward_status_locking_modify ( bank );
1012
1014
if ( epoch_reward_status -> discriminant == fd_epoch_reward_status_enum_Active ) {
1013
1015
FD_LOG_NOTICE (( "Done partitioning rewards for current epoch" ));
1014
1016
}
1015
1017
epoch_reward_status -> discriminant = fd_epoch_reward_status_enum_Inactive ;
1016
- fd_bank_epoch_reward_status_end_locking_modify ( slot_ctx -> bank );
1018
+ fd_bank_epoch_reward_status_end_locking_modify ( bank );
1017
1019
}
1018
1020
1019
1021
/* Sets the epoch reward status to active.
@@ -1061,7 +1063,9 @@ set_epoch_reward_status_active( fd_bank_t * bank,
1061
1063
static void
1062
1064
distribute_epoch_rewards_in_partition ( fd_partitioned_stake_rewards_dlist_t * partition ,
1063
1065
fd_stake_reward_t * pool ,
1064
- fd_exec_slot_ctx_t * slot_ctx ,
1066
+ fd_bank_t * bank ,
1067
+ fd_funk_t * funk ,
1068
+ fd_funk_txn_t * funk_txn ,
1065
1069
fd_spad_t * runtime_spad ) {
1066
1070
1067
1071
ulong lamports_distributed = 0UL ;
@@ -1072,7 +1076,9 @@ distribute_epoch_rewards_in_partition( fd_partitioned_stake_rewards_dlist_t * pa
1072
1076
iter = fd_partitioned_stake_rewards_dlist_iter_fwd_next ( iter , partition , pool ) ) {
1073
1077
fd_stake_reward_t * stake_reward = fd_partitioned_stake_rewards_dlist_iter_ele ( iter , partition , pool );
1074
1078
1075
- if ( distribute_epoch_reward_to_stake_acc ( slot_ctx ,
1079
+ if ( distribute_epoch_reward_to_stake_acc ( bank ,
1080
+ funk ,
1081
+ funk_txn ,
1076
1082
& stake_reward -> stake_pubkey ,
1077
1083
stake_reward -> lamports ,
1078
1084
stake_reward -> credits_observed ) == 0 ) {
@@ -1083,33 +1089,30 @@ distribute_epoch_rewards_in_partition( fd_partitioned_stake_rewards_dlist_t * pa
1083
1089
}
1084
1090
1085
1091
/* Update the epoch rewards sysvar with the amount distributed and burnt */
1086
- fd_sysvar_epoch_rewards_distribute ( slot_ctx ,
1092
+ fd_sysvar_epoch_rewards_distribute ( bank ,
1093
+ funk ,
1094
+ funk_txn ,
1087
1095
lamports_distributed + lamports_burned ,
1088
1096
runtime_spad );
1089
1097
1090
1098
FD_LOG_DEBUG (( "lamports burned: %lu, lamports distributed: %lu" , lamports_burned , lamports_distributed ));
1091
1099
1092
- fd_bank_capitalization_set ( slot_ctx -> bank , fd_bank_capitalization_get ( slot_ctx -> bank ) + lamports_distributed );
1100
+ fd_bank_capitalization_set ( bank , fd_bank_capitalization_get ( bank ) + lamports_distributed );
1093
1101
}
1094
1102
1095
1103
/* Process reward distribution for the block if it is inside reward interval.
1096
1104
1097
1105
https://github.com/anza-xyz/agave/blob/cbc8320d35358da14d79ebcada4dfb6756ffac79/runtime/src/bank/partitioned_epoch_rewards/distribution.rs#L42 */
1098
1106
void
1099
- fd_distribute_partitioned_epoch_rewards ( fd_exec_slot_ctx_t * slot_ctx ,
1100
- fd_tpool_t * tpool ,
1101
- fd_spad_t * * exec_spads ,
1102
- ulong exec_spad_cnt ,
1103
- fd_spad_t * runtime_spad ) {
1104
-
1105
- (void )tpool ;
1106
- (void )exec_spads ;
1107
- (void )exec_spad_cnt ;
1107
+ fd_distribute_partitioned_epoch_rewards ( fd_bank_t * bank ,
1108
+ fd_funk_t * funk ,
1109
+ fd_funk_txn_t * funk_txn ,
1110
+ fd_spad_t * runtime_spad ) {
1108
1111
1109
- fd_epoch_reward_status_global_t const * epoch_reward_status = fd_bank_epoch_reward_status_locking_query ( slot_ctx -> bank );
1112
+ fd_epoch_reward_status_global_t const * epoch_reward_status = fd_bank_epoch_reward_status_locking_query ( bank );
1110
1113
1111
1114
if ( epoch_reward_status -> discriminant == fd_epoch_reward_status_enum_Inactive ) {
1112
- fd_bank_epoch_reward_status_end_locking_query ( slot_ctx -> bank );
1115
+ fd_bank_epoch_reward_status_end_locking_query ( bank );
1113
1116
return ;
1114
1117
}
1115
1118
@@ -1123,12 +1126,12 @@ fd_distribute_partitioned_epoch_rewards( fd_exec_slot_ctx_t * slot_ctx,
1123
1126
FD_LOG_CRIT (( "Failed to join pool" ));
1124
1127
}
1125
1128
1126
- ulong height = fd_bank_block_height_get ( slot_ctx -> bank );
1129
+ ulong height = fd_bank_block_height_get ( bank );
1127
1130
ulong distribution_starting_block_height = status -> distribution_starting_block_height ;
1128
1131
ulong distribution_end_exclusive = distribution_starting_block_height + status -> partitioned_stake_rewards .partitions_len ;
1129
1132
1130
- fd_epoch_schedule_t const * epoch_schedule = fd_bank_epoch_schedule_query ( slot_ctx -> bank );
1131
- ulong epoch = fd_slot_to_epoch ( epoch_schedule , slot_ctx -> slot , NULL );
1133
+ fd_epoch_schedule_t const * epoch_schedule = fd_bank_epoch_schedule_query ( bank );
1134
+ ulong epoch = fd_slot_to_epoch ( epoch_schedule , bank -> slot , NULL );
1132
1135
1133
1136
if ( FD_UNLIKELY ( get_slots_in_epoch ( epoch , epoch_schedule ) <= status -> partitioned_stake_rewards .partitions_len ) ) {
1134
1137
FD_LOG_ERR (( "Should not be distributing rewards" ));
@@ -1138,16 +1141,18 @@ fd_distribute_partitioned_epoch_rewards( fd_exec_slot_ctx_t * slot_ctx,
1138
1141
ulong partition_index = height - distribution_starting_block_height ;
1139
1142
distribute_epoch_rewards_in_partition ( & partitions [ partition_index ],
1140
1143
pool ,
1141
- slot_ctx ,
1144
+ bank ,
1145
+ funk ,
1146
+ funk_txn ,
1142
1147
runtime_spad );
1143
1148
}
1144
1149
1145
- fd_bank_epoch_reward_status_end_locking_query ( slot_ctx -> bank );
1150
+ fd_bank_epoch_reward_status_end_locking_query ( bank );
1146
1151
1147
1152
/* If we have finished distributing rewards, set the status to inactive */
1148
1153
if ( fd_ulong_sat_add ( height , 1UL ) >= distribution_end_exclusive ) {
1149
- set_epoch_reward_status_inactive ( slot_ctx );
1150
- fd_sysvar_epoch_rewards_set_inactive ( slot_ctx , runtime_spad );
1154
+ set_epoch_reward_status_inactive ( bank );
1155
+ fd_sysvar_epoch_rewards_set_inactive ( bank , funk , funk_txn , runtime_spad );
1151
1156
}
1152
1157
}
1153
1158
@@ -1217,7 +1222,7 @@ fd_rewards_recalculate_partitioned_rewards( fd_exec_slot_ctx_t * slot_ctx,
1217
1222
fd_sysvar_epoch_rewards_t * epoch_rewards = fd_sysvar_epoch_rewards_read ( slot_ctx -> funk , slot_ctx -> funk_txn , runtime_spad );
1218
1223
if ( FD_UNLIKELY ( epoch_rewards == NULL ) ) {
1219
1224
FD_LOG_NOTICE (( "Failed to read or decode epoch rewards sysvar - may not have been created yet" ));
1220
- set_epoch_reward_status_inactive ( slot_ctx );
1225
+ set_epoch_reward_status_inactive ( slot_ctx -> bank );
1221
1226
return ;
1222
1227
}
1223
1228
@@ -1338,6 +1343,6 @@ fd_rewards_recalculate_partitioned_rewards( fd_exec_slot_ctx_t * slot_ctx,
1338
1343
epoch_rewards -> distribution_starting_block_height ,
1339
1344
& stake_rewards_by_partition -> partitioned_stake_rewards );
1340
1345
} else {
1341
- set_epoch_reward_status_inactive ( slot_ctx );
1346
+ set_epoch_reward_status_inactive ( slot_ctx -> bank );
1342
1347
}
1343
1348
}
0 commit comments