@@ -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 ,
964
- fd_pubkey_t * stake_pubkey ,
965
- ulong reward_lamports ,
966
- ulong new_credits_observed ) {
963
+ distribute_epoch_reward_to_stake_acc ( fd_bank_t * bank ,
964
+ fd_funk_t * funk ,
965
+ fd_funk_txn_t * funk_txn ,
966
+ fd_pubkey_t * stake_pubkey ,
967
+ ulong reward_lamports ,
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,44 +1076,45 @@ 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 ,
1076
- & stake_reward -> stake_pubkey ,
1077
- stake_reward -> lamports ,
1078
- stake_reward -> credits_observed ) == 0 ) {
1079
+ if ( distribute_epoch_reward_to_stake_acc (
1080
+ bank ,
1081
+ funk ,
1082
+ funk_txn ,
1083
+ & stake_reward -> stake_pubkey ,
1084
+ stake_reward -> lamports ,
1085
+ stake_reward -> credits_observed ) == 0 ) {
1079
1086
lamports_distributed += stake_reward -> lamports ;
1080
1087
} else {
1081
1088
lamports_burned += stake_reward -> lamports ;
1082
1089
}
1083
1090
}
1084
1091
1085
1092
/* Update the epoch rewards sysvar with the amount distributed and burnt */
1086
- fd_sysvar_epoch_rewards_distribute ( slot_ctx ,
1087
- lamports_distributed + lamports_burned ,
1088
- runtime_spad );
1093
+ fd_sysvar_epoch_rewards_distribute (
1094
+ bank ,
1095
+ funk ,
1096
+ funk_txn ,
1097
+ lamports_distributed + lamports_burned ,
1098
+ runtime_spad );
1089
1099
1090
1100
FD_LOG_DEBUG (( "lamports burned: %lu, lamports distributed: %lu" , lamports_burned , lamports_distributed ));
1091
1101
1092
- fd_bank_capitalization_set ( slot_ctx -> bank , fd_bank_capitalization_get ( slot_ctx -> bank ) + lamports_distributed );
1102
+ fd_bank_capitalization_set ( bank , fd_bank_capitalization_get ( bank ) + lamports_distributed );
1093
1103
}
1094
1104
1095
1105
/* Process reward distribution for the block if it is inside reward interval.
1096
1106
1097
1107
https://github.com/anza-xyz/agave/blob/cbc8320d35358da14d79ebcada4dfb6756ffac79/runtime/src/bank/partitioned_epoch_rewards/distribution.rs#L42 */
1098
1108
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 ;
1109
+ fd_distribute_partitioned_epoch_rewards ( fd_bank_t * bank ,
1110
+ fd_funk_t * funk ,
1111
+ fd_funk_txn_t * funk_txn ,
1112
+ fd_spad_t * runtime_spad ) {
1108
1113
1109
- fd_epoch_reward_status_global_t const * epoch_reward_status = fd_bank_epoch_reward_status_locking_query ( slot_ctx -> bank );
1114
+ fd_epoch_reward_status_global_t const * epoch_reward_status = fd_bank_epoch_reward_status_locking_query ( bank );
1110
1115
1111
1116
if ( epoch_reward_status -> discriminant == fd_epoch_reward_status_enum_Inactive ) {
1112
- fd_bank_epoch_reward_status_end_locking_query ( slot_ctx -> bank );
1117
+ fd_bank_epoch_reward_status_end_locking_query ( bank );
1113
1118
return ;
1114
1119
}
1115
1120
@@ -1123,31 +1128,34 @@ fd_distribute_partitioned_epoch_rewards( fd_exec_slot_ctx_t * slot_ctx,
1123
1128
FD_LOG_CRIT (( "Failed to join pool" ));
1124
1129
}
1125
1130
1126
- ulong height = fd_bank_block_height_get ( slot_ctx -> bank );
1131
+ ulong height = fd_bank_block_height_get ( bank );
1127
1132
ulong distribution_starting_block_height = status -> distribution_starting_block_height ;
1128
1133
ulong distribution_end_exclusive = distribution_starting_block_height + status -> partitioned_stake_rewards .partitions_len ;
1129
1134
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 );
1135
+ fd_epoch_schedule_t const * epoch_schedule = fd_bank_epoch_schedule_query ( bank );
1136
+ ulong epoch = fd_slot_to_epoch ( epoch_schedule , bank -> slot , NULL );
1132
1137
1133
1138
if ( FD_UNLIKELY ( get_slots_in_epoch ( epoch , epoch_schedule ) <= status -> partitioned_stake_rewards .partitions_len ) ) {
1134
1139
FD_LOG_ERR (( "Should not be distributing rewards" ));
1135
1140
}
1136
1141
1137
1142
if ( (height >=distribution_starting_block_height ) && (height < distribution_end_exclusive ) ) {
1138
1143
ulong partition_index = height - distribution_starting_block_height ;
1139
- distribute_epoch_rewards_in_partition ( & partitions [ partition_index ],
1140
- pool ,
1141
- slot_ctx ,
1142
- runtime_spad );
1144
+ distribute_epoch_rewards_in_partition (
1145
+ & partitions [ partition_index ],
1146
+ pool ,
1147
+ bank ,
1148
+ funk ,
1149
+ funk_txn ,
1150
+ runtime_spad );
1143
1151
}
1144
1152
1145
- fd_bank_epoch_reward_status_end_locking_query ( slot_ctx -> bank );
1153
+ fd_bank_epoch_reward_status_end_locking_query ( bank );
1146
1154
1147
1155
/* If we have finished distributing rewards, set the status to inactive */
1148
1156
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 );
1157
+ set_epoch_reward_status_inactive ( bank );
1158
+ fd_sysvar_epoch_rewards_set_inactive ( bank , funk , funk_txn , runtime_spad );
1151
1159
}
1152
1160
}
1153
1161
@@ -1217,7 +1225,7 @@ fd_rewards_recalculate_partitioned_rewards( fd_exec_slot_ctx_t * slot_ctx,
1217
1225
fd_sysvar_epoch_rewards_t * epoch_rewards = fd_sysvar_epoch_rewards_read ( slot_ctx -> funk , slot_ctx -> funk_txn , runtime_spad );
1218
1226
if ( FD_UNLIKELY ( epoch_rewards == NULL ) ) {
1219
1227
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 );
1228
+ set_epoch_reward_status_inactive ( slot_ctx -> bank );
1221
1229
return ;
1222
1230
}
1223
1231
@@ -1338,6 +1346,6 @@ fd_rewards_recalculate_partitioned_rewards( fd_exec_slot_ctx_t * slot_ctx,
1338
1346
epoch_rewards -> distribution_starting_block_height ,
1339
1347
& stake_rewards_by_partition -> partitioned_stake_rewards );
1340
1348
} else {
1341
- set_epoch_reward_status_inactive ( slot_ctx );
1349
+ set_epoch_reward_status_inactive ( slot_ctx -> bank );
1342
1350
}
1343
1351
}
0 commit comments