Skip to content

Commit 23d78a5

Browse files
updating sysvar cache apis
1 parent 4e38549 commit 23d78a5

30 files changed

+247
-205
lines changed

src/discof/replay/fd_replay_tile.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1544,6 +1544,8 @@ prepare_new_block_execution( fd_replay_tile_ctx_t * ctx,
15441544
fork->slot_ctx->funk_txn = fd_funk_txn_prepare(ctx->funk, fork->slot_ctx->funk_txn, &xid, 1);
15451545
fd_funk_txn_end_write( ctx->funk );
15461546

1547+
fd_sysvar_cache_invalidate( fork->slot_ctx->sysvar_cache );
1548+
15471549
int is_epoch_boundary = 0;
15481550
/* TODO: Currently all of the epoch boundary/rewards logic is not
15491551
multhreaded at the epoch boundary. */

src/flamenco/rewards/fd_rewards.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,7 @@ calculate_reward_points_partitioned( fd_exec_slot_ctx_t * slot_ctx,
389389
int is_some = fd_new_warmup_cooldown_rate_epoch( slot_ctx->slot_bank.slot,
390390
slot_ctx->sysvar_cache,
391391
&slot_ctx->epoch_ctx->features,
392+
slot_ctx->runtime_wksp,
392393
new_warmup_cooldown_rate_epoch,
393394
_err );
394395
if( FD_UNLIKELY( !is_some ) ) {
@@ -604,7 +605,8 @@ calculate_stake_vote_rewards( fd_exec_slot_ctx_t * slot_ct
604605
ulong * new_warmup_cooldown_rate_epoch = &new_warmup_cooldown_rate_epoch_val;
605606
int is_some = fd_new_warmup_cooldown_rate_epoch( slot_ctx->slot_bank.slot,
606607
slot_ctx->sysvar_cache,
607-
&slot_ctx->epoch_ctx->features,
608+
&slot_ctx->epoch_ctx->features,
609+
slot_ctx->runtime_wksp,
608610
new_warmup_cooldown_rate_epoch,
609611
_err );
610612
if( FD_UNLIKELY( !is_some ) ) {
@@ -696,7 +698,7 @@ calculate_validator_rewards( fd_exec_slot_ctx_t * slot_ctx,
696698
fd_spad_t * runtime_spad ) {
697699
/* https://github.com/firedancer-io/solana/blob/dab3da8e7b667d7527565bddbdbecf7ec1fb868e/runtime/src/bank.rs#L2759-L2786 */
698700

699-
fd_stake_history_t const * stake_history = fd_sysvar_cache_stake_history( slot_ctx->sysvar_cache );
701+
fd_stake_history_t const * stake_history = fd_sysvar_cache_stake_history( slot_ctx->sysvar_cache, slot_ctx->runtime_wksp );
700702
if( FD_UNLIKELY( !stake_history ) ) {
701703
FD_LOG_ERR(( "StakeHistory sysvar is missing from sysvar cache" ));
702704
}
@@ -1181,7 +1183,8 @@ fd_rewards_recalculate_partitioned_rewards( fd_exec_slot_ctx_t * slot_ctx,
11811183
if( FD_UNLIKELY( fd_sysvar_epoch_rewards_read( epoch_rewards,
11821184
slot_ctx->sysvar_cache,
11831185
slot_ctx->funk,
1184-
slot_ctx->funk_txn )==NULL ) ) {
1186+
slot_ctx->funk_txn,
1187+
slot_ctx->runtime_wksp )==NULL ) ) {
11851188
FD_LOG_NOTICE(( "failed to read sysvar epoch rewards - the sysvar may not have been created yet" ));
11861189
set_epoch_reward_status_inactive( slot_ctx, runtime_spad );
11871190
return;
@@ -1212,12 +1215,14 @@ fd_rewards_recalculate_partitioned_rewards( fd_exec_slot_ctx_t * slot_ctx,
12121215
int is_some = fd_new_warmup_cooldown_rate_epoch( slot_ctx->slot_bank.slot,
12131216
slot_ctx->sysvar_cache,
12141217
&slot_ctx->epoch_ctx->features,
1215-
new_warmup_cooldown_rate_epoch, _err );
1218+
slot_ctx->runtime_wksp,
1219+
new_warmup_cooldown_rate_epoch,
1220+
_err );
12161221
if( FD_UNLIKELY( !is_some ) ) {
12171222
new_warmup_cooldown_rate_epoch = NULL;
12181223
}
12191224

1220-
fd_stake_history_t const * stake_history = fd_sysvar_cache_stake_history( slot_ctx->sysvar_cache );
1225+
fd_stake_history_t const * stake_history = fd_sysvar_cache_stake_history( slot_ctx->sysvar_cache, slot_ctx->runtime_wksp );
12211226
if( FD_UNLIKELY( !stake_history ) ) {
12221227
FD_LOG_ERR(( "StakeHistory sysvar is missing from sysvar cache" ));
12231228
}

src/flamenco/runtime/context/fd_exec_slot_ctx.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@ fd_exec_slot_ctx_new( void * mem,
2525
fd_exec_slot_ctx_t * self = (fd_exec_slot_ctx_t *)mem;
2626
fd_slot_bank_new( &self->slot_bank );
2727

28-
self->sysvar_cache = fd_sysvar_cache_new( fd_spad_alloc( runtime_spad, fd_sysvar_cache_align(), fd_sysvar_cache_footprint() ), fd_wksp_containing( runtime_spad ) );
28+
uchar * sysvar_cache_mem = fd_spad_alloc( runtime_spad, fd_sysvar_cache_align(), fd_sysvar_cache_footprint() );
29+
if( FD_UNLIKELY( !sysvar_cache_mem ) ) {
30+
FD_LOG_WARNING(( "failed to allocate sysvar cache" ));
31+
}
32+
self->sysvar_cache = fd_sysvar_cache_new( sysvar_cache_mem );
2933

3034
FD_COMPILER_MFENCE();
3135
self->magic = FD_EXEC_SLOT_CTX_MAGIC;

src/flamenco/runtime/fd_executor.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ fd_executor_load_transaction_accounts( fd_exec_txn_ctx_t * txn_ctx ) {
442442
}
443443
txn_ctx->instr_info_cnt = txn_ctx->txn_descriptor->instr_cnt;
444444

445-
fd_epoch_schedule_t const * schedule = fd_sysvar_cache_epoch_schedule( txn_ctx->sysvar_cache );
445+
fd_epoch_schedule_t const * schedule = fd_sysvar_cache_epoch_schedule( txn_ctx->sysvar_cache, txn_ctx->runtime_pub_wksp );
446446
ulong epoch = fd_slot_to_epoch( schedule, txn_ctx->slot, NULL );
447447

448448
/* https://github.com/anza-xyz/agave/blob/v2.2.0/svm/src/account_loader.rs#L429-L443 */
@@ -811,7 +811,7 @@ fd_executor_validate_transaction_fee_payer( fd_exec_txn_ctx_t * txn_ctx ) {
811811

812812
/* Collect rent from the fee payer and set the starting lamports (to avoid unbalanced lamports issues in instruction execution)
813813
https://github.com/anza-xyz/agave/blob/16de8b75ebcd57022409b422de557dd37b1de8db/svm/src/transaction_processor.rs#L438-L445 */
814-
fd_epoch_schedule_t const * schedule = fd_sysvar_cache_epoch_schedule( txn_ctx->sysvar_cache );
814+
fd_epoch_schedule_t const * schedule = fd_sysvar_cache_epoch_schedule( txn_ctx->sysvar_cache, txn_ctx->runtime_pub_wksp );
815815
ulong epoch = fd_slot_to_epoch( schedule, txn_ctx->slot, NULL );
816816
txn_ctx->collected_rent += fd_runtime_collect_rent_from_account( txn_ctx->slot,
817817
&txn_ctx->schedule,
@@ -849,7 +849,7 @@ fd_executor_setup_accessed_accounts_for_txn( fd_exec_txn_ctx_t * txn_ctx ) {
849849

850850
if( txn_ctx->txn_descriptor->transaction_version == FD_TXN_V0 ) {
851851
/* https://github.com/anza-xyz/agave/blob/368ea563c423b0a85cc317891187e15c9a321521/runtime/src/bank/address_lookup_table.rs#L44-L48 */
852-
fd_slot_hashes_global_t const * slot_hashes_global = fd_sysvar_cache_slot_hashes( txn_ctx->sysvar_cache );
852+
fd_slot_hashes_global_t const * slot_hashes_global = fd_sysvar_cache_slot_hashes( txn_ctx->sysvar_cache, txn_ctx->runtime_pub_wksp );
853853
if( FD_UNLIKELY( !slot_hashes_global ) ) {
854854
return FD_RUNTIME_TXN_ERR_ACCOUNT_NOT_FOUND;
855855
}
@@ -1409,7 +1409,7 @@ fd_execute_txn( fd_execute_txn_task_info_t * task_info ) {
14091409

14101410
int
14111411
fd_executor_txn_check( fd_exec_txn_ctx_t * txn_ctx ) {
1412-
fd_rent_t const * rent = fd_sysvar_cache_rent( txn_ctx->sysvar_cache );
1412+
fd_rent_t const * rent = fd_sysvar_cache_rent( txn_ctx->sysvar_cache, txn_ctx->runtime_pub_wksp );
14131413

14141414
ulong starting_lamports_l = 0;
14151415
ulong starting_lamports_h = 0;

src/flamenco/runtime/fd_runtime.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,8 @@ fd_runtime_sysvar_cache_load( fd_exec_slot_ctx_t * slot_ctx,
224224
fd_sysvar_cache_restore( slot_ctx->sysvar_cache,
225225
slot_ctx->funk,
226226
slot_ctx->funk_txn,
227-
runtime_spad );
227+
runtime_spad,
228+
slot_ctx->runtime_wksp );
228229

229230
return FD_RUNTIME_EXECUTE_SUCCESS;
230231
}
@@ -272,7 +273,8 @@ fd_runtime_validate_fee_collector( fd_exec_slot_ctx_t const * slot_ctx,
272273
We already know that the post deposit balance is >0 because we are paying a >0 amount.
273274
So TLDR we just check if the account is rent exempt.
274275
*/
275-
ulong minbal = fd_rent_exempt_minimum_balance( fd_sysvar_cache_rent( slot_ctx->sysvar_cache ), collector->vt->get_data_len( collector ) );
276+
ulong minbal = fd_rent_exempt_minimum_balance( fd_sysvar_cache_rent( slot_ctx->sysvar_cache, slot_ctx->runtime_wksp ),
277+
collector->vt->get_data_len( collector ) );
276278
if( FD_UNLIKELY( collector->vt->get_lamports( collector ) + fee < minbal ) ) {
277279
FD_BASE58_ENCODE_32_BYTES( collector->pubkey->key, _out_key );
278280
FD_LOG_WARNING(("cannot pay a rent paying account (%s)", _out_key ));
@@ -531,8 +533,8 @@ fd_runtime_freeze( fd_exec_slot_ctx_t * slot_ctx, fd_spad_t * runtime_spad ) {
531533
FD_LOG_DEBUG(( "fd_runtime_freeze: capitalization %lu ", slot_ctx->slot_bank.capitalization));
532534
slot_ctx->slot_bank.collected_rent = 0;
533535

536+
/* At this point we want to invalidate the sysvar cache entries. */
534537
fd_sysvar_cache_invalidate( slot_ctx->sysvar_cache );
535-
FD_TEST( slot_ctx->sysvar_cache->has_clock==0 );
536538
}
537539

538540
#define FD_RENT_EXEMPT (-1L)
@@ -2342,7 +2344,7 @@ fd_new_target_program_account( fd_exec_slot_ctx_t * slot_ctx,
23422344
};
23432345

23442346
/* https://github.com/anza-xyz/agave/blob/v2.1.0/runtime/src/bank/builtins/core_bpf_migration/mod.rs#L89-L90 */
2345-
fd_rent_t const * rent = fd_sysvar_cache_rent( slot_ctx->sysvar_cache );
2347+
fd_rent_t const * rent = fd_sysvar_cache_rent( slot_ctx->sysvar_cache, slot_ctx->runtime_wksp );
23462348
if( FD_UNLIKELY( rent==NULL ) ) {
23472349
return -1;
23482350
}
@@ -2415,7 +2417,7 @@ fd_new_target_program_data_account( fd_exec_slot_ctx_t * slot_ctx,
24152417
}
24162418

24172419
/* https://github.com/anza-xyz/agave/blob/v2.1.0/runtime/src/bank/builtins/core_bpf_migration/mod.rs#L127-L132 */
2418-
const fd_rent_t * rent = fd_sysvar_cache_rent( slot_ctx->sysvar_cache );
2420+
const fd_rent_t * rent = fd_sysvar_cache_rent( slot_ctx->sysvar_cache, slot_ctx->runtime_wksp );
24192421
if( FD_UNLIKELY( rent==NULL ) ) {
24202422
return -1;
24212423
}
@@ -2860,6 +2862,7 @@ fd_runtime_process_new_epoch( fd_exec_slot_ctx_t * slot_ctx,
28602862
int is_some = fd_new_warmup_cooldown_rate_epoch( slot_ctx->slot_bank.slot,
28612863
slot_ctx->sysvar_cache,
28622864
&slot_ctx->epoch_ctx->features,
2865+
slot_ctx->runtime_wksp,
28632866
new_rate_activation_epoch,
28642867
_err );
28652868
if( FD_UNLIKELY( !is_some ) ) {
@@ -2892,7 +2895,7 @@ fd_runtime_process_new_epoch( fd_exec_slot_ctx_t * slot_ctx,
28922895

28932896
/* Refresh vote accounts in stakes cache using updated stake weights, and merges slot bank vote accounts with the epoch bank vote accounts.
28942897
https://github.com/anza-xyz/agave/blob/v2.1.6/runtime/src/stakes.rs#L363-L370 */
2895-
fd_stake_history_t const * history = fd_sysvar_cache_stake_history( slot_ctx->sysvar_cache );
2898+
fd_stake_history_t const * history = fd_sysvar_cache_stake_history( slot_ctx->sysvar_cache, slot_ctx->runtime_wksp );
28962899
if( FD_UNLIKELY( !history ) ) {
28972900
FD_LOG_ERR(( "StakeHistory sysvar is missing from sysvar cache" ));
28982901
}

src/flamenco/runtime/program/fd_address_lookup_table_program.c

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ create_lookup_table( fd_exec_instr_ctx_t * ctx,
259259
ulong derivation_slot = 1UL;
260260

261261
do {
262-
fd_slot_hashes_global_t const * slot_hashes_global = fd_sysvar_cache_slot_hashes( ctx->txn_ctx->sysvar_cache );
262+
fd_slot_hashes_global_t const * slot_hashes_global = fd_sysvar_cache_slot_hashes( ctx->txn_ctx->sysvar_cache, ctx->txn_ctx->runtime_pub_wksp );
263263

264264
if( FD_UNLIKELY( !slot_hashes_global ) ) {
265265
return FD_EXECUTOR_INSTR_ERR_UNSUPPORTED_SYSVAR;
@@ -678,18 +678,11 @@ extend_lookup_table( fd_exec_instr_ctx_t * ctx,
678678
}
679679

680680
/* https://github.com/solana-labs/solana/blob/v1.17.4/programs/address-lookup-table/src/processor.rs#L290 */
681-
// fd_sol_sysvar_clock_t clock[1];
682-
// if( FD_UNLIKELY( !fd_sysvar_clock_read( clock,
683-
// ctx->txn_ctx->sysvar_cache,
684-
// ctx->txn_ctx->funk,
685-
// ctx->txn_ctx->funk_txn,
686-
// NULL ) ) )
687-
// return FD_EXECUTOR_INSTR_ERR_UNSUPPORTED_SYSVAR;
688-
689681
fd_sol_sysvar_clock_t const * clock = fd_sysvar_clock_read( ctx->txn_ctx->sysvar_cache,
690682
ctx->txn_ctx->funk,
691683
ctx->txn_ctx->funk_txn,
692-
ctx->txn_ctx->spad );
684+
ctx->txn_ctx->spad,
685+
ctx->txn_ctx->runtime_pub_wksp );
693686
if( FD_UNLIKELY( !clock ) ) {
694687
return FD_EXECUTOR_INSTR_ERR_UNSUPPORTED_SYSVAR;
695688
}
@@ -886,7 +879,8 @@ deactivate_lookup_table( fd_exec_instr_ctx_t * ctx ) {
886879
fd_sol_sysvar_clock_t const * clock = fd_sysvar_clock_read( ctx->txn_ctx->sysvar_cache,
887880
ctx->txn_ctx->funk,
888881
ctx->txn_ctx->funk_txn,
889-
ctx->txn_ctx->spad );
882+
ctx->txn_ctx->spad,
883+
ctx->txn_ctx->runtime_pub_wksp );
890884
if( FD_UNLIKELY( !clock ) ) {
891885
return FD_EXECUTOR_INSTR_ERR_UNSUPPORTED_SYSVAR;
892886
}
@@ -1008,13 +1002,14 @@ close_lookup_table( fd_exec_instr_ctx_t * ctx ) {
10081002
fd_sol_sysvar_clock_t const * clock = fd_sysvar_clock_read( ctx->txn_ctx->sysvar_cache,
10091003
ctx->txn_ctx->funk,
10101004
ctx->txn_ctx->funk_txn,
1011-
ctx->txn_ctx->spad );
1005+
ctx->txn_ctx->spad,
1006+
ctx->txn_ctx->runtime_pub_wksp );
10121007
if( FD_UNLIKELY( !clock ) ) {
10131008
return FD_EXECUTOR_INSTR_ERR_UNSUPPORTED_SYSVAR;
10141009
}
10151010

10161011
/* https://github.com/solana-labs/solana/blob/v1.17.4/programs/address-lookup-table/src/processor.rs#L438 */
1017-
fd_slot_hashes_global_t const * slot_hashes_global = fd_sysvar_cache_slot_hashes( ctx->txn_ctx->sysvar_cache );
1012+
fd_slot_hashes_global_t const * slot_hashes_global = fd_sysvar_cache_slot_hashes( ctx->txn_ctx->sysvar_cache, ctx->txn_ctx->runtime_pub_wksp );
10181013
if( FD_UNLIKELY( !slot_hashes_global ) ) {
10191014
return FD_EXECUTOR_INSTR_ERR_UNSUPPORTED_SYSVAR;
10201015
}

src/flamenco/runtime/program/fd_bpf_loader_program.c

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -794,19 +794,11 @@ process_loader_upgradeable_instruction( fd_exec_instr_ctx_t * instr_ctx ) {
794794
return err;
795795
}
796796

797-
// fd_sol_sysvar_clock_t clock = {0};
798-
// if( FD_UNLIKELY( !fd_sysvar_clock_read( &clock,
799-
// instr_ctx->txn_ctx->sysvar_cache,
800-
// instr_ctx->txn_ctx->funk,
801-
// instr_ctx->txn_ctx->funk_txn,
802-
// NULL ) ) ) {
803-
// return FD_EXECUTOR_INSTR_ERR_GENERIC_ERR;
804-
// }
805-
806797
fd_sol_sysvar_clock_t const * clock = fd_sysvar_clock_read( instr_ctx->txn_ctx->sysvar_cache,
807798
instr_ctx->txn_ctx->funk,
808799
instr_ctx->txn_ctx->funk_txn,
809-
instr_ctx->txn_ctx->spad );
800+
instr_ctx->txn_ctx->spad,
801+
instr_ctx->txn_ctx->runtime_pub_wksp );
810802
if( FD_UNLIKELY( !clock ) ) {
811803
return FD_EXECUTOR_INSTR_ERR_GENERIC_ERR;
812804
}
@@ -1262,7 +1254,8 @@ process_loader_upgradeable_instruction( fd_exec_instr_ctx_t * instr_ctx ) {
12621254
fd_sol_sysvar_clock_t const * clock = fd_sysvar_clock_read( instr_ctx->txn_ctx->sysvar_cache,
12631255
instr_ctx->txn_ctx->funk,
12641256
instr_ctx->txn_ctx->funk_txn,
1265-
instr_ctx->txn_ctx->spad );
1257+
instr_ctx->txn_ctx->spad,
1258+
instr_ctx->txn_ctx->runtime_pub_wksp );
12661259
if( FD_UNLIKELY( !clock ) ) {
12671260
return FD_EXECUTOR_INSTR_ERR_GENERIC_ERR;
12681261
}
@@ -1675,7 +1668,8 @@ process_loader_upgradeable_instruction( fd_exec_instr_ctx_t * instr_ctx ) {
16751668
fd_sol_sysvar_clock_t const * clock = fd_sysvar_clock_read( instr_ctx->txn_ctx->sysvar_cache,
16761669
instr_ctx->txn_ctx->funk,
16771670
instr_ctx->txn_ctx->funk_txn,
1678-
instr_ctx->txn_ctx->spad );
1671+
instr_ctx->txn_ctx->spad,
1672+
instr_ctx->txn_ctx->runtime_pub_wksp );
16791673
if( FD_UNLIKELY( !clock ) ) {
16801674
return FD_EXECUTOR_INSTR_ERR_UNSUPPORTED_SYSVAR;
16811675
}
@@ -1799,7 +1793,8 @@ process_loader_upgradeable_instruction( fd_exec_instr_ctx_t * instr_ctx ) {
17991793
fd_sol_sysvar_clock_t const * clock = fd_sysvar_clock_read( instr_ctx->txn_ctx->sysvar_cache,
18001794
instr_ctx->txn_ctx->funk,
18011795
instr_ctx->txn_ctx->funk_txn,
1802-
instr_ctx->txn_ctx->spad );
1796+
instr_ctx->txn_ctx->spad,
1797+
instr_ctx->txn_ctx->runtime_pub_wksp );
18031798
if( FD_UNLIKELY( !clock ) ) {
18041799
return FD_EXECUTOR_INSTR_ERR_UNSUPPORTED_SYSVAR;
18051800
}
@@ -1974,7 +1969,7 @@ process_loader_upgradeable_instruction( fd_exec_instr_ctx_t * instr_ctx ) {
19741969
}
19751970

19761971
/* https://github.com/anza-xyz/agave/blob/v2.2.6/programs/bpf_loader/src/lib.rs#L1356-L1359 */
1977-
fd_sol_sysvar_clock_t const * clock = fd_sysvar_cache_clock( instr_ctx->txn_ctx->sysvar_cache );
1972+
fd_sol_sysvar_clock_t const * clock = fd_sysvar_cache_clock( instr_ctx->txn_ctx->sysvar_cache, instr_ctx->txn_ctx->runtime_pub_wksp );
19781973
if( FD_UNLIKELY( clock==NULL ) ) {
19791974
return FD_EXECUTOR_INSTR_ERR_UNSUPPORTED_SYSVAR;
19801975
}

0 commit comments

Comments
 (0)