Skip to content

Commit 41d36c4

Browse files
more
1 parent e9c18e2 commit 41d36c4

File tree

9 files changed

+126
-103
lines changed

9 files changed

+126
-103
lines changed

src/app/ledger/main.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ runtime_replay( fd_ledger_args_t * ledger_args ) {
312312
poh_hash ));
313313

314314
if( ledger_args->checkpt_mismatch ) {
315-
fd_runtime_checkpt( ledger_args->capture_ctx, ledger_args->slot_ctx, ULONG_MAX );
315+
fd_runtime_checkpt( ledger_args->capture_ctx, ledger_args->slot_ctx->funk, ULONG_MAX );
316316
}
317317
if( ledger_args->abort_on_mismatch ) {
318318
ret = 1;
@@ -340,7 +340,7 @@ runtime_replay( fd_ledger_args_t * ledger_args ) {
340340
bank_hash ));
341341

342342
if( ledger_args->checkpt_mismatch ) {
343-
fd_runtime_checkpt( ledger_args->capture_ctx, ledger_args->slot_ctx, ULONG_MAX );
343+
fd_runtime_checkpt( ledger_args->capture_ctx, ledger_args->slot_ctx->funk, ULONG_MAX );
344344
}
345345
if( ledger_args->abort_on_mismatch ) {
346346
ret = 1;

src/discof/replay/fd_replay_tile.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,7 @@ funk_and_txncache_publish( fd_replay_tile_ctx_t * ctx, ulong wmk, fd_funk_txn_xi
636636
funk_publish( ctx, to_root_txn, wmk );
637637

638638
if( FD_UNLIKELY( ctx->capture_ctx ) ) {
639-
fd_runtime_checkpt( ctx->capture_ctx, ctx->slot_ctx, wmk );
639+
fd_runtime_checkpt( ctx->capture_ctx, ctx->slot_ctx->funk, wmk );
640640
}
641641

642642
}
@@ -906,7 +906,9 @@ prepare_new_block_execution( fd_replay_tile_ctx_t * ctx,
906906
int is_epoch_boundary = 0;
907907
/* TODO: Currently all of the epoch boundary/rewards logic is not
908908
multhreaded at the epoch boundary. */
909-
fd_runtime_block_pre_execute_process_new_epoch( ctx->slot_ctx,
909+
fd_runtime_block_pre_execute_process_new_epoch( ctx->slot_ctx->bank,
910+
ctx->slot_ctx->funk,
911+
ctx->slot_ctx->funk_txn,
910912
NULL,
911913
ctx->exec_spads,
912914
ctx->exec_spad_cnt,

src/flamenco/rewards/fd_rewards.c

Lines changed: 51 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -960,21 +960,23 @@ calculate_rewards_and_distribute_vote_rewards( fd_bank_t *
960960

961961
/* Distributes a single partitioned reward to a single stake account */
962962
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 ) {
967969
FD_TXN_ACCOUNT_DECL( stake_acc_rec );
968970
if( FD_UNLIKELY( fd_txn_account_init_from_funk_mutable( stake_acc_rec,
969971
stake_pubkey,
970-
slot_ctx->funk,
971-
slot_ctx->funk_txn,
972+
funk,
973+
funk_txn,
972974
0,
973975
0UL ) != FD_ACC_MGR_SUCCESS ) ) {
974976
FD_LOG_ERR(( "Unable to modify stake account" ));
975977
}
976978

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 );
978980

979981
fd_stake_state_v2_t stake_state[1] = {0};
980982
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,
10001002
FD_LOG_ERR(( "write_stake_state failed" ));
10011003
}
10021004

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 );
10041006

10051007
return 0;
10061008
}
10071009

10081010
/* Sets the epoch reward status to inactive, and destroys any allocated state associated with the active state. */
10091011
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 );
10121014
if( epoch_reward_status->discriminant == fd_epoch_reward_status_enum_Active ) {
10131015
FD_LOG_NOTICE(( "Done partitioning rewards for current epoch" ));
10141016
}
10151017
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 );
10171019
}
10181020

10191021
/* Sets the epoch reward status to active.
@@ -1061,7 +1063,9 @@ set_epoch_reward_status_active( fd_bank_t * bank,
10611063
static void
10621064
distribute_epoch_rewards_in_partition( fd_partitioned_stake_rewards_dlist_t * partition,
10631065
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,
10651069
fd_spad_t * runtime_spad ) {
10661070

10671071
ulong lamports_distributed = 0UL;
@@ -1072,44 +1076,45 @@ distribute_epoch_rewards_in_partition( fd_partitioned_stake_rewards_dlist_t * pa
10721076
iter = fd_partitioned_stake_rewards_dlist_iter_fwd_next( iter, partition, pool ) ) {
10731077
fd_stake_reward_t * stake_reward = fd_partitioned_stake_rewards_dlist_iter_ele( iter, partition, pool );
10741078

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 ) {
10791086
lamports_distributed += stake_reward->lamports;
10801087
} else {
10811088
lamports_burned += stake_reward->lamports;
10821089
}
10831090
}
10841091

10851092
/* 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 );
10891099

10901100
FD_LOG_DEBUG(( "lamports burned: %lu, lamports distributed: %lu", lamports_burned, lamports_distributed ));
10911101

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 );
10931103
}
10941104

10951105
/* Process reward distribution for the block if it is inside reward interval.
10961106
10971107
https://github.com/anza-xyz/agave/blob/cbc8320d35358da14d79ebcada4dfb6756ffac79/runtime/src/bank/partitioned_epoch_rewards/distribution.rs#L42 */
10981108
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 ) {
11081113

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 );
11101115

11111116
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 );
11131118
return;
11141119
}
11151120

@@ -1123,31 +1128,34 @@ fd_distribute_partitioned_epoch_rewards( fd_exec_slot_ctx_t * slot_ctx,
11231128
FD_LOG_CRIT(( "Failed to join pool" ));
11241129
}
11251130

1126-
ulong height = fd_bank_block_height_get( slot_ctx->bank );
1131+
ulong height = fd_bank_block_height_get( bank );
11271132
ulong distribution_starting_block_height = status->distribution_starting_block_height;
11281133
ulong distribution_end_exclusive = distribution_starting_block_height + status->partitioned_stake_rewards.partitions_len;
11291134

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 );
11321137

11331138
if( FD_UNLIKELY( get_slots_in_epoch( epoch, epoch_schedule ) <= status->partitioned_stake_rewards.partitions_len ) ) {
11341139
FD_LOG_ERR(( "Should not be distributing rewards" ));
11351140
}
11361141

11371142
if( (height>=distribution_starting_block_height) && (height < distribution_end_exclusive) ) {
11381143
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 );
11431151
}
11441152

1145-
fd_bank_epoch_reward_status_end_locking_query( slot_ctx->bank );
1153+
fd_bank_epoch_reward_status_end_locking_query( bank );
11461154

11471155
/* If we have finished distributing rewards, set the status to inactive */
11481156
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 );
11511159
}
11521160
}
11531161

@@ -1217,7 +1225,7 @@ fd_rewards_recalculate_partitioned_rewards( fd_exec_slot_ctx_t * slot_ctx,
12171225
fd_sysvar_epoch_rewards_t * epoch_rewards = fd_sysvar_epoch_rewards_read( slot_ctx->funk, slot_ctx->funk_txn, runtime_spad );
12181226
if( FD_UNLIKELY( epoch_rewards == NULL ) ) {
12191227
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 );
12211229
return;
12221230
}
12231231

@@ -1338,6 +1346,6 @@ fd_rewards_recalculate_partitioned_rewards( fd_exec_slot_ctx_t * slot_ctx,
13381346
epoch_rewards->distribution_starting_block_height,
13391347
&stake_rewards_by_partition->partitioned_stake_rewards );
13401348
} else {
1341-
set_epoch_reward_status_inactive( slot_ctx );
1349+
set_epoch_reward_status_inactive( slot_ctx->bank );
13421350
}
13431351
}

src/flamenco/rewards/fd_rewards.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,10 @@ fd_rewards_recalculate_partitioned_rewards( fd_exec_slot_ctx_t * slot_ctx,
5454
fd_spad_t * runtime_spad );
5555

5656
void
57-
fd_distribute_partitioned_epoch_rewards( fd_exec_slot_ctx_t * slot_ctx,
58-
fd_tpool_t * tpool,
59-
fd_spad_t * * exec_spads,
60-
ulong exec_spad_cnt,
61-
fd_spad_t * runtime_spad );
57+
fd_distribute_partitioned_epoch_rewards( fd_bank_t * bank,
58+
fd_funk_t * funk,
59+
fd_funk_txn_t * funk_txn,
60+
fd_spad_t * runtime_spad );
6261

6362
FD_PROTOTYPES_END
6463

src/flamenco/runtime/fd_runtime.c

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3593,7 +3593,7 @@ fd_runtime_publish_old_txns( fd_exec_slot_ctx_t * slot_ctx,
35933593
fd_funk_txn_pool_t * txnpool = fd_funk_txn_pool( funk );
35943594

35953595
if( capture_ctx != NULL ) {
3596-
fd_runtime_checkpt( capture_ctx, slot_ctx, slot_ctx->slot );
3596+
fd_runtime_checkpt( capture_ctx, slot_ctx->funk, slot_ctx->slot );
35973597
}
35983598

35993599
int do_eah = 0;
@@ -3748,34 +3748,36 @@ fd_runtime_block_execute_tpool( fd_exec_slot_ctx_t * slot_ctx,
37483748
}
37493749

37503750
void
3751-
fd_runtime_block_pre_execute_process_new_epoch( fd_exec_slot_ctx_t * slot_ctx,
3752-
fd_tpool_t * tpool,
3753-
fd_spad_t * * exec_spads,
3754-
ulong exec_spad_cnt,
3755-
fd_spad_t * runtime_spad,
3756-
int * is_epoch_boundary ) {
3751+
fd_runtime_block_pre_execute_process_new_epoch( fd_bank_t * bank,
3752+
fd_funk_t * funk,
3753+
fd_funk_txn_t * funk_txn,
3754+
fd_tpool_t * tpool,
3755+
fd_spad_t * * exec_spads,
3756+
ulong exec_spad_cnt,
3757+
fd_spad_t * runtime_spad,
3758+
int * is_epoch_boundary ) {
37573759

37583760
/* Update block height. */
3759-
fd_bank_block_height_set( slot_ctx->bank, fd_bank_block_height_get( slot_ctx->bank ) + 1UL );
3761+
fd_bank_block_height_set( bank, fd_bank_block_height_get( bank ) + 1UL );
37603762

3761-
if( slot_ctx->slot != 0UL ) {
3762-
fd_epoch_schedule_t const * epoch_schedule = fd_bank_epoch_schedule_query( slot_ctx->bank );
3763+
if( bank->slot != 0UL ) {
3764+
fd_epoch_schedule_t const * epoch_schedule = fd_bank_epoch_schedule_query( bank );
37633765

37643766
ulong slot_idx;
3765-
ulong prev_epoch = fd_slot_to_epoch( epoch_schedule, fd_bank_prev_slot_get( slot_ctx->bank ), &slot_idx );
3766-
ulong new_epoch = fd_slot_to_epoch( epoch_schedule, slot_ctx->slot, &slot_idx );
3767+
ulong prev_epoch = fd_slot_to_epoch( epoch_schedule, fd_bank_prev_slot_get( bank ), &slot_idx );
3768+
ulong new_epoch = fd_slot_to_epoch( epoch_schedule, bank->slot, &slot_idx );
37673769
if( FD_UNLIKELY( slot_idx==1UL && new_epoch==0UL ) ) {
37683770
/* The block after genesis has a height of 1. */
3769-
fd_bank_block_height_set( slot_ctx->bank, 1UL );
3771+
fd_bank_block_height_set( bank, 1UL );
37703772
}
37713773

37723774
if( FD_UNLIKELY( prev_epoch<new_epoch || !slot_idx ) ) {
37733775
FD_LOG_DEBUG(( "Epoch boundary" ));
37743776
/* Epoch boundary! */
37753777
fd_runtime_process_new_epoch(
3776-
slot_ctx->bank,
3777-
slot_ctx->funk,
3778-
slot_ctx->funk_txn,
3778+
bank,
3779+
funk,
3780+
funk_txn,
37793781
new_epoch - 1UL,
37803782
tpool,
37813783
exec_spads,
@@ -3787,12 +3789,12 @@ fd_runtime_block_pre_execute_process_new_epoch( fd_exec_slot_ctx_t * slot_ctx,
37873789
*is_epoch_boundary = 0;
37883790
}
37893791

3790-
if( FD_LIKELY( slot_ctx->slot!=0UL ) ) {
3791-
fd_distribute_partitioned_epoch_rewards( slot_ctx,
3792-
tpool,
3793-
exec_spads,
3794-
exec_spad_cnt,
3795-
runtime_spad );
3792+
if( FD_LIKELY( bank->slot!=0UL ) ) {
3793+
fd_distribute_partitioned_epoch_rewards(
3794+
bank,
3795+
funk,
3796+
funk_txn,
3797+
runtime_spad );
37963798
}
37973799
}
37983800

@@ -3844,7 +3846,9 @@ fd_runtime_block_eval_tpool( fd_exec_slot_ctx_t * slot_ctx,
38443846
}
38453847

38463848
int is_epoch_boundary = 0;
3847-
fd_runtime_block_pre_execute_process_new_epoch( slot_ctx,
3849+
fd_runtime_block_pre_execute_process_new_epoch( slot_ctx->bank,
3850+
slot_ctx->funk,
3851+
slot_ctx->funk_txn,
38483852
tpool,
38493853
exec_spads,
38503854
exec_spad_cnt,
@@ -3927,9 +3931,9 @@ fd_runtime_block_eval_tpool( fd_exec_slot_ctx_t * slot_ctx,
39273931
/******************************************************************************/
39283932

39293933
void
3930-
fd_runtime_checkpt( fd_capture_ctx_t * capture_ctx,
3931-
fd_exec_slot_ctx_t * slot_ctx,
3932-
ulong slot ) {
3934+
fd_runtime_checkpt( fd_capture_ctx_t * capture_ctx,
3935+
fd_funk_t * funk,
3936+
ulong slot ) {
39333937
int is_checkpt_freq = capture_ctx != NULL && slot % capture_ctx->checkpt_freq == 0;
39343938
int is_abort_slot = slot == ULONG_MAX;
39353939
if( !is_checkpt_freq && !is_abort_slot ) {
@@ -3944,7 +3948,7 @@ fd_runtime_checkpt( fd_capture_ctx_t * capture_ctx,
39443948
}
39453949

39463950
unlink( capture_ctx->checkpt_path );
3947-
int err = fd_wksp_checkpt( fd_funk_wksp( slot_ctx->funk ), capture_ctx->checkpt_path, 0666, 0, NULL );
3951+
int err = fd_wksp_checkpt( fd_funk_wksp( funk ), capture_ctx->checkpt_path, 0666, 0, NULL );
39483952
if ( err ) {
39493953
FD_LOG_ERR(( "backup failed: error %d", err ));
39503954
}

src/flamenco/runtime/fd_runtime.h

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -596,12 +596,14 @@ fd_runtime_is_epoch_boundary( fd_bank_t * bank,
596596
the bank hash.
597597
*/
598598
void
599-
fd_runtime_block_pre_execute_process_new_epoch( fd_exec_slot_ctx_t * slot_ctx,
600-
fd_tpool_t * tpool,
601-
fd_spad_t * * exec_spads,
602-
ulong exec_spad_cnt,
603-
fd_spad_t * runtime_spad,
604-
int * is_epoch_boundary );
599+
fd_runtime_block_pre_execute_process_new_epoch( fd_bank_t * bank,
600+
fd_funk_t * funk,
601+
fd_funk_txn_t * funk_txn,
602+
fd_tpool_t * tpool,
603+
fd_spad_t * * exec_spads,
604+
ulong exec_spad_cnt,
605+
fd_spad_t * runtime_spad,
606+
int * is_epoch_boundary );
605607

606608
/* This function is responsible for inserting fresh entries or updating existing entries in the program cache.
607609
When the client boots up, the program cache is empty. As programs get invoked, this function is responsible
@@ -626,9 +628,9 @@ fd_runtime_update_program_cache( fd_exec_slot_ctx_t * slot_ctx,
626628
/* Debugging Tools ************************************************************/
627629

628630
void
629-
fd_runtime_checkpt( fd_capture_ctx_t * capture_ctx,
630-
fd_exec_slot_ctx_t * slot_ctx,
631-
ulong slot );
631+
fd_runtime_checkpt( fd_capture_ctx_t * capture_ctx,
632+
fd_funk_t * funk,
633+
ulong slot );
632634

633635
/* Block Parsing **************************************************************/
634636

0 commit comments

Comments
 (0)