From 707744067c26dfb43182637857678749cf6af662 Mon Sep 17 00:00:00 2001 From: Ishan Bhatt Date: Fri, 27 Jun 2025 15:27:37 +0000 Subject: [PATCH 01/27] intiial --- src/flamenco/runtime/fd_runtime.c | 49 ++++++++++--------- .../runtime/sysvar/fd_sysvar_recent_hashes.c | 44 ++++++++++------- .../runtime/sysvar/fd_sysvar_recent_hashes.h | 20 +++++--- .../runtime/tests/harness/fd_block_harness.c | 2 +- .../runtime/tests/harness/fd_txn_harness.c | 4 +- 5 files changed, 69 insertions(+), 50 deletions(-) diff --git a/src/flamenco/runtime/fd_runtime.c b/src/flamenco/runtime/fd_runtime.c index ed0d0ba68f..c5e5249a93 100644 --- a/src/flamenco/runtime/fd_runtime.c +++ b/src/flamenco/runtime/fd_runtime.c @@ -464,19 +464,22 @@ fd_runtime_update_rent_epoch( fd_bank_t * bank, } static void -fd_runtime_freeze( fd_exec_slot_ctx_t * slot_ctx, fd_spad_t * runtime_spad ) { +fd_runtime_freeze( fd_bank_t * bank, + fd_funk_t * funk, + fd_funk_txn_t * funk_txn, + fd_spad_t * runtime_spad ) { - fd_runtime_update_rent_epoch( slot_ctx->bank, slot_ctx->funk, slot_ctx->funk_txn ); + fd_runtime_update_rent_epoch( bank, funk, funk_txn ); - fd_sysvar_recent_hashes_update( slot_ctx, runtime_spad ); + fd_sysvar_recent_hashes_update( bank, funk, funk_txn, runtime_spad ); ulong fees = 0UL; ulong burn = 0UL; - ulong execution_fees = fd_bank_execution_fees_get( slot_ctx->bank ); - ulong priority_fees = fd_bank_priority_fees_get( slot_ctx->bank ); + ulong execution_fees = fd_bank_execution_fees_get( bank ); + ulong priority_fees = fd_bank_priority_fees_get( bank ); - if( FD_FEATURE_ACTIVE_BANK( slot_ctx->bank, reward_full_priority_fee ) ) { + if( FD_FEATURE_ACTIVE_BANK( bank, reward_full_priority_fee ) ) { ulong half_fee = execution_fees / 2; fees = fd_ulong_sat_add( priority_fees, execution_fees - half_fee ); burn = half_fee; @@ -494,30 +497,30 @@ fd_runtime_freeze( fd_exec_slot_ctx_t * slot_ctx, fd_spad_t * runtime_spad ) { /* do_create=1 because we might wanna pay fees to a leader account that we've purged due to 0 balance. */ - fd_epoch_leaders_t const * leaders = fd_bank_epoch_leaders_locking_query( slot_ctx->bank ); + fd_epoch_leaders_t const * leaders = fd_bank_epoch_leaders_locking_query( bank ); if( FD_UNLIKELY( !leaders ) ) { FD_LOG_WARNING(( "fd_runtime_freeze: leaders not found" )); break; } - fd_pubkey_t const * leader = fd_epoch_leaders_get( leaders, slot_ctx->slot ); + fd_pubkey_t const * leader = fd_epoch_leaders_get( leaders, bank->slot ); if( FD_UNLIKELY( !leader ) ) { FD_LOG_WARNING(( "fd_runtime_freeze: leader not found" )); break; } - int err = fd_txn_account_init_from_funk_mutable( rec, leader, slot_ctx->funk, slot_ctx->funk_txn, 1, 0UL ); + int err = fd_txn_account_init_from_funk_mutable( rec, leader, funk, funk_txn, 1, 0UL ); if( FD_UNLIKELY( err ) ) { FD_LOG_WARNING(("fd_runtime_freeze: fd_txn_account_init_from_funk_mutable for leader (%s) failed (%d)", FD_BASE58_ENC_32_ALLOCA( leader ), err)); burn = fd_ulong_sat_add( burn, fees ); break; } - fd_bank_epoch_leaders_end_locking_query( slot_ctx->bank ); + fd_bank_epoch_leaders_end_locking_query( bank ); - if ( FD_LIKELY( FD_FEATURE_ACTIVE_BANK( slot_ctx->bank, validate_fee_collector_account ) ) ) { + if ( FD_LIKELY( FD_FEATURE_ACTIVE_BANK( bank, validate_fee_collector_account ) ) ) { ulong _burn; - if( FD_UNLIKELY( _burn=fd_runtime_validate_fee_collector( slot_ctx->bank, rec, fees ) ) ) { + if( FD_UNLIKELY( _burn=fd_runtime_validate_fee_collector( bank, rec, fees ) ) ) { if( FD_UNLIKELY( _burn!=fees ) ) { FD_LOG_ERR(( "expected _burn(%lu)==fees(%lu)", _burn, fees )); } @@ -529,22 +532,22 @@ fd_runtime_freeze( fd_exec_slot_ctx_t * slot_ctx, fd_spad_t * runtime_spad ) { /* TODO: is it ok to not check the overflow error here? */ rec->vt->checked_add_lamports( rec, fees ); - rec->vt->set_slot( rec, slot_ctx->slot ); + rec->vt->set_slot( rec, bank->slot ); - fd_txn_account_mutable_fini( rec, slot_ctx->funk, slot_ctx->funk_txn ); + fd_txn_account_mutable_fini( rec, funk, funk_txn ); } while(0); - ulong old = fd_bank_capitalization_get( slot_ctx->bank ); - fd_bank_capitalization_set( slot_ctx->bank, fd_ulong_sat_sub( old, burn ) ); - FD_LOG_DEBUG(( "fd_runtime_freeze: burn %lu, capitalization %lu->%lu ", burn, old, fd_bank_capitalization_get( slot_ctx->bank ) )); + ulong old = fd_bank_capitalization_get( bank ); + fd_bank_capitalization_set( bank, fd_ulong_sat_sub( old, burn ) ); + FD_LOG_DEBUG(( "fd_runtime_freeze: burn %lu, capitalization %lu->%lu ", burn, old, fd_bank_capitalization_get( bank ) )); - fd_bank_execution_fees_set( slot_ctx->bank, 0UL ); + fd_bank_execution_fees_set( bank, 0UL ); - fd_bank_priority_fees_set( slot_ctx->bank, 0UL ); + fd_bank_priority_fees_set( bank, 0UL ); } - fd_runtime_run_incinerator( slot_ctx->bank, slot_ctx->funk, slot_ctx->funk_txn ); + fd_runtime_run_incinerator( bank, funk, funk_txn ); } @@ -1326,7 +1329,7 @@ fd_runtime_block_execute_finalize_start( fd_exec_slot_ctx_t * slot_c fd_sysvar_slot_history_update( slot_ctx, runtime_spad ); /* This slot is now "frozen" and can't be changed anymore. */ - fd_runtime_freeze( slot_ctx, runtime_spad ); + fd_runtime_freeze( slot_ctx->bank, slot_ctx->funk, slot_ctx->funk_txn, runtime_spad ); int result = fd_bpf_scan_and_create_bpf_program_cache_entry( slot_ctx, runtime_spad ); if( FD_UNLIKELY( result ) ) { @@ -3111,7 +3114,7 @@ fd_runtime_block_collect_txns( fd_runtime_block_info_t const * block_info, static void fd_runtime_init_program( fd_exec_slot_ctx_t * slot_ctx, fd_spad_t * runtime_spad ) { - fd_sysvar_recent_hashes_init( slot_ctx, runtime_spad ); + fd_sysvar_recent_hashes_init( slot_ctx->bank, slot_ctx->funk, slot_ctx->funk_txn, runtime_spad ); fd_sysvar_clock_init( slot_ctx->bank, slot_ctx->funk, slot_ctx->funk_txn ); fd_sysvar_slot_history_init( slot_ctx, runtime_spad ); fd_sysvar_slot_hashes_init( slot_ctx, runtime_spad ); @@ -3436,7 +3439,7 @@ fd_runtime_process_genesis_block( fd_exec_slot_ctx_t * slot_ctx, } } - fd_runtime_freeze( slot_ctx, runtime_spad ); + fd_runtime_freeze( slot_ctx->bank, slot_ctx->funk, slot_ctx->funk_txn, runtime_spad ); /* sort and update bank hash */ fd_hash_t * bank_hash = fd_bank_bank_hash_modify( slot_ctx->bank ); diff --git a/src/flamenco/runtime/sysvar/fd_sysvar_recent_hashes.c b/src/flamenco/runtime/sysvar/fd_sysvar_recent_hashes.c index 9813558f08..ae8c0481a6 100644 --- a/src/flamenco/runtime/sysvar/fd_sysvar_recent_hashes.c +++ b/src/flamenco/runtime/sysvar/fd_sysvar_recent_hashes.c @@ -23,8 +23,8 @@ account data for the recent blockhashes sysvar. */ static void -encode_rbh_from_blockhash_queue( fd_exec_slot_ctx_t * slot_ctx, uchar * enc ) { - fd_block_hash_queue_global_t const * bhq = fd_bank_block_hash_queue_query( slot_ctx->bank ); +encode_rbh_from_blockhash_queue( fd_bank_t * bank, uchar * enc ) { + fd_block_hash_queue_global_t const * bhq = fd_bank_block_hash_queue_query( bank ); fd_hash_hash_age_pair_t_mapnode_t * ages_pool = fd_block_hash_queue_ages_pool_join( bhq ); fd_hash_hash_age_pair_t_mapnode_t * ages_root = fd_block_hash_queue_ages_root_join( bhq ); @@ -55,29 +55,31 @@ encode_rbh_from_blockhash_queue( fd_exec_slot_ctx_t * slot_ctx, uchar * enc ) { // https://github.com/solana-labs/solana/blob/8f2c8b8388a495d2728909e30460aa40dcc5d733/sdk/program/src/fee_calculator.rs#L110 void -fd_sysvar_recent_hashes_init( fd_exec_slot_ctx_t * slot_ctx, - fd_spad_t * runtime_spad ) { +fd_sysvar_recent_hashes_init( fd_bank_t * bank, + fd_funk_t * funk, + fd_funk_txn_t * funk_txn, + fd_spad_t * runtime_spad ) { FD_SPAD_FRAME_BEGIN( runtime_spad ) { - if( slot_ctx->slot != 0 ) { + if( bank->slot != 0 ) { return; } ulong sz = FD_RECENT_BLOCKHASHES_ACCOUNT_MAX_SIZE; uchar * enc = fd_spad_alloc( runtime_spad, FD_SPAD_ALIGN, sz ); fd_memset( enc, 0, sz ); - encode_rbh_from_blockhash_queue( slot_ctx, enc ); - fd_sysvar_set( slot_ctx->bank, slot_ctx->funk, slot_ctx->funk_txn, &fd_sysvar_owner_id, &fd_sysvar_recent_block_hashes_id, enc, sz, slot_ctx->slot ); + encode_rbh_from_blockhash_queue( bank, enc ); + fd_sysvar_set( bank, funk, funk_txn, &fd_sysvar_owner_id, &fd_sysvar_recent_block_hashes_id, enc, sz, bank->slot ); } FD_SPAD_FRAME_END; } // https://github.com/anza-xyz/agave/blob/e8750ba574d9ac7b72e944bc1227dc7372e3a490/accounts-db/src/blockhash_queue.rs#L113 static void -register_blockhash( fd_exec_slot_ctx_t * slot_ctx, fd_hash_t const * hash ) { +register_blockhash( fd_bank_t * bank, fd_hash_t const * hash ) { - fd_block_hash_queue_global_t * bhq = fd_bank_block_hash_queue_modify( slot_ctx->bank ); + fd_block_hash_queue_global_t * bhq = fd_bank_block_hash_queue_modify( bank ); fd_hash_hash_age_pair_t_mapnode_t * ages_pool = fd_block_hash_queue_ages_pool_join( bhq ); fd_hash_hash_age_pair_t_mapnode_t * ages_root = fd_block_hash_queue_ages_root_join( bhq ); bhq->last_hash_index++; @@ -97,9 +99,12 @@ register_blockhash( fd_exec_slot_ctx_t * slot_ctx, fd_hash_t const * hash ) { } fd_hash_hash_age_pair_t_mapnode_t * node = fd_hash_hash_age_pair_t_map_acquire( ages_pool ); - node->elem = (fd_hash_hash_age_pair_t){ + node->elem = (fd_hash_hash_age_pair_t) { .key = *hash, - .val = (fd_hash_age_t){ .hash_index = bhq->last_hash_index, .fee_calculator = (fd_fee_calculator_t){ .lamports_per_signature = fd_bank_lamports_per_signature_get( slot_ctx->bank ) }, .timestamp = (ulong)fd_log_wallclock() } + .val = (fd_hash_age_t){ .hash_index = bhq->last_hash_index, + .fee_calculator = (fd_fee_calculator_t) { + .lamports_per_signature = fd_bank_lamports_per_signature_get( bank ) }, + .timestamp = (ulong)fd_log_wallclock() } }; // https://github.com/anza-xyz/agave/blob/e8750ba574d9ac7b72e944bc1227dc7372e3a490/accounts-db/src/blockhash_queue.rs#L121-L128 fd_hash_hash_age_pair_t_map_insert( ages_pool, &ages_root, node ); @@ -117,11 +122,14 @@ register_blockhash( fd_exec_slot_ctx_t * slot_ctx, fd_hash_t const * hash ) { 3. Manually serialize the recent blockhashes 4. Set the sysvar account with the new data */ void -fd_sysvar_recent_hashes_update( fd_exec_slot_ctx_t * slot_ctx, fd_spad_t * runtime_spad ) { +fd_sysvar_recent_hashes_update( fd_bank_t * bank, + fd_funk_t * funk, + fd_funk_txn_t * funk_txn, + fd_spad_t * runtime_spad ) { FD_SPAD_FRAME_BEGIN( runtime_spad ) { /* Update the blockhash queue */ - register_blockhash( slot_ctx, fd_bank_poh_query( slot_ctx->bank ) ); + register_blockhash( bank, fd_bank_poh_query( bank ) ); /* Derive the new sysvar recent blockhashes from the blockhash queue */ ulong sz = FD_RECENT_BLOCKHASHES_ACCOUNT_MAX_SIZE; @@ -130,17 +138,17 @@ fd_sysvar_recent_hashes_update( fd_exec_slot_ctx_t * slot_ctx, fd_spad_t * runti fd_memset( enc, 0, sz ); /* Encode the recent blockhashes */ - encode_rbh_from_blockhash_queue( slot_ctx, enc ); + encode_rbh_from_blockhash_queue( bank, enc ); /* Set the sysvar from the encoded data */ - fd_sysvar_set( slot_ctx->bank, - slot_ctx->funk, - slot_ctx->funk_txn, + fd_sysvar_set( bank, + funk, + funk_txn, &fd_sysvar_owner_id, &fd_sysvar_recent_block_hashes_id, enc_start, sz, - slot_ctx->slot ); + bank->slot ); } FD_SPAD_FRAME_END; } diff --git a/src/flamenco/runtime/sysvar/fd_sysvar_recent_hashes.h b/src/flamenco/runtime/sysvar/fd_sysvar_recent_hashes.h index b951e14eb8..6e1f8b6bf9 100644 --- a/src/flamenco/runtime/sysvar/fd_sysvar_recent_hashes.h +++ b/src/flamenco/runtime/sysvar/fd_sysvar_recent_hashes.h @@ -1,6 +1,7 @@ #ifndef HEADER_fd_src_flamenco_runtime_sysvar_fd_recent_hashes_h #define HEADER_fd_src_flamenco_runtime_sysvar_fd_recent_hashes_h +#include "../fd_bank.h" #include "../../types/fd_types.h" #include "../../fd_flamenco_base.h" #include "../../../funk/fd_funk.h" @@ -19,13 +20,18 @@ FD_PROTOTYPES_BEGIN /* Initialize the recent hashes sysvar account. */ void -fd_sysvar_recent_hashes_init( fd_exec_slot_ctx_t * slot_ctx, - fd_spad_t * runtime_spad ); +fd_sysvar_recent_hashes_init( fd_bank_t * bank, + fd_funk_t * funk, + fd_funk_txn_t * funk_txn, + fd_spad_t * runtime_spad ); -/* Update the recent hashes sysvar account. This should be called at the start of every slot, before execution commences. */ +/* Update the recent hashes sysvar account. This should be called at + the start of every slot, before execution commences. */ void -fd_sysvar_recent_hashes_update( fd_exec_slot_ctx_t * slot_ctx, - fd_spad_t * runtime_spad ); +fd_sysvar_recent_hashes_update( fd_bank_t * bank, + fd_funk_t * funk, + fd_funk_txn_t * funk_txn, + fd_spad_t * runtime_spad ); /* fd_sysvar_recent_hashes_read reads the recent hashes sysvar from funk. @@ -33,7 +39,9 @@ fd_sysvar_recent_hashes_update( fd_exec_slot_ctx_t * slot_ctx, lamports, this function returns NULL. */ fd_recent_block_hashes_global_t * -fd_sysvar_recent_hashes_read( fd_funk_t * funk, fd_funk_txn_t * funk_txn, fd_spad_t * spad ); +fd_sysvar_recent_hashes_read( fd_funk_t * funk, + fd_funk_txn_t * funk_txn, + fd_spad_t * spad ); FD_PROTOTYPES_END diff --git a/src/flamenco/runtime/tests/harness/fd_block_harness.c b/src/flamenco/runtime/tests/harness/fd_block_harness.c index e124133a65..1d0f61b4df 100644 --- a/src/flamenco/runtime/tests/harness/fd_block_harness.c +++ b/src/flamenco/runtime/tests/harness/fd_block_harness.c @@ -447,7 +447,7 @@ fd_runtime_fuzz_block_ctx_create( fd_runtime_fuzz_runner_t * runner, fd_block_block_hash_entry_t blockhash_entry; memcpy( &blockhash_entry.blockhash, test_ctx->blockhash_queue[i]->bytes, sizeof(fd_hash_t) ); fd_bank_poh_set( slot_ctx->bank, blockhash_entry.blockhash ); - fd_sysvar_recent_hashes_update( slot_ctx, runner->spad ); + fd_sysvar_recent_hashes_update( slot_ctx->bank, slot_ctx->funk, slot_ctx->funk_txn, runner->spad ); } // Set the current poh from the input (we skip POH verification in this fuzzing target) diff --git a/src/flamenco/runtime/tests/harness/fd_txn_harness.c b/src/flamenco/runtime/tests/harness/fd_txn_harness.c index b8085d7ae5..0cfd2bcd9e 100644 --- a/src/flamenco/runtime/tests/harness/fd_txn_harness.c +++ b/src/flamenco/runtime/tests/harness/fd_txn_harness.c @@ -233,7 +233,7 @@ fd_runtime_fuzz_txn_ctx_create( fd_runtime_fuzz_runner_t * runner, fd_block_block_hash_entry_t blockhash_entry; memcpy( &blockhash_entry.blockhash, test_ctx->blockhash_queue[i]->bytes, sizeof(fd_hash_t) ); fd_bank_poh_set( slot_ctx->bank, blockhash_entry.blockhash ); - fd_sysvar_recent_hashes_update( slot_ctx, runner->spad ); + fd_sysvar_recent_hashes_update( slot_ctx->bank, slot_ctx->funk, slot_ctx->funk_txn, runner->spad ); } } else { // Add a default empty blockhash and use it as genesis @@ -243,7 +243,7 @@ fd_runtime_fuzz_txn_ctx_create( fd_runtime_fuzz_runner_t * runner, fd_block_block_hash_entry_t blockhash_entry; memcpy( &blockhash_entry.blockhash, empty_bytes, sizeof(fd_hash_t) ); fd_bank_poh_set( slot_ctx->bank, blockhash_entry.blockhash ); - fd_sysvar_recent_hashes_update( slot_ctx, runner->spad ); + fd_sysvar_recent_hashes_update( slot_ctx->bank, slot_ctx->funk, slot_ctx->funk_txn, runner->spad ); } /* Create the raw txn (https://solana.com/docs/core/transactions#transaction-size) */ From 819e87f5b83bac72d9842b32998fdfbef241f683 Mon Sep 17 00:00:00 2001 From: Ishan Bhatt Date: Fri, 27 Jun 2025 16:00:16 +0000 Subject: [PATCH 02/27] removing slot ctx pt 2 of many --- src/discof/replay/fd_replay_tile.c | 8 +- src/flamenco/runtime/fd_hashes.c | 25 +++--- src/flamenco/runtime/fd_hashes.h | 18 ++-- src/flamenco/runtime/fd_runtime.c | 83 +++++++++++-------- src/flamenco/runtime/fd_runtime.h | 12 ++- .../runtime/program/fd_bpf_program_util.c | 69 +++++++-------- .../runtime/program/fd_bpf_program_util.h | 6 +- .../sysvar/fd_sysvar_last_restart_slot.c | 47 ++++++----- .../sysvar/fd_sysvar_last_restart_slot.h | 9 +- .../runtime/sysvar/fd_sysvar_slot_hashes.c | 32 ++++--- .../runtime/sysvar/fd_sysvar_slot_hashes.h | 17 +++- .../runtime/sysvar/fd_sysvar_slot_history.c | 34 +++++--- .../runtime/sysvar/fd_sysvar_slot_history.h | 12 ++- .../runtime/tests/harness/fd_block_harness.c | 2 +- .../runtime/tests/harness/fd_instr_harness.c | 2 +- .../runtime/tests/harness/fd_txn_harness.c | 6 +- 16 files changed, 225 insertions(+), 157 deletions(-) diff --git a/src/discof/replay/fd_replay_tile.c b/src/discof/replay/fd_replay_tile.c index 4286ccbe3c..1c38aff954 100644 --- a/src/discof/replay/fd_replay_tile.c +++ b/src/discof/replay/fd_replay_tile.c @@ -1087,7 +1087,11 @@ prepare_new_block_execution( fd_replay_tile_ctx_t * ctx, an epoch). We pop a frame when rewards are done being distributed. */ fd_spad_push( ctx->runtime_spad ); - int res = fd_runtime_block_execute_prepare( ctx->slot_ctx, ctx->blockstore, ctx->runtime_spad ); + int res = fd_runtime_block_execute_prepare( ctx->slot_ctx->bank, + ctx->slot_ctx->funk, + ctx->slot_ctx->funk_txn, + ctx->blockstore, + ctx->runtime_spad ); if( res != FD_RUNTIME_EXECUTE_SUCCESS ) { FD_LOG_ERR(( "block prep execute failed" )); } @@ -1580,7 +1584,7 @@ init_after_snapshot( fd_replay_tile_ctx_t * ctx, fd_sha256_hash( poh->hash, 32UL, poh->hash ); } - FD_TEST( fd_runtime_block_execute_prepare( ctx->slot_ctx, ctx->blockstore, ctx->runtime_spad ) == 0 ); + FD_TEST( fd_runtime_block_execute_prepare( ctx->slot_ctx->bank, ctx->slot_ctx->funk, ctx->slot_ctx->funk_txn, ctx->blockstore, ctx->runtime_spad ) == 0 ); fd_runtime_block_info_t info = { .signature_cnt = 0 }; fd_exec_para_cb_ctx_t exec_para_ctx_block_finalize = { diff --git a/src/flamenco/runtime/fd_hashes.c b/src/flamenco/runtime/fd_hashes.c index 7403f2dca6..cdf3bd06ec 100644 --- a/src/flamenco/runtime/fd_hashes.c +++ b/src/flamenco/runtime/fd_hashes.c @@ -410,26 +410,25 @@ fd_account_hash_task( void * tpool, for( ulong i=start_idx; i<=stop_idx; i++ ) { fd_accounts_hash_task_info_t * task_info = &task_data->info[i]; - fd_exec_slot_ctx_t * slot_ctx = task_info->slot_ctx; - fd_account_hash( slot_ctx->funk, - slot_ctx->funk_txn, + fd_account_hash( task_info->funk, + task_info->funk_txn, task_info, lthash, - slot_ctx->slot, - fd_bank_features_query( slot_ctx->bank ) + task_info->bank->slot, + fd_bank_features_query( task_info->bank ) ); } } void -fd_collect_modified_accounts( fd_exec_slot_ctx_t * slot_ctx, +fd_collect_modified_accounts( fd_bank_t * bank, + fd_funk_t * funk, + fd_funk_txn_t * funk_txn, fd_accounts_hash_task_data_t * task_data, fd_spad_t * runtime_spad ) { - fd_funk_t * funk = slot_ctx->funk; - fd_funk_txn_t * txn = slot_ctx->funk_txn; ulong rec_cnt = 0; - for( fd_funk_rec_t const * rec = fd_funk_txn_first_rec( funk, txn ); + for( fd_funk_rec_t const * rec = fd_funk_txn_first_rec( funk, funk_txn ); NULL != rec; rec = fd_funk_txn_next_rec( funk, rec ) ) { @@ -451,7 +450,7 @@ fd_collect_modified_accounts( fd_exec_slot_ctx_t * slot_ctx, /* Iterate over accounts that have been changed in the current database transaction. */ ulong recs_iterated = 0; - for( fd_funk_rec_t const * rec = fd_funk_txn_first_rec( funk, txn ); + for( fd_funk_rec_t const * rec = fd_funk_txn_first_rec( funk, funk_txn ); NULL != rec; rec = fd_funk_txn_next_rec( funk, rec ) ) { @@ -460,7 +459,9 @@ fd_collect_modified_accounts( fd_exec_slot_ctx_t * slot_ctx, fd_accounts_hash_task_info_t * task_info = &task_data->info[recs_iterated++]; memcpy( task_info->acc_pubkey, rec->pair.key->uc, sizeof(fd_pubkey_t) ); - task_info->slot_ctx = slot_ctx; + task_info->bank = bank; + task_info->funk = funk; + task_info->funk_txn = funk_txn; task_info->hash_changed = 0; task_info->should_erase = 0; } @@ -620,7 +621,7 @@ fd_update_hash_bank_tpool( fd_exec_slot_ctx_t * slot_ctx, alignof(fd_accounts_hash_task_data_t), sizeof(fd_accounts_hash_task_data_t) ); - fd_collect_modified_accounts( slot_ctx, task_data, runtime_spad ); + fd_collect_modified_accounts( slot_ctx->bank, slot_ctx->funk, slot_ctx->funk_txn, task_data, runtime_spad ); ulong wcnt = 0UL; diff --git a/src/flamenco/runtime/fd_hashes.h b/src/flamenco/runtime/fd_hashes.h index 1519ae4388..aab22ec82a 100644 --- a/src/flamenco/runtime/fd_hashes.h +++ b/src/flamenco/runtime/fd_hashes.h @@ -3,8 +3,8 @@ #include "../fd_flamenco_base.h" #include "../types/fd_types.h" -#include "../../funk/fd_funk.h" #include "../../ballet/lthash/fd_lthash.h" +#include "fd_bank.h" #include "fd_runtime_public.h" #define FD_PUBKEY_HASH_PAIR_ALIGN (16UL) @@ -31,11 +31,13 @@ struct fd_subrange_task_info { typedef struct fd_subrange_task_info fd_subrange_task_info_t; struct fd_accounts_hash_task_info { - fd_exec_slot_ctx_t * slot_ctx; - fd_pubkey_t acc_pubkey[1]; - fd_hash_t acc_hash[1]; - uint should_erase; - uint hash_changed; + fd_funk_t * funk; + fd_funk_txn_t * funk_txn; + fd_bank_t * bank; + fd_pubkey_t acc_pubkey[1]; + fd_hash_t acc_hash[1]; + uint should_erase; + uint hash_changed; }; typedef struct fd_accounts_hash_task_info fd_accounts_hash_task_info_t; @@ -90,7 +92,9 @@ fd_update_hash_bank_exec_hash( fd_exec_slot_ctx_t * slot_ctx, fd_spad_t * runtime_spad ); void -fd_collect_modified_accounts( fd_exec_slot_ctx_t * slot_ctx, +fd_collect_modified_accounts( fd_bank_t * bank, + fd_funk_t * funk, + fd_funk_txn_t * funk_txn, fd_accounts_hash_task_data_t * task_data, fd_spad_t * runtime_spad ); diff --git a/src/flamenco/runtime/fd_runtime.c b/src/flamenco/runtime/fd_runtime.c index c5e5249a93..98b19ccd40 100644 --- a/src/flamenco/runtime/fd_runtime.c +++ b/src/flamenco/runtime/fd_runtime.c @@ -781,27 +781,29 @@ fd_runtime_new_fee_rate_governor_derived( fd_bank_t * bank, } static int -fd_runtime_block_sysvar_update_pre_execute( fd_exec_slot_ctx_t * slot_ctx, - fd_spad_t * runtime_spad ) { +fd_runtime_block_sysvar_update_pre_execute( fd_bank_t * bank, + fd_funk_t * funk, + fd_funk_txn_t * funk_txn, + fd_spad_t * runtime_spad ) { // let (fee_rate_governor, fee_components_time_us) = measure_us!( // FeeRateGovernor::new_derived(&parent.fee_rate_governor, parent.signature_count()) // ); /* https://github.com/firedancer-io/solana/blob/dab3da8e7b667d7527565bddbdbecf7ec1fb868e/runtime/src/bank.rs#L1312-L1314 */ - fd_runtime_new_fee_rate_governor_derived( slot_ctx->bank, fd_bank_parent_signature_cnt_get( slot_ctx->bank ) ); + fd_runtime_new_fee_rate_governor_derived( bank, fd_bank_parent_signature_cnt_get( bank ) ); // TODO: move all these out to a fd_sysvar_update() call... long clock_update_time = -fd_log_wallclock(); - fd_sysvar_clock_update( slot_ctx->bank, slot_ctx->funk, slot_ctx->funk_txn, runtime_spad ); + fd_sysvar_clock_update( bank, funk, funk_txn, runtime_spad ); clock_update_time += fd_log_wallclock(); double clock_update_time_ms = (double)clock_update_time * 1e-6; - FD_LOG_INFO(( "clock updated - slot: %lu, elapsed: %6.6f ms", slot_ctx->slot, clock_update_time_ms )); + FD_LOG_INFO(( "clock updated - slot: %lu, elapsed: %6.6f ms", bank->slot, clock_update_time_ms )); // It has to go into the current txn previous info but is not in slot 0 - if( slot_ctx->slot != 0 ) { - fd_sysvar_slot_hashes_update( slot_ctx, runtime_spad ); + if( bank->slot != 0 ) { + fd_sysvar_slot_hashes_update( bank, funk, funk_txn, runtime_spad ); } - fd_sysvar_last_restart_slot_update( slot_ctx, runtime_spad ); + fd_sysvar_last_restart_slot_update( bank, funk, funk_txn, runtime_spad ); return 0; } @@ -1284,34 +1286,36 @@ fd_runtime_poh_verify( fd_poh_verifier_t * poh_info ) { } int -fd_runtime_block_execute_prepare( fd_exec_slot_ctx_t * slot_ctx, - fd_blockstore_t * blockstore, - fd_spad_t * runtime_spad ) { +fd_runtime_block_execute_prepare( fd_bank_t * bank, + fd_funk_t * funk, + fd_funk_txn_t * funk_txn, + fd_blockstore_t * blockstore, + fd_spad_t * runtime_spad ) { - if( blockstore && slot_ctx->slot != 0UL ) { + if( blockstore && bank->slot != 0UL ) { fd_blockstore_block_height_update( blockstore, - slot_ctx->slot, - fd_bank_block_height_get( slot_ctx->bank ) ); + bank->slot, + fd_bank_block_height_get( bank ) ); } - fd_bank_execution_fees_set( slot_ctx->bank, 0UL ); + fd_bank_execution_fees_set( bank, 0UL ); - fd_bank_priority_fees_set( slot_ctx->bank, 0UL ); + fd_bank_priority_fees_set( bank, 0UL ); - fd_bank_signature_count_set( slot_ctx->bank, 0UL ); + fd_bank_signature_count_set( bank, 0UL ); - fd_bank_txn_count_set( slot_ctx->bank, 0UL ); + fd_bank_txn_count_set( bank, 0UL ); - fd_bank_nonvote_txn_count_set( slot_ctx->bank, 0UL ); + fd_bank_nonvote_txn_count_set( bank, 0UL ); - fd_bank_failed_txn_count_set( slot_ctx->bank, 0UL ); + fd_bank_failed_txn_count_set( bank, 0UL ); - fd_bank_nonvote_failed_txn_count_set( slot_ctx->bank, 0UL ); + fd_bank_nonvote_failed_txn_count_set( bank, 0UL ); - fd_bank_total_compute_units_used_set( slot_ctx->bank, 0UL ); + fd_bank_total_compute_units_used_set( bank, 0UL ); - int result = fd_runtime_block_sysvar_update_pre_execute( slot_ctx, runtime_spad ); + int result = fd_runtime_block_sysvar_update_pre_execute( bank, funk, funk_txn, runtime_spad ); if( FD_UNLIKELY( result != 0 ) ) { FD_LOG_WARNING(("updating sysvars failed")); return result; @@ -1321,17 +1325,19 @@ fd_runtime_block_execute_prepare( fd_exec_slot_ctx_t * slot_ctx, } void -fd_runtime_block_execute_finalize_start( fd_exec_slot_ctx_t * slot_ctx, +fd_runtime_block_execute_finalize_start( fd_bank_t * bank, + fd_funk_t * funk, + fd_funk_txn_t * funk_txn, fd_spad_t * runtime_spad, fd_accounts_hash_task_data_t * * task_data, ulong lt_hash_cnt ) { - fd_sysvar_slot_history_update( slot_ctx, runtime_spad ); + fd_sysvar_slot_history_update( bank, funk, funk_txn, runtime_spad ); /* This slot is now "frozen" and can't be changed anymore. */ - fd_runtime_freeze( slot_ctx->bank, slot_ctx->funk, slot_ctx->funk_txn, runtime_spad ); + fd_runtime_freeze( bank, funk, funk_txn, runtime_spad ); - int result = fd_bpf_scan_and_create_bpf_program_cache_entry( slot_ctx, runtime_spad ); + int result = fd_bpf_scan_and_create_bpf_program_cache_entry( bank, funk, funk_txn, runtime_spad ); if( FD_UNLIKELY( result ) ) { FD_LOG_WARNING(( "update bpf program cache failed" )); return; @@ -1348,7 +1354,7 @@ fd_runtime_block_execute_finalize_start( fd_exec_slot_ctx_t * slot_c fd_lthash_zero( &((*task_data)->lthash_values)[i] ); } - fd_collect_modified_accounts( slot_ctx, *task_data, runtime_spad ); + fd_collect_modified_accounts( bank, funk, funk_txn, *task_data, runtime_spad ); } int @@ -1421,7 +1427,12 @@ fd_runtime_block_execute_finalize_para( fd_exec_slot_ctx_t * slot_ct fd_accounts_hash_task_data_t * task_data = NULL; - fd_runtime_block_execute_finalize_start( slot_ctx, runtime_spad, &task_data, worker_cnt ); + fd_runtime_block_execute_finalize_start( slot_ctx->bank, + slot_ctx->funk, + slot_ctx->funk_txn, + runtime_spad, + &task_data, + worker_cnt ); exec_para_ctx->fn_arg_1 = (void*)task_data; exec_para_ctx->fn_arg_2 = (void*)worker_cnt; @@ -3116,12 +3127,12 @@ fd_runtime_init_program( fd_exec_slot_ctx_t * slot_ctx, fd_spad_t * runtime_spad ) { fd_sysvar_recent_hashes_init( slot_ctx->bank, slot_ctx->funk, slot_ctx->funk_txn, runtime_spad ); fd_sysvar_clock_init( slot_ctx->bank, slot_ctx->funk, slot_ctx->funk_txn ); - fd_sysvar_slot_history_init( slot_ctx, runtime_spad ); - fd_sysvar_slot_hashes_init( slot_ctx, runtime_spad ); + fd_sysvar_slot_history_init( slot_ctx->bank, slot_ctx->funk, slot_ctx->funk_txn, runtime_spad ); + fd_sysvar_slot_hashes_init( slot_ctx->bank, slot_ctx->funk, slot_ctx->funk_txn, runtime_spad ); fd_sysvar_epoch_schedule_init( slot_ctx ); fd_sysvar_rent_init( slot_ctx ); fd_sysvar_stake_history_init( slot_ctx ); - fd_sysvar_last_restart_slot_init( slot_ctx ); + fd_sysvar_last_restart_slot_init( slot_ctx->bank, slot_ctx->funk, slot_ctx->funk_txn ); fd_builtin_programs_init( slot_ctx ); fd_stake_program_config_init( slot_ctx ); @@ -3417,7 +3428,7 @@ fd_runtime_process_genesis_block( fd_exec_slot_ctx_t * slot_ctx, fd_bank_total_compute_units_used_set( slot_ctx->bank, 0UL ); - fd_sysvar_slot_history_update( slot_ctx, runtime_spad ); + fd_sysvar_slot_history_update( slot_ctx->bank, slot_ctx->funk, slot_ctx->funk_txn, runtime_spad ); fd_runtime_update_leaders( slot_ctx->bank, 0, runtime_spad ); @@ -3853,7 +3864,11 @@ fd_runtime_block_execute_tpool( fd_exec_slot_ctx_t * slot_ctx, long block_execute_time = -fd_log_wallclock(); - int res = fd_runtime_block_execute_prepare( slot_ctx, blockstore, runtime_spad ); + int res = fd_runtime_block_execute_prepare( slot_ctx->bank, + slot_ctx->funk, + slot_ctx->funk_txn, + blockstore, + runtime_spad ); if( res != FD_RUNTIME_EXECUTE_SUCCESS ) { return res; } diff --git a/src/flamenco/runtime/fd_runtime.h b/src/flamenco/runtime/fd_runtime.h index a462108c9b..e58095e2cc 100644 --- a/src/flamenco/runtime/fd_runtime.h +++ b/src/flamenco/runtime/fd_runtime.h @@ -499,12 +499,16 @@ void fd_runtime_poh_verify( fd_poh_verifier_t * poh_info ); int -fd_runtime_block_execute_prepare( fd_exec_slot_ctx_t * slot_ctx, - fd_blockstore_t * blockstore, - fd_spad_t * runtime_spad ); +fd_runtime_block_execute_prepare( fd_bank_t * bank, + fd_funk_t * funk, + fd_funk_txn_t * funk_txn, + fd_blockstore_t * blockstore, + fd_spad_t * runtime_spad ); void -fd_runtime_block_execute_finalize_start( fd_exec_slot_ctx_t * slot_ctx, +fd_runtime_block_execute_finalize_start( fd_bank_t * bank, + fd_funk_t * funk, + fd_funk_txn_t * funk_txn, fd_spad_t * runtime_spad, fd_accounts_hash_task_data_t * * task_data, ulong lt_hash_cnt ); diff --git a/src/flamenco/runtime/program/fd_bpf_program_util.c b/src/flamenco/runtime/program/fd_bpf_program_util.c index 5cfdcd9578..723fa91d0a 100644 --- a/src/flamenco/runtime/program/fd_bpf_program_util.c +++ b/src/flamenco/runtime/program/fd_bpf_program_util.c @@ -80,7 +80,8 @@ fd_bpf_get_executable_program_content_for_v4_loader( fd_txn_account_t * pro } static int -fd_bpf_get_executable_program_content_for_upgradeable_loader( fd_exec_slot_ctx_t * slot_ctx, +fd_bpf_get_executable_program_content_for_upgradeable_loader( fd_funk_t * funk, + fd_funk_txn_t * funk_txn, fd_txn_account_t * program_acc, uchar const ** program_data, ulong * program_data_len, @@ -104,8 +105,8 @@ fd_bpf_get_executable_program_content_for_upgradeable_loader( fd_exec_slot_ctx_t if( fd_txn_account_init_from_funk_readonly( programdata_acc, programdata_address, - slot_ctx->funk, - slot_ctx->funk_txn ) != FD_ACC_MGR_SUCCESS ) { + funk, + funk_txn ) != FD_ACC_MGR_SUCCESS ) { return -1; } @@ -164,15 +165,15 @@ fd_bpf_get_sbpf_versions( uint * sbpf_min_version, } static int -fd_bpf_create_bpf_program_cache_entry( fd_exec_slot_ctx_t * slot_ctx, - fd_txn_account_t * program_acc, - fd_spad_t * runtime_spad ) { +fd_bpf_create_bpf_program_cache_entry( fd_bank_t * bank, + fd_funk_t * funk, + fd_funk_txn_t * funk_txn, + fd_txn_account_t * program_acc, + fd_spad_t * runtime_spad ) { FD_SPAD_FRAME_BEGIN( runtime_spad ) { fd_pubkey_t * program_pubkey = program_acc->pubkey; - fd_funk_t * funk = slot_ctx->funk; - fd_funk_txn_t * funk_txn = slot_ctx->funk_txn; fd_funk_rec_key_t id = fd_acc_mgr_cache_key( program_pubkey ); uchar const * program_data = NULL; @@ -183,7 +184,7 @@ fd_bpf_create_bpf_program_cache_entry( fd_exec_slot_ctx_t * slot_ctx, int res; if( !memcmp( program_acc->vt->get_owner( program_acc ), fd_solana_bpf_loader_upgradeable_program_id.key, sizeof(fd_pubkey_t) ) ) { - res = fd_bpf_get_executable_program_content_for_upgradeable_loader( slot_ctx, program_acc, &program_data, &program_data_len, runtime_spad ); + res = fd_bpf_get_executable_program_content_for_upgradeable_loader( funk, funk_txn, program_acc, &program_data, &program_data_len, runtime_spad ); } else if( !memcmp( program_acc->vt->get_owner( program_acc ), fd_solana_bpf_loader_v4_program_id.key, sizeof(fd_pubkey_t) ) ) { res = fd_bpf_get_executable_program_content_for_v4_loader( program_acc, &program_data, &program_data_len ); } else { @@ -198,8 +199,8 @@ fd_bpf_create_bpf_program_cache_entry( fd_exec_slot_ctx_t * slot_ctx, uint min_sbpf_version, max_sbpf_version; fd_bpf_get_sbpf_versions( &min_sbpf_version, &max_sbpf_version, - slot_ctx->slot, - fd_bank_features_query( slot_ctx->bank ) ); + bank->slot, + fd_bank_features_query( bank ) ); if( fd_sbpf_elf_peek( &elf_info, program_data, program_data_len, /* deploy checks */ 0, min_sbpf_version, max_sbpf_version ) == NULL ) { FD_LOG_DEBUG(( "fd_sbpf_elf_peek() failed: %s", fd_sbpf_strerror() )); return FD_EXECUTOR_INSTR_ERR_INVALID_ACC_DATA; @@ -242,8 +243,8 @@ fd_bpf_create_bpf_program_cache_entry( fd_exec_slot_ctx_t * slot_ctx, } fd_vm_syscall_register_slot( syscalls, - slot_ctx->slot, - fd_bank_features_query( slot_ctx->bank ), + bank->slot, + fd_bank_features_query( bank ), 0 ); /* Load program. */ @@ -264,13 +265,16 @@ fd_bpf_create_bpf_program_cache_entry( fd_exec_slot_ctx_t * slot_ctx, } fd_exec_instr_ctx_t dummy_instr_ctx = {0}; fd_exec_txn_ctx_t dummy_txn_ctx = {0}; - dummy_txn_ctx.slot = slot_ctx->slot; + dummy_txn_ctx.slot = bank->slot; - if( FD_UNLIKELY( !slot_ctx->bank ) ) { + ulong slot; + if( FD_UNLIKELY( !bank ) ) { /* We only handle this case for some unit tests. */ dummy_txn_ctx.features = (fd_features_t){0}; + slot = 0UL; } else { - dummy_txn_ctx.features = fd_bank_features_get( slot_ctx->bank ); + dummy_txn_ctx.features = fd_bank_features_get( bank ); + slot = bank->slot; } dummy_instr_ctx.txn_ctx = &dummy_txn_ctx; vm = fd_vm_init( vm, @@ -293,7 +297,7 @@ fd_bpf_create_bpf_program_cache_entry( fd_exec_slot_ctx_t * slot_ctx, 0U, NULL, 0, - FD_FEATURE_ACTIVE( slot_ctx->slot, &dummy_txn_ctx.features, bpf_account_data_direct_mapping ), + FD_FEATURE_ACTIVE( bank->slot, &dummy_txn_ctx.features, bpf_account_data_direct_mapping ), 0 ); if( FD_UNLIKELY( !vm ) ) { @@ -312,7 +316,7 @@ fd_bpf_create_bpf_program_cache_entry( fd_exec_slot_ctx_t * slot_ctx, validated_prog->calldests = fd_sbpf_calldests_join( validated_prog->calldests_shmem ); validated_prog->entry_pc = prog->entry_pc; - validated_prog->last_updated_slot = slot_ctx->slot; + validated_prog->last_updated_slot = slot; validated_prog->text_off = prog->text_off; validated_prog->text_cnt = prog->text_cnt; validated_prog->text_sz = prog->text_sz; @@ -325,11 +329,13 @@ fd_bpf_create_bpf_program_cache_entry( fd_exec_slot_ctx_t * slot_ctx, } static int -fd_bpf_check_and_create_bpf_program_cache_entry( fd_exec_slot_ctx_t * slot_ctx, - fd_pubkey_t const * pubkey, - fd_spad_t * runtime_spad ) { +fd_bpf_check_and_create_bpf_program_cache_entry( fd_bank_t * bank, + fd_funk_t * funk, + fd_funk_txn_t * funk_txn, + fd_pubkey_t const * pubkey, + fd_spad_t * runtime_spad ) { FD_TXN_ACCOUNT_DECL( exec_rec ); - if( fd_txn_account_init_from_funk_readonly( exec_rec, pubkey, slot_ctx->funk, slot_ctx->funk_txn ) != FD_ACC_MGR_SUCCESS ) { + if( fd_txn_account_init_from_funk_readonly( exec_rec, pubkey, funk, funk_txn ) != FD_ACC_MGR_SUCCESS ) { return -1; } @@ -340,7 +346,7 @@ fd_bpf_check_and_create_bpf_program_cache_entry( fd_exec_slot_ctx_t * slot_ctx, return -1; } - if( fd_bpf_create_bpf_program_cache_entry( slot_ctx, exec_rec, runtime_spad ) != 0 ) { + if( fd_bpf_create_bpf_program_cache_entry( bank, funk, funk_txn, exec_rec, runtime_spad ) != 0 ) { return -1; } @@ -485,7 +491,7 @@ fd_bpf_scan_and_create_bpf_program_cache_entry_para( fd_exec_slot_ctx_t * slo } fd_pubkey_t const * pubkey = fd_type_pun_const( recs[i]->pair.key[0].uc ); - int res = fd_bpf_check_and_create_bpf_program_cache_entry( slot_ctx, pubkey, runtime_spad ); + int res = fd_bpf_check_and_create_bpf_program_cache_entry( slot_ctx->bank, slot_ctx->funk, slot_ctx->funk_txn, pubkey, runtime_spad ); if( res==0 ) { cached_cnt++; } @@ -511,25 +517,23 @@ fd_bpf_scan_and_create_bpf_program_cache_entry_para( fd_exec_slot_ctx_t * slo } int -fd_bpf_scan_and_create_bpf_program_cache_entry( fd_exec_slot_ctx_t * slot_ctx, - fd_spad_t * runtime_spad ) { - fd_funk_t * funk = slot_ctx->funk; +fd_bpf_scan_and_create_bpf_program_cache_entry( fd_bank_t * bank, + fd_funk_t * funk, + fd_funk_txn_t * funk_txn, + fd_spad_t * runtime_spad ) { ulong cnt = 0UL; /* Use random-ish xid to avoid concurrency issues */ fd_funk_txn_xid_t cache_xid = fd_funk_generate_xid(); fd_funk_txn_start_write( funk ); - fd_funk_txn_t * cache_txn = fd_funk_txn_prepare( funk, slot_ctx->funk_txn, &cache_xid, 1 ); + fd_funk_txn_t * cache_txn = fd_funk_txn_prepare( funk, funk_txn, &cache_xid, 1 ); if( !cache_txn ) { FD_LOG_ERR(( "fd_funk_txn_prepare() failed" )); return -1; } fd_funk_txn_end_write( funk ); - fd_funk_txn_t * funk_txn = slot_ctx->funk_txn; - slot_ctx->funk_txn = cache_txn; - fd_funk_txn_start_read( funk ); for (fd_funk_rec_t const *rec = fd_funk_txn_first_rec( funk, funk_txn ); NULL != rec; @@ -540,7 +544,7 @@ fd_bpf_scan_and_create_bpf_program_cache_entry( fd_exec_slot_ctx_t * slot_ctx, fd_pubkey_t const * pubkey = fd_type_pun_const( rec->pair.key[0].uc ); - int res = fd_bpf_check_and_create_bpf_program_cache_entry( slot_ctx, pubkey, runtime_spad ); + int res = fd_bpf_check_and_create_bpf_program_cache_entry( bank, funk, cache_txn, pubkey, runtime_spad ); if( res==0 ) { cnt++; @@ -557,7 +561,6 @@ fd_bpf_scan_and_create_bpf_program_cache_entry( fd_exec_slot_ctx_t * slot_ctx, } fd_funk_txn_end_write( funk ); - slot_ctx->funk_txn = funk_txn; return 0; } diff --git a/src/flamenco/runtime/program/fd_bpf_program_util.h b/src/flamenco/runtime/program/fd_bpf_program_util.h index 80f8416b59..d8548d5c79 100644 --- a/src/flamenco/runtime/program/fd_bpf_program_util.h +++ b/src/flamenco/runtime/program/fd_bpf_program_util.h @@ -63,8 +63,10 @@ fd_sbpf_validated_program_from_sbpf_program( fd_sbpf_program_t const * prog, fd_sbpf_validated_program_t * valid_prog ); int -fd_bpf_scan_and_create_bpf_program_cache_entry( fd_exec_slot_ctx_t * slot_ctx, - fd_spad_t * runtime_spad ); +fd_bpf_scan_and_create_bpf_program_cache_entry( fd_bank_t * bank, + fd_funk_t * funk, + fd_funk_txn_t * funk_txn, + fd_spad_t * runtime_spad ); void fd_bpf_is_bpf_program( fd_funk_rec_t const * rec, diff --git a/src/flamenco/runtime/sysvar/fd_sysvar_last_restart_slot.c b/src/flamenco/runtime/sysvar/fd_sysvar_last_restart_slot.c index 2b07df9b3e..be35048d15 100644 --- a/src/flamenco/runtime/sysvar/fd_sysvar_last_restart_slot.c +++ b/src/flamenco/runtime/sysvar/fd_sysvar_last_restart_slot.c @@ -5,15 +5,17 @@ #include "../fd_runtime.h" void -fd_sysvar_last_restart_slot_init( fd_exec_slot_ctx_t * slot_ctx ) { +fd_sysvar_last_restart_slot_init( fd_bank_t * bank, + fd_funk_t * funk, + fd_funk_txn_t * funk_txn ) { - if( !FD_FEATURE_ACTIVE_BANK( slot_ctx->bank, last_restart_slot_sysvar ) ) { + if( !FD_FEATURE_ACTIVE_BANK( bank, last_restart_slot_sysvar ) ) { FD_LOG_INFO(( "sysvar LastRestartSlot not supported by this ledger version!" )); return; } - ulong sz = fd_sol_sysvar_last_restart_slot_size( fd_bank_last_restart_slot_query( slot_ctx->bank ) ); + ulong sz = fd_sol_sysvar_last_restart_slot_size( fd_bank_last_restart_slot_query( bank ) ); uchar enc[ sz ]; fd_memset( enc, 0, sz ); @@ -21,16 +23,16 @@ fd_sysvar_last_restart_slot_init( fd_exec_slot_ctx_t * slot_ctx ) { .data = enc, .dataend = enc + sz, }; - int err = fd_sol_sysvar_last_restart_slot_encode( fd_bank_last_restart_slot_query( slot_ctx->bank ), &encode ); + int err = fd_sol_sysvar_last_restart_slot_encode( fd_bank_last_restart_slot_query( bank ), &encode ); FD_TEST( err==FD_BINCODE_SUCCESS ); - fd_sysvar_set( slot_ctx->bank, - slot_ctx->funk, - slot_ctx->funk_txn, + fd_sysvar_set( bank, + funk, + funk_txn, &fd_sysvar_owner_id, &fd_sysvar_last_restart_slot_id, enc, sz, - slot_ctx->slot ); + bank->slot ); } fd_sol_sysvar_last_restart_slot_t * @@ -59,35 +61,36 @@ fd_sysvar_last_restart_slot_read( fd_funk_t * funk, Agave's solana_runtime::bank::Bank::update_last_restart_slot */ void -fd_sysvar_last_restart_slot_update( fd_exec_slot_ctx_t * slot_ctx, fd_spad_t * runtime_spad ) { +fd_sysvar_last_restart_slot_update( fd_bank_t * bank, + fd_funk_t * funk, + fd_funk_txn_t * funk_txn, + fd_spad_t * runtime_spad ) { /* https://github.com/solana-labs/solana/blob/v1.18.18/runtime/src/bank.rs#L2093-L2095 */ - if( !FD_FEATURE_ACTIVE_BANK( slot_ctx->bank, last_restart_slot_sysvar ) ) return; + if( !FD_FEATURE_ACTIVE_BANK( bank, last_restart_slot_sysvar ) ) return; int has_current_last_restart_slot = 0; ulong current_last_restart_slot = 0UL; /* https://github.com/solana-labs/solana/blob/v1.18.18/runtime/src/bank.rs#L2098-L2106 */ - fd_sol_sysvar_last_restart_slot_t * old_account = fd_sysvar_last_restart_slot_read( slot_ctx->funk, - slot_ctx->funk_txn, - runtime_spad ); + fd_sol_sysvar_last_restart_slot_t * old_account = fd_sysvar_last_restart_slot_read( funk, funk_txn, runtime_spad ); ulong old_account_slot = old_account ? old_account->slot : 0UL; has_current_last_restart_slot = 1; current_last_restart_slot = old_account_slot; /* https://github.com/solana-labs/solana/blob/v1.18.18/runtime/src/bank.rs#L2108-L2120 */ /* FIXME: Query hard forks list */ - ulong last_restart_slot = fd_bank_last_restart_slot_get( slot_ctx->bank ).slot; + ulong last_restart_slot = fd_bank_last_restart_slot_get( bank ).slot; /* https://github.com/solana-labs/solana/blob/v1.18.18/runtime/src/bank.rs#L2122-L2130 */ if( !has_current_last_restart_slot || current_last_restart_slot != last_restart_slot ) { - fd_sysvar_set( slot_ctx->bank, - slot_ctx->funk, - slot_ctx->funk_txn, - &fd_sysvar_owner_id, - &fd_sysvar_last_restart_slot_id, - &last_restart_slot, - sizeof(ulong), - slot_ctx->slot ); + fd_sysvar_set( bank, + funk, + funk_txn, + &fd_sysvar_owner_id, + &fd_sysvar_last_restart_slot_id, + &last_restart_slot, + sizeof(ulong), + bank->slot ); } } diff --git a/src/flamenco/runtime/sysvar/fd_sysvar_last_restart_slot.h b/src/flamenco/runtime/sysvar/fd_sysvar_last_restart_slot.h index 3c9ede4f6a..b711860c6e 100644 --- a/src/flamenco/runtime/sysvar/fd_sysvar_last_restart_slot.h +++ b/src/flamenco/runtime/sysvar/fd_sysvar_last_restart_slot.h @@ -12,13 +12,18 @@ FD_PROTOTYPES_BEGIN state. */ void -fd_sysvar_last_restart_slot_init( fd_exec_slot_ctx_t * slot_ctx ); +fd_sysvar_last_restart_slot_init( fd_bank_t * bank, + fd_funk_t * funk, + fd_funk_txn_t * funk_txn ); /* fd_sysvar_last_restart_slot_update performs a sysvar update before transaction processing. TODO not completely implemented. */ void -fd_sysvar_last_restart_slot_update( fd_exec_slot_ctx_t * slot_ctx, fd_spad_t * runtime_spad ); +fd_sysvar_last_restart_slot_update( fd_bank_t * bank, + fd_funk_t * funk, + fd_funk_txn_t * funk_txn, + fd_spad_t * runtime_spad ); /* fd_sysvar_last_restart_slot_read queries the last restart slot sysvar from the given funk. If the account doesn't exist in funk or if the diff --git a/src/flamenco/runtime/sysvar/fd_sysvar_slot_hashes.c b/src/flamenco/runtime/sysvar/fd_sysvar_slot_hashes.c index d958de387d..1967669a8f 100644 --- a/src/flamenco/runtime/sysvar/fd_sysvar_slot_hashes.c +++ b/src/flamenco/runtime/sysvar/fd_sysvar_slot_hashes.c @@ -3,7 +3,6 @@ #include "../fd_acc_mgr.h" #include "../fd_borrowed_account.h" #include "../fd_system_ids.h" -#include "../context/fd_exec_slot_ctx.h" /* FIXME These constants should be header defines */ /* https://github.com/solana-labs/solana/blob/8f2c8b8388a495d2728909e30460aa40dcc5d733/sdk/program/src/slot_hashes.rs#L11 */ @@ -13,7 +12,9 @@ FD_FN_UNUSED static const ulong slot_hashes_max_entries = 512; static const ulong slot_hashes_account_size = 20488; void -fd_sysvar_slot_hashes_write( fd_exec_slot_ctx_t * slot_ctx, +fd_sysvar_slot_hashes_write( fd_bank_t * bank, + fd_funk_t * funk, + fd_funk_txn_t * funk_txn, fd_slot_hashes_global_t * slot_hashes_global ) { uchar enc[slot_hashes_account_size]; fd_memset( enc, 0, slot_hashes_account_size ); @@ -24,7 +25,7 @@ fd_sysvar_slot_hashes_write( fd_exec_slot_ctx_t * slot_ctx, if( fd_slot_hashes_encode_global( slot_hashes_global, &ctx ) ) { FD_LOG_ERR(("fd_slot_hashes_encode failed")); } - fd_sysvar_set( slot_ctx->bank, slot_ctx->funk, slot_ctx->funk_txn, &fd_sysvar_owner_id, &fd_sysvar_slot_hashes_id, enc, slot_hashes_account_size, slot_ctx->slot ); + fd_sysvar_set( bank, funk, funk_txn, &fd_sysvar_owner_id, &fd_sysvar_slot_hashes_id, enc, slot_hashes_account_size, bank->slot ); } ulong @@ -78,23 +79,28 @@ fd_sysvar_slot_hashes_delete( void * mem ) { } void -fd_sysvar_slot_hashes_init( fd_exec_slot_ctx_t * slot_ctx, - fd_spad_t * runtime_spad ) { +fd_sysvar_slot_hashes_init( fd_bank_t * bank, + fd_funk_t * funk, + fd_funk_txn_t * funk_txn, + fd_spad_t * runtime_spad ) { FD_SPAD_FRAME_BEGIN( runtime_spad ) { void * mem = fd_spad_alloc( runtime_spad, FD_SYSVAR_SLOT_HASHES_ALIGN, fd_sysvar_slot_hashes_footprint( FD_SYSVAR_SLOT_HASHES_CAP ) ); fd_slot_hash_t * shnull = NULL; fd_slot_hashes_global_t * slot_hashes_global = fd_sysvar_slot_hashes_join( fd_sysvar_slot_hashes_new( mem, FD_SYSVAR_SLOT_HASHES_CAP ), &shnull ); - fd_sysvar_slot_hashes_write( slot_ctx, slot_hashes_global); + fd_sysvar_slot_hashes_write( bank, funk, funk_txn, slot_hashes_global); fd_sysvar_slot_hashes_delete( fd_sysvar_slot_hashes_leave( slot_hashes_global, shnull ) ); } FD_SPAD_FRAME_END; } /* https://github.com/anza-xyz/agave/blob/b11ca828cfc658b93cb86a6c5c70561875abe237/runtime/src/bank.rs#L2283-L2294 */ void -fd_sysvar_slot_hashes_update( fd_exec_slot_ctx_t * slot_ctx, fd_spad_t * runtime_spad ) { +fd_sysvar_slot_hashes_update( fd_bank_t * bank, + fd_funk_t * funk, + fd_funk_txn_t * funk_txn, + fd_spad_t * runtime_spad ) { FD_SPAD_FRAME_BEGIN( runtime_spad ) { - fd_slot_hashes_global_t * slot_hashes_global = fd_sysvar_slot_hashes_read( slot_ctx->funk, slot_ctx->funk_txn, runtime_spad ); + fd_slot_hashes_global_t * slot_hashes_global = fd_sysvar_slot_hashes_read( funk, funk_txn, runtime_spad ); fd_slot_hash_t * hashes = NULL; if( FD_UNLIKELY( !slot_hashes_global ) ) { /* Note: Agave's implementation initializes a new slot_hashes if it doesn't already exist (refer to above URL). */ @@ -108,8 +114,8 @@ FD_SPAD_FRAME_BEGIN( runtime_spad ) { !deq_fd_slot_hash_t_iter_done( hashes, iter ); iter = deq_fd_slot_hash_t_iter_next( hashes, iter ) ) { fd_slot_hash_t * ele = deq_fd_slot_hash_t_iter_ele( hashes, iter ); - if( ele->slot == slot_ctx->slot ) { - fd_hash_t const * bank_hash = fd_bank_bank_hash_query( slot_ctx->bank ); + if( ele->slot == bank->slot ) { + fd_hash_t const * bank_hash = fd_bank_bank_hash_query( bank ); memcpy( &ele->hash, bank_hash, sizeof(fd_hash_t) ); found = 1; } @@ -118,8 +124,8 @@ FD_SPAD_FRAME_BEGIN( runtime_spad ) { if( !found ) { // https://github.com/firedancer-io/solana/blob/08a1ef5d785fe58af442b791df6c4e83fe2e7c74/runtime/src/bank.rs#L2371 fd_slot_hash_t slot_hash = { - .hash = fd_bank_bank_hash_get( slot_ctx->bank ), // parent hash? - .slot = fd_bank_prev_slot_get( slot_ctx->bank ), // parent_slot + .hash = fd_bank_bank_hash_get( bank ), // parent hash? + .slot = fd_bank_prev_slot_get( bank ), // parent_slot }; FD_LOG_DEBUG(( "fd_sysvar_slot_hash_update: slot %lu, hash %s", slot_hash.slot, FD_BASE58_ENC_32_ALLOCA( slot_hash.hash.key ) )); @@ -129,7 +135,7 @@ FD_SPAD_FRAME_BEGIN( runtime_spad ) { deq_fd_slot_hash_t_push_head( hashes, slot_hash ); } - fd_sysvar_slot_hashes_write( slot_ctx, slot_hashes_global ); + fd_sysvar_slot_hashes_write( bank, funk, funk_txn, slot_hashes_global ); fd_sysvar_slot_hashes_leave( slot_hashes_global, hashes ); } FD_SPAD_FRAME_END; } diff --git a/src/flamenco/runtime/sysvar/fd_sysvar_slot_hashes.h b/src/flamenco/runtime/sysvar/fd_sysvar_slot_hashes.h index a48a8c5203..b190d6ef00 100644 --- a/src/flamenco/runtime/sysvar/fd_sysvar_slot_hashes.h +++ b/src/flamenco/runtime/sysvar/fd_sysvar_slot_hashes.h @@ -5,6 +5,8 @@ #include "../../../funk/fd_funk_txn.h" #include "../../fd_flamenco_base.h" #include "../../types/fd_types.h" +#include "../fd_bank.h" + /* The slot hashes sysvar contains the most recent hashes of the slot's parent bank hashes. */ /* FD_SYSVAR_SLOT_HASHES_CAP is the max number of entries that the @@ -38,16 +40,23 @@ fd_sysvar_slot_hashes_delete( void * mem ); /* Write a funk entry for the slot hashes sysvar account (exposed for tests) */ void -fd_sysvar_slot_hashes_write( fd_exec_slot_ctx_t * slot_ctx, +fd_sysvar_slot_hashes_write( fd_bank_t * bank, + fd_funk_t * funk, + fd_funk_txn_t * funk_txn, fd_slot_hashes_global_t * slot_hashes_global ); void -fd_sysvar_slot_hashes_init( fd_exec_slot_ctx_t * slot_ctx, - fd_spad_t * runtime_spad ); +fd_sysvar_slot_hashes_init( fd_bank_t * bank, + fd_funk_t * funk, + fd_funk_txn_t * funk_txn, + fd_spad_t * runtime_spad ); /* Update the slot hashes sysvar account. This should be called at the end of every slot, before execution commences. */ void -fd_sysvar_slot_hashes_update( fd_exec_slot_ctx_t * slot_ctx, fd_spad_t * runtime_spad ); +fd_sysvar_slot_hashes_update( fd_bank_t * bank, + fd_funk_t * funk, + fd_funk_txn_t * funk_txn, + fd_spad_t * runtime_spad ); /* fd_sysvar_slot_hashes_read reads the slot hashes sysvar from funk. If the account doesn't exist in funk or if the account has zero diff --git a/src/flamenco/runtime/sysvar/fd_sysvar_slot_history.c b/src/flamenco/runtime/sysvar/fd_sysvar_slot_history.c index 717d6f8890..a5b6307ccf 100644 --- a/src/flamenco/runtime/sysvar/fd_sysvar_slot_history.c +++ b/src/flamenco/runtime/sysvar/fd_sysvar_slot_history.c @@ -37,7 +37,9 @@ fd_sysvar_slot_history_set( fd_slot_history_global_t * history, FD_FN_UNUSED static const ulong blocks_len = slot_history_max_entries / bits_per_block; int -fd_sysvar_slot_history_write_history( fd_exec_slot_ctx_t * slot_ctx, +fd_sysvar_slot_history_write_history( fd_bank_t * bank, + fd_funk_t * funk, + fd_funk_txn_t * funk_txn, fd_slot_history_global_t * history ) { ulong sz = slot_history_min_account_size; uchar enc[ sz ]; @@ -48,12 +50,15 @@ fd_sysvar_slot_history_write_history( fd_exec_slot_ctx_t * slot_ctx, int err = fd_slot_history_encode_global( history, &ctx ); if (0 != err) return err; - return fd_sysvar_set( slot_ctx->bank, slot_ctx->funk, slot_ctx->funk_txn, &fd_sysvar_owner_id, &fd_sysvar_slot_history_id, enc, sz, slot_ctx->slot ); + return fd_sysvar_set( bank, funk, funk_txn, &fd_sysvar_owner_id, &fd_sysvar_slot_history_id, enc, sz, bank->slot ); } /* https://github.com/solana-labs/solana/blob/8f2c8b8388a495d2728909e30460aa40dcc5d733/sdk/program/src/slot_history.rs#L16 */ void -fd_sysvar_slot_history_init( fd_exec_slot_ctx_t * slot_ctx, fd_spad_t * runtime_spad ) { +fd_sysvar_slot_history_init( fd_bank_t * bank, + fd_funk_t * funk, + fd_funk_txn_t * funk_txn, + fd_spad_t * runtime_spad ) { FD_SPAD_FRAME_BEGIN( runtime_spad ) { /* Create a new slot history instance */ @@ -65,27 +70,30 @@ fd_sysvar_slot_history_init( fd_exec_slot_ctx_t * slot_ctx, fd_spad_t * runtime_ fd_slot_history_global_t * history = (fd_slot_history_global_t *)mem; ulong * blocks = (ulong *)fd_ulong_align_up( (ulong)((uchar*)history + sizeof(fd_slot_history_global_t)), alignof(ulong) ); - history->next_slot = slot_ctx->slot + 1UL; + history->next_slot = bank->slot + 1UL; history->bits_bitvec_offset = (ulong)((uchar*)blocks - (uchar*)history); history->bits_len = slot_history_max_entries; history->bits_bitvec_len = blocks_len; memset( blocks, 0, sizeof(ulong) * blocks_len ); /* TODO: handle slot != 0 init case */ - fd_sysvar_slot_history_set( history, slot_ctx->slot ); - fd_sysvar_slot_history_write_history( slot_ctx, history ); + fd_sysvar_slot_history_set( history, bank->slot ); + fd_sysvar_slot_history_write_history( bank, funk, funk_txn, history ); } FD_SPAD_FRAME_END; } /* https://github.com/solana-labs/solana/blob/8f2c8b8388a495d2728909e30460aa40dcc5d733/runtime/src/bank.rs#L2345 */ int -fd_sysvar_slot_history_update( fd_exec_slot_ctx_t * slot_ctx, fd_spad_t * runtime_spad ) { +fd_sysvar_slot_history_update( fd_bank_t * bank, + fd_funk_t * funk, + fd_funk_txn_t * funk_txn, + fd_spad_t * runtime_spad ) { /* Set current_slot, and update next_slot */ fd_pubkey_t const * key = &fd_sysvar_slot_history_id; FD_TXN_ACCOUNT_DECL( rec ); - int err = fd_txn_account_init_from_funk_readonly( rec, key, slot_ctx->funk, slot_ctx->funk_txn ); + int err = fd_txn_account_init_from_funk_readonly( rec, key, funk, funk_txn ); if (err) FD_LOG_CRIT(( "fd_txn_account_init_from_funk_readonly(slot_history) failed: %d", err )); @@ -108,12 +116,12 @@ fd_sysvar_slot_history_update( fd_exec_slot_ctx_t * slot_ctx, fd_spad_t * runtim fd_slot_history_global_t * history = fd_slot_history_decode_global( mem, &ctx ); /* https://github.com/solana-labs/solana/blob/8f2c8b8388a495d2728909e30460aa40dcc5d733/sdk/program/src/slot_history.rs#L48 */ - fd_sysvar_slot_history_set( history, slot_ctx->slot ); - history->next_slot = slot_ctx->slot + 1; + fd_sysvar_slot_history_set( history, bank->slot ); + history->next_slot = bank->slot + 1; ulong sz = slot_history_min_account_size; - err = fd_txn_account_init_from_funk_mutable( rec, key, slot_ctx->funk, slot_ctx->funk_txn, 1, sz ); + err = fd_txn_account_init_from_funk_mutable( rec, key, funk, funk_txn, 1, sz ); if (err) FD_LOG_CRIT(( "fd_txn_account_init_from_funk_mutable(slot_history) failed: %d", err )); @@ -126,13 +134,13 @@ fd_sysvar_slot_history_update( fd_exec_slot_ctx_t * slot_ctx, fd_spad_t * runtim return FD_EXECUTOR_INSTR_ERR_CUSTOM_ERR; } - fd_rent_t const * rent = fd_bank_rent_query( slot_ctx->bank ); + fd_rent_t const * rent = fd_bank_rent_query( bank ); rec->vt->set_lamports( rec, fd_rent_exempt_minimum_balance( rent, sz ) ); rec->vt->set_data_len( rec, sz ); rec->vt->set_owner( rec, &fd_sysvar_owner_id ); - fd_txn_account_mutable_fini( rec, slot_ctx->funk, slot_ctx->funk_txn ); + fd_txn_account_mutable_fini( rec, funk, funk_txn ); return 0; } diff --git a/src/flamenco/runtime/sysvar/fd_sysvar_slot_history.h b/src/flamenco/runtime/sysvar/fd_sysvar_slot_history.h index b49fefb06e..2b71105bb4 100644 --- a/src/flamenco/runtime/sysvar/fd_sysvar_slot_history.h +++ b/src/flamenco/runtime/sysvar/fd_sysvar_slot_history.h @@ -14,13 +14,17 @@ /* Initialize the slot history sysvar account. */ void -fd_sysvar_slot_history_init( fd_exec_slot_ctx_t * slot_ctx, - fd_spad_t * runtime_spad ); +fd_sysvar_slot_history_init( fd_bank_t * bank, + fd_funk_t * funk, + fd_funk_txn_t * funk_txn, + fd_spad_t * runtime_spad ); /* Update the slot history sysvar account. This should be called at the end of every slot, after execution has concluded. */ int -fd_sysvar_slot_history_update( fd_exec_slot_ctx_t * slot_ctx, - fd_spad_t * runtime_spad ); +fd_sysvar_slot_history_update( fd_bank_t * bank, + fd_funk_t * funk, + fd_funk_txn_t * funk_txn, + fd_spad_t * runtime_spad ); /* fd_sysvar_slot_history_read reads the slot history sysvar from funk. If the account doesn't exist in funk or if the account has zero diff --git a/src/flamenco/runtime/tests/harness/fd_block_harness.c b/src/flamenco/runtime/tests/harness/fd_block_harness.c index 1d0f61b4df..046760a7b2 100644 --- a/src/flamenco/runtime/tests/harness/fd_block_harness.c +++ b/src/flamenco/runtime/tests/harness/fd_block_harness.c @@ -347,7 +347,7 @@ fd_runtime_fuzz_block_ctx_create( fd_runtime_fuzz_runner_t * runner, /* Add accounts to bpf program cache */ - fd_bpf_scan_and_create_bpf_program_cache_entry( slot_ctx, runner->spad ); + fd_bpf_scan_and_create_bpf_program_cache_entry( slot_ctx->bank, slot_ctx->funk, slot_ctx->funk_txn, runner->spad ); /* Finish init epoch bank sysvars */ fd_epoch_schedule_t * epoch_schedule = fd_sysvar_epoch_schedule_read( funk, funk_txn, runner->spad ); diff --git a/src/flamenco/runtime/tests/harness/fd_instr_harness.c b/src/flamenco/runtime/tests/harness/fd_instr_harness.c index 2b0713f09d..ad0fa4d70f 100644 --- a/src/flamenco/runtime/tests/harness/fd_instr_harness.c +++ b/src/flamenco/runtime/tests/harness/fd_instr_harness.c @@ -219,7 +219,7 @@ fd_runtime_fuzz_instr_ctx_create( fd_runtime_fuzz_runner_t * runner, } /* Add accounts to bpf program cache */ - fd_bpf_scan_and_create_bpf_program_cache_entry( slot_ctx, runner->spad ); + fd_bpf_scan_and_create_bpf_program_cache_entry( slot_ctx->bank, slot_ctx->funk, slot_ctx->funk_txn, runner->spad ); /* Fill missing sysvar cache values with defaults */ /* We create mock accounts for each of the sysvars and hardcode the data fields before loading it into the account manager */ diff --git a/src/flamenco/runtime/tests/harness/fd_txn_harness.c b/src/flamenco/runtime/tests/harness/fd_txn_harness.c index 0cfd2bcd9e..33bf5b906a 100644 --- a/src/flamenco/runtime/tests/harness/fd_txn_harness.c +++ b/src/flamenco/runtime/tests/harness/fd_txn_harness.c @@ -69,7 +69,7 @@ fd_runtime_fuzz_txn_ctx_create( fd_runtime_fuzz_runner_t * runner, } /* Add accounts to bpf program cache */ - fd_bpf_scan_and_create_bpf_program_cache_entry( slot_ctx, runner->spad ); + fd_bpf_scan_and_create_bpf_program_cache_entry( slot_ctx->bank, slot_ctx->funk, slot_ctx->funk_txn, runner->spad ); /* Setup Bank manager */ @@ -131,7 +131,7 @@ fd_runtime_fuzz_txn_ctx_create( fd_runtime_fuzz_runner_t * runner, fd_slot_hash_t * dummy_elem = deq_fd_slot_hash_t_push_tail_nocopy( slot_hashes ); memset( dummy_elem, 0, sizeof(fd_slot_hash_t) ); - fd_sysvar_slot_hashes_write( slot_ctx, default_slot_hashes_global ); + fd_sysvar_slot_hashes_write( slot_ctx->bank, slot_ctx->funk, slot_ctx->funk_txn, default_slot_hashes_global ); fd_sysvar_slot_hashes_delete( fd_sysvar_slot_hashes_leave( default_slot_hashes_global, slot_hashes ) ); } FD_SPAD_FRAME_END; @@ -150,7 +150,7 @@ fd_runtime_fuzz_txn_ctx_create( fd_runtime_fuzz_runner_t * runner, FD_TXN_ACCOUNT_DECL( acc ); int err = fd_txn_account_init_from_funk_readonly( acc, &fd_sysvar_last_restart_slot_id, funk, funk_txn ); if( err==FD_ACC_MGR_ERR_UNKNOWN_ACCOUNT ) { - fd_sysvar_last_restart_slot_init( slot_ctx ); + fd_sysvar_last_restart_slot_init( slot_ctx->bank, slot_ctx->funk, slot_ctx->funk_txn ); } /* Provide a default clock if not present */ From 04a9ec19edfb4103ce21d0c00dceaa161c06155a Mon Sep 17 00:00:00 2001 From: Ishan Bhatt Date: Fri, 27 Jun 2025 16:28:34 +0000 Subject: [PATCH 03/27] removing banks --- src/flamenco/runtime/fd_hashes.c | 122 +++++++++++++----------------- src/flamenco/runtime/fd_hashes.h | 4 +- src/flamenco/runtime/fd_runtime.c | 20 ++--- 3 files changed, 66 insertions(+), 80 deletions(-) diff --git a/src/flamenco/runtime/fd_hashes.c b/src/flamenco/runtime/fd_hashes.c index cdf3bd06ec..ccec8f0f96 100644 --- a/src/flamenco/runtime/fd_hashes.c +++ b/src/flamenco/runtime/fd_hashes.c @@ -195,37 +195,25 @@ fd_calculate_epoch_accounts_hash_values( fd_exec_slot_ctx_t * slot_ctx ) { } -// https://github.com/solana-labs/solana/blob/b0dcaf29e358c37a0fcb8f1285ce5fff43c8ec55/runtime/src/bank/epoch_accounts_hash_utils.rs#L13 -static int -fd_should_include_epoch_accounts_hash( fd_exec_slot_ctx_t * slot_ctx ) { - if( FD_FEATURE_ACTIVE_BANK( slot_ctx->bank, accounts_lt_hash) ) { - return 0; - } - - ulong calculation_stop = fd_bank_eah_stop_slot_get( slot_ctx->bank ); - ulong prev_slot = fd_bank_prev_slot_get( slot_ctx->bank ); - return prev_slot < calculation_stop && (slot_ctx->slot >= calculation_stop); -} - // slot_ctx should be const. static void -fd_hash_bank( fd_exec_slot_ctx_t * slot_ctx, +fd_hash_bank( fd_bank_t * bank, fd_capture_ctx_t * capture_ctx, fd_hash_t * hash, fd_pubkey_hash_pair_t * dirty_keys, ulong dirty_key_cnt ) { - fd_hash_t const * bank_hash = fd_bank_bank_hash_query( slot_ctx->bank ); + fd_hash_t const * bank_hash = fd_bank_bank_hash_query( bank ); - fd_bank_prev_bank_hash_set( slot_ctx->bank, *bank_hash ); + fd_bank_prev_bank_hash_set( bank, *bank_hash ); - fd_bank_parent_signature_cnt_set( slot_ctx->bank, fd_bank_signature_count_get( slot_ctx->bank ) ); + fd_bank_parent_signature_cnt_set( bank, fd_bank_signature_count_get( bank ) ); - fd_bank_lamports_per_signature_set( slot_ctx->bank, fd_bank_lamports_per_signature_get( slot_ctx->bank ) ); + fd_bank_lamports_per_signature_set( bank, fd_bank_lamports_per_signature_get( bank ) ); fd_hash_t account_delta_hash; - if( !FD_FEATURE_ACTIVE_BANK( slot_ctx->bank, remove_accounts_delta_hash) ) { + if( !FD_FEATURE_ACTIVE_BANK( bank, remove_accounts_delta_hash) ) { sort_pubkey_hash_pair_inplace( dirty_keys, dirty_key_cnt ); fd_pubkey_hash_pair_list_t list1 = { .pairs = dirty_keys, .pairs_len = dirty_key_cnt }; fd_hash_account_deltas(&list1, 1, &account_delta_hash ); @@ -234,50 +222,43 @@ fd_hash_bank( fd_exec_slot_ctx_t * slot_ctx, fd_sha256_t sha; fd_sha256_init( &sha ); fd_sha256_append( &sha, (uchar const *)bank_hash, sizeof( fd_hash_t ) ); - if( !FD_FEATURE_ACTIVE_BANK( slot_ctx->bank, remove_accounts_delta_hash) ) + if( !FD_FEATURE_ACTIVE_BANK( bank, remove_accounts_delta_hash) ) fd_sha256_append( &sha, (uchar const *) &account_delta_hash, sizeof( fd_hash_t ) ); - fd_sha256_append( &sha, (uchar const *) fd_bank_signature_count_query( slot_ctx->bank ), sizeof( ulong ) ); + fd_sha256_append( &sha, (uchar const *) fd_bank_signature_count_query( bank ), sizeof( ulong ) ); - fd_sha256_append( &sha, (uchar const *) fd_bank_poh_query( slot_ctx->bank )->hash, sizeof( fd_hash_t ) ); + fd_sha256_append( &sha, (uchar const *) fd_bank_poh_query( bank )->hash, sizeof( fd_hash_t ) ); fd_sha256_fini( &sha, hash->hash ); // https://github.com/anza-xyz/agave/blob/766cd682423b8049ddeac3c0ec6cebe0a1356e9e/runtime/src/bank.rs#L5250 - if( FD_FEATURE_ACTIVE_BANK( slot_ctx->bank, accounts_lt_hash ) ) { + if( FD_FEATURE_ACTIVE_BANK( bank, accounts_lt_hash ) ) { fd_sha256_init( &sha ); fd_sha256_append( &sha, (uchar const *) &hash->hash, sizeof( fd_hash_t ) ); - fd_slot_lthash_t const * lthash = fd_bank_lthash_query( slot_ctx->bank ); + fd_slot_lthash_t const * lthash = fd_bank_lthash_query( bank ); fd_sha256_append( &sha, (uchar const *) lthash->lthash, sizeof( lthash->lthash ) ); fd_sha256_fini( &sha, hash->hash ); - } else { - if (fd_should_include_epoch_accounts_hash(slot_ctx)) { - fd_sha256_init( &sha ); - fd_sha256_append( &sha, (uchar const *) &hash->hash, sizeof( fd_hash_t ) ); - fd_sha256_append( &sha, (uchar const *) fd_bank_epoch_account_hash_query( slot_ctx->bank ), sizeof( fd_hash_t ) ); - fd_sha256_fini( &sha, hash->hash ); - } } - if( capture_ctx != NULL && capture_ctx->capture != NULL && slot_ctx->slot>=capture_ctx->solcap_start_slot ) { + if( capture_ctx != NULL && capture_ctx->capture != NULL && bank->slot>=capture_ctx->solcap_start_slot ) { uchar *lthash = NULL; - if( FD_FEATURE_ACTIVE_BANK( slot_ctx->bank, accounts_lt_hash ) ) { + if( FD_FEATURE_ACTIVE_BANK( bank, accounts_lt_hash ) ) { lthash = (uchar *)fd_alloca_check( 1UL, 32UL ); - fd_slot_lthash_t const * lthash_val = fd_bank_lthash_query( slot_ctx->bank ); + fd_slot_lthash_t const * lthash_val = fd_bank_lthash_query( bank ); fd_lthash_hash((fd_lthash_value_t *) lthash_val->lthash, lthash); } fd_solcap_write_bank_preimage( capture_ctx->capture, hash->hash, - fd_bank_prev_bank_hash_query( slot_ctx->bank ), - FD_FEATURE_ACTIVE_BANK( slot_ctx->bank, remove_accounts_delta_hash) ? NULL : account_delta_hash.hash, + fd_bank_prev_bank_hash_query( bank ), + FD_FEATURE_ACTIVE_BANK( bank, remove_accounts_delta_hash) ? NULL : account_delta_hash.hash, lthash, - fd_bank_poh_query( slot_ctx->bank )->hash, - fd_bank_signature_count_get( slot_ctx->bank ) ); + fd_bank_poh_query( bank )->hash, + fd_bank_signature_count_get( bank ) ); } - if( FD_FEATURE_ACTIVE_BANK( slot_ctx->bank, remove_accounts_delta_hash) ) { + if( FD_FEATURE_ACTIVE_BANK( bank, remove_accounts_delta_hash) ) { FD_LOG_NOTICE(( "\n\n[Replay]\n" "slot: %lu\n" "bank hash: %s\n" @@ -285,12 +266,12 @@ fd_hash_bank( fd_exec_slot_ctx_t * slot_ctx, "lthash: %s\n" "signature_count: %lu\n" "last_blockhash: %s\n", - slot_ctx->slot, + bank->slot, FD_BASE58_ENC_32_ALLOCA( hash->hash ), - FD_BASE58_ENC_32_ALLOCA( fd_bank_prev_bank_hash_query( slot_ctx->bank ) ), - FD_LTHASH_ENC_32_ALLOCA( (fd_lthash_value_t *) fd_bank_lthash_query( slot_ctx->bank )->lthash ), - fd_bank_signature_count_get( slot_ctx->bank ), - FD_BASE58_ENC_32_ALLOCA( fd_bank_poh_query( slot_ctx->bank )->hash ) )); + FD_BASE58_ENC_32_ALLOCA( fd_bank_prev_bank_hash_query( bank ) ), + FD_LTHASH_ENC_32_ALLOCA( (fd_lthash_value_t *) fd_bank_lthash_query( bank )->lthash ), + fd_bank_signature_count_get( bank ), + FD_BASE58_ENC_32_ALLOCA( fd_bank_poh_query( bank )->hash ) )); } else { FD_LOG_NOTICE(( "\n\n[Replay]\n" "slot: %lu\n" @@ -300,13 +281,13 @@ fd_hash_bank( fd_exec_slot_ctx_t * slot_ctx, "lthash: %s\n" "signature_count: %lu\n" "last_blockhash: %s\n", - slot_ctx->slot, + bank->slot, FD_BASE58_ENC_32_ALLOCA( hash->hash ), - FD_BASE58_ENC_32_ALLOCA( fd_bank_prev_bank_hash_query( slot_ctx->bank ) ), + FD_BASE58_ENC_32_ALLOCA( fd_bank_prev_bank_hash_query( bank ) ), FD_BASE58_ENC_32_ALLOCA( account_delta_hash.hash ), - FD_LTHASH_ENC_32_ALLOCA( (fd_lthash_value_t *) fd_bank_lthash_query( slot_ctx->bank )->lthash ), - fd_bank_signature_count_get( slot_ctx->bank ), - FD_BASE58_ENC_32_ALLOCA( fd_bank_poh_query( slot_ctx->bank )->hash ) )); + FD_LTHASH_ENC_32_ALLOCA( (fd_lthash_value_t *) fd_bank_lthash_query( bank )->lthash ), + fd_bank_signature_count_get( bank ), + FD_BASE58_ENC_32_ALLOCA( fd_bank_poh_query( bank )->hash ) )); } } @@ -472,7 +453,9 @@ fd_collect_modified_accounts( fd_bank_t * bank, } int -fd_update_hash_bank_exec_hash( fd_exec_slot_ctx_t * slot_ctx, +fd_update_hash_bank_exec_hash( fd_bank_t * bank, + fd_funk_t * funk, + fd_funk_txn_t * funk_txn, fd_hash_t * hash, fd_capture_ctx_t * capture_ctx, fd_accounts_hash_task_data_t * task_datas, @@ -483,11 +466,8 @@ fd_update_hash_bank_exec_hash( fd_exec_slot_ctx_t * slot_ctx, fd_spad_t * runtime_spad ) { ulong dirty_key_cnt = 0; - fd_funk_t * funk = slot_ctx->funk; - fd_funk_txn_t * txn = slot_ctx->funk_txn; - // Apply the lthash changes to the bank lthash - fd_slot_lthash_t * lthash_val = fd_bank_lthash_modify( slot_ctx->bank ); + fd_slot_lthash_t * lthash_val = fd_bank_lthash_modify( bank ); for( ulong i = 0; i < lt_hashes_cnt; i++ ) { fd_lthash_add( (fd_lthash_value_t *)lthash_val->lthash, <_hashes[i] ); } @@ -510,16 +490,16 @@ fd_update_hash_bank_exec_hash( fd_exec_slot_ctx_t * slot_ctx, FD_TXN_ACCOUNT_DECL( acc_rec ); fd_pubkey_t const * acc_key = task_info->acc_pubkey; - int err = fd_txn_account_init_from_funk_mutable( acc_rec, acc_key, funk, txn, 0, 0UL); + int err = fd_txn_account_init_from_funk_mutable( acc_rec, acc_key, funk, funk_txn, 0, 0UL); if( FD_UNLIKELY( err!=FD_ACC_MGR_SUCCESS ) ) { FD_LOG_ERR(( "failed to modify account during bank hash" )); } /* Update hash */ acc_rec->vt->set_hash( acc_rec, task_info->acc_hash ); - acc_rec->vt->set_slot( acc_rec, slot_ctx->slot ); + acc_rec->vt->set_slot( acc_rec, bank->slot ); - fd_txn_account_mutable_fini( acc_rec, funk, txn ); + fd_txn_account_mutable_fini( acc_rec, funk, funk_txn ); /* Add account to "dirty keys" list, which will be added to the bank hash. */ @@ -541,16 +521,16 @@ fd_update_hash_bank_exec_hash( fd_exec_slot_ctx_t * slot_ctx, "rent_epoch: %lu, " "data_len: %lu", acc_key_string, - slot_ctx->slot, + bank->slot, acc_rec->vt->get_lamports( acc_rec ), owner_string, acc_rec->vt->is_executable( acc_rec ) ? "true" : "false", acc_rec->vt->get_rent_epoch( acc_rec ), acc_rec->vt->get_data_len( acc_rec ) )); - if( capture_ctx != NULL && capture_ctx->capture != NULL && slot_ctx->slot>=capture_ctx->solcap_start_slot ) { - fd_account_meta_t const * acc_meta = fd_funk_get_acc_meta_readonly( slot_ctx->funk, - slot_ctx->funk_txn, + if( capture_ctx != NULL && capture_ctx->capture != NULL && bank->slot>=capture_ctx->solcap_start_slot ) { + fd_account_meta_t const * acc_meta = fd_funk_get_acc_meta_readonly( funk, + funk_txn, task_info->acc_pubkey, NULL, &err, @@ -577,9 +557,9 @@ fd_update_hash_bank_exec_hash( fd_exec_slot_ctx_t * slot_ctx, /* Sort and hash "dirty keys" to the accounts delta hash. */ - fd_bank_signature_count_set( slot_ctx->bank, signature_cnt ); + fd_bank_signature_count_set( bank, signature_cnt ); - fd_hash_bank( slot_ctx, capture_ctx, hash, dirty_keys, dirty_key_cnt); + fd_hash_bank( bank, capture_ctx, hash, dirty_keys, dirty_key_cnt); for( ulong i = 0; i < task_data->info_sz; i++ ) { fd_accounts_hash_task_info_t * task_info = &task_data->info[i]; @@ -591,16 +571,16 @@ fd_update_hash_bank_exec_hash( fd_exec_slot_ctx_t * slot_ctx, /* All removed recs should be stored with the slot from the funk txn. */ int err = FD_ACC_MGR_SUCCESS; fd_funk_rec_t const * rec = NULL; - fd_funk_get_acc_meta_readonly( slot_ctx->funk, - slot_ctx->funk_txn, - task_info->acc_pubkey, - &rec, - &err, - NULL); + fd_funk_get_acc_meta_readonly( funk, + funk_txn, + task_info->acc_pubkey, + &rec, + &err, + NULL); if( err != FD_ACC_MGR_SUCCESS ) { FD_LOG_ERR(( "failed to view account" )); } - fd_funk_rec_remove( funk, txn, rec->pair.key, NULL, rec->pair.xid->ul[0] ); + fd_funk_rec_remove( funk, funk_txn, rec->pair.key, NULL, rec->pair.xid->ul[0] ); } } @@ -672,7 +652,9 @@ fd_update_hash_bank_tpool( fd_exec_slot_ctx_t * slot_ctx, } } - return fd_update_hash_bank_exec_hash( slot_ctx, + return fd_update_hash_bank_exec_hash( slot_ctx->bank, + slot_ctx->funk, + slot_ctx->funk_txn, hash, capture_ctx, task_data, diff --git a/src/flamenco/runtime/fd_hashes.h b/src/flamenco/runtime/fd_hashes.h index aab22ec82a..88d0a0f9a0 100644 --- a/src/flamenco/runtime/fd_hashes.h +++ b/src/flamenco/runtime/fd_hashes.h @@ -81,7 +81,9 @@ fd_accounts_hash_counter_and_gather_tpool_cb( void * para_arg_1, void * fn_arg_4 ); int -fd_update_hash_bank_exec_hash( fd_exec_slot_ctx_t * slot_ctx, +fd_update_hash_bank_exec_hash( fd_bank_t * bank, + fd_funk_t * funk, + fd_funk_txn_t * funk_txn, fd_hash_t * hash, fd_capture_ctx_t * capture_ctx, fd_accounts_hash_task_data_t * task_datas, diff --git a/src/flamenco/runtime/fd_runtime.c b/src/flamenco/runtime/fd_runtime.c index 98b19ccd40..6873e08a77 100644 --- a/src/flamenco/runtime/fd_runtime.c +++ b/src/flamenco/runtime/fd_runtime.c @@ -1366,15 +1366,17 @@ fd_runtime_block_execute_finalize_finish( fd_exec_slot_ctx_t * slot_ ulong lt_hash_cnt ) { fd_hash_t * bank_hash = fd_bank_bank_hash_modify( slot_ctx->bank ); - int err = fd_update_hash_bank_exec_hash( slot_ctx, - bank_hash, - capture_ctx, - task_data, - 1UL, - task_data->lthash_values, - lt_hash_cnt, - block_info->signature_cnt, - runtime_spad ); + int err = fd_update_hash_bank_exec_hash( slot_ctx->bank , + slot_ctx->funk, + slot_ctx->funk_txn, + bank_hash, + capture_ctx, + task_data, + 1UL, + task_data->lthash_values, + lt_hash_cnt, + block_info->signature_cnt, + runtime_spad ); if( FD_UNLIKELY( err ) ) { FD_LOG_ERR(( "Unable to hash at end of slot" )); From 382f336f43f9dd12afd15e9086c1eea6a1760f21 Mon Sep 17 00:00:00 2001 From: Ishan Bhatt Date: Fri, 27 Jun 2025 16:55:38 +0000 Subject: [PATCH 04/27] more slot ctx replacement --- src/discof/replay/fd_replay_tile.c | 18 +++++++----- src/flamenco/runtime/fd_hashes.c | 5 ++-- src/flamenco/runtime/fd_runtime.c | 47 ++++++++++++++++++------------ src/flamenco/runtime/fd_runtime.h | 8 +++-- 4 files changed, 49 insertions(+), 29 deletions(-) diff --git a/src/discof/replay/fd_replay_tile.c b/src/discof/replay/fd_replay_tile.c index 1c38aff954..ab8e66899a 100644 --- a/src/discof/replay/fd_replay_tile.c +++ b/src/discof/replay/fd_replay_tile.c @@ -1593,7 +1593,9 @@ init_after_snapshot( fd_replay_tile_ctx_t * ctx, .para_arg_2 = stem, }; - fd_runtime_block_execute_finalize_para( ctx->slot_ctx, + fd_runtime_block_execute_finalize_para( ctx->slot_ctx->bank, + ctx->slot_ctx->funk, + ctx->slot_ctx->funk_txn, ctx->capture_ctx, &info, ctx->exec_cnt, @@ -1971,12 +1973,14 @@ after_credit( fd_replay_tile_ctx_t * ctx, .para_arg_2 = stem, }; - fd_runtime_block_execute_finalize_para( ctx->slot_ctx, - ctx->capture_ctx, - runtime_block_info, - ctx->exec_cnt, - ctx->runtime_spad, - &exec_para_ctx_block_finalize ); + fd_runtime_block_execute_finalize_para( ctx->slot_ctx->bank, + ctx->slot_ctx->funk, + ctx->slot_ctx->funk_txn, + ctx->capture_ctx, + runtime_block_info, + ctx->exec_cnt, + ctx->runtime_spad, + &exec_para_ctx_block_finalize ); /* Update blockstore with the freshly computed bank hash */ fd_block_map_query_t query[1] = { 0 }; diff --git a/src/flamenco/runtime/fd_hashes.c b/src/flamenco/runtime/fd_hashes.c index ccec8f0f96..7907cc17e4 100644 --- a/src/flamenco/runtime/fd_hashes.c +++ b/src/flamenco/runtime/fd_hashes.c @@ -629,8 +629,9 @@ fd_update_hash_bank_tpool( fd_exec_slot_ctx_t * slot_ctx, break; } ulong end_idx = fd_ulong_sat_sub((worker_idx) * cnt_per_worker, 1UL); - if( end_idx >= task_data->info_sz ) - end_idx = fd_ulong_sat_sub( task_data->info_sz, 1UL );; + if( end_idx >= task_data->info_sz ) { + end_idx = fd_ulong_sat_sub( task_data->info_sz, 1UL ); + } fd_tpool_exec( tpool, worker_idx, fd_account_hash_task, task_data, start_idx, end_idx, <_hashes[worker_idx], slot_ctx, 0UL, diff --git a/src/flamenco/runtime/fd_runtime.c b/src/flamenco/runtime/fd_runtime.c index 6873e08a77..b6e417194c 100644 --- a/src/flamenco/runtime/fd_runtime.c +++ b/src/flamenco/runtime/fd_runtime.c @@ -1358,17 +1358,19 @@ fd_runtime_block_execute_finalize_start( fd_bank_t * bank, } int -fd_runtime_block_execute_finalize_finish( fd_exec_slot_ctx_t * slot_ctx, - fd_capture_ctx_t * capture_ctx, - fd_runtime_block_info_t const * block_info, - fd_spad_t * runtime_spad, - fd_accounts_hash_task_data_t * task_data, - ulong lt_hash_cnt ) { - - fd_hash_t * bank_hash = fd_bank_bank_hash_modify( slot_ctx->bank ); - int err = fd_update_hash_bank_exec_hash( slot_ctx->bank , - slot_ctx->funk, - slot_ctx->funk_txn, +fd_runtime_block_execute_finalize_finish( fd_bank_t * bank, + fd_funk_t * funk, + fd_funk_txn_t * funk_txn, + fd_capture_ctx_t * capture_ctx, + fd_runtime_block_info_t const * block_info, + fd_spad_t * runtime_spad, + fd_accounts_hash_task_data_t * task_data, + ulong lt_hash_cnt ) { + + fd_hash_t * bank_hash = fd_bank_bank_hash_modify( bank ); + int err = fd_update_hash_bank_exec_hash( bank, + funk, + funk_txn, bank_hash, capture_ctx, task_data, @@ -1420,7 +1422,9 @@ block_finalize_tpool_wrapper( void * para_arg_1, } int -fd_runtime_block_execute_finalize_para( fd_exec_slot_ctx_t * slot_ctx, +fd_runtime_block_execute_finalize_para( fd_bank_t * bank, + fd_funk_t * funk, + fd_funk_txn_t * funk_txn, fd_capture_ctx_t * capture_ctx, fd_runtime_block_info_t const * block_info, ulong worker_cnt, @@ -1429,19 +1433,24 @@ fd_runtime_block_execute_finalize_para( fd_exec_slot_ctx_t * slot_ct fd_accounts_hash_task_data_t * task_data = NULL; - fd_runtime_block_execute_finalize_start( slot_ctx->bank, - slot_ctx->funk, - slot_ctx->funk_txn, + fd_runtime_block_execute_finalize_start( bank, + funk, + funk_txn, runtime_spad, &task_data, worker_cnt ); exec_para_ctx->fn_arg_1 = (void*)task_data; exec_para_ctx->fn_arg_2 = (void*)worker_cnt; - exec_para_ctx->fn_arg_3 = (void*)slot_ctx; fd_exec_para_call_func( exec_para_ctx ); - fd_runtime_block_execute_finalize_finish( slot_ctx, capture_ctx, block_info, runtime_spad, task_data, worker_cnt ); + fd_runtime_block_execute_finalize_finish( bank, + funk, + funk_txn, + capture_ctx, + block_info, + runtime_spad, + task_data, worker_cnt ); return 0; } @@ -3921,7 +3930,9 @@ fd_runtime_block_execute_tpool( fd_exec_slot_ctx_t * slot_ctx, .para_arg_1 = tpool }; - res = fd_runtime_block_execute_finalize_para( slot_ctx, + res = fd_runtime_block_execute_finalize_para( slot_ctx->bank, + slot_ctx->funk, + slot_ctx->funk_txn, capture_ctx, block_info, fd_tpool_worker_cnt( tpool ), diff --git a/src/flamenco/runtime/fd_runtime.h b/src/flamenco/runtime/fd_runtime.h index e58095e2cc..06c54ffc18 100644 --- a/src/flamenco/runtime/fd_runtime.h +++ b/src/flamenco/runtime/fd_runtime.h @@ -514,7 +514,9 @@ fd_runtime_block_execute_finalize_start( fd_bank_t * bank, ulong lt_hash_cnt ); int -fd_runtime_block_execute_finalize_finish( fd_exec_slot_ctx_t * slot_ctx, +fd_runtime_block_execute_finalize_finish( fd_bank_t * bank, + fd_funk_t * funk, + fd_funk_txn_t * funk_txn, fd_capture_ctx_t * capture_ctx, fd_runtime_block_info_t const * block_info, fd_spad_t * runtime_spad, @@ -522,7 +524,9 @@ fd_runtime_block_execute_finalize_finish( fd_exec_slot_ctx_t * slot_ ulong lt_hash_cnt ); int -fd_runtime_block_execute_finalize_para( fd_exec_slot_ctx_t * slot_ctx, +fd_runtime_block_execute_finalize_para( fd_bank_t * bank, + fd_funk_t * funk, + fd_funk_txn_t * funk_txn, fd_capture_ctx_t * capture_ctx, fd_runtime_block_info_t const * block_info, ulong worker_cnt, From b187d27e8513246b0501d4f29ba759a4df0996ff Mon Sep 17 00:00:00 2001 From: Ishan Bhatt Date: Fri, 27 Jun 2025 17:26:53 +0000 Subject: [PATCH 05/27] more slot ctx replacement --- src/flamenco/features/fd_features.h | 2 +- src/flamenco/runtime/fd_bank.c | 2 +- src/flamenco/runtime/fd_bank.h | 6 +- src/flamenco/runtime/fd_executor.c | 41 +-- src/flamenco/runtime/fd_executor.h | 12 +- src/flamenco/runtime/fd_runtime.c | 278 ++++++++++-------- src/flamenco/runtime/fd_runtime.h | 24 +- .../runtime/program/fd_bpf_loader_program.c | 38 +-- .../runtime/program/fd_bpf_loader_program.h | 10 +- .../runtime/program/fd_builtin_programs.c | 36 +-- .../runtime/program/fd_builtin_programs.h | 10 +- .../runtime/tests/harness/fd_instr_harness.c | 30 +- .../runtime/tests/harness/fd_txn_harness.c | 2 +- 13 files changed, 266 insertions(+), 225 deletions(-) diff --git a/src/flamenco/features/fd_features.h b/src/flamenco/features/fd_features.h index 6daf0d9627..5b3c967dfe 100644 --- a/src/flamenco/features/fd_features.h +++ b/src/flamenco/features/fd_features.h @@ -24,7 +24,7 @@ #define FD_FEATURE_SET_ACTIVE(_features, _feature_name, _slot) ((_features)-> _feature_name = _slot) #define FD_FEATURE_JUST_ACTIVATED(_slot_ctx, _feature_name) FD_FEATURE_JUST_ACTIVATED_( _slot_ctx->slot, fd_bank_features_get(_slot_ctx->bank), _feature_name ) #define FD_FEATURE_ACTIVE_OFFSET(_slot, _features, _offset) FD_FEATURE_ACTIVE_OFFSET_( _slot, _features, _offset ) -#define FD_FEATURE_JUST_ACTIVATED_OFFSET(_slot_ctx, _offset) FD_FEATURE_JUST_ACTIVATED_OFFSET_( _slot_ctx->slot, fd_bank_features_get(_slot_ctx->bank), _offset ) +#define FD_FEATURE_JUST_ACTIVATED_OFFSET(_bank, _offset) FD_FEATURE_JUST_ACTIVATED_OFFSET_( _bank->slot, fd_bank_features_get(_bank), _offset ) #define FD_FEATURE_ACTIVE(_slot, _features, _feature_name) FD_FEATURE_ACTIVE_(_slot, _features, _feature_name) #define FD_FEATURE_ACTIVE_BANK(_bank, _feature_name) FD_FEATURE_ACTIVE_(_bank->slot, fd_bank_features_query( _bank ), _feature_name ) diff --git a/src/flamenco/runtime/fd_bank.c b/src/flamenco/runtime/fd_bank.c index 62d5006581..a673af1527 100644 --- a/src/flamenco/runtime/fd_bank.c +++ b/src/flamenco/runtime/fd_bank.c @@ -108,7 +108,7 @@ fd_bank_footprint( void ) { FD_STORE( type, bank->name, value ); \ } \ type \ - fd_bank_##name##_get( fd_bank_t * bank ) { \ + fd_bank_##name##_get( fd_bank_t const * bank ) { \ type val = FD_LOAD( type, bank->name ); \ return val; \ } diff --git a/src/flamenco/runtime/fd_bank.h b/src/flamenco/runtime/fd_bank.h index 335209ae63..a77e11d528 100644 --- a/src/flamenco/runtime/fd_bank.h +++ b/src/flamenco/runtime/fd_bank.h @@ -445,9 +445,9 @@ typedef struct fd_banks fd_banks_t; type const * fd_bank_##name##_query( fd_bank_t * bank ); \ type * fd_bank_##name##_modify( fd_bank_t * bank ); -#define X(type, name, footprint, align, cow, has_lock) \ - void fd_bank_##name##_set( fd_bank_t * bank, type value ); \ - type fd_bank_##name##_get( fd_bank_t * bank ); \ +#define X(type, name, footprint, align, cow, has_lock) \ + void fd_bank_##name##_set( fd_bank_t * bank, type value ); \ + type fd_bank_##name##_get( fd_bank_t const * bank ); \ HAS_LOCK_##has_lock(type, name) FD_BANKS_ITER(X) #undef X diff --git a/src/flamenco/runtime/fd_executor.c b/src/flamenco/runtime/fd_executor.c index 3272957c43..2f47287cb7 100644 --- a/src/flamenco/runtime/fd_executor.c +++ b/src/flamenco/runtime/fd_executor.c @@ -1256,13 +1256,13 @@ fd_executor_is_blockhash_valid_for_age( fd_block_hash_queue_global_t const * blo } void -fd_exec_txn_ctx_from_exec_slot_ctx( fd_exec_slot_ctx_t const * slot_ctx, - fd_exec_txn_ctx_t * ctx, - fd_wksp_t const * funk_wksp, - fd_wksp_t const * runtime_pub_wksp, - ulong funk_txn_gaddr, - ulong funk_gaddr, - fd_bank_hash_cmp_t * bank_hash_cmp ) { +fd_exec_txn_ctx_from_exec_slot_ctx( fd_bank_t * bank, + fd_exec_txn_ctx_t * ctx, + fd_wksp_t const * funk_wksp, + fd_wksp_t const * runtime_pub_wksp, + ulong funk_txn_gaddr, + ulong funk_gaddr, + fd_bank_hash_cmp_t * bank_hash_cmp ) { ctx->runtime_pub_wksp = (fd_wksp_t *)runtime_pub_wksp; @@ -1275,15 +1275,15 @@ fd_exec_txn_ctx_from_exec_slot_ctx( fd_exec_slot_ctx_t const * slot_ctx, FD_LOG_ERR(( "Could not find valid funk %lu", funk_gaddr )); } - ctx->status_cache = slot_ctx->status_cache; + /* TODO: Implement status cachce*/ ctx->bank_hash_cmp = bank_hash_cmp; - ctx->enable_exec_recording = fd_bank_enable_exec_recording_get( slot_ctx->bank ); + ctx->enable_exec_recording = fd_bank_enable_exec_recording_get( bank ); - ctx->bank = slot_ctx->bank; + ctx->bank = bank; - ctx->slot = slot_ctx->bank->slot; + ctx->slot = bank->slot; ctx->features = fd_bank_features_get( ctx->bank ); } @@ -1389,21 +1389,22 @@ fd_executor_setup_accounts_for_txn( fd_exec_txn_ctx_t * txn_ctx ) { /* Stuff to be done before multithreading can begin */ int -fd_execute_txn_prepare_start( fd_exec_slot_ctx_t const * slot_ctx, - fd_exec_txn_ctx_t * txn_ctx, - fd_txn_t const * txn_descriptor, - fd_rawtxn_b_t const * txn_raw ) { +fd_execute_txn_prepare_start( fd_bank_t * bank, + fd_funk_t const * funk, + fd_funk_txn_t const * funk_txn, + fd_exec_txn_ctx_t * txn_ctx, + fd_txn_t const * txn_descriptor, + fd_rawtxn_b_t const * txn_raw ) { - fd_funk_t * funk = slot_ctx->funk; fd_wksp_t * funk_wksp = fd_funk_wksp( funk ); /* FIXME: just pass in the runtime workspace, instead of getting it from fd_wksp_containing */ - fd_wksp_t * runtime_pub_wksp = fd_wksp_containing( slot_ctx ); - ulong funk_txn_gaddr = fd_wksp_gaddr( funk_wksp, slot_ctx->funk_txn ); - ulong funk_gaddr = fd_wksp_gaddr( funk_wksp, slot_ctx->funk->shmem ); + fd_wksp_t * runtime_pub_wksp = fd_wksp_containing( bank ); + ulong funk_txn_gaddr = fd_wksp_gaddr( funk_wksp, funk_txn ); + ulong funk_gaddr = fd_wksp_gaddr( funk_wksp, funk->shmem ); /* Init txn ctx */ fd_exec_txn_ctx_new( txn_ctx ); - fd_exec_txn_ctx_from_exec_slot_ctx( slot_ctx, + fd_exec_txn_ctx_from_exec_slot_ctx( bank, txn_ctx, funk_wksp, runtime_pub_wksp, diff --git a/src/flamenco/runtime/fd_executor.h b/src/flamenco/runtime/fd_executor.h index c806a00c70..8af9568b54 100644 --- a/src/flamenco/runtime/fd_executor.h +++ b/src/flamenco/runtime/fd_executor.h @@ -65,10 +65,12 @@ fd_execute_instr( fd_exec_txn_ctx_t * txn_ctx, fd_instr_info_t * instr_info ); int -fd_execute_txn_prepare_start( fd_exec_slot_ctx_t const * slot_ctx, - fd_exec_txn_ctx_t * txn_ctx, - fd_txn_t const * txn_descriptor, - fd_rawtxn_b_t const * txn_raw ); +fd_execute_txn_prepare_start( fd_bank_t * bank, + fd_funk_t const * funk, + fd_funk_txn_t const * funk_txn, + fd_exec_txn_ctx_t * txn_ctx, + fd_txn_t const * txn_descriptor, + fd_rawtxn_b_t const * txn_raw ); /* Execute the given transaction. @@ -139,7 +141,7 @@ fd_instr_stack_pop( fd_exec_txn_ctx_t * txn_ctx, fd_instr_info_t const * instr ); void -fd_exec_txn_ctx_from_exec_slot_ctx( fd_exec_slot_ctx_t const * slot_ctx, +fd_exec_txn_ctx_from_exec_slot_ctx( fd_bank_t * bank, fd_exec_txn_ctx_t * ctx, fd_wksp_t const * funk_wksp, fd_wksp_t const * runtime_pub_wksp, diff --git a/src/flamenco/runtime/fd_runtime.c b/src/flamenco/runtime/fd_runtime.c index b6e417194c..201542818a 100644 --- a/src/flamenco/runtime/fd_runtime.c +++ b/src/flamenco/runtime/fd_runtime.c @@ -1393,12 +1393,11 @@ block_finalize_tpool_wrapper( void * para_arg_1, void * para_arg_2 FD_PARAM_UNUSED, void * arg_1, void * arg_2, - void * arg_3, + void * arg_3 FD_PARAM_UNUSED, void * arg_4 FD_PARAM_UNUSED ) { fd_tpool_t * tpool = (fd_tpool_t *)para_arg_1; fd_accounts_hash_task_data_t * task_data = (fd_accounts_hash_task_data_t *)arg_1; ulong worker_cnt = (ulong)arg_2; - fd_exec_slot_ctx_t * slot_ctx = (fd_exec_slot_ctx_t *)arg_3; ulong cnt_per_worker = (worker_cnt>1) ? (task_data->info_sz / (worker_cnt-1UL)) + 1UL : task_data->info_sz; for( ulong worker_idx=1UL; worker_idxinfo_sz, 1UL );; fd_tpool_exec( tpool, worker_idx, fd_account_hash_task, task_data, start_idx, end_idx, - &task_data->lthash_values[worker_idx], slot_ctx, 0UL, + &task_data->lthash_values[worker_idx], NULL, 0UL, 0UL, 0UL, worker_idx, 0UL, 0UL, 0UL ); } @@ -1463,7 +1462,9 @@ fd_runtime_block_execute_finalize_para( fd_bank_t * bank, the slot_ctx, and for setting up the accessed accounts. */ int -fd_runtime_prepare_txns_start( fd_exec_slot_ctx_t * slot_ctx, +fd_runtime_prepare_txns_start( fd_bank_t * bank, + fd_funk_t * funk, + fd_funk_txn_t * funk_txn, fd_execute_txn_task_info_t * task_info, fd_txn_p_t * txns, ulong txn_cnt, @@ -1484,7 +1485,9 @@ fd_runtime_prepare_txns_start( fd_exec_slot_ctx_t * slot_ctx, task_info[txn_idx].txn_ctx->spad = runtime_spad; task_info[txn_idx].txn_ctx->spad_wksp = fd_wksp_containing( runtime_spad ); - int err = fd_execute_txn_prepare_start( slot_ctx, + int err = fd_execute_txn_prepare_start( bank, + funk, + funk_txn, txn_ctx, txn_descriptor, &raw_txn ); @@ -1767,13 +1770,15 @@ fd_runtime_finalize_txn( fd_funk_t * funk, NOTE: The executor tile doesn't exist yet. */ static int -fd_runtime_prepare_and_execute_txn( fd_exec_slot_ctx_t const * slot_ctx, +fd_runtime_prepare_and_execute_txn( fd_bank_t * bank, + fd_funk_t * funk, + fd_funk_txn_t * funk_txn, fd_txn_p_t * txn, fd_execute_txn_task_info_t * task_info, fd_spad_t * exec_spad, fd_capture_ctx_t * capture_ctx ) { - uchar dump_txn = !!( capture_ctx && slot_ctx->slot >= capture_ctx->dump_proto_start_slot && capture_ctx->dump_txn_to_pb ); + uchar dump_txn = !!( capture_ctx && bank->slot >= capture_ctx->dump_proto_start_slot && capture_ctx->dump_txn_to_pb ); int res = 0; fd_exec_txn_ctx_t * txn_ctx = task_info->txn_ctx; @@ -1785,7 +1790,7 @@ fd_runtime_prepare_and_execute_txn( fd_exec_slot_ctx_t const * slot_ctx, fd_rawtxn_b_t raw_txn = { .raw = txn->payload, .txn_sz = (ushort)txn->payload_sz }; - res = fd_execute_txn_prepare_start( slot_ctx, txn_ctx, txn_descriptor, &raw_txn ); + res = fd_execute_txn_prepare_start( bank, funk, funk_txn, txn_ctx, txn_descriptor, &raw_txn ); if( FD_UNLIKELY( res ) ) { txn->flags = 0U; return -1; @@ -1823,21 +1828,25 @@ fd_runtime_prepare_execute_finalize_txn_task( void * tpool, ulong t1, void * args, void * reduce, - ulong stride FD_PARAM_UNUSED, - ulong l0 FD_PARAM_UNUSED, + ulong stride, + ulong l0, ulong l1 FD_PARAM_UNUSED, ulong m0 FD_PARAM_UNUSED, ulong m1 FD_PARAM_UNUSED, ulong n0 FD_PARAM_UNUSED, ulong n1 FD_PARAM_UNUSED ) { - fd_exec_slot_ctx_t * slot_ctx = (fd_exec_slot_ctx_t *)tpool; + fd_bank_t * bank = (fd_bank_t *)tpool; fd_capture_ctx_t * capture_ctx = (fd_capture_ctx_t *)t0; fd_txn_p_t * txn = (fd_txn_p_t *)t1; fd_execute_txn_task_info_t * task_info = (fd_execute_txn_task_info_t *)args; fd_spad_t * exec_spad = (fd_spad_t *)reduce; + fd_funk_t * funk = (fd_funk_t *)stride; + fd_funk_txn_t * funk_txn = (fd_funk_txn_t *)l0; - fd_runtime_prepare_and_execute_txn( slot_ctx, + fd_runtime_prepare_and_execute_txn( bank, + funk, + funk_txn, txn, task_info, exec_spad, @@ -1847,7 +1856,7 @@ fd_runtime_prepare_execute_finalize_txn_task( void * tpool, return; } - fd_runtime_finalize_txn( slot_ctx->funk, slot_ctx->funk_txn, task_info, task_info->txn_ctx->spad, slot_ctx->bank ); + fd_runtime_finalize_txn( funk, funk_txn, task_info, task_info->txn_ctx->spad, bank ); } /* fd_executor_txn_verify and fd_runtime_pre_execute_check are responisble @@ -1884,15 +1893,17 @@ fd_runtime_prepare_execute_finalize_txn_task( void * tpool, is paralled by fd_executor_load_transaction_accounts(). */ int -fd_runtime_process_txns_in_microblock_stream( fd_exec_slot_ctx_t * slot_ctx, - fd_capture_ctx_t * capture_ctx, - fd_txn_p_t * txns, - ulong txn_cnt, - fd_tpool_t * tpool, - fd_spad_t * * exec_spads, - ulong exec_spad_cnt, - fd_spad_t * runtime_spad, - fd_cost_tracker_t * cost_tracker_opt ) { +fd_runtime_process_txns_in_microblock_stream( fd_bank_t * bank, + fd_funk_t * funk, + fd_funk_txn_t * funk_txn, + fd_capture_ctx_t * capture_ctx, + fd_txn_p_t * txns, + ulong txn_cnt, + fd_tpool_t * tpool, + fd_spad_t * * exec_spads, + ulong exec_spad_cnt, + fd_spad_t * runtime_spad, + fd_cost_tracker_t * cost_tracker_opt ) { int res = 0; @@ -1931,9 +1942,9 @@ fd_runtime_process_txns_in_microblock_stream( fd_exec_slot_ctx_t * slot_ctx, } fd_tpool_exec( tpool, worker_idx, fd_runtime_prepare_execute_finalize_txn_task, - slot_ctx, (ulong)capture_ctx, (ulong)task_infos[curr_exec_idx].txn, - &task_infos[ curr_exec_idx ], exec_spads[ worker_idx ], 0UL, - 0UL, 0UL, 0UL, 0UL, 0UL, 0UL ); + bank, (ulong)capture_ctx, (ulong)task_infos[curr_exec_idx].txn, + &task_infos[ curr_exec_idx ], exec_spads[ worker_idx ], (ulong)funk, + (ulong)funk_txn, 0UL, 0UL, 0UL, 0UL, 0UL); curr_exec_idx++; } @@ -1945,7 +1956,7 @@ fd_runtime_process_txns_in_microblock_stream( fd_exec_slot_ctx_t * slot_ctx, /* Verify cost tracker limits (only for offline replay) https://github.com/anza-xyz/agave/blob/v2.2.0/ledger/src/blockstore_processor.rs#L284-L299 */ - if( cost_tracker_opt!=NULL && FD_FEATURE_ACTIVE_BANK( slot_ctx->bank, apply_cost_tracker_during_replay ) ) { + if( cost_tracker_opt!=NULL && FD_FEATURE_ACTIVE_BANK( bank, apply_cost_tracker_during_replay ) ) { for( ulong i=exec_idx_start; islot )); + FD_LOG_WARNING(( "Block cost limits exceeded for slot %lu", bank->slot )); break; } } @@ -1993,10 +2004,10 @@ the cache only at epoch boundaries. https://github.com/solana-labs/solana/blob/c091fd3da8014c0ef83b626318018f238f506435/runtime/src/stakes.rs#L65 */ static void -fd_update_stake_delegations( fd_exec_slot_ctx_t * slot_ctx, - fd_epoch_info_t * temp_info ) { +fd_update_stake_delegations( fd_bank_t * bank, + fd_epoch_info_t * temp_info ) { - fd_stakes_global_t * stakes = fd_bank_stakes_locking_modify( slot_ctx->bank ); + fd_stakes_global_t * stakes = fd_bank_stakes_locking_modify( bank ); fd_delegation_pair_t_mapnode_t * stake_delegations_pool = fd_stakes_stake_delegations_pool_join( stakes ); fd_delegation_pair_t_mapnode_t * stake_delegations_root = fd_stakes_stake_delegations_root_join( stakes ); @@ -2021,26 +2032,26 @@ fd_update_stake_delegations( fd_exec_slot_ctx_t * slot_ctx, fd_stakes_stake_delegations_pool_update( stakes, stake_delegations_pool ); fd_stakes_stake_delegations_root_update( stakes, stake_delegations_root ); - fd_bank_stakes_end_locking_modify( slot_ctx->bank ); + fd_bank_stakes_end_locking_modify( bank ); /* At the epoch boundary, release all of the stake account keys because at this point all of the changes have been applied to the stakes. */ - fd_account_keys_global_t * stake_account_keys = fd_bank_stake_account_keys_locking_modify( slot_ctx->bank ); - fd_account_keys_pair_t_mapnode_t * account_keys_pool = fd_account_keys_account_keys_pool_join( stake_account_keys ); - fd_account_keys_pair_t_mapnode_t * account_keys_root = fd_account_keys_account_keys_root_join( stake_account_keys ); + fd_account_keys_global_t * stake_account_keys = fd_bank_stake_account_keys_locking_modify( bank ); + fd_account_keys_pair_t_mapnode_t * account_keys_pool = fd_account_keys_account_keys_pool_join( stake_account_keys ); + fd_account_keys_pair_t_mapnode_t * account_keys_root = fd_account_keys_account_keys_root_join( stake_account_keys ); fd_account_keys_pair_t_map_release_tree( account_keys_pool, account_keys_root ); account_keys_root = NULL; fd_account_keys_account_keys_pool_update( stake_account_keys, account_keys_pool ); fd_account_keys_account_keys_root_update( stake_account_keys, account_keys_root ); - fd_bank_stake_account_keys_end_locking_modify( slot_ctx->bank ); + fd_bank_stake_account_keys_end_locking_modify( bank ); } /* Replace the stakes in T-2 (slot_ctx->slot_bank.epoch_stakes) by the stakes at T-1 (epoch_bank->next_epoch_stakes) */ static void -fd_update_epoch_stakes( fd_exec_slot_ctx_t * slot_ctx ) { +fd_update_epoch_stakes( fd_bank_t * bank ) { /* Copy epoch_bank->next_epoch_stakes into slot_ctx->slot_bank.epoch_stakes */ @@ -2048,19 +2059,19 @@ fd_update_epoch_stakes( fd_exec_slot_ctx_t * slot_ctx ) { fd_vote_accounts_pair_global_t_map_footprint( 50000UL ) + 4000 * 50000UL; - fd_vote_accounts_global_t const * next_epoch_stakes = fd_bank_next_epoch_stakes_locking_query( slot_ctx->bank ); + fd_vote_accounts_global_t const * next_epoch_stakes = fd_bank_next_epoch_stakes_locking_query( bank ); - fd_vote_accounts_global_t * epoch_stakes = fd_bank_epoch_stakes_locking_modify( slot_ctx->bank ); + fd_vote_accounts_global_t * epoch_stakes = fd_bank_epoch_stakes_locking_modify( bank ); fd_memcpy( epoch_stakes, next_epoch_stakes, total_sz ); - fd_bank_epoch_stakes_end_locking_modify( slot_ctx->bank ); + fd_bank_epoch_stakes_end_locking_modify( bank ); - fd_bank_next_epoch_stakes_end_locking_query( slot_ctx->bank ); + fd_bank_next_epoch_stakes_end_locking_query( bank ); } /* Copy epoch_bank->stakes.vote_accounts into epoch_bank->next_epoch_stakes. */ static void -fd_update_next_epoch_stakes( fd_exec_slot_ctx_t * slot_ctx ) { +fd_update_next_epoch_stakes( fd_bank_t * bank ) { /* FIXME: This is technically not correct, since the vote accounts could be laid out after the stake delegations from fd_stakes. @@ -2073,16 +2084,15 @@ fd_update_next_epoch_stakes( fd_exec_slot_ctx_t * slot_ctx ) { fd_vote_accounts_pair_global_t_map_footprint( 50000UL ) + 4000 * 50000UL; - - fd_stakes_global_t const * stakes = fd_bank_stakes_locking_query( slot_ctx->bank ); + fd_stakes_global_t const * stakes = fd_bank_stakes_locking_query( bank ); fd_vote_accounts_global_t const * vote_stakes = &stakes->vote_accounts; - fd_vote_accounts_global_t * next_epoch_stakes = fd_bank_next_epoch_stakes_locking_modify( slot_ctx->bank ); + fd_vote_accounts_global_t * next_epoch_stakes = fd_bank_next_epoch_stakes_locking_modify( bank ); fd_memcpy( next_epoch_stakes, vote_stakes, total_sz ); - fd_bank_next_epoch_stakes_end_locking_modify( slot_ctx->bank ); + fd_bank_next_epoch_stakes_end_locking_modify( bank ); - fd_bank_stakes_end_locking_query( slot_ctx->bank ); + fd_bank_stakes_end_locking_query( bank ); } /* Mimics `bank.new_target_program_account()`. Assumes `out_rec` is a modifiable record. @@ -2094,9 +2104,9 @@ fd_update_next_epoch_stakes( fd_exec_slot_ctx_t * slot_ctx ) { https://github.com/anza-xyz/agave/blob/v2.1.0/runtime/src/bank/builtins/core_bpf_migration/mod.rs#L79-L95 */ static int -fd_new_target_program_account( fd_exec_slot_ctx_t * slot_ctx, - fd_pubkey_t const * target_program_data_address, - fd_txn_account_t * out_rec ) { +fd_new_target_program_account( fd_bank_t * bank, + fd_pubkey_t const * target_program_data_address, + fd_txn_account_t * out_rec ) { /* https://github.com/anza-xyz/agave/blob/v2.1.0/sdk/account/src/lib.rs#L471 */ out_rec->vt->set_rent_epoch( out_rec, 0UL ); @@ -2111,7 +2121,7 @@ fd_new_target_program_account( fd_exec_slot_ctx_t * slot_ctx, }; /* https://github.com/anza-xyz/agave/blob/v2.1.0/runtime/src/bank/builtins/core_bpf_migration/mod.rs#L89-L90 */ - fd_rent_t const * rent = fd_bank_rent_query( slot_ctx->bank ); + fd_rent_t const * rent = fd_bank_rent_query( bank ); if( FD_UNLIKELY( rent==NULL ) ) { return -1; } @@ -2143,11 +2153,11 @@ fd_new_target_program_account( fd_exec_slot_ctx_t * slot_ctx, https://github.com/anza-xyz/agave/blob/v2.1.0/runtime/src/bank/builtins/core_bpf_migration/mod.rs#L97-L153 */ static int -fd_new_target_program_data_account( fd_exec_slot_ctx_t * slot_ctx, - fd_pubkey_t * config_upgrade_authority_address, - fd_txn_account_t * buffer_acc_rec, - fd_txn_account_t * new_target_program_data_account, - fd_spad_t * runtime_spad ) { +fd_new_target_program_data_account( fd_bank_t * bank, + fd_pubkey_t * config_upgrade_authority_address, + fd_txn_account_t * buffer_acc_rec, + fd_txn_account_t * new_target_program_data_account, + fd_spad_t * runtime_spad ) { FD_SPAD_FRAME_BEGIN( runtime_spad ) { @@ -2173,7 +2183,7 @@ fd_new_target_program_data_account( fd_exec_slot_ctx_t * slot_ctx, } /* https://github.com/anza-xyz/agave/blob/v2.1.0/runtime/src/bank/builtins/core_bpf_migration/mod.rs#L127-L132 */ - fd_rent_t const * rent = fd_bank_rent_query( slot_ctx->bank ); + fd_rent_t const * rent = fd_bank_rent_query( bank ); if( FD_UNLIKELY( rent==NULL ) ) { return -1; } @@ -2187,7 +2197,7 @@ fd_new_target_program_data_account( fd_exec_slot_ctx_t * slot_ctx, .discriminant = fd_bpf_upgradeable_loader_state_enum_program_data, .inner = { .program_data = { - .slot = slot_ctx->slot, + .slot = bank->slot, .upgrade_authority_address = config_upgrade_authority_address } } @@ -2224,12 +2234,14 @@ fd_new_target_program_data_account( fd_exec_slot_ctx_t * slot_ctx, - upgrade_authority_address: upgrade_authority_address https://github.com/anza-xyz/agave/blob/v2.1.0/runtime/src/bank/builtins/core_bpf_migration/mod.rs#L235-L318 */ static void -fd_migrate_builtin_to_core_bpf( fd_exec_slot_ctx_t * slot_ctx, - fd_pubkey_t * upgrade_authority_address, - fd_pubkey_t const * builtin_program_id, - fd_pubkey_t const * source_buffer_address, - uchar stateless, - fd_spad_t * runtime_spad ) { +fd_migrate_builtin_to_core_bpf( fd_bank_t * bank, + fd_funk_t * funk, + fd_funk_txn_t * funk_txn, + fd_pubkey_t * upgrade_authority_address, + fd_pubkey_t const * builtin_program_id, + fd_pubkey_t const * source_buffer_address, + uchar stateless, + fd_spad_t * runtime_spad ) { int err; /* https://github.com/anza-xyz/agave/blob/v2.1.0/runtime/src/bank/builtins/core_bpf_migration/mod.rs#L242-L243 @@ -2245,7 +2257,7 @@ fd_migrate_builtin_to_core_bpf( fd_exec_slot_ctx_t * slot_ctx, will no longer be the native loader. https://github.com/anza-xyz/agave/blob/v2.1.0/runtime/src/bank/builtins/core_bpf_migration/target_builtin.rs#L23-L50 */ FD_TXN_ACCOUNT_DECL( target_program_account ); - uchar program_exists = ( fd_txn_account_init_from_funk_readonly( target_program_account, builtin_program_id, slot_ctx->funk, slot_ctx->funk_txn )==FD_ACC_MGR_SUCCESS ); + uchar program_exists = ( fd_txn_account_init_from_funk_readonly( target_program_account, builtin_program_id, funk, funk_txn )==FD_ACC_MGR_SUCCESS ); if( !stateless ) { /* The program account should exist. https://github.com/anza-xyz/agave/blob/v2.1.0/runtime/src/bank/builtins/core_bpf_migration/target_builtin.rs#L30-L33 */ @@ -2284,7 +2296,7 @@ fd_migrate_builtin_to_core_bpf( fd_exec_slot_ctx_t * slot_ctx, return; } FD_TXN_ACCOUNT_DECL( program_data_account ); - if( FD_UNLIKELY( fd_txn_account_init_from_funk_readonly( program_data_account, target_program_data_address, slot_ctx->funk, slot_ctx->funk_txn )==FD_ACC_MGR_SUCCESS ) ) { + if( FD_UNLIKELY( fd_txn_account_init_from_funk_readonly( program_data_account, target_program_data_address, funk, funk_txn )==FD_ACC_MGR_SUCCESS ) ) { FD_LOG_WARNING(( "Program data account %s already exists, skipping migration...", FD_BASE58_ENC_32_ALLOCA( target_program_data_address ) )); return; } @@ -2298,7 +2310,7 @@ fd_migrate_builtin_to_core_bpf( fd_exec_slot_ctx_t * slot_ctx, /* The buffer account should exist. https://github.com/anza-xyz/agave/blob/v2.1.0/runtime/src/bank/builtins/core_bpf_migration/source_buffer.rs#L26-L29 */ FD_TXN_ACCOUNT_DECL( source_buffer_account ); - if( FD_UNLIKELY( fd_txn_account_init_from_funk_mutable( source_buffer_account, source_buffer_address, slot_ctx->funk, slot_ctx->funk_txn, 0, 0UL )!=FD_ACC_MGR_SUCCESS ) ) { + if( FD_UNLIKELY( fd_txn_account_init_from_funk_mutable( source_buffer_account, source_buffer_address, funk, funk_txn, 0, 0UL )!=FD_ACC_MGR_SUCCESS ) ) { FD_LOG_WARNING(( "Buffer account %s does not exist, skipping migration...", FD_BASE58_ENC_32_ALLOCA( source_buffer_address ) )); return; } @@ -2321,40 +2333,40 @@ fd_migrate_builtin_to_core_bpf( fd_exec_slot_ctx_t * slot_ctx, ulong lamports_to_burn = ( stateless ? 0UL : target_program_account->vt->get_lamports( target_program_account ) ) + source_buffer_account->vt->get_lamports( source_buffer_account ); /* Start a funk write txn */ - fd_funk_txn_t * parent_txn = slot_ctx->funk_txn; + fd_funk_txn_t * parent_txn = funk_txn; fd_funk_txn_xid_t migration_xid = fd_funk_generate_xid(); - fd_funk_txn_start_write( slot_ctx->funk ); - slot_ctx->funk_txn = fd_funk_txn_prepare( slot_ctx->funk, slot_ctx->funk_txn, &migration_xid, 0UL ); - fd_funk_txn_end_write( slot_ctx->funk ); + fd_funk_txn_start_write( funk ); + funk_txn = fd_funk_txn_prepare( funk, funk_txn, &migration_xid, 0UL ); + fd_funk_txn_end_write( funk ); /* Attempt serialization of program account. If the program is stateless, we want to create the account. Otherwise, we want a writable handle to modify the existing account. https://github.com/anza-xyz/agave/blob/v2.1.0/runtime/src/bank/builtins/core_bpf_migration/mod.rs#L246-L249 */ FD_TXN_ACCOUNT_DECL( new_target_program_account ); - err = fd_txn_account_init_from_funk_mutable( new_target_program_account, builtin_program_id, slot_ctx->funk, slot_ctx->funk_txn, stateless, SIZE_OF_PROGRAM ); + err = fd_txn_account_init_from_funk_mutable( new_target_program_account, builtin_program_id, funk, funk_txn, stateless, SIZE_OF_PROGRAM ); if( FD_UNLIKELY( err ) ) { FD_LOG_WARNING(( "Builtin program ID %s does not exist", FD_BASE58_ENC_32_ALLOCA( builtin_program_id ) )); goto fail; } new_target_program_account->vt->set_data_len( new_target_program_account, SIZE_OF_PROGRAM ); - new_target_program_account->vt->set_slot( new_target_program_account, slot_ctx->slot ); + new_target_program_account->vt->set_slot( new_target_program_account, bank->slot ); /* Create a new target program account. This modifies the existing record. */ - err = fd_new_target_program_account( slot_ctx, target_program_data_address, new_target_program_account ); + err = fd_new_target_program_account( bank, target_program_data_address, new_target_program_account ); if( FD_UNLIKELY( err ) ) { FD_LOG_WARNING(( "Failed to write new program state to %s", FD_BASE58_ENC_32_ALLOCA( builtin_program_id ) )); goto fail; } - fd_txn_account_mutable_fini( new_target_program_account, slot_ctx->funk, slot_ctx->funk_txn ); + fd_txn_account_mutable_fini( new_target_program_account, funk, funk_txn ); /* Create a new target program data account. */ ulong new_target_program_data_account_sz = PROGRAMDATA_METADATA_SIZE - BUFFER_METADATA_SIZE + source_buffer_account->vt->get_data_len( source_buffer_account ); FD_TXN_ACCOUNT_DECL( new_target_program_data_account ); err = fd_txn_account_init_from_funk_mutable( new_target_program_data_account, target_program_data_address, - slot_ctx->funk, - slot_ctx->funk_txn, + funk, + funk_txn, 1, new_target_program_data_account_sz ); if( FD_UNLIKELY( err ) ) { @@ -2362,9 +2374,9 @@ fd_migrate_builtin_to_core_bpf( fd_exec_slot_ctx_t * slot_ctx, goto fail; } new_target_program_data_account->vt->set_data_len( new_target_program_data_account, new_target_program_data_account_sz ); - new_target_program_data_account->vt->set_slot( new_target_program_data_account, slot_ctx->slot ); + new_target_program_data_account->vt->set_slot( new_target_program_data_account, bank->slot ); - err = fd_new_target_program_data_account( slot_ctx, + err = fd_new_target_program_data_account( bank, upgrade_authority_address, source_buffer_account, new_target_program_data_account, @@ -2374,14 +2386,17 @@ fd_migrate_builtin_to_core_bpf( fd_exec_slot_ctx_t * slot_ctx, goto fail; } - fd_txn_account_mutable_fini( new_target_program_data_account, slot_ctx->funk, slot_ctx->funk_txn ); + fd_txn_account_mutable_fini( new_target_program_data_account, funk, funk_txn ); /* Deploy the new target Core BPF program. https://github.com/anza-xyz/agave/blob/v2.1.0/runtime/src/bank/builtins/core_bpf_migration/mod.rs#L268-L271 */ - err = fd_directly_invoke_loader_v3_deploy( slot_ctx, - new_target_program_data_account->vt->get_data( new_target_program_data_account ) + PROGRAMDATA_METADATA_SIZE, - new_target_program_data_account->vt->get_data_len( new_target_program_data_account ) - PROGRAMDATA_METADATA_SIZE, - runtime_spad ); + err = fd_directly_invoke_loader_v3_deploy( + bank, + funk, + funk_txn, + new_target_program_data_account->vt->get_data( new_target_program_data_account ) + PROGRAMDATA_METADATA_SIZE, + new_target_program_data_account->vt->get_data_len( new_target_program_data_account ) - PROGRAMDATA_METADATA_SIZE, + runtime_spad ); if( FD_UNLIKELY( err ) ) { FD_LOG_WARNING(( "Failed to deploy program %s", FD_BASE58_ENC_32_ALLOCA( builtin_program_id ) )); goto fail; @@ -2393,9 +2408,9 @@ fd_migrate_builtin_to_core_bpf( fd_exec_slot_ctx_t * slot_ctx, /* Update capitalization. https://github.com/anza-xyz/agave/blob/v2.1.0/runtime/src/bank/builtins/core_bpf_migration/mod.rs#L286-L297 */ if( lamports_to_burn>lamports_to_fund ) { - fd_bank_capitalization_set( slot_ctx->bank, fd_bank_capitalization_get( slot_ctx->bank ) - ( lamports_to_burn - lamports_to_fund ) ); + fd_bank_capitalization_set( bank, fd_bank_capitalization_get( bank ) - ( lamports_to_burn - lamports_to_fund ) ); } else { - fd_bank_capitalization_set( slot_ctx->bank, fd_bank_capitalization_get( slot_ctx->bank ) + ( lamports_to_fund - lamports_to_burn ) ); + fd_bank_capitalization_set( bank, fd_bank_capitalization_get( bank ) + ( lamports_to_fund - lamports_to_burn ) ); } /* Reclaim the source buffer account @@ -2404,30 +2419,32 @@ fd_migrate_builtin_to_core_bpf( fd_exec_slot_ctx_t * slot_ctx, source_buffer_account->vt->set_data_len( source_buffer_account, 0 ); source_buffer_account->vt->clear_owner( source_buffer_account ); - fd_txn_account_mutable_fini( source_buffer_account, slot_ctx->funk, slot_ctx->funk_txn ); + fd_txn_account_mutable_fini( source_buffer_account, funk, funk_txn ); /* Publish the in-preparation transaction into the parent. We should not have to create a BPF cache entry here because the program is technically "delayed visibility", so the program should not be invokable until the next slot. The cache entry will be created at the end of the block as a part of the finalize routine. */ - fd_funk_txn_start_write( slot_ctx->funk ); - fd_funk_txn_publish_into_parent( slot_ctx->funk, slot_ctx->funk_txn, 1 ); - fd_funk_txn_end_write( slot_ctx->funk ); - slot_ctx->funk_txn = parent_txn; + fd_funk_txn_start_write( funk ); + fd_funk_txn_publish_into_parent( funk, funk_txn, 1 ); + fd_funk_txn_end_write( funk ); + funk_txn = parent_txn; return; fail: /* Cancel the in-preparation transaction and discard any in-progress changes. */ - fd_funk_txn_start_write( slot_ctx->funk ); - fd_funk_txn_cancel( slot_ctx->funk, slot_ctx->funk_txn, 0UL ); - fd_funk_txn_end_write( slot_ctx->funk ); - slot_ctx->funk_txn = parent_txn; + fd_funk_txn_start_write( funk ); + fd_funk_txn_cancel( funk, funk_txn, 0UL ); + fd_funk_txn_end_write( funk ); + funk_txn = parent_txn; } /* https://github.com/anza-xyz/agave/blob/v2.1.0/runtime/src/bank.rs#L6704 */ static void -fd_apply_builtin_program_feature_transitions( fd_exec_slot_ctx_t * slot_ctx, - fd_spad_t * runtime_spad ) { +fd_apply_builtin_program_feature_transitions( fd_bank_t * bank, + fd_funk_t * funk, + fd_funk_txn_t * funk_txn, + fd_spad_t * runtime_spad ) { /* TODO: Set the upgrade authority properly from the core bpf migration config. Right now it's set to None. Migrate any necessary stateless builtins to core BPF. So far, the only "stateless" builtin @@ -2439,28 +2456,33 @@ fd_apply_builtin_program_feature_transitions( fd_exec_slot_ctx_t * slot_ctx, fd_builtin_program_t const * builtins = fd_builtins(); for( ulong i=0UL; islot, fd_bank_features_get( slot_ctx->bank ), builtins[i].core_bpf_migration_config->enable_feature_offset ) ) { + if( builtins[i].core_bpf_migration_config && FD_FEATURE_ACTIVE_OFFSET( bank->slot, fd_bank_features_get( bank ), builtins[i].core_bpf_migration_config->enable_feature_offset ) ) { FD_LOG_NOTICE(( "Migrating builtin program %s to core BPF", FD_BASE58_ENC_32_ALLOCA( builtins[i].pubkey->key ) )); - fd_migrate_builtin_to_core_bpf( slot_ctx, - builtins[i].core_bpf_migration_config->upgrade_authority_address, - builtins[i].core_bpf_migration_config->builtin_program_id, - builtins[i].core_bpf_migration_config->source_buffer_address, - 0, - runtime_spad ); + fd_migrate_builtin_to_core_bpf( + bank, + funk, + funk_txn, + builtins[i].core_bpf_migration_config->upgrade_authority_address, + builtins[i].core_bpf_migration_config->builtin_program_id, + builtins[i].core_bpf_migration_config->source_buffer_address, + 0, + runtime_spad ); } /* https://github.com/anza-xyz/agave/blob/v2.1.0/runtime/src/bank.rs#L6753-L6774 */ - if( builtins[i].enable_feature_offset!=NO_ENABLE_FEATURE_ID && FD_FEATURE_JUST_ACTIVATED_OFFSET( slot_ctx, builtins[i].enable_feature_offset ) ) { + if( builtins[i].enable_feature_offset!=NO_ENABLE_FEATURE_ID && FD_FEATURE_JUST_ACTIVATED_OFFSET( bank, builtins[i].enable_feature_offset ) ) { FD_LOG_NOTICE(( "Enabling builtin program %s", FD_BASE58_ENC_32_ALLOCA( builtins[i].pubkey->key ) )); - fd_write_builtin_account( slot_ctx, *builtins[i].pubkey, builtins[i].data,strlen(builtins[i].data) ); + fd_write_builtin_account( bank, funk, funk_txn, *builtins[i].pubkey, builtins[i].data, strlen(builtins[i].data) ); } } /* https://github.com/anza-xyz/agave/blob/v2.1.0/runtime/src/bank.rs#L6776-L6793 */ fd_stateless_builtin_program_t const * stateless_builtins = fd_stateless_builtins(); for( ulong i=0UL; islot, fd_bank_features_get( slot_ctx->bank ), stateless_builtins[i].core_bpf_migration_config->enable_feature_offset ) ) { + if( stateless_builtins[i].core_bpf_migration_config && FD_FEATURE_ACTIVE_OFFSET( bank->slot, fd_bank_features_get( bank ), stateless_builtins[i].core_bpf_migration_config->enable_feature_offset ) ) { FD_LOG_NOTICE(( "Migrating stateless builtin program %s to core BPF", FD_BASE58_ENC_32_ALLOCA( stateless_builtins[i].pubkey->key ) )); - fd_migrate_builtin_to_core_bpf( slot_ctx, + fd_migrate_builtin_to_core_bpf( bank, + funk, + funk_txn, stateless_builtins[i].core_bpf_migration_config->upgrade_authority_address, stateless_builtins[i].core_bpf_migration_config->builtin_program_id, stateless_builtins[i].core_bpf_migration_config->source_buffer_address, @@ -2472,8 +2494,8 @@ fd_apply_builtin_program_feature_transitions( fd_exec_slot_ctx_t * slot_ctx, /* https://github.com/anza-xyz/agave/blob/c1080de464cfb578c301e975f498964b5d5313db/runtime/src/bank.rs#L6795-L6805 */ fd_precompile_program_t const * precompiles = fd_precompiles(); for( ulong i=0UL; ibank, slot_ctx->funk, slot_ctx->funk_txn, runtime_spad ); /* Change the speed of the poh clock https://github.com/anza-xyz/agave/blob/v2.1.0/runtime/src/bank.rs#L6627-L6649 */ @@ -2637,7 +2659,7 @@ fd_runtime_process_new_epoch( fd_exec_slot_ctx_t * slot_ctx, See the comment in fd_exec_slot_ctx_recover_. */ if( fd_bank_use_prev_epoch_stake_get( slot_ctx->bank ) == epoch ) { - fd_update_epoch_stakes( slot_ctx ); + fd_update_epoch_stakes( slot_ctx->bank ); } /* Updates stake history sysvar accumulated values. */ @@ -2654,7 +2676,7 @@ fd_runtime_process_new_epoch( fd_exec_slot_ctx_t * slot_ctx, stakes->epoch = epoch; fd_bank_stakes_end_locking_modify( slot_ctx->bank ); - fd_update_stake_delegations( slot_ctx, &temp_info ); + fd_update_stake_delegations( slot_ctx->bank, &temp_info ); /* Refresh vote accounts in stakes cache using updated stake weights, and merges slot bank vote accounts with the epoch bank vote accounts. https://github.com/anza-xyz/agave/blob/v2.1.6/runtime/src/stakes.rs#L363-L370 */ @@ -2697,10 +2719,10 @@ fd_runtime_process_new_epoch( fd_exec_slot_ctx_t * slot_ctx, runtime_spad ); /* Replace stakes at T-2 (slot_ctx->slot_bank.epoch_stakes) by stakes at T-1 (epoch_bank->next_epoch_stakes) */ - fd_update_epoch_stakes( slot_ctx ); + fd_update_epoch_stakes( slot_ctx->bank ); /* Replace stakes at T-1 (epoch_bank->next_epoch_stakes) by updated stakes at T (stakes->vote_accounts) */ - fd_update_next_epoch_stakes( slot_ctx ); + fd_update_next_epoch_stakes( slot_ctx->bank ); /* Update current leaders using slot_ctx->slot_bank.epoch_stakes (new T-2 stakes) */ fd_runtime_update_leaders( slot_ctx->bank, slot_ctx->slot, runtime_spad ); @@ -3533,10 +3555,11 @@ fd_runtime_read_genesis( fd_exec_slot_ctx_t * slot_ctx, fd_memcpy( genesis_hash_bm, buf, sizeof(fd_hash_t) ); if( !is_snapshot ) { - fd_runtime_init_bank_from_genesis( slot_ctx, - genesis_block, - &genesis_hash, - runtime_spad ); + fd_runtime_init_bank_from_genesis( + slot_ctx, + genesis_block, + &genesis_hash, + runtime_spad ); fd_runtime_init_program( slot_ctx, runtime_spad ); @@ -3547,12 +3570,13 @@ fd_runtime_read_genesis( fd_exec_slot_ctx_t * slot_ctx, FD_TXN_ACCOUNT_DECL( rec ); - int err = fd_txn_account_init_from_funk_mutable( rec, - &a->key, - slot_ctx->funk, - slot_ctx->funk_txn, - 1, /* do_create */ - a->account.data_len ); + int err = fd_txn_account_init_from_funk_mutable( + rec, + &a->key, + slot_ctx->funk, + slot_ctx->funk_txn, + 1, /* do_create */ + a->account.data_len ); if( FD_UNLIKELY( err ) ) { FD_LOG_ERR(( "fd_txn_account_init_from_funk_mutable failed (%d)", err )); @@ -3573,7 +3597,7 @@ fd_runtime_read_genesis( fd_exec_slot_ctx_t * slot_ctx, for( ulong i=0UL; i < genesis_block->native_instruction_processors_len; i++ ) { fd_string_pubkey_pair_t * a = &genesis_block->native_instruction_processors[i]; - fd_write_builtin_account( slot_ctx, a->pubkey, (const char *) a->string, a->string_len ); + fd_write_builtin_account( slot_ctx->bank, slot_ctx->funk, slot_ctx->funk_txn, a->pubkey, (const char *) a->string, a->string_len ); } fd_features_restore( slot_ctx, runtime_spad ); @@ -3908,7 +3932,9 @@ fd_runtime_block_execute_tpool( fd_exec_slot_ctx_t * slot_ctx, if( !mblock_txn_cnt ) continue; - res = fd_runtime_process_txns_in_microblock_stream( slot_ctx, + res = fd_runtime_process_txns_in_microblock_stream( slot_ctx->bank, + slot_ctx->funk, + slot_ctx->funk_txn, capture_ctx, mblock_txn_ptrs, mblock_txn_cnt, diff --git a/src/flamenco/runtime/fd_runtime.h b/src/flamenco/runtime/fd_runtime.h index 06c54ffc18..dadf001309 100644 --- a/src/flamenco/runtime/fd_runtime.h +++ b/src/flamenco/runtime/fd_runtime.h @@ -540,7 +540,9 @@ fd_runtime_block_execute_finalize_para( fd_bank_t * bank, for various transaction sanitization checks. */ int -fd_runtime_prepare_txns_start( fd_exec_slot_ctx_t * slot_ctx, +fd_runtime_prepare_txns_start( fd_bank_t * bank, + fd_funk_t * funk, + fd_funk_txn_t * funk_txn, fd_execute_txn_task_info_t * task_info, fd_txn_p_t * txns, ulong txn_cnt, @@ -566,15 +568,17 @@ fd_runtime_process_txns( fd_exec_slot_ctx_t * slot_ctx, all transactions are conflict-free. */ int -fd_runtime_process_txns_in_microblock_stream( fd_exec_slot_ctx_t * slot_ctx, - fd_capture_ctx_t * capture_ctx, - fd_txn_p_t * all_txns, - ulong total_txn_cnt, - fd_tpool_t * tpool, - fd_spad_t * * exec_spads, - ulong exec_spad_cnt, - fd_spad_t * runtime_spad, - fd_cost_tracker_t * cost_tracker_opt ); +fd_runtime_process_txns_in_microblock_stream( fd_bank_t * bank, + fd_funk_t * funk, + fd_funk_txn_t * funk_txn, + fd_capture_ctx_t * capture_ctx, + fd_txn_p_t * all_txns, + ulong total_txn_cnt, + fd_tpool_t * tpool, + fd_spad_t * * exec_spads, + ulong exec_spad_cnt, + fd_spad_t * runtime_spad, + fd_cost_tracker_t * cost_tracker_opt ); void fd_runtime_finalize_txn( fd_funk_t * funk, diff --git a/src/flamenco/runtime/program/fd_bpf_loader_program.c b/src/flamenco/runtime/program/fd_bpf_loader_program.c index 10bb67f5d2..08da8e2829 100644 --- a/src/flamenco/runtime/program/fd_bpf_loader_program.c +++ b/src/flamenco/runtime/program/fd_bpf_loader_program.c @@ -2479,25 +2479,27 @@ fd_bpf_loader_program_execute( fd_exec_instr_ctx_t * ctx ) { /* Public APIs */ int -fd_directly_invoke_loader_v3_deploy( fd_exec_slot_ctx_t * slot_ctx, - uchar const * elf, - ulong elf_sz, - fd_spad_t * runtime_spad ) { +fd_directly_invoke_loader_v3_deploy( fd_bank_t * bank, + fd_funk_t * funk, + fd_funk_txn_t * funk_txn, + uchar const * elf, + ulong elf_sz, + fd_spad_t * runtime_spad ) { /* Set up a dummy instr and txn context */ - fd_exec_txn_ctx_t * txn_ctx = fd_exec_txn_ctx_join( fd_exec_txn_ctx_new( fd_spad_alloc( runtime_spad, FD_EXEC_TXN_CTX_ALIGN, FD_EXEC_TXN_CTX_FOOTPRINT ) ), runtime_spad, fd_wksp_containing( runtime_spad ) ); - fd_funk_t * funk = slot_ctx->funk; - fd_wksp_t * funk_wksp = fd_funk_wksp( funk ); - fd_wksp_t * runtime_wksp = fd_wksp_containing( slot_ctx ); - ulong funk_txn_gaddr = fd_wksp_gaddr( funk_wksp, slot_ctx->funk_txn ); - ulong funk_gaddr = fd_wksp_gaddr( funk_wksp, funk->shmem ); - - fd_exec_txn_ctx_from_exec_slot_ctx( slot_ctx, - txn_ctx, - funk_wksp, - runtime_wksp, - funk_txn_gaddr, - funk_gaddr, - NULL ); + fd_exec_txn_ctx_t * txn_ctx = fd_exec_txn_ctx_join( fd_exec_txn_ctx_new( fd_spad_alloc( runtime_spad, FD_EXEC_TXN_CTX_ALIGN, FD_EXEC_TXN_CTX_FOOTPRINT ) ), runtime_spad, fd_wksp_containing( runtime_spad ) ); + fd_wksp_t * funk_wksp = fd_funk_wksp( funk ); + fd_wksp_t * runtime_wksp = fd_wksp_containing( runtime_spad ); + ulong funk_txn_gaddr = fd_wksp_gaddr( funk_wksp, funk_txn ); + ulong funk_gaddr = fd_wksp_gaddr( funk_wksp, funk->shmem ); + + fd_exec_txn_ctx_from_exec_slot_ctx( + bank, + txn_ctx, + funk_wksp, + runtime_wksp, + funk_txn_gaddr, + funk_gaddr, + NULL ); fd_exec_txn_ctx_setup_basic( txn_ctx ); txn_ctx->instr_stack_sz = 1; diff --git a/src/flamenco/runtime/program/fd_bpf_loader_program.h b/src/flamenco/runtime/program/fd_bpf_loader_program.h index c3ac0d0185..efb9c685a0 100644 --- a/src/flamenco/runtime/program/fd_bpf_loader_program.h +++ b/src/flamenco/runtime/program/fd_bpf_loader_program.h @@ -94,10 +94,12 @@ read_bpf_upgradeable_loader_state_for_program( fd_exec_txn_ctx_t * https://github.com/anza-xyz/agave/blob/v2.1.0/runtime/src/bank/builtins/core_bpf_migration/mod.rs#L155-L233 */ int -fd_directly_invoke_loader_v3_deploy( fd_exec_slot_ctx_t * slot_ctx, - uchar const * elf, - ulong elf_sz, - fd_spad_t * runtime_spad ); +fd_directly_invoke_loader_v3_deploy( fd_bank_t * bank, + fd_funk_t * funk, + fd_funk_txn_t * funk_txn, + uchar const * elf, + ulong elf_sz, + fd_spad_t * runtime_spad ); FD_PROTOTYPES_END diff --git a/src/flamenco/runtime/program/fd_builtin_programs.c b/src/flamenco/runtime/program/fd_builtin_programs.c index 3b3d5d63fd..91f25f17b5 100644 --- a/src/flamenco/runtime/program/fd_builtin_programs.c +++ b/src/flamenco/runtime/program/fd_builtin_programs.c @@ -149,16 +149,16 @@ static fd_core_bpf_migration_config_t const * migrating_builtins[] = { /* https://github.com/solana-labs/solana/blob/8f2c8b8388a495d2728909e30460aa40dcc5d733/sdk/src/native_loader.rs#L19 */ void -fd_write_builtin_account( fd_exec_slot_ctx_t * slot_ctx, - fd_pubkey_t const pubkey, - char const * data, - ulong sz ) { +fd_write_builtin_account( fd_bank_t * bank, + fd_funk_t * funk, + fd_funk_txn_t * funk_txn, + fd_pubkey_t const pubkey, + char const * data, + ulong sz ) { - fd_funk_t * funk = slot_ctx->funk; - fd_funk_txn_t * txn = slot_ctx->funk_txn; FD_TXN_ACCOUNT_DECL( rec ); - int err = fd_txn_account_init_from_funk_mutable( rec, &pubkey, funk, txn, 1, sz ); + int err = fd_txn_account_init_from_funk_mutable( rec, &pubkey, funk, funk_txn, 1, sz ); FD_TEST( !err ); rec->vt->set_data( rec, data, sz ); @@ -167,9 +167,9 @@ fd_write_builtin_account( fd_exec_slot_ctx_t * slot_ctx, rec->vt->set_executable( rec, 1 ); rec->vt->set_owner( rec, &fd_solana_native_loader_id ); - fd_txn_account_mutable_fini( rec, funk, txn ); + fd_txn_account_mutable_fini( rec, funk, funk_txn ); - fd_bank_capitalization_set( slot_ctx->bank, fd_bank_capitalization_get( slot_ctx->bank ) + 1UL ); + fd_bank_capitalization_set( bank, fd_bank_capitalization_get( bank ) + 1UL ); // err = fd_acc_mgr_commit( acc_mgr, rec, slot_ctx ); FD_TEST( !err ); @@ -220,31 +220,31 @@ void fd_builtin_programs_init( fd_exec_slot_ctx_t * slot_ctx ) { } else if( builtins[i].enable_feature_offset!=NO_ENABLE_FEATURE_ID && !FD_FEATURE_ACTIVE_OFFSET( slot_ctx->slot, fd_bank_features_get( slot_ctx->bank ), builtins[i].enable_feature_offset ) ) { continue; } else { - fd_write_builtin_account( slot_ctx, *builtins[i].pubkey, builtins[i].data, strlen(builtins[i].data) ); + fd_write_builtin_account( slot_ctx->bank, slot_ctx->funk, slot_ctx->funk_txn, *builtins[i].pubkey, builtins[i].data, strlen(builtins[i].data) ); } } //TODO: remove when no longer necessary if( FD_FEATURE_ACTIVE_BANK( slot_ctx->bank, zk_token_sdk_enabled ) ) { - fd_write_builtin_account( slot_ctx, fd_solana_zk_token_proof_program_id, "zk_token_proof_program", 22UL ); + fd_write_builtin_account( slot_ctx->bank, slot_ctx->funk, slot_ctx->funk_txn, fd_solana_zk_token_proof_program_id, "zk_token_proof_program", 22UL ); } if( FD_FEATURE_ACTIVE_BANK( slot_ctx->bank, zk_elgamal_proof_program_enabled ) ) { - fd_write_builtin_account( slot_ctx, fd_solana_zk_elgamal_proof_program_id, "zk_elgamal_proof_program", 24UL ); + fd_write_builtin_account( slot_ctx->bank, slot_ctx->funk, slot_ctx->funk_txn, fd_solana_zk_elgamal_proof_program_id, "zk_elgamal_proof_program", 24UL ); } /* Precompiles have empty account data */ if( fd_bank_cluster_version_get( slot_ctx->bank ).major == 1 ) { char data[1] = {1}; - fd_write_builtin_account( slot_ctx, fd_solana_keccak_secp_256k_program_id, data, 1 ); - fd_write_builtin_account( slot_ctx, fd_solana_ed25519_sig_verify_program_id, data, 1 ); + fd_write_builtin_account( slot_ctx->bank, slot_ctx->funk, slot_ctx->funk_txn, fd_solana_keccak_secp_256k_program_id, data, 1 ); + fd_write_builtin_account( slot_ctx->bank, slot_ctx->funk, slot_ctx->funk_txn, fd_solana_ed25519_sig_verify_program_id, data, 1 ); if( FD_FEATURE_ACTIVE_BANK( slot_ctx->bank, enable_secp256r1_precompile ) ) - fd_write_builtin_account( slot_ctx, fd_solana_secp256r1_program_id, data, 1 ); + fd_write_builtin_account( slot_ctx->bank, slot_ctx->funk, slot_ctx->funk_txn, fd_solana_secp256r1_program_id, data, 1 ); } else { - fd_write_builtin_account( slot_ctx, fd_solana_keccak_secp_256k_program_id, "", 0 ); - fd_write_builtin_account( slot_ctx, fd_solana_ed25519_sig_verify_program_id, "", 0 ); + fd_write_builtin_account( slot_ctx->bank, slot_ctx->funk, slot_ctx->funk_txn, fd_solana_keccak_secp_256k_program_id, "", 0 ); + fd_write_builtin_account( slot_ctx->bank, slot_ctx->funk, slot_ctx->funk_txn, fd_solana_ed25519_sig_verify_program_id, "", 0 ); if( FD_FEATURE_ACTIVE_BANK( slot_ctx->bank, enable_secp256r1_precompile ) ) - fd_write_builtin_account( slot_ctx, fd_solana_secp256r1_program_id, "", 0 ); + fd_write_builtin_account( slot_ctx->bank, slot_ctx->funk, slot_ctx->funk_txn, fd_solana_secp256r1_program_id, "", 0 ); } /* Inline SPL token mint program ("inlined to avoid an external dependency on the spl-token crate") */ diff --git a/src/flamenco/runtime/program/fd_builtin_programs.h b/src/flamenco/runtime/program/fd_builtin_programs.h index 119445d45f..f2a708ecb6 100644 --- a/src/flamenco/runtime/program/fd_builtin_programs.h +++ b/src/flamenco/runtime/program/fd_builtin_programs.h @@ -52,10 +52,12 @@ void fd_builtin_programs_init( fd_exec_slot_ctx_t * slot_ctx ); void -fd_write_builtin_account( fd_exec_slot_ctx_t * slot_ctx, - fd_pubkey_t const pubkey, - char const * data, - ulong sz ); +fd_write_builtin_account( fd_bank_t * bank, + fd_funk_t * funk, + fd_funk_txn_t * funk_txn, + fd_pubkey_t const pubkey, + char const * data, + ulong sz ); fd_builtin_program_t const * fd_builtins( void ); diff --git a/src/flamenco/runtime/tests/harness/fd_instr_harness.c b/src/flamenco/runtime/tests/harness/fd_instr_harness.c index ad0fa4d70f..a295b0ee50 100644 --- a/src/flamenco/runtime/tests/harness/fd_instr_harness.c +++ b/src/flamenco/runtime/tests/harness/fd_instr_harness.c @@ -93,13 +93,14 @@ fd_runtime_fuzz_instr_ctx_create( fd_runtime_fuzz_runner_t * runner, txn_descriptor->transaction_version = FD_TXN_V0; txn_descriptor->acct_addr_cnt = (ushort)test_ctx->accounts_count; - fd_exec_txn_ctx_from_exec_slot_ctx( slot_ctx, - txn_ctx, - funk_wksp, - runtime_wksp, - funk_txn_gaddr, - funk_gaddr, - NULL ); + fd_exec_txn_ctx_from_exec_slot_ctx( + slot_ctx->bank, + txn_ctx, + funk_wksp, + runtime_wksp, + funk_txn_gaddr, + funk_gaddr, + NULL ); fd_exec_txn_ctx_setup_basic( txn_ctx ); txn_ctx->txn_descriptor = txn_descriptor; @@ -366,13 +367,14 @@ fd_runtime_fuzz_instr_ctx_create( fd_runtime_fuzz_runner_t * runner, ctx->instr = info; /* Refresh the setup from the updated slot and epoch ctx. */ - fd_exec_txn_ctx_from_exec_slot_ctx( slot_ctx, - txn_ctx, - funk_wksp, - runtime_wksp, - funk_txn_gaddr, - funk_gaddr, - NULL ); + fd_exec_txn_ctx_from_exec_slot_ctx( + slot_ctx->bank, + txn_ctx, + funk_wksp, + runtime_wksp, + funk_txn_gaddr, + funk_gaddr, + NULL ); fd_log_collector_init( &ctx->txn_ctx->log_collector, 1 ); fd_base58_encode_32( txn_ctx->account_keys[ ctx->instr->program_id ].uc, NULL, ctx->program_id_base58 ); diff --git a/src/flamenco/runtime/tests/harness/fd_txn_harness.c b/src/flamenco/runtime/tests/harness/fd_txn_harness.c index 33bf5b906a..6b98da3e43 100644 --- a/src/flamenco/runtime/tests/harness/fd_txn_harness.c +++ b/src/flamenco/runtime/tests/harness/fd_txn_harness.c @@ -286,7 +286,7 @@ fd_runtime_fuzz_txn_ctx_exec( fd_runtime_fuzz_runner_t * runner, tpool->worker_cnt = 1; tpool->worker_max = 1; - fd_runtime_prepare_txns_start( slot_ctx, task_info, txn, 1UL, runner->spad ); + fd_runtime_prepare_txns_start( slot_ctx->bank, slot_ctx->funk, slot_ctx->funk_txn, task_info, txn, 1UL, runner->spad ); /* Setup the spad for account allocation */ task_info->txn_ctx->spad = runner->spad; From d9f0fa27acabb7fa539ec2fb30842bee6ec9060c Mon Sep 17 00:00:00 2001 From: Ishan Bhatt Date: Fri, 27 Jun 2025 17:57:17 +0000 Subject: [PATCH 06/27] more replacement --- src/app/ledger/main.c | 4 +- src/discof/replay/fd_replay_tile.c | 2 +- src/flamenco/features/fd_features.h | 2 +- src/flamenco/rewards/fd_rewards.c | 277 ++++++++++-------- src/flamenco/rewards/fd_rewards.h | 20 +- src/flamenco/runtime/fd_runtime.c | 171 ++++++----- src/flamenco/runtime/fd_runtime.h | 6 +- src/flamenco/runtime/fd_runtime_init.c | 13 +- src/flamenco/runtime/fd_runtime_init.h | 6 +- .../runtime/sysvar/fd_sysvar_epoch_rewards.c | 17 +- .../runtime/sysvar/fd_sysvar_epoch_rewards.h | 15 +- .../runtime/sysvar/fd_sysvar_stake_history.c | 16 +- .../runtime/sysvar/fd_sysvar_stake_history.h | 5 +- .../runtime/tests/harness/fd_txn_harness.c | 11 +- src/flamenco/snapshot/fd_snapshot.c | 6 +- src/flamenco/stakes/fd_stakes.c | 114 +++---- src/flamenco/stakes/fd_stakes.h | 29 +- 17 files changed, 412 insertions(+), 302 deletions(-) diff --git a/src/app/ledger/main.c b/src/app/ledger/main.c index 67acd21d5e..cb11895fa0 100644 --- a/src/app/ledger/main.c +++ b/src/app/ledger/main.c @@ -162,7 +162,7 @@ int runtime_replay( fd_ledger_args_t * ledger_args ) { int ret = 0; - fd_features_restore( ledger_args->slot_ctx, ledger_args->runtime_spad ); + fd_features_restore( ledger_args->slot_ctx->bank, ledger_args->slot_ctx->funk, ledger_args->slot_ctx->funk_txn, ledger_args->runtime_spad ); fd_runtime_update_leaders( ledger_args->slot_ctx->bank, ledger_args->slot_ctx->slot, ledger_args->runtime_spad ); @@ -519,7 +519,7 @@ fd_ledger_main_setup( fd_ledger_args_t * args ) { fd_flamenco_boot( NULL, NULL ); /* Finish other runtime setup steps */ - fd_features_restore( args->slot_ctx, args->runtime_spad ); + fd_features_restore( args->slot_ctx->bank, args->slot_ctx->funk, args->slot_ctx->funk_txn, args->runtime_spad ); fd_runtime_update_leaders( args->slot_ctx->bank, args->slot_ctx->slot, args->runtime_spad ); fd_calculate_epoch_accounts_hash_values( args->slot_ctx ); diff --git a/src/discof/replay/fd_replay_tile.c b/src/discof/replay/fd_replay_tile.c index ab8e66899a..3dbb2d05b1 100644 --- a/src/discof/replay/fd_replay_tile.c +++ b/src/discof/replay/fd_replay_tile.c @@ -1008,7 +1008,7 @@ prepare_new_block_execution( fd_replay_tile_ctx_t * ctx, /* if it is an epoch boundary, push out stake weights */ if( ctx->slot_ctx->slot != 0 ) { - is_new_epoch_in_new_block = (int)fd_runtime_is_epoch_boundary( ctx->slot_ctx, ctx->slot_ctx->slot, fd_bank_prev_slot_get( ctx->slot_ctx->bank ) ); + is_new_epoch_in_new_block = (int)fd_runtime_is_epoch_boundary( ctx->slot_ctx->bank, ctx->slot_ctx->slot, fd_bank_prev_slot_get( ctx->slot_ctx->bank ) ); } /* Update starting PoH hash for the new slot for tick verification later */ diff --git a/src/flamenco/features/fd_features.h b/src/flamenco/features/fd_features.h index 5b3c967dfe..94aa6b818b 100644 --- a/src/flamenco/features/fd_features.h +++ b/src/flamenco/features/fd_features.h @@ -22,7 +22,7 @@ #define FD_FEATURE_JUST_ACTIVATED_OFFSET_(_slot, _features, _offset) (_slot == (_features).f[_offset>>3] ) #define FD_FEATURE_SET_ACTIVE(_features, _feature_name, _slot) ((_features)-> _feature_name = _slot) -#define FD_FEATURE_JUST_ACTIVATED(_slot_ctx, _feature_name) FD_FEATURE_JUST_ACTIVATED_( _slot_ctx->slot, fd_bank_features_get(_slot_ctx->bank), _feature_name ) +#define FD_FEATURE_JUST_ACTIVATED(_bank, _feature_name) FD_FEATURE_JUST_ACTIVATED_( _bank->slot, fd_bank_features_get(_bank), _feature_name ) #define FD_FEATURE_ACTIVE_OFFSET(_slot, _features, _offset) FD_FEATURE_ACTIVE_OFFSET_( _slot, _features, _offset ) #define FD_FEATURE_JUST_ACTIVATED_OFFSET(_bank, _offset) FD_FEATURE_JUST_ACTIVATED_OFFSET_( _bank->slot, fd_bank_features_get(_bank), _offset ) #define FD_FEATURE_ACTIVE(_slot, _features, _feature_name) FD_FEATURE_ACTIVE_(_slot, _features, _feature_name) diff --git a/src/flamenco/rewards/fd_rewards.c b/src/flamenco/rewards/fd_rewards.c index 95ef26e1f0..97cc93c932 100644 --- a/src/flamenco/rewards/fd_rewards.c +++ b/src/flamenco/rewards/fd_rewards.c @@ -55,19 +55,19 @@ validator( fd_inflation_t const * inflation, double year) { https://github.com/anza-xyz/agave/blob/7117ed9653ce19e8b2dea108eff1f3eb6a3378a7/runtime/src/bank.rs#L2095 */ static FD_FN_CONST ulong -get_inflation_start_slot( fd_exec_slot_ctx_t * slot_ctx ) { - ulong devnet_and_testnet = FD_FEATURE_ACTIVE_BANK( slot_ctx->bank, devnet_and_testnet ) ? fd_bank_features_query( slot_ctx->bank )->devnet_and_testnet : ULONG_MAX; +get_inflation_start_slot( fd_bank_t * bank ) { + ulong devnet_and_testnet = FD_FEATURE_ACTIVE_BANK( bank, devnet_and_testnet ) ? fd_bank_features_query( bank )->devnet_and_testnet : ULONG_MAX; ulong enable = ULONG_MAX; - if( FD_FEATURE_ACTIVE_BANK( slot_ctx->bank, full_inflation_vote ) && - FD_FEATURE_ACTIVE_BANK( slot_ctx->bank, full_inflation_enable ) ) { - enable = fd_bank_features_query( slot_ctx->bank )->full_inflation_enable; + if( FD_FEATURE_ACTIVE_BANK( bank, full_inflation_vote ) && + FD_FEATURE_ACTIVE_BANK( bank, full_inflation_enable ) ) { + enable = fd_bank_features_query( bank )->full_inflation_enable; } ulong min_slot = fd_ulong_min( enable, devnet_and_testnet ); if( min_slot == ULONG_MAX ) { - if( FD_FEATURE_ACTIVE_BANK( slot_ctx->bank, pico_inflation ) ) { - min_slot = fd_bank_features_query( slot_ctx->bank )->pico_inflation; + if( FD_FEATURE_ACTIVE_BANK( bank, pico_inflation ) ) { + min_slot = fd_bank_features_query( bank )->pico_inflation; } else { min_slot = 0; } @@ -77,10 +77,10 @@ get_inflation_start_slot( fd_exec_slot_ctx_t * slot_ctx ) { /* https://github.com/anza-xyz/agave/blob/7117ed9653ce19e8b2dea108eff1f3eb6a3378a7/runtime/src/bank.rs#L2110 */ static ulong -get_inflation_num_slots( fd_exec_slot_ctx_t * slot_ctx, +get_inflation_num_slots( fd_bank_t * bank, fd_epoch_schedule_t const * epoch_schedule, - ulong slot ) { - ulong inflation_activation_slot = get_inflation_start_slot( slot_ctx ); + ulong slot ) { + ulong inflation_activation_slot = get_inflation_start_slot( bank ); ulong inflation_start_slot = fd_epoch_slot0( epoch_schedule, fd_ulong_sat_sub( fd_slot_to_epoch( epoch_schedule, inflation_activation_slot, NULL ), @@ -93,11 +93,11 @@ get_inflation_num_slots( fd_exec_slot_ctx_t * slot_ctx, /* https://github.com/anza-xyz/agave/blob/7117ed9653ce19e8b2dea108eff1f3eb6a3378a7/runtime/src/bank.rs#L2121 */ static double -slot_in_year_for_inflation( fd_exec_slot_ctx_t * slot_ctx ) { - fd_epoch_schedule_t const * epoch_schedule = fd_bank_epoch_schedule_query( slot_ctx->bank ); +slot_in_year_for_inflation( fd_bank_t * bank ) { + fd_epoch_schedule_t const * epoch_schedule = fd_bank_epoch_schedule_query( bank ); - ulong num_slots = get_inflation_num_slots( slot_ctx, epoch_schedule, slot_ctx->slot ); - return (double)num_slots / (double)fd_bank_slots_per_year_get( slot_ctx->bank ); + ulong num_slots = get_inflation_num_slots( bank, epoch_schedule, bank->slot ); + return (double)num_slots / (double)fd_bank_slots_per_year_get( bank ); } /* For a given stake and vote_state, calculate how many points were earned (credits * stake) and new value @@ -276,35 +276,35 @@ get_slots_in_epoch( ulong epoch, /* https://github.com/anza-xyz/agave/blob/cbc8320d35358da14d79ebcada4dfb6756ffac79/runtime/src/bank.rs#L2082 */ static double -epoch_duration_in_years( fd_exec_slot_ctx_t * slot_ctx, - ulong prev_epoch ) { - ulong slots_in_epoch = get_slots_in_epoch( prev_epoch, fd_bank_epoch_schedule_query( slot_ctx->bank ) ); - return (double)slots_in_epoch / (double)fd_bank_slots_per_year_get( slot_ctx->bank ); +epoch_duration_in_years( fd_bank_t * bank, + ulong prev_epoch ) { + ulong slots_in_epoch = get_slots_in_epoch( prev_epoch, fd_bank_epoch_schedule_query( bank ) ); + return (double)slots_in_epoch / (double)fd_bank_slots_per_year_get( bank ); } /* https://github.com/anza-xyz/agave/blob/7117ed9653ce19e8b2dea108eff1f3eb6a3378a7/runtime/src/bank.rs#L2128 */ static void -calculate_previous_epoch_inflation_rewards( fd_exec_slot_ctx_t * slot_ctx, +calculate_previous_epoch_inflation_rewards( fd_bank_t * bank, ulong prev_epoch_capitalization, ulong prev_epoch, fd_prev_epoch_inflation_rewards_t * rewards ) { - double slot_in_year = slot_in_year_for_inflation( slot_ctx ); + double slot_in_year = slot_in_year_for_inflation( bank ); - rewards->validator_rate = validator( fd_bank_inflation_query( slot_ctx->bank ), slot_in_year ); - rewards->foundation_rate = foundation( fd_bank_inflation_query( slot_ctx->bank ), slot_in_year ); - rewards->prev_epoch_duration_in_years = epoch_duration_in_years( slot_ctx, prev_epoch ); + rewards->validator_rate = validator( fd_bank_inflation_query( bank ), slot_in_year ); + rewards->foundation_rate = foundation( fd_bank_inflation_query( bank ), slot_in_year ); + rewards->prev_epoch_duration_in_years = epoch_duration_in_years( bank, prev_epoch ); rewards->validator_rewards = (ulong)(rewards->validator_rate * (double)prev_epoch_capitalization * rewards->prev_epoch_duration_in_years); FD_LOG_DEBUG(( "Rewards %lu, Rate %.16f, Duration %.18f Capitalization %lu Slot in year %.16f", rewards->validator_rewards, rewards->validator_rate, rewards->prev_epoch_duration_in_years, prev_epoch_capitalization, slot_in_year )); } /* https://github.com/anza-xyz/agave/blob/cbc8320d35358da14d79ebcada4dfb6756ffac79/programs/stake/src/lib.rs#L29 */ static ulong -get_minimum_stake_delegation( fd_exec_slot_ctx_t * slot_ctx ) { - if( !FD_FEATURE_ACTIVE_BANK( slot_ctx->bank, stake_minimum_delegation_for_rewards ) ) { +get_minimum_stake_delegation( fd_bank_t * bank ) { + if( !FD_FEATURE_ACTIVE_BANK( bank, stake_minimum_delegation_for_rewards ) ) { return 0UL; } - if( FD_FEATURE_ACTIVE_BANK( slot_ctx->bank, stake_raise_minimum_delegation_to_1_sol ) ) { + if( FD_FEATURE_ACTIVE_BANK( bank, stake_raise_minimum_delegation_to_1_sol ) ) { return LAMPORTS_PER_SOL; } @@ -372,7 +372,9 @@ calculate_points_tpool_task( void *tpool, https://github.com/anza-xyz/agave/blob/cbc8320d35358da14d79ebcada4dfb6756ffac79/runtime/src/bank/partitioned_epoch_rewards/calculation.rs#L472 */ static void -calculate_reward_points_partitioned( fd_exec_slot_ctx_t * slot_ctx, +calculate_reward_points_partitioned( fd_bank_t * bank, + fd_funk_t * funk, + fd_funk_txn_t * funk_txn, fd_stake_history_t const * stake_history, ulong rewards, fd_point_value_t * result, @@ -381,19 +383,20 @@ calculate_reward_points_partitioned( fd_exec_slot_ctx_t * slot_ctx, fd_spad_t * runtime_spad ) { uint128 points = 0; - ulong minimum_stake_delegation = get_minimum_stake_delegation( slot_ctx ); + ulong minimum_stake_delegation = get_minimum_stake_delegation( bank ); /* Calculate the points for each stake delegation */ int _err[1]; ulong new_warmup_cooldown_rate_epoch_val = 0UL; ulong * new_warmup_cooldown_rate_epoch = &new_warmup_cooldown_rate_epoch_val; - int is_some = fd_new_warmup_cooldown_rate_epoch( slot_ctx->slot, - slot_ctx->funk, - slot_ctx->funk_txn, - runtime_spad, - fd_bank_features_query( slot_ctx->bank ), - new_warmup_cooldown_rate_epoch, - _err ); + int is_some = fd_new_warmup_cooldown_rate_epoch( + bank->slot, + funk, + funk_txn, + runtime_spad, + fd_bank_features_query( bank ), + new_warmup_cooldown_rate_epoch, + _err ); if( FD_UNLIKELY( !is_some ) ) { new_warmup_cooldown_rate_epoch = NULL; } @@ -427,18 +430,18 @@ calculate_stake_vote_rewards_account( fd_epoch_info_t const * ulong start_idx, ulong end_idx ) { - fd_epoch_info_pair_t const * stake_infos = temp_info->stake_infos; - fd_exec_slot_ctx_t * slot_ctx = task_args->slot_ctx; - fd_stake_history_t const * stake_history = task_args->stake_history; - ulong rewarded_epoch = task_args->rewarded_epoch; - ulong * new_warmup_cooldown_rate_epoch = task_args->new_warmup_cooldown_rate_epoch; - fd_point_value_t * point_value = task_args->point_value; - fd_calculate_stake_vote_rewards_result_t * result = task_args->result; // written to - fd_spad_t * spad = task_args->exec_spads[ fd_tile_idx() ]; + fd_epoch_info_pair_t const * stake_infos = temp_info->stake_infos; + fd_bank_t * bank = task_args->bank; + fd_stake_history_t const * stake_history = task_args->stake_history; + ulong rewarded_epoch = task_args->rewarded_epoch; + ulong * new_warmup_cooldown_rate_epoch = task_args->new_warmup_cooldown_rate_epoch; + fd_point_value_t * point_value = task_args->point_value; + fd_calculate_stake_vote_rewards_result_t * result = task_args->result; // written to + fd_spad_t * spad = task_args->exec_spads[ fd_tile_idx() ]; FD_SPAD_FRAME_BEGIN( spad ) { - ulong minimum_stake_delegation = get_minimum_stake_delegation( slot_ctx ); + ulong minimum_stake_delegation = get_minimum_stake_delegation( bank ); ulong total_stake_rewards = 0UL; ulong dlist_additional_cnt = 0UL; @@ -454,7 +457,7 @@ calculate_stake_vote_rewards_account( fd_epoch_info_t const * fd_pubkey_t const * stake_acc = &stake_info->account; fd_stake_t const * stake = &stake_info->stake; - if( FD_FEATURE_ACTIVE_BANK( slot_ctx->bank, stake_minimum_delegation_for_rewards ) ) { + if( FD_FEATURE_ACTIVE_BANK( bank, stake_minimum_delegation_for_rewards ) ) { if( stake->delegation.stakeslot, - slot_ctx->funk, - slot_ctx->funk_txn, + int is_some = fd_new_warmup_cooldown_rate_epoch( bank->slot, + funk, + funk_txn, runtime_spad, - fd_bank_features_query( slot_ctx->bank ), + fd_bank_features_query( bank ), new_warmup_cooldown_rate_epoch, _err ); if( FD_UNLIKELY( !is_some ) ) { @@ -665,7 +670,7 @@ calculate_stake_vote_rewards( fd_exec_slot_ctx_t * slot_ct } fd_calculate_stake_vote_rewards_task_args_t task_args = { - .slot_ctx = slot_ctx, + .bank = bank, .stake_history = stake_history, .rewarded_epoch = rewarded_epoch, .new_warmup_cooldown_rate_epoch = new_warmup_cooldown_rate_epoch, @@ -690,7 +695,9 @@ calculate_stake_vote_rewards( fd_exec_slot_ctx_t * slot_ct https://github.com/anza-xyz/agave/blob/cbc8320d35358da14d79ebcada4dfb6756ffac79/runtime/src/bank/partitioned_epoch_rewards/calculation.rs#L273 */ static void -calculate_validator_rewards( fd_exec_slot_ctx_t * slot_ctx, +calculate_validator_rewards( fd_bank_t * bank, + fd_funk_t * funk, + fd_funk_txn_t * funk_txn, ulong rewarded_epoch, ulong rewards, fd_calculate_validator_rewards_result_t * result, @@ -700,13 +707,15 @@ calculate_validator_rewards( fd_exec_slot_ctx_t * slot_ctx, ulong exec_spad_cnt, fd_spad_t * runtime_spad ) { /* https://github.com/firedancer-io/solana/blob/dab3da8e7b667d7527565bddbdbecf7ec1fb868e/runtime/src/bank.rs#L2759-L2786 */ - fd_stake_history_t const * stake_history = fd_sysvar_stake_history_read( slot_ctx->funk, slot_ctx->funk_txn, runtime_spad ); + fd_stake_history_t const * stake_history = fd_sysvar_stake_history_read( funk, funk_txn, runtime_spad ); if( FD_UNLIKELY( !stake_history ) ) { FD_LOG_ERR(( "Unable to read and decode stake history sysvar" )); } /* Calculate the epoch reward points from stake/vote accounts */ - calculate_reward_points_partitioned( slot_ctx, + calculate_reward_points_partitioned( bank, + funk, + funk_txn, stake_history, rewards, &result->point_value, @@ -715,16 +724,19 @@ calculate_validator_rewards( fd_exec_slot_ctx_t * slot_ctx, runtime_spad ); /* Calculate the stake and vote rewards for each account */ - calculate_stake_vote_rewards( slot_ctx, - stake_history, - rewarded_epoch, - &result->point_value, - &result->calculate_stake_vote_rewards_result, - temp_info, - tpool, - exec_spads, - exec_spad_cnt, - runtime_spad ); + calculate_stake_vote_rewards( + bank, + funk, + funk_txn, + stake_history, + rewarded_epoch, + &result->point_value, + &result->calculate_stake_vote_rewards_result, + temp_info, + tpool, + exec_spads, + exec_spad_cnt, + runtime_spad ); } /* Calculate the number of blocks required to distribute rewards to all stake accounts. @@ -808,7 +820,9 @@ hash_rewards_into_partitions( fd_stake_reward_calculation_t * stake_ https://github.com/anza-xyz/agave/blob/7117ed9653ce19e8b2dea108eff1f3eb6a3378a7/runtime/src/bank/partitioned_epoch_rewards/calculation.rs#L214 */ static void -calculate_rewards_for_partitioning( fd_exec_slot_ctx_t * slot_ctx, +calculate_rewards_for_partitioning( fd_bank_t * bank, + fd_funk_t * funk, + fd_funk_txn_t * funk_txn, ulong prev_epoch, const fd_hash_t * parent_blockhash, fd_partitioned_rewards_calculation_t * result, @@ -820,27 +834,33 @@ calculate_rewards_for_partitioning( fd_exec_slot_ctx_t * slot_ /* https://github.com/anza-xyz/agave/blob/7117ed9653ce19e8b2dea108eff1f3eb6a3378a7/runtime/src/bank/partitioned_epoch_rewards/calculation.rs#L227 */ fd_prev_epoch_inflation_rewards_t rewards; - calculate_previous_epoch_inflation_rewards( slot_ctx, - fd_bank_capitalization_get( slot_ctx->bank ), + calculate_previous_epoch_inflation_rewards( bank, + fd_bank_capitalization_get( bank ), prev_epoch, &rewards ); fd_calculate_validator_rewards_result_t validator_result[1] = {0}; - calculate_validator_rewards( slot_ctx, - prev_epoch, - rewards.validator_rewards, - validator_result, - temp_info, - tpool, - exec_spads, - exec_spad_cnt, - runtime_spad ); + calculate_validator_rewards( + bank, + funk, + funk_txn, + prev_epoch, + rewards.validator_rewards, + validator_result, + temp_info, + tpool, + exec_spads, + exec_spad_cnt, + runtime_spad ); fd_stake_reward_calculation_t * stake_reward_calculation = &validator_result->calculate_stake_vote_rewards_result.stake_reward_calculation; - fd_epoch_schedule_t const * epoch_schedule = fd_bank_epoch_schedule_query( slot_ctx->bank ); - ulong num_partitions = get_reward_distribution_num_blocks( epoch_schedule, - slot_ctx->slot, - stake_reward_calculation->stake_rewards_len ); + fd_epoch_schedule_t const * epoch_schedule = fd_bank_epoch_schedule_query( bank ); + + ulong num_partitions = get_reward_distribution_num_blocks( + epoch_schedule, + bank->slot, + stake_reward_calculation->stake_rewards_len ); + hash_rewards_into_partitions( stake_reward_calculation, parent_blockhash, num_partitions, @@ -856,7 +876,7 @@ calculate_rewards_for_partitioning( fd_exec_slot_ctx_t * slot_ result->validator_rate = rewards.validator_rate; result->foundation_rate = rewards.foundation_rate; result->prev_epoch_duration_in_years = rewards.prev_epoch_duration_in_years; - result->capitalization = fd_bank_capitalization_get( slot_ctx->bank ); + result->capitalization = fd_bank_capitalization_get( bank ); result->point_value = validator_result->point_value; } @@ -864,7 +884,9 @@ calculate_rewards_for_partitioning( fd_exec_slot_ctx_t * slot_ https://github.com/anza-xyz/agave/blob/7117ed9653ce19e8b2dea108eff1f3eb6a3378a7/runtime/src/bank/partitioned_epoch_rewards/calculation.rs#L97 */ static void -calculate_rewards_and_distribute_vote_rewards( fd_exec_slot_ctx_t * slot_ctx, +calculate_rewards_and_distribute_vote_rewards( fd_bank_t * bank, + fd_funk_t * funk, + fd_funk_txn_t * funk_txn, ulong prev_epoch, fd_hash_t const * parent_blockhash, fd_calculate_rewards_and_distribute_vote_rewards_result_t * result, @@ -876,15 +898,18 @@ calculate_rewards_and_distribute_vote_rewards( fd_exec_slot_ctx_t * /* https://github.com/firedancer-io/solana/blob/dab3da8e7b667d7527565bddbdbecf7ec1fb868e/runtime/src/bank.rs#L2406-L2492 */ fd_partitioned_rewards_calculation_t rewards_calc_result[1] = {0}; - calculate_rewards_for_partitioning( slot_ctx, - prev_epoch, - parent_blockhash, - rewards_calc_result, - temp_info, - tpool, - exec_spads, - exec_spad_cnt, - runtime_spad ); + calculate_rewards_for_partitioning( + bank, + funk, + funk_txn, + prev_epoch, + parent_blockhash, + rewards_calc_result, + temp_info, + tpool, + exec_spads, + exec_spad_cnt, + runtime_spad ); /* Iterate over all the vote reward nodes */ for( fd_vote_reward_t_mapnode_t * vote_reward_node = fd_vote_reward_t_map_minimum( rewards_calc_result->vote_reward_map_pool, rewards_calc_result->vote_reward_map_root); @@ -900,20 +925,20 @@ calculate_rewards_and_distribute_vote_rewards( fd_exec_slot_ctx_t * if( FD_UNLIKELY( fd_txn_account_init_from_funk_mutable( vote_rec, vote_pubkey, - slot_ctx->funk, - slot_ctx->funk_txn, + funk, + funk_txn, 1, 0UL ) != FD_ACC_MGR_SUCCESS ) ) { FD_LOG_ERR(( "Unable to modify vote account" )); } - vote_rec->vt->set_slot( vote_rec, slot_ctx->slot ); + vote_rec->vt->set_slot( vote_rec, bank->slot ); if( FD_UNLIKELY( vote_rec->vt->checked_add_lamports( vote_rec, vote_reward_node->elem.vote_rewards ) ) ) { FD_LOG_ERR(( "Adding lamports to vote account would cause overflow" )); } - fd_txn_account_mutable_fini( vote_rec, slot_ctx->funk, slot_ctx->funk_txn ); + fd_txn_account_mutable_fini( vote_rec, funk, funk_txn ); result->distributed_rewards = fd_ulong_sat_add( result->distributed_rewards, vote_reward_node->elem.vote_rewards ); } @@ -926,7 +951,7 @@ calculate_rewards_and_distribute_vote_rewards( fd_exec_slot_ctx_t * FD_LOG_ERR(( "Unexpected rewards calculation result" )); } - fd_bank_capitalization_set( slot_ctx->bank, fd_bank_capitalization_get( slot_ctx->bank ) + result->distributed_rewards ); + fd_bank_capitalization_set( bank, fd_bank_capitalization_get( bank ) + result->distributed_rewards ); /* Cheap because this doesn't copy all the rewards, just pointers to the dlist */ result->stake_rewards_by_partition = rewards_calc_result->stake_rewards_by_partition; @@ -996,13 +1021,13 @@ set_epoch_reward_status_inactive( fd_exec_slot_ctx_t * slot_ctx ) { Takes ownership of the given stake_rewards_by_partition data structure, which will be destroyed when set_epoch_reward_status_inactive is called. */ static void -set_epoch_reward_status_active( fd_exec_slot_ctx_t * slot_ctx, +set_epoch_reward_status_active( fd_bank_t * bank, ulong distribution_starting_block_height, fd_partitioned_stake_rewards_t * partitioned_rewards ) { FD_LOG_NOTICE(( "Setting epoch reward status as active" )); - fd_epoch_reward_status_global_t * epoch_reward_status = fd_bank_epoch_reward_status_locking_modify( slot_ctx->bank ); + fd_epoch_reward_status_global_t * epoch_reward_status = fd_bank_epoch_reward_status_locking_modify( bank ); epoch_reward_status->discriminant = fd_epoch_reward_status_enum_Active; epoch_reward_status->inner.Active.distribution_starting_block_height = distribution_starting_block_height; @@ -1026,7 +1051,7 @@ set_epoch_reward_status_active( fd_exec_slot_ctx_t * slot_ctx, fd_memcpy( partitions_mem, fd_partitioned_stake_rewards_dlist_leave( partitioned_rewards->partitions ), partitions_footprint ); epoch_reward_status->inner.Active.partitioned_stake_rewards.partitions_offset = (ulong)partitions_mem - (ulong)&epoch_reward_status->inner.Active.partitioned_stake_rewards; - fd_bank_epoch_reward_status_end_locking_modify( slot_ctx->bank ); + fd_bank_epoch_reward_status_end_locking_modify( bank ); } /* Process reward credits for a partition of rewards. @@ -1131,7 +1156,9 @@ fd_distribute_partitioned_epoch_rewards( fd_exec_slot_ctx_t * slot_ctx, https://github.com/anza-xyz/agave/blob/7117ed9653ce19e8b2dea108eff1f3eb6a3378a7/runtime/src/bank/partitioned_epoch_rewards/calculation.rs#L41 */ void -fd_begin_partitioned_rewards( fd_exec_slot_ctx_t * slot_ctx, +fd_begin_partitioned_rewards( fd_bank_t * bank, + fd_funk_t * funk, + fd_funk_txn_t * funk_txn, fd_hash_t const * parent_blockhash, ulong parent_epoch, fd_epoch_info_t * temp_info, @@ -1142,32 +1169,38 @@ fd_begin_partitioned_rewards( fd_exec_slot_ctx_t * slot_ctx, /* https://github.com/anza-xyz/agave/blob/7117ed9653ce19e8b2dea108eff1f3eb6a3378a7/runtime/src/bank/partitioned_epoch_rewards/calculation.rs#L55 */ fd_calculate_rewards_and_distribute_vote_rewards_result_t rewards_result[1] = {0}; - calculate_rewards_and_distribute_vote_rewards( slot_ctx, - parent_epoch, - parent_blockhash, - rewards_result, - temp_info, - tpool, - exec_spads, - exec_spad_cnt, - runtime_spad ); + calculate_rewards_and_distribute_vote_rewards( + bank, + funk, + funk_txn, + parent_epoch, + parent_blockhash, + rewards_result, + temp_info, + tpool, + exec_spads, + exec_spad_cnt, + runtime_spad ); /* https://github.com/anza-xyz/agave/blob/9a7bf72940f4b3cd7fc94f54e005868ce707d53d/runtime/src/bank/partitioned_epoch_rewards/calculation.rs#L62 */ - ulong distribution_starting_block_height = fd_bank_block_height_get( slot_ctx->bank ) + REWARD_CALCULATION_NUM_BLOCKS; + ulong distribution_starting_block_height = fd_bank_block_height_get( bank ) + REWARD_CALCULATION_NUM_BLOCKS; /* Set the epoch reward status to be active */ - set_epoch_reward_status_active( slot_ctx, + set_epoch_reward_status_active( bank, distribution_starting_block_height, &rewards_result->stake_rewards_by_partition.partitioned_stake_rewards ); /* Initialize the epoch rewards sysvar https://github.com/anza-xyz/agave/blob/9a7bf72940f4b3cd7fc94f54e005868ce707d53d/runtime/src/bank/partitioned_epoch_rewards/calculation.rs#L78 */ - fd_sysvar_epoch_rewards_init( slot_ctx, - rewards_result->distributed_rewards, - distribution_starting_block_height, - rewards_result->stake_rewards_by_partition.partitioned_stake_rewards.partitions_len, - rewards_result->point_value, - parent_blockhash ); + fd_sysvar_epoch_rewards_init( + bank, + funk, + funk_txn, + rewards_result->distributed_rewards, + distribution_starting_block_height, + rewards_result->stake_rewards_by_partition.partitioned_stake_rewards.partitions_len, + rewards_result->point_value, + parent_blockhash ); } /* @@ -1247,7 +1280,9 @@ fd_rewards_recalculate_partitioned_rewards( fd_exec_slot_ctx_t * slot_ctx, .deactivating = 0UL }; - fd_accumulate_stake_infos( slot_ctx, + fd_accumulate_stake_infos( slot_ctx->bank, + slot_ctx->funk, + slot_ctx->funk_txn, stakes, stake_history, new_warmup_cooldown_rate_epoch, @@ -1272,7 +1307,9 @@ fd_rewards_recalculate_partitioned_rewards( fd_exec_slot_ctx_t * slot_ctx, /* In future, the calculation will be cached in the snapshot, but for now we just re-calculate it (as Agave does). */ fd_calculate_stake_vote_rewards_result_t calculate_stake_vote_rewards_result[1]; - calculate_stake_vote_rewards( slot_ctx, + calculate_stake_vote_rewards( slot_ctx->bank, + slot_ctx->funk, + slot_ctx->funk_txn, stake_history, rewarded_epoch, &point_value, @@ -1297,7 +1334,7 @@ fd_rewards_recalculate_partitioned_rewards( fd_exec_slot_ctx_t * slot_ctx, runtime_spad ); /* Update the epoch reward status with the newly re-calculated partitions. */ - set_epoch_reward_status_active( slot_ctx, + set_epoch_reward_status_active( slot_ctx->bank, epoch_rewards->distribution_starting_block_height, &stake_rewards_by_partition->partitioned_stake_rewards ); } else { diff --git a/src/flamenco/rewards/fd_rewards.h b/src/flamenco/rewards/fd_rewards.h index 26668d91bc..80f66f5c4d 100644 --- a/src/flamenco/rewards/fd_rewards.h +++ b/src/flamenco/rewards/fd_rewards.h @@ -23,7 +23,7 @@ struct fd_calculate_points_task_args { typedef struct fd_calculate_points_task_args fd_calculate_points_task_args_t; struct fd_calculate_stake_vote_rewards_task_args { - fd_exec_slot_ctx_t * slot_ctx; + fd_bank_t * bank; fd_stake_history_t const * stake_history; ulong rewarded_epoch; ulong * new_warmup_cooldown_rate_epoch; @@ -35,14 +35,16 @@ struct fd_calculate_stake_vote_rewards_task_args { typedef struct fd_calculate_stake_vote_rewards_task_args fd_calculate_stake_vote_rewards_task_args_t; void -fd_begin_partitioned_rewards( fd_exec_slot_ctx_t * slot_ctx, - fd_hash_t const * parent_blockhash, - ulong parent_epoch, - fd_epoch_info_t * temp_info, - fd_tpool_t * tpool, - fd_spad_t * * exec_spads, - ulong exec_spad_cnt, - fd_spad_t * runtime_spad ); +fd_begin_partitioned_rewards( fd_bank_t * bank, + fd_funk_t * funk, + fd_funk_txn_t * funk_txn, + fd_hash_t const * parent_blockhash, + ulong parent_epoch, + fd_epoch_info_t * temp_info, + fd_tpool_t * tpool, + fd_spad_t * * exec_spads, + ulong exec_spad_cnt, + fd_spad_t * runtime_spad ); void fd_rewards_recalculate_partitioned_rewards( fd_exec_slot_ctx_t * slot_ctx, diff --git a/src/flamenco/runtime/fd_runtime.c b/src/flamenco/runtime/fd_runtime.c index 201542818a..d8146f03bc 100644 --- a/src/flamenco/runtime/fd_runtime.c +++ b/src/flamenco/runtime/fd_runtime.c @@ -2504,7 +2504,9 @@ fd_apply_builtin_program_feature_transitions( fd_bank_t * bank, static void fd_feature_activate( fd_features_t * features, - fd_exec_slot_ctx_t * slot_ctx, + fd_bank_t * bank, + fd_funk_t * funk, + fd_funk_txn_t * funk_txn, fd_feature_id_t const * id, uchar const acct[ static 32 ], fd_spad_t * runtime_spad ) { @@ -2515,7 +2517,7 @@ fd_feature_activate( fd_features_t * features, } FD_TXN_ACCOUNT_DECL( acct_rec ); - int err = fd_txn_account_init_from_funk_readonly( acct_rec, (fd_pubkey_t*)acct, slot_ctx->funk, slot_ctx->funk_txn ); + int err = fd_txn_account_init_from_funk_readonly( acct_rec, (fd_pubkey_t*)acct, funk, funk_txn ); if( FD_UNLIKELY( err != FD_ACC_MGR_SUCCESS ) ) { return; } @@ -2540,13 +2542,13 @@ fd_feature_activate( fd_features_t * features, FD_LOG_INFO(( "Feature %s not activated at %lu, activating", FD_BASE58_ENC_32_ALLOCA( acct ), feature->activated_at )); FD_TXN_ACCOUNT_DECL( modify_acct_rec ); - err = fd_txn_account_init_from_funk_mutable( modify_acct_rec, (fd_pubkey_t *)acct, slot_ctx->funk, slot_ctx->funk_txn, 0, 0UL ); + err = fd_txn_account_init_from_funk_mutable( modify_acct_rec, (fd_pubkey_t *)acct, funk, funk_txn, 0, 0UL ); if( FD_UNLIKELY( err != FD_ACC_MGR_SUCCESS ) ) { return; } feature->has_activated_at = 1; - feature->activated_at = slot_ctx->slot; + feature->activated_at = bank->slot; fd_bincode_encode_ctx_t encode_ctx = { .data = modify_acct_rec->vt->get_data_mut( modify_acct_rec ), .dataend = modify_acct_rec->vt->get_data_mut( modify_acct_rec ) + modify_acct_rec->vt->get_data_len( modify_acct_rec ), @@ -2556,26 +2558,29 @@ fd_feature_activate( fd_features_t * features, FD_LOG_ERR(( "Failed to encode feature account %s (%d)", FD_BASE58_ENC_32_ALLOCA( acct ), decode_err )); } - fd_txn_account_mutable_fini( modify_acct_rec, slot_ctx->funk, slot_ctx->funk_txn ); + fd_txn_account_mutable_fini( modify_acct_rec, funk, funk_txn ); } } FD_SPAD_FRAME_END; } static void -fd_features_activate( fd_exec_slot_ctx_t * slot_ctx, fd_spad_t * runtime_spad ) { - fd_features_t * features = fd_bank_features_modify( slot_ctx->bank ); +fd_features_activate( fd_bank_t * bank, + fd_funk_t * funk, + fd_funk_txn_t * funk_txn, + fd_spad_t * runtime_spad ) { + fd_features_t * features = fd_bank_features_modify( bank ); for( fd_feature_id_t const * id = fd_feature_iter_init(); !fd_feature_iter_done( id ); id = fd_feature_iter_next( id ) ) { - fd_feature_activate( features, slot_ctx, id, id->id.key, runtime_spad ); + fd_feature_activate( features, bank, funk, funk_txn, id, id->id.key, runtime_spad ); } } uint -fd_runtime_is_epoch_boundary( fd_exec_slot_ctx_t * slot_ctx, ulong curr_slot, ulong prev_slot ) { +fd_runtime_is_epoch_boundary( fd_bank_t * bank, ulong curr_slot, ulong prev_slot ) { ulong slot_idx; - fd_epoch_schedule_t const * schedule = fd_bank_epoch_schedule_query( slot_ctx->bank ); + fd_epoch_schedule_t const * schedule = fd_bank_epoch_schedule_query( bank ); ulong prev_epoch = fd_slot_to_epoch( schedule, prev_slot, &slot_idx ); ulong new_epoch = fd_slot_to_epoch( schedule, curr_slot, &slot_idx ); @@ -2598,53 +2603,55 @@ fd_runtime_is_epoch_boundary( fd_exec_slot_ctx_t * slot_ctx, ulong curr_slot, ul */ /* process for the start of a new epoch */ static void -fd_runtime_process_new_epoch( fd_exec_slot_ctx_t * slot_ctx, - ulong parent_epoch, - fd_tpool_t * tpool, - fd_spad_t * * exec_spads, - ulong exec_spad_cnt, - fd_spad_t * runtime_spad ) { +fd_runtime_process_new_epoch( fd_bank_t * bank, + fd_funk_t * funk, + fd_funk_txn_t * funk_txn, + ulong parent_epoch, + fd_tpool_t * tpool, + fd_spad_t * * exec_spads, + ulong exec_spad_cnt, + fd_spad_t * runtime_spad ) { FD_LOG_NOTICE(( "fd_process_new_epoch start" )); long start = fd_log_wallclock(); ulong slot; - fd_epoch_schedule_t const * epoch_schedule = fd_bank_epoch_schedule_query( slot_ctx->bank ); - ulong epoch = fd_slot_to_epoch( epoch_schedule, slot_ctx->slot, &slot ); + fd_epoch_schedule_t const * epoch_schedule = fd_bank_epoch_schedule_query( bank ); + ulong epoch = fd_slot_to_epoch( epoch_schedule, bank->slot, &slot ); /* Activate new features https://github.com/anza-xyz/agave/blob/v2.1.0/runtime/src/bank.rs#L6587-L6598 */ - fd_features_activate( slot_ctx, runtime_spad ); - fd_features_restore( slot_ctx, runtime_spad ); + fd_features_activate( bank, funk, funk_txn, runtime_spad ); + fd_features_restore( bank, funk, funk_txn, runtime_spad ); /* Apply builtin program feature transitions https://github.com/anza-xyz/agave/blob/v2.1.0/runtime/src/bank.rs#L6621-L6624 */ - fd_apply_builtin_program_feature_transitions( slot_ctx->bank, slot_ctx->funk, slot_ctx->funk_txn, runtime_spad ); + fd_apply_builtin_program_feature_transitions( bank, funk, funk_txn, runtime_spad ); /* Change the speed of the poh clock https://github.com/anza-xyz/agave/blob/v2.1.0/runtime/src/bank.rs#L6627-L6649 */ - if( FD_FEATURE_JUST_ACTIVATED( slot_ctx, update_hashes_per_tick6 ) ) { - fd_bank_hashes_per_tick_set( slot_ctx->bank, UPDATED_HASHES_PER_TICK6 ); - } else if( FD_FEATURE_JUST_ACTIVATED( slot_ctx, update_hashes_per_tick5 ) ) { - fd_bank_hashes_per_tick_set( slot_ctx->bank, UPDATED_HASHES_PER_TICK5 ); - } else if( FD_FEATURE_JUST_ACTIVATED( slot_ctx, update_hashes_per_tick4 ) ) { - fd_bank_hashes_per_tick_set( slot_ctx->bank, UPDATED_HASHES_PER_TICK4 ); - } else if( FD_FEATURE_JUST_ACTIVATED( slot_ctx, update_hashes_per_tick3 ) ) { - fd_bank_hashes_per_tick_set( slot_ctx->bank, UPDATED_HASHES_PER_TICK3 ); - } else if( FD_FEATURE_JUST_ACTIVATED( slot_ctx, update_hashes_per_tick2 ) ) { - fd_bank_hashes_per_tick_set( slot_ctx->bank, UPDATED_HASHES_PER_TICK2 ); + if( FD_FEATURE_JUST_ACTIVATED( bank, update_hashes_per_tick6 ) ) { + fd_bank_hashes_per_tick_set( bank, UPDATED_HASHES_PER_TICK6 ); + } else if( FD_FEATURE_JUST_ACTIVATED( bank, update_hashes_per_tick5 ) ) { + fd_bank_hashes_per_tick_set( bank, UPDATED_HASHES_PER_TICK5 ); + } else if( FD_FEATURE_JUST_ACTIVATED( bank, update_hashes_per_tick4 ) ) { + fd_bank_hashes_per_tick_set( bank, UPDATED_HASHES_PER_TICK4 ); + } else if( FD_FEATURE_JUST_ACTIVATED( bank, update_hashes_per_tick3 ) ) { + fd_bank_hashes_per_tick_set( bank, UPDATED_HASHES_PER_TICK3 ); + } else if( FD_FEATURE_JUST_ACTIVATED( bank, update_hashes_per_tick2 ) ) { + fd_bank_hashes_per_tick_set( bank, UPDATED_HASHES_PER_TICK2 ); } /* Get the new rate activation epoch */ int _err[1]; ulong new_rate_activation_epoch_val = 0UL; ulong * new_rate_activation_epoch = &new_rate_activation_epoch_val; - int is_some = fd_new_warmup_cooldown_rate_epoch( slot_ctx->slot, - slot_ctx->funk, - slot_ctx->funk_txn, + int is_some = fd_new_warmup_cooldown_rate_epoch( bank->slot, + funk, + funk_txn, runtime_spad, - fd_bank_features_query( slot_ctx->bank ), + fd_bank_features_query( bank ), new_rate_activation_epoch, _err ); if( FD_UNLIKELY( !is_some ) ) { @@ -2658,29 +2665,32 @@ fd_runtime_process_new_epoch( fd_exec_slot_ctx_t * slot_ctx, This is due to a subtlety in how Agave's stake caches interact when loading from snapshots. See the comment in fd_exec_slot_ctx_recover_. */ - if( fd_bank_use_prev_epoch_stake_get( slot_ctx->bank ) == epoch ) { - fd_update_epoch_stakes( slot_ctx->bank ); + if( fd_bank_use_prev_epoch_stake_get( bank ) == epoch ) { + fd_update_epoch_stakes( bank ); } /* Updates stake history sysvar accumulated values. */ - fd_stakes_activate_epoch( slot_ctx, - new_rate_activation_epoch, - &temp_info, - tpool, - exec_spads, - exec_spad_cnt, - runtime_spad ); + fd_stakes_activate_epoch( + bank, + funk, + funk_txn, + new_rate_activation_epoch, + &temp_info, + tpool, + exec_spads, + exec_spad_cnt, + runtime_spad ); /* Update the stakes epoch value to the new epoch */ - fd_stakes_global_t * stakes = fd_bank_stakes_locking_modify( slot_ctx->bank ); + fd_stakes_global_t * stakes = fd_bank_stakes_locking_modify( bank ); stakes->epoch = epoch; - fd_bank_stakes_end_locking_modify( slot_ctx->bank ); + fd_bank_stakes_end_locking_modify( bank ); - fd_update_stake_delegations( slot_ctx->bank, &temp_info ); + fd_update_stake_delegations( bank, &temp_info ); /* Refresh vote accounts in stakes cache using updated stake weights, and merges slot bank vote accounts with the epoch bank vote accounts. https://github.com/anza-xyz/agave/blob/v2.1.6/runtime/src/stakes.rs#L363-L370 */ - fd_stake_history_t const * history = fd_sysvar_stake_history_read( slot_ctx->funk, slot_ctx->funk_txn, runtime_spad ); + fd_stake_history_t const * history = fd_sysvar_stake_history_read( funk, funk_txn, runtime_spad ); if( FD_UNLIKELY( !history ) ) { FD_LOG_ERR(( "StakeHistory sysvar could not be read and decoded" )); } @@ -2695,39 +2705,43 @@ fd_runtime_process_new_epoch( fd_exec_slot_ctx_t * slot_ctx, fd_spad_push( runtime_spad ); - fd_refresh_vote_accounts( slot_ctx, - history, - new_rate_activation_epoch, - &temp_info, - tpool, - exec_spads, - exec_spad_cnt, - runtime_spad ); + fd_refresh_vote_accounts( + bank, + funk, + funk_txn, + history, + new_rate_activation_epoch, + &temp_info, + tpool, + exec_spads, + exec_spad_cnt, + runtime_spad ); /* Distribute rewards */ - fd_block_hash_queue_global_t const * bhq = (fd_block_hash_queue_global_t *)&slot_ctx->bank->block_hash_queue[0]; + fd_block_hash_queue_global_t const * bhq = fd_bank_block_hash_queue_query( bank ); fd_hash_t const * parent_blockhash = fd_block_hash_queue_last_hash_join( bhq ); - fd_begin_partitioned_rewards( slot_ctx, - parent_blockhash, - parent_epoch, - &temp_info, - tpool, - exec_spads, - exec_spad_cnt, - runtime_spad ); + fd_begin_partitioned_rewards( + bank, + funk, + funk_txn, + parent_blockhash, + parent_epoch, + &temp_info, + tpool, + exec_spads, + exec_spad_cnt, + runtime_spad ); /* Replace stakes at T-2 (slot_ctx->slot_bank.epoch_stakes) by stakes at T-1 (epoch_bank->next_epoch_stakes) */ - fd_update_epoch_stakes( slot_ctx->bank ); + fd_update_epoch_stakes( bank ); /* Replace stakes at T-1 (epoch_bank->next_epoch_stakes) by updated stakes at T (stakes->vote_accounts) */ - fd_update_next_epoch_stakes( slot_ctx->bank ); + fd_update_next_epoch_stakes( bank ); /* Update current leaders using slot_ctx->slot_bank.epoch_stakes (new T-2 stakes) */ - fd_runtime_update_leaders( slot_ctx->bank, slot_ctx->slot, runtime_spad ); - - fd_calculate_epoch_accounts_hash_values( slot_ctx ); + fd_runtime_update_leaders( bank, bank->slot, runtime_spad ); FD_LOG_NOTICE(( "fd_process_new_epoch end" )); @@ -3600,7 +3614,7 @@ fd_runtime_read_genesis( fd_exec_slot_ctx_t * slot_ctx, fd_write_builtin_account( slot_ctx->bank, slot_ctx->funk, slot_ctx->funk_txn, a->pubkey, (const char *) a->string, a->string_len ); } - fd_features_restore( slot_ctx, runtime_spad ); + fd_features_restore( slot_ctx->bank, slot_ctx->funk, slot_ctx->funk_txn, runtime_spad ); slot_ctx->slot = 0UL; @@ -4005,12 +4019,15 @@ fd_runtime_block_pre_execute_process_new_epoch( fd_exec_slot_ctx_t * slot_ctx, if( FD_UNLIKELY( prev_epochbank, + slot_ctx->funk, + slot_ctx->funk_txn, + new_epoch - 1UL, + tpool, + exec_spads, + exec_spad_cnt, + runtime_spad ); *is_epoch_boundary = 1; } } else { diff --git a/src/flamenco/runtime/fd_runtime.h b/src/flamenco/runtime/fd_runtime.h index dadf001309..e2734a76a9 100644 --- a/src/flamenco/runtime/fd_runtime.h +++ b/src/flamenco/runtime/fd_runtime.h @@ -590,9 +590,9 @@ fd_runtime_finalize_txn( fd_funk_t * funk, /* Epoch Boundary *************************************************************/ uint -fd_runtime_is_epoch_boundary( fd_exec_slot_ctx_t * slot_ctx, - ulong curr_slot, - ulong prev_slot ); +fd_runtime_is_epoch_boundary( fd_bank_t * bank, + ulong curr_slot, + ulong prev_slot ); /* This is roughly Agave's process_new_epoch() which gets called from diff --git a/src/flamenco/runtime/fd_runtime_init.c b/src/flamenco/runtime/fd_runtime_init.c index d3e30662d5..387fbc3763 100644 --- a/src/flamenco/runtime/fd_runtime_init.c +++ b/src/flamenco/runtime/fd_runtime_init.c @@ -12,7 +12,8 @@ static void fd_feature_restore( fd_features_t * features, - fd_exec_slot_ctx_t * slot_ctx, + fd_funk_t * funk, + fd_funk_txn_t * funk_txn, fd_feature_id_t const * id, uchar const acct[ static 32 ], fd_spad_t * runtime_spad ) { @@ -25,8 +26,8 @@ fd_feature_restore( fd_features_t * features, FD_TXN_ACCOUNT_DECL( acct_rec ); int err = fd_txn_account_init_from_funk_readonly( acct_rec, (fd_pubkey_t *)acct, - slot_ctx->funk, - slot_ctx->funk_txn ); + funk, + funk_txn ); if( FD_UNLIKELY( err!=FD_ACC_MGR_SUCCESS ) ) { return; } @@ -67,12 +68,12 @@ fd_feature_restore( fd_features_t * features, } void -fd_features_restore( fd_exec_slot_ctx_t * slot_ctx, fd_spad_t * runtime_spad ) { - fd_features_t * features = fd_bank_features_modify( slot_ctx->bank ); +fd_features_restore( fd_bank_t * bank, fd_funk_t * funk, fd_funk_txn_t * funk_txn, fd_spad_t * runtime_spad ) { + fd_features_t * features = fd_bank_features_modify( bank ); for( fd_feature_id_t const * id = fd_feature_iter_init(); !fd_feature_iter_done( id ); id = fd_feature_iter_next( id ) ) { - fd_feature_restore( features, slot_ctx, id, id->id.key, runtime_spad ); + fd_feature_restore( features, funk, funk_txn, id, id->id.key, runtime_spad ); } } diff --git a/src/flamenco/runtime/fd_runtime_init.h b/src/flamenco/runtime/fd_runtime_init.h index 9ddb46e229..30bae5f64a 100644 --- a/src/flamenco/runtime/fd_runtime_init.h +++ b/src/flamenco/runtime/fd_runtime_init.h @@ -4,6 +4,7 @@ /* fd_runtime_init.h provides APIs for backing up and restoring a Solana runtime environment. This file must not depend on fd_executor.h. */ +#include "fd_bank.h" #include "../fd_flamenco_base.h" #include "../../funk/fd_funk_rec.h" @@ -20,7 +21,10 @@ FD_PROTOTYPES_BEGIN snapshot. */ void -fd_features_restore( fd_exec_slot_ctx_t * slot_ctx, fd_spad_t * runtime_spad ); +fd_features_restore( fd_bank_t * bank, + fd_funk_t * funk, + fd_funk_txn_t * funk_txn, + fd_spad_t * runtime_spad ); FD_PROTOTYPES_END diff --git a/src/flamenco/runtime/sysvar/fd_sysvar_epoch_rewards.c b/src/flamenco/runtime/sysvar/fd_sysvar_epoch_rewards.c index 911cf4d3e1..944e6b9494 100644 --- a/src/flamenco/runtime/sysvar/fd_sysvar_epoch_rewards.c +++ b/src/flamenco/runtime/sysvar/fd_sysvar_epoch_rewards.c @@ -6,7 +6,10 @@ #include "../fd_system_ids.h" static void -write_epoch_rewards( fd_exec_slot_ctx_t * slot_ctx, fd_sysvar_epoch_rewards_t * epoch_rewards ) { +write_epoch_rewards( fd_bank_t * bank, + fd_funk_t * funk, + fd_funk_txn_t * funk_txn, + fd_sysvar_epoch_rewards_t * epoch_rewards ) { ulong sz = fd_sysvar_epoch_rewards_size( epoch_rewards ); uchar enc[sz]; fd_memset( enc, 0, sz ); @@ -18,7 +21,7 @@ write_epoch_rewards( fd_exec_slot_ctx_t * slot_ctx, fd_sysvar_epoch_rewards_t * FD_LOG_ERR(( "fd_sysvar_epoch_rewards_encode failed" )); } - fd_sysvar_set( slot_ctx->bank, slot_ctx->funk, slot_ctx->funk_txn, &fd_sysvar_owner_id, &fd_sysvar_epoch_rewards_id, enc, sz, slot_ctx->slot ); + fd_sysvar_set( bank, funk, funk_txn, &fd_sysvar_owner_id, &fd_sysvar_epoch_rewards_id, enc, sz, bank->slot ); } fd_sysvar_epoch_rewards_t * @@ -68,7 +71,7 @@ fd_sysvar_epoch_rewards_distribute( fd_exec_slot_ctx_t * slot_ctx, epoch_rewards->distributed_rewards += distributed; - write_epoch_rewards( slot_ctx, epoch_rewards ); + write_epoch_rewards( slot_ctx->bank, slot_ctx->funk, slot_ctx->funk_txn, epoch_rewards ); } void @@ -85,14 +88,16 @@ fd_sysvar_epoch_rewards_set_inactive( fd_exec_slot_ctx_t * slot_ctx, epoch_rewards->active = 0; - write_epoch_rewards( slot_ctx, epoch_rewards ); + write_epoch_rewards( slot_ctx->bank, slot_ctx->funk, slot_ctx->funk_txn, epoch_rewards ); } /* Create EpochRewards sysvar with calculated rewards https://github.com/anza-xyz/agave/blob/cbc8320d35358da14d79ebcada4dfb6756ffac79/runtime/src/bank/partitioned_epoch_rewards/sysvar.rs#L25 */ void -fd_sysvar_epoch_rewards_init( fd_exec_slot_ctx_t * slot_ctx, +fd_sysvar_epoch_rewards_init( fd_bank_t * bank, + fd_funk_t * funk, + fd_funk_txn_t * funk_txn, ulong distributed_rewards, ulong distribution_starting_block_height, ulong num_partitions, @@ -113,5 +118,5 @@ fd_sysvar_epoch_rewards_init( fd_exec_slot_ctx_t * slot_ctx, fd_memcpy( &epoch_rewards.parent_blockhash, last_blockhash, FD_HASH_FOOTPRINT ); - write_epoch_rewards( slot_ctx, &epoch_rewards ); + write_epoch_rewards( bank, funk, funk_txn, &epoch_rewards ); } diff --git a/src/flamenco/runtime/sysvar/fd_sysvar_epoch_rewards.h b/src/flamenco/runtime/sysvar/fd_sysvar_epoch_rewards.h index 1ba356f63e..24d8befaa8 100644 --- a/src/flamenco/runtime/sysvar/fd_sysvar_epoch_rewards.h +++ b/src/flamenco/runtime/sysvar/fd_sysvar_epoch_rewards.h @@ -36,13 +36,14 @@ fd_sysvar_epoch_rewards_set_inactive( fd_exec_slot_ctx_t * slot_ctx, https://github.com/anza-xyz/agave/blob/cbc8320d35358da14d79ebcada4dfb6756ffac79/runtime/src/bank/partitioned_epoch_rewards/sysvar.rs#L25 */ void fd_sysvar_epoch_rewards_init( - fd_exec_slot_ctx_t * slot_ctx, - ulong distributed_rewards, - ulong distribution_starting_block_height, - ulong num_partitions, - fd_point_value_t point_value, - const fd_hash_t * last_blockhash -); + fd_bank_t * bank, + fd_funk_t * funk, + fd_funk_txn_t * funk_txn, + ulong distributed_rewards, + ulong distribution_starting_block_height, + ulong num_partitions, + fd_point_value_t point_value, + fd_hash_t const * last_blockhash ); FD_PROTOTYPES_END diff --git a/src/flamenco/runtime/sysvar/fd_sysvar_stake_history.c b/src/flamenco/runtime/sysvar/fd_sysvar_stake_history.c index ac4ee8f01e..85e53d8593 100644 --- a/src/flamenco/runtime/sysvar/fd_sysvar_stake_history.c +++ b/src/flamenco/runtime/sysvar/fd_sysvar_stake_history.c @@ -7,7 +7,9 @@ of the corresponding fd_types entry. */ static void -write_stake_history( fd_exec_slot_ctx_t * slot_ctx, +write_stake_history( fd_bank_t * bank, + fd_funk_t * funk, + fd_funk_txn_t * funk_txn, fd_stake_history_t * stake_history ) { /* https://github.com/solana-labs/solana/blob/8f2c8b8388a495d2728909e30460aa40dcc5d733/sdk/program/src/sysvar/stake_history.rs#L12 */ uchar enc[16392] = {0}; @@ -18,7 +20,7 @@ write_stake_history( fd_exec_slot_ctx_t * slot_ctx, if( FD_UNLIKELY( fd_stake_history_encode( stake_history, &encode )!=FD_BINCODE_SUCCESS ) ) FD_LOG_ERR(("fd_stake_history_encode failed")); - fd_sysvar_set( slot_ctx->bank, slot_ctx->funk, slot_ctx->funk_txn, &fd_sysvar_owner_id, &fd_sysvar_stake_history_id, enc, sizeof(enc), slot_ctx->slot ); + fd_sysvar_set( bank, funk, funk_txn, &fd_sysvar_owner_id, &fd_sysvar_stake_history_id, enc, sizeof(enc), bank->slot ); } fd_stake_history_t * @@ -50,15 +52,17 @@ void fd_sysvar_stake_history_init( fd_exec_slot_ctx_t * slot_ctx ) { fd_stake_history_t stake_history; fd_stake_history_new( &stake_history ); - write_stake_history( slot_ctx, &stake_history ); + write_stake_history( slot_ctx->bank, slot_ctx->funk, slot_ctx->funk_txn, &stake_history ); } void -fd_sysvar_stake_history_update( fd_exec_slot_ctx_t * slot_ctx, +fd_sysvar_stake_history_update( fd_bank_t * bank, + fd_funk_t * funk, + fd_funk_txn_t * funk_txn, fd_epoch_stake_history_entry_pair_t * pair, fd_spad_t * runtime_spad ) { // Need to make this maybe zero copies of map... - fd_stake_history_t * stake_history = fd_sysvar_stake_history_read( slot_ctx->funk, slot_ctx->funk_txn, runtime_spad ); + fd_stake_history_t * stake_history = fd_sysvar_stake_history_read( funk, funk_txn, runtime_spad ); if( stake_history->fd_stake_history_offset == 0 ) { stake_history->fd_stake_history_offset = stake_history->fd_stake_history_size - 1; @@ -78,5 +82,5 @@ fd_sysvar_stake_history_update( fd_exec_slot_ctx_t * slot_ctx, stake_history->fd_stake_history[ idx ].entry.effective = pair->entry.effective; stake_history->fd_stake_history[ idx ].entry.deactivating = pair->entry.deactivating; - write_stake_history( slot_ctx, stake_history ); + write_stake_history( bank, funk, funk_txn, stake_history ); } diff --git a/src/flamenco/runtime/sysvar/fd_sysvar_stake_history.h b/src/flamenco/runtime/sysvar/fd_sysvar_stake_history.h index 67dbb36da7..358435be09 100644 --- a/src/flamenco/runtime/sysvar/fd_sysvar_stake_history.h +++ b/src/flamenco/runtime/sysvar/fd_sysvar_stake_history.h @@ -3,6 +3,7 @@ #include "../../fd_flamenco_base.h" #include "../../types/fd_types.h" +#include "../../runtime/fd_bank.h" #include "../../../funk/fd_funk.h" /* FD_SYSVAR_STAKE_HISTORY_CAP is the max number of entries that the @@ -31,7 +32,9 @@ fd_sysvar_stake_history_read( fd_funk_t * funk, /* Update the stake history sysvar account - called during epoch boundary */ void -fd_sysvar_stake_history_update( fd_exec_slot_ctx_t * slot_ctx, +fd_sysvar_stake_history_update( fd_bank_t * bank, + fd_funk_t * funk, + fd_funk_txn_t * funk_txn, fd_epoch_stake_history_entry_pair_t * pair, fd_spad_t * runtime_spad ); diff --git a/src/flamenco/runtime/tests/harness/fd_txn_harness.c b/src/flamenco/runtime/tests/harness/fd_txn_harness.c index 6b98da3e43..77e128f3bd 100644 --- a/src/flamenco/runtime/tests/harness/fd_txn_harness.c +++ b/src/flamenco/runtime/tests/harness/fd_txn_harness.c @@ -143,7 +143,7 @@ fd_runtime_fuzz_txn_ctx_create( fd_runtime_fuzz_runner_t * runner, // Provide a 0-set default entry fd_epoch_stake_history_entry_pair_t entry = {0}; fd_sysvar_stake_history_init( slot_ctx ); - fd_sysvar_stake_history_update( slot_ctx, &entry, runner->spad ); + fd_sysvar_stake_history_update( slot_ctx->bank, slot_ctx->funk, slot_ctx->funk_txn, &entry, runner->spad ); } /* Provide default last restart slot sysvar if not provided */ @@ -176,7 +176,14 @@ fd_runtime_fuzz_txn_ctx_create( fd_runtime_fuzz_runner_t * runner, if( !epoch_rewards ) { fd_point_value_t point_value = {0}; fd_hash_t const * last_hash = test_ctx->blockhash_queue_count > 0 ? (fd_hash_t const *)test_ctx->blockhash_queue[0]->bytes : (fd_hash_t const *)empty_bytes; - fd_sysvar_epoch_rewards_init( slot_ctx, 0UL, 2UL, 1UL, point_value, last_hash); + fd_sysvar_epoch_rewards_init( + slot_ctx->bank, + slot_ctx->funk, + slot_ctx->funk_txn, + 0UL, + 2UL, + 1UL, + point_value, last_hash); } /* A NaN rent exemption threshold is U.B. in Solana Labs */ diff --git a/src/flamenco/snapshot/fd_snapshot.c b/src/flamenco/snapshot/fd_snapshot.c index 91ee4edc75..87bc444bf5 100644 --- a/src/flamenco/snapshot/fd_snapshot.c +++ b/src/flamenco/snapshot/fd_snapshot.c @@ -237,7 +237,11 @@ fd_snapshot_load_fini( fd_snapshot_load_ctx_t * ctx ) { } // In order to calculate the snapshot hash, we need to know what features are active... - fd_features_restore( ctx->slot_ctx, ctx->runtime_spad ); + fd_features_restore( + ctx->slot_ctx->bank, + ctx->slot_ctx->funk, + ctx->slot_ctx->funk_txn, + ctx->runtime_spad ); fd_calculate_epoch_accounts_hash_values( ctx->slot_ctx ); int snapshots_lt_hash = FD_FEATURE_ACTIVE_BANK( ctx->slot_ctx->bank, snapshots_lt_hash ); diff --git a/src/flamenco/stakes/fd_stakes.c b/src/flamenco/stakes/fd_stakes.c index d213b8f915..d97c938d25 100644 --- a/src/flamenco/stakes/fd_stakes.c +++ b/src/flamenco/stakes/fd_stakes.c @@ -172,7 +172,8 @@ fd_stake_weights_by_node( fd_vote_accounts_global_t const * accs, /* Helper function to deserialize a vote account. If successful, populates vote account info in `elem` and saves the decoded vote state in `vote_state` */ static fd_vote_state_versioned_t * -deserialize_and_update_vote_account( fd_exec_slot_ctx_t * slot_ctx, +deserialize_and_update_vote_account( fd_funk_t * funk, + fd_funk_txn_t * funk_txn, fd_vote_accounts_pair_global_t_mapnode_t * elem, fd_stake_weight_t_mapnode_t * stake_delegations_root, fd_stake_weight_t_mapnode_t * stake_delegations_pool, @@ -182,8 +183,8 @@ deserialize_and_update_vote_account( fd_exec_slot_ctx_t * FD_TXN_ACCOUNT_DECL( vote_account ); if( FD_UNLIKELY( fd_txn_account_init_from_funk_readonly( vote_account, vote_account_pubkey, - slot_ctx->funk, - slot_ctx->funk_txn ) ) ) { + funk, + funk_txn ) ) ) { FD_LOG_DEBUG(( "Vote account not found" )); return NULL; } @@ -420,7 +421,9 @@ new vote account keys from this epoch. https://github.com/solana-labs/solana/blob/c091fd3da8014c0ef83b626318018f238f506435/runtime/src/stakes.rs#L562 */ void -fd_refresh_vote_accounts( fd_exec_slot_ctx_t * slot_ctx, +fd_refresh_vote_accounts( fd_bank_t * bank, + fd_funk_t * funk, + fd_funk_txn_t * funk_txn, fd_stake_history_t const * history, ulong * new_rate_activation_epoch, fd_epoch_info_t * temp_info, @@ -429,12 +432,12 @@ fd_refresh_vote_accounts( fd_exec_slot_ctx_t * slot_ctx, ulong exec_spad_cnt, fd_spad_t * runtime_spad ) { - fd_stakes_global_t * stakes = fd_bank_stakes_locking_modify( slot_ctx->bank ); + fd_stakes_global_t * stakes = fd_bank_stakes_locking_modify( bank ); fd_vote_accounts_global_t * vote_accounts = &stakes->vote_accounts; fd_vote_accounts_pair_global_t_mapnode_t * stakes_vote_accounts_pool = fd_vote_accounts_vote_accounts_pool_join( vote_accounts ); fd_vote_accounts_pair_global_t_mapnode_t * stakes_vote_accounts_root = fd_vote_accounts_vote_accounts_root_join( vote_accounts ); - fd_account_keys_global_t * vote_account_keys = fd_bank_vote_account_keys_locking_modify( slot_ctx->bank ); + fd_account_keys_global_t * vote_account_keys = fd_bank_vote_account_keys_locking_modify( bank ); fd_account_keys_pair_t_mapnode_t * vote_account_keys_pool = fd_account_keys_account_keys_pool_join( vote_account_keys ); fd_account_keys_pair_t_mapnode_t * vote_account_keys_root = fd_account_keys_account_keys_root_join( vote_account_keys ); @@ -504,12 +507,15 @@ fd_refresh_vote_accounts( fd_exec_slot_ctx_t * slot_ctx, elem; elem = fd_vote_accounts_pair_global_t_map_successor( stakes_vote_accounts_pool, elem ) ) { fd_pubkey_t const * vote_account_pubkey = &elem->elem.key; - fd_vote_state_versioned_t * vote_state = deserialize_and_update_vote_account( slot_ctx, - elem, - root, - pool, - vote_account_pubkey, - runtime_spad ); + fd_vote_state_versioned_t * vote_state = deserialize_and_update_vote_account( + funk, + funk_txn, + elem, + root, + pool, + vote_account_pubkey, + runtime_spad ); + if( FD_LIKELY( vote_state ) ) { total_epoch_stake += elem->elem.stake; // Insert into the temporary vote states cache @@ -539,7 +545,8 @@ fd_refresh_vote_accounts( fd_exec_slot_ctx_t * slot_ctx, } fd_vote_accounts_pair_global_t_mapnode_t * new_vote_node = fd_vote_accounts_pair_global_t_map_acquire( stakes_vote_accounts_pool ); - fd_vote_state_versioned_t * vote_state = deserialize_and_update_vote_account( slot_ctx, + fd_vote_state_versioned_t * vote_state = deserialize_and_update_vote_account( funk, + funk_txn, new_vote_node, root, pool, @@ -563,9 +570,9 @@ fd_refresh_vote_accounts( fd_exec_slot_ctx_t * slot_ctx, fd_vote_accounts_vote_accounts_pool_update( &stakes->vote_accounts, stakes_vote_accounts_pool ); fd_vote_accounts_vote_accounts_root_update( &stakes->vote_accounts, stakes_vote_accounts_root ); - fd_bank_stakes_end_locking_modify( slot_ctx->bank ); + fd_bank_stakes_end_locking_modify( bank ); - fd_bank_total_epoch_stake_set( slot_ctx->bank, total_epoch_stake ); + fd_bank_total_epoch_stake_set( bank, total_epoch_stake ); /* At this point, we need to flush the vote account keys cache */ vote_account_keys_pool = fd_account_keys_account_keys_pool_join( vote_account_keys ); @@ -574,7 +581,7 @@ fd_refresh_vote_accounts( fd_exec_slot_ctx_t * slot_ctx, vote_account_keys_root = NULL; fd_account_keys_account_keys_pool_update( vote_account_keys, vote_account_keys_pool ); fd_account_keys_account_keys_root_update( vote_account_keys, vote_account_keys_root ); - fd_bank_vote_account_keys_end_locking_modify( slot_ctx->bank ); + fd_bank_vote_account_keys_end_locking_modify( bank ); } static void @@ -583,7 +590,8 @@ accumulate_stake_cache_delegations( fd_delegation_pair_t_mapnode_t * * dele ulong worker_idx, fd_delegation_pair_t_mapnode_t * end_node ) { - fd_exec_slot_ctx_t const * slot_ctx = task_args->slot_ctx; + fd_funk_t * funk = task_args->funk; + fd_funk_txn_t * funk_txn = task_args->funk_txn; fd_stake_history_t const * history = task_args->stake_history; ulong * new_rate_activation_epoch = task_args->new_rate_activation_epoch; fd_stake_history_entry_t * accumulator = task_args->accumulator; @@ -604,8 +612,8 @@ accumulate_stake_cache_delegations( fd_delegation_pair_t_mapnode_t * * dele FD_TXN_ACCOUNT_DECL( acc ); int rc = fd_txn_account_init_from_funk_readonly( acc, &n->elem.account, - slot_ctx->funk, - slot_ctx->funk_txn ); + funk, + funk_txn ); if( FD_UNLIKELY( rc!=FD_ACC_MGR_SUCCESS || acc->vt->get_lamports( acc )==0UL ) ) { FD_LOG_WARNING(("Failed to init account")); continue; @@ -670,7 +678,9 @@ accumulate_stake_cache_delegations_tpool_task( void *tpool, used to save intermediate state about stake and vote accounts to avoid them from having to be recomputed on every access, especially at the epoch boundary. Also collects stats in `accumulator` */ void -fd_accumulate_stake_infos( fd_exec_slot_ctx_t const * slot_ctx, +fd_accumulate_stake_infos( fd_bank_t * bank, + fd_funk_t * funk, + fd_funk_txn_t * funk_txn, fd_stakes_global_t const * stakes, fd_stake_history_t const * history, ulong * new_rate_activation_epoch, @@ -718,7 +728,8 @@ fd_accumulate_stake_infos( fd_exec_slot_ctx_t const * slot_ctx, batch_delegation_roots[worker_cnt] = NULL; fd_accumulate_delegations_task_args_t task_args = { - .slot_ctx = slot_ctx, + .funk = funk, + .funk_txn = funk_txn, .stake_history = history, .new_rate_activation_epoch = new_rate_activation_epoch, .accumulator = accumulator, @@ -740,12 +751,12 @@ fd_accumulate_stake_infos( fd_exec_slot_ctx_t const * slot_ctx, } temp_info->stake_infos_new_keys_start_idx = temp_info->stake_infos_len; - fd_account_keys_global_t const * stake_account_keys = fd_bank_stake_account_keys_locking_query( slot_ctx->bank ); + fd_account_keys_global_t const * stake_account_keys = fd_bank_stake_account_keys_locking_query( bank ); fd_account_keys_pair_t_mapnode_t * account_keys_pool = fd_account_keys_account_keys_pool_join( stake_account_keys ); fd_account_keys_pair_t_mapnode_t * account_keys_root = fd_account_keys_account_keys_root_join( stake_account_keys ); if( !account_keys_pool ) { - fd_bank_stake_account_keys_end_locking_query( slot_ctx->bank ); + fd_bank_stake_account_keys_end_locking_query( bank ); return; } @@ -754,7 +765,7 @@ fd_accumulate_stake_infos( fd_exec_slot_ctx_t const * slot_ctx, n; n = fd_account_keys_pair_t_map_successor( account_keys_pool, n ) ) { FD_TXN_ACCOUNT_DECL( acc ); - int rc = fd_txn_account_init_from_funk_readonly(acc, &n->elem.key, slot_ctx->funk, slot_ctx->funk_txn ); + int rc = fd_txn_account_init_from_funk_readonly(acc, &n->elem.key, funk, funk_txn ); if( FD_UNLIKELY( rc!=FD_ACC_MGR_SUCCESS || acc->vt->get_lamports( acc )==0UL ) ) { continue; } @@ -782,24 +793,26 @@ fd_accumulate_stake_infos( fd_exec_slot_ctx_t const * slot_ctx, accumulator->deactivating += new_entry.deactivating; } - fd_bank_stake_account_keys_end_locking_query( slot_ctx->bank ); + fd_bank_stake_account_keys_end_locking_query( bank ); } /* https://github.com/solana-labs/solana/blob/88aeaa82a856fc807234e7da0b31b89f2dc0e091/runtime/src/stakes.rs#L169 */ void -fd_stakes_activate_epoch( fd_exec_slot_ctx_t * slot_ctx, - ulong * new_rate_activation_epoch, - fd_epoch_info_t * temp_info, - fd_tpool_t * tpool, - fd_spad_t * * exec_spads, - ulong exec_spad_cnt, - fd_spad_t * runtime_spad ) { - - fd_stakes_global_t const * stakes = fd_bank_stakes_locking_query( slot_ctx->bank ); +fd_stakes_activate_epoch( fd_bank_t * bank, + fd_funk_t * funk, + fd_funk_txn_t * funk_txn, + ulong * new_rate_activation_epoch, + fd_epoch_info_t * temp_info, + fd_tpool_t * tpool, + fd_spad_t * * exec_spads, + ulong exec_spad_cnt, + fd_spad_t * runtime_spad ) { + + fd_stakes_global_t const * stakes = fd_bank_stakes_locking_query( bank ); fd_delegation_pair_t_mapnode_t * stake_delegations_pool = fd_stakes_stake_delegations_pool_join( stakes ); fd_delegation_pair_t_mapnode_t * stake_delegations_root = fd_stakes_stake_delegations_root_join( stakes ); - fd_account_keys_global_t const * stake_account_keys = fd_bank_stake_account_keys_locking_query( slot_ctx->bank ); + fd_account_keys_global_t const * stake_account_keys = fd_bank_stake_account_keys_locking_query( bank ); fd_account_keys_pair_t_mapnode_t * account_keys_pool = NULL; fd_account_keys_pair_t_mapnode_t * account_keys_root = NULL; @@ -814,7 +827,7 @@ fd_stakes_activate_epoch( fd_exec_slot_ctx_t * slot_ctx, /* Add a new entry to the Stake History sysvar for the previous epoch https://github.com/solana-labs/solana/blob/88aeaa82a856fc807234e7da0b31b89f2dc0e091/runtime/src/stakes.rs#L181-L192 */ - fd_stake_history_t const * history = fd_sysvar_stake_history_read( slot_ctx->funk, slot_ctx->funk_txn, runtime_spad ); + fd_stake_history_t const * history = fd_sysvar_stake_history_read( funk, funk_txn, runtime_spad ); if( FD_UNLIKELY( !history ) ) FD_LOG_ERR(( "StakeHistory sysvar is missing from sysvar cache" )); ulong stake_delegations_size = fd_delegation_pair_t_map_size( @@ -822,7 +835,7 @@ fd_stakes_activate_epoch( fd_exec_slot_ctx_t * slot_ctx, stake_delegations_size += !!account_keys_pool ? fd_account_keys_pair_t_map_size( account_keys_pool, account_keys_root ) : 0UL; - fd_bank_stake_account_keys_end_locking_query( slot_ctx->bank ); + fd_bank_stake_account_keys_end_locking_query( bank ); temp_info->stake_infos_len = 0UL; temp_info->stake_infos = (fd_epoch_info_pair_t *)fd_spad_alloc( runtime_spad, FD_EPOCH_INFO_PAIR_ALIGN, sizeof(fd_epoch_info_pair_t)*stake_delegations_size ); @@ -835,16 +848,19 @@ fd_stakes_activate_epoch( fd_exec_slot_ctx_t * slot_ctx, }; /* Accumulate stats for stake accounts */ - fd_accumulate_stake_infos( slot_ctx, - stakes, - history, - new_rate_activation_epoch, - &accumulator, - temp_info, - tpool, - exec_spads, - exec_spad_cnt, - runtime_spad ); + fd_accumulate_stake_infos( + bank, + funk, + funk_txn, + stakes, + history, + new_rate_activation_epoch, + &accumulator, + temp_info, + tpool, + exec_spads, + exec_spad_cnt, + runtime_spad ); /* https://github.com/anza-xyz/agave/blob/v2.1.6/runtime/src/stakes.rs#L359 */ fd_epoch_stake_history_entry_pair_t new_elem = { @@ -856,9 +872,9 @@ fd_stakes_activate_epoch( fd_exec_slot_ctx_t * slot_ctx, } }; - fd_sysvar_stake_history_update( slot_ctx, &new_elem, runtime_spad ); + fd_sysvar_stake_history_update( bank, funk, funk_txn, &new_elem, runtime_spad ); - fd_bank_stakes_end_locking_query( slot_ctx->bank ); + fd_bank_stakes_end_locking_query( bank ); } diff --git a/src/flamenco/stakes/fd_stakes.h b/src/flamenco/stakes/fd_stakes.h index d9af20a434..9f7e2ef257 100644 --- a/src/flamenco/stakes/fd_stakes.h +++ b/src/flamenco/stakes/fd_stakes.h @@ -3,6 +3,8 @@ #include "../fd_flamenco_base.h" #include "../types/fd_types.h" +#include "../runtime/fd_bank.h" +#include "../../funk/fd_funk.h" FD_PROTOTYPES_BEGIN @@ -34,7 +36,8 @@ struct fd_compute_stake_delegations { typedef struct fd_compute_stake_delegations fd_compute_stake_delegations_t; struct fd_accumulate_delegations_task_args { - fd_exec_slot_ctx_t const * slot_ctx; + fd_funk_t * funk; + fd_funk_txn_t * funk_txn; fd_stake_history_t const * stake_history; ulong * new_rate_activation_epoch; fd_stake_history_entry_t * accumulator; @@ -52,13 +55,15 @@ fd_stake_weights_by_node( fd_vote_accounts_global_t const * accs, void -fd_stakes_activate_epoch( fd_exec_slot_ctx_t * slot_ctx, - ulong * new_rate_activation_epoch, - fd_epoch_info_t * temp_info, - fd_tpool_t * tpool, - fd_spad_t * * exec_spads, - ulong exec_spad_cnt, - fd_spad_t * runtime_spad ); +fd_stakes_activate_epoch( fd_bank_t * bank, + fd_funk_t * funk, + fd_funk_txn_t * funk_txn, + ulong * new_rate_activation_epoch, + fd_epoch_info_t * temp_info, + fd_tpool_t * tpool, + fd_spad_t * * exec_spads, + ulong exec_spad_cnt, + fd_spad_t * runtime_spad ); fd_stake_history_entry_t stake_and_activating( fd_delegation_t const * delegation, @@ -83,7 +88,9 @@ void fd_stakes_upsert_stake_delegation( fd_exec_slot_ctx_t * slot_ctx, fd_borrowed_account_t * stake_account, ulong * new_rate_activation_epoch ); void -fd_refresh_vote_accounts( fd_exec_slot_ctx_t * slot_ctx, +fd_refresh_vote_accounts( fd_bank_t * bank, + fd_funk_t * funk, + fd_funk_txn_t * funk_txn, fd_stake_history_t const * history, ulong * new_rate_activation_epoch, fd_epoch_info_t * temp_info, @@ -105,7 +112,9 @@ fd_populate_vote_accounts( fd_exec_slot_ctx_t * slot_ctx, fd_spad_t * runtime_spad ); void -fd_accumulate_stake_infos( fd_exec_slot_ctx_t const * slot_ctx, +fd_accumulate_stake_infos( fd_bank_t * bank, + fd_funk_t * funk, + fd_funk_txn_t * funk_txn, fd_stakes_global_t const * stakes, fd_stake_history_t const * history, ulong * new_rate_activation_epoch, From 39efc28c98507695cb6b3cea23e3557410a510db Mon Sep 17 00:00:00 2001 From: Ishan Bhatt Date: Tue, 8 Jul 2025 13:35:42 +0000 Subject: [PATCH 07/27] patch --- src/flamenco/runtime/fd_runtime.c | 7 +- .../runtime/program/fd_bpf_program_util.c | 69 ++++++++++--------- .../runtime/program/fd_bpf_program_util.h | 6 +- .../runtime/tests/harness/fd_block_harness.c | 2 +- .../runtime/tests/harness/fd_instr_harness.c | 2 +- .../runtime/tests/harness/fd_txn_harness.c | 2 +- 6 files changed, 46 insertions(+), 42 deletions(-) diff --git a/src/flamenco/runtime/fd_runtime.c b/src/flamenco/runtime/fd_runtime.c index 857e03e983..8ac25f86ac 100644 --- a/src/flamenco/runtime/fd_runtime.c +++ b/src/flamenco/runtime/fd_runtime.c @@ -1032,7 +1032,12 @@ fd_runtime_block_execute_finalize_start( fd_bank_t * bank, /* This slot is now "frozen" and can't be changed anymore. */ fd_runtime_freeze( bank, funk, funk_txn, runtime_spad ); - int result = fd_bpf_scan_and_create_bpf_program_cache_entry( bank, funk, funk_txn, runtime_spad ); + fd_exec_slot_ctx_t slot_ctx[1]; + slot_ctx->bank = bank; + slot_ctx->funk = funk; + slot_ctx->funk_txn = funk_txn; + + int result = fd_bpf_scan_and_create_bpf_program_cache_entry( slot_ctx, runtime_spad ); if( FD_UNLIKELY( result ) ) { FD_LOG_WARNING(( "update bpf program cache failed" )); return; diff --git a/src/flamenco/runtime/program/fd_bpf_program_util.c b/src/flamenco/runtime/program/fd_bpf_program_util.c index f9f100c268..e000dff31f 100644 --- a/src/flamenco/runtime/program/fd_bpf_program_util.c +++ b/src/flamenco/runtime/program/fd_bpf_program_util.c @@ -197,15 +197,15 @@ fd_bpf_get_programdata_from_account( fd_funk_t const * funk, /* Parse ELF info from programdata. */ static int -fd_bpf_parse_elf_info( fd_sbpf_elf_info_t * elf_info, - uchar const * program_data, - ulong program_data_len, - fd_bank_t * bank ) { +fd_bpf_parse_elf_info( fd_sbpf_elf_info_t * elf_info, + uchar const * program_data, + ulong program_data_len, + fd_exec_slot_ctx_t const * slot_ctx ) { uint min_sbpf_version, max_sbpf_version; fd_bpf_get_sbpf_versions( &min_sbpf_version, &max_sbpf_version, - bank->slot, - fd_bank_features_query( bank ) ); + slot_ctx->slot, + fd_bank_features_query( slot_ctx->bank ) ); if( FD_UNLIKELY( !fd_sbpf_elf_peek( elf_info, program_data, program_data_len, /* deploy checks */ 0, min_sbpf_version, max_sbpf_version ) ) ) { FD_LOG_DEBUG(( "fd_sbpf_elf_peek() failed: %s", fd_sbpf_strerror() )); return -1; @@ -227,7 +227,7 @@ fd_bpf_parse_elf_info( fd_sbpf_elf_info_t * elf_info, On success, `validated_prog` is updated with the loaded sBPF program metadata, as well as the `last_verified_epoch` and `failed_verification` flags. */ static int -fd_bpf_validate_sbpf_program( fd_bank_t * bank, +fd_bpf_validate_sbpf_program( fd_exec_slot_ctx_t const * slot_ctx, fd_sbpf_elf_info_t const * elf_info, uchar const * program_data, ulong program_data_len, @@ -235,9 +235,9 @@ fd_bpf_validate_sbpf_program( fd_bank_t * bank, fd_sbpf_validated_program_t * validated_prog /* out */ ) { /* Mark the program as validated for this epoch. */ - fd_epoch_schedule_t const * epoch_schedule = fd_bank_epoch_schedule_query( bank ); + fd_epoch_schedule_t const * epoch_schedule = fd_bank_epoch_schedule_query( slot_ctx->bank ); validated_prog->last_epoch_verification_ran = fd_slot_to_epoch( epoch_schedule, - bank->slot, + slot_ctx->slot, NULL ); ulong prog_align = fd_sbpf_program_align(); @@ -256,8 +256,8 @@ fd_bpf_validate_sbpf_program( fd_bank_t * bank, } fd_vm_syscall_register_slot( syscalls, - bank->slot, - fd_bank_features_query( bank ), + slot_ctx->slot, + fd_bank_features_query( slot_ctx->bank ), 0 ); /* Load program. */ @@ -276,7 +276,7 @@ fd_bpf_validate_sbpf_program( fd_bank_t * bank, FD_LOG_CRIT(( "fd_vm_new() or fd_vm_join() failed" )); } - int direct_mapping = FD_FEATURE_ACTIVE( bank->slot, fd_bank_features_query( bank ), bpf_account_data_direct_mapping ); + int direct_mapping = FD_FEATURE_ACTIVE( slot_ctx->slot, fd_bank_features_query( slot_ctx->bank ), bpf_account_data_direct_mapping ); vm = fd_vm_init( vm, NULL, /* OK since unused in `fd_vm_validate()` */ @@ -357,16 +357,16 @@ fd_publish_failed_verification_rec( fd_funk_t * funk, The program will still be added to the cache even if verifications fail. This is to prevent a DOS vector where an attacker could spam invocations to programs that failed verification. */ static void -fd_bpf_create_bpf_program_cache_entry( fd_bank_t * bank, - fd_funk_t * funk, - fd_funk_txn_t * funk_txn, +fd_bpf_create_bpf_program_cache_entry( fd_exec_slot_ctx_t * slot_ctx, fd_txn_account_t const * program_acc, fd_spad_t * runtime_spad ) { FD_SPAD_FRAME_BEGIN( runtime_spad ) { /* Prepare the funk record for the program cache. */ fd_pubkey_t const * program_pubkey = program_acc->pubkey; - fd_funk_rec_key_t id = fd_acc_mgr_cache_key( program_pubkey ); + fd_funk_t * funk = slot_ctx->funk; + fd_funk_txn_t * funk_txn = slot_ctx->funk_txn; + fd_funk_rec_key_t id = fd_acc_mgr_cache_key( program_pubkey ); /* This prepare should never fail. */ int funk_err = FD_FUNK_SUCCESS; @@ -385,7 +385,7 @@ fd_bpf_create_bpf_program_cache_entry( fd_bank_t * bank, } fd_sbpf_elf_info_t elf_info = {0}; - if( FD_UNLIKELY( fd_bpf_parse_elf_info( &elf_info, program_data, program_data_len, bank ) ) ) { + if( FD_UNLIKELY( fd_bpf_parse_elf_info( &elf_info, program_data, program_data_len, slot_ctx ) ) ) { fd_publish_failed_verification_rec( funk, prepare, rec ); return; } @@ -404,7 +404,7 @@ fd_bpf_create_bpf_program_cache_entry( fd_bank_t * bank, /* Note that the validated program points to the funk record data and writes into the record directly to avoid an expensive memcpy. */ fd_sbpf_validated_program_t * validated_prog = fd_sbpf_validated_program_new( val, &elf_info ); - int res = fd_bpf_validate_sbpf_program( bank, &elf_info, program_data, program_data_len, runtime_spad, validated_prog ); + int res = fd_bpf_validate_sbpf_program( slot_ctx, &elf_info, program_data, program_data_len, runtime_spad, validated_prog ); if( FD_UNLIKELY( res ) ) { fd_publish_failed_verification_rec( funk, prepare, rec ); return; @@ -415,13 +415,11 @@ fd_bpf_create_bpf_program_cache_entry( fd_bank_t * bank, } static int -fd_bpf_check_and_create_bpf_program_cache_entry( fd_bank_t * bank, - fd_funk_t * funk, - fd_funk_txn_t * funk_txn, - fd_pubkey_t const * pubkey, - fd_spad_t * runtime_spad ) { +fd_bpf_check_and_create_bpf_program_cache_entry( fd_exec_slot_ctx_t * slot_ctx, + fd_pubkey_t const * pubkey, + fd_spad_t * runtime_spad ) { FD_TXN_ACCOUNT_DECL( exec_rec ); - if( FD_UNLIKELY( fd_txn_account_init_from_funk_readonly( exec_rec, pubkey, funk, funk_txn ) != FD_ACC_MGR_SUCCESS ) ) { + if( FD_UNLIKELY( fd_txn_account_init_from_funk_readonly( exec_rec, pubkey, slot_ctx->funk, slot_ctx->funk_txn ) != FD_ACC_MGR_SUCCESS ) ) { return -1; } @@ -429,29 +427,31 @@ fd_bpf_check_and_create_bpf_program_cache_entry( fd_bank_t * bank, return -1; } - fd_bpf_create_bpf_program_cache_entry( bank, funk, funk_txn, exec_rec, runtime_spad ); + fd_bpf_create_bpf_program_cache_entry( slot_ctx, exec_rec, runtime_spad ); return 0; } int -fd_bpf_scan_and_create_bpf_program_cache_entry( fd_bank_t * bank, - fd_funk_t * funk, - fd_funk_txn_t * funk_txn, - fd_spad_t * runtime_spad ) { +fd_bpf_scan_and_create_bpf_program_cache_entry( fd_exec_slot_ctx_t * slot_ctx, + fd_spad_t * runtime_spad ) { + fd_funk_t * funk = slot_ctx->funk; ulong cnt = 0UL; /* Use random-ish xid to avoid concurrency issues */ fd_funk_txn_xid_t cache_xid = fd_funk_generate_xid(); fd_funk_txn_start_write( funk ); - fd_funk_txn_t * cache_txn = fd_funk_txn_prepare( funk, funk_txn, &cache_xid, 1 ); + fd_funk_txn_t * cache_txn = fd_funk_txn_prepare( funk, slot_ctx->funk_txn, &cache_xid, 1 ); if( !cache_txn ) { FD_LOG_ERR(( "fd_funk_txn_prepare() failed" )); return -1; } fd_funk_txn_end_write( funk ); + fd_funk_txn_t * funk_txn = slot_ctx->funk_txn; + slot_ctx->funk_txn = cache_txn; + fd_funk_txn_start_read( funk ); for (fd_funk_rec_t const *rec = fd_funk_txn_first_rec( funk, funk_txn ); NULL != rec; @@ -462,7 +462,7 @@ fd_bpf_scan_and_create_bpf_program_cache_entry( fd_bank_t * bank, fd_pubkey_t const * pubkey = fd_type_pun_const( rec->pair.key[0].uc ); - int res = fd_bpf_check_and_create_bpf_program_cache_entry( bank, funk, cache_txn, pubkey, runtime_spad ); + int res = fd_bpf_check_and_create_bpf_program_cache_entry( slot_ctx, pubkey, runtime_spad ); if( res==0 ) { cnt++; @@ -479,6 +479,7 @@ fd_bpf_scan_and_create_bpf_program_cache_entry( fd_bank_t * bank, } fd_funk_txn_end_write( funk ); + slot_ctx->funk_txn = funk_txn; return 0; } @@ -546,7 +547,7 @@ FD_SPAD_FRAME_BEGIN( runtime_spad ) { fd_sbpf_validated_program_t const * prog = NULL; int err = fd_bpf_load_cache_entry( slot_ctx->funk, slot_ctx->funk_txn, program_pubkey, &prog ); if( FD_UNLIKELY( err ) ) { - fd_bpf_create_bpf_program_cache_entry( slot_ctx->bank, slot_ctx->funk, slot_ctx->funk_txn, exec_rec, runtime_spad ); + fd_bpf_create_bpf_program_cache_entry( slot_ctx, exec_rec, runtime_spad ); return; } @@ -592,7 +593,7 @@ FD_SPAD_FRAME_BEGIN( runtime_spad ) { } /* Parse the ELF info */ - if( FD_UNLIKELY( fd_bpf_parse_elf_info( &elf_info, program_data, program_data_len, slot_ctx->bank ) ) ) { + if( FD_UNLIKELY( fd_bpf_parse_elf_info( &elf_info, program_data, program_data_len, slot_ctx ) ) ) { modified_prog->failed_verification = 1; fd_funk_rec_modify_publish( query ); return; @@ -601,7 +602,7 @@ FD_SPAD_FRAME_BEGIN( runtime_spad ) { /* Validate the sBPF program. This will set the program's flags accordingly. The return code does not matter here because we publish regardless of the return code. */ modified_prog = fd_sbpf_validated_program_new( data, &elf_info ); - fd_bpf_validate_sbpf_program( slot_ctx->bank, &elf_info, program_data, program_data_len, runtime_spad, modified_prog ); + fd_bpf_validate_sbpf_program( slot_ctx, &elf_info, program_data, program_data_len, runtime_spad, modified_prog ); if( modified_prog->failed_verification ) { FD_LOG_ERR(("program fialed veriifecation;")); diff --git a/src/flamenco/runtime/program/fd_bpf_program_util.h b/src/flamenco/runtime/program/fd_bpf_program_util.h index 01abc49bb0..3b267633d2 100644 --- a/src/flamenco/runtime/program/fd_bpf_program_util.h +++ b/src/flamenco/runtime/program/fd_bpf_program_util.h @@ -62,10 +62,8 @@ fd_sbpf_validated_program_from_sbpf_program( fd_sbpf_program_t const * prog, fd_sbpf_validated_program_t * valid_prog ); int -fd_bpf_scan_and_create_bpf_program_cache_entry( fd_bank_t * bank, - fd_funk_t * funk, - fd_funk_txn_t * funk_txn, - fd_spad_t * runtime_spad ); +fd_bpf_scan_and_create_bpf_program_cache_entry( fd_exec_slot_ctx_t * slot_ctx, + fd_spad_t * runtime_spad ); int fd_bpf_scan_and_create_bpf_program_cache_entry_para( fd_exec_slot_ctx_t * slot_ctx, diff --git a/src/flamenco/runtime/tests/harness/fd_block_harness.c b/src/flamenco/runtime/tests/harness/fd_block_harness.c index 6b7792336c..5219ee2a39 100644 --- a/src/flamenco/runtime/tests/harness/fd_block_harness.c +++ b/src/flamenco/runtime/tests/harness/fd_block_harness.c @@ -348,7 +348,7 @@ fd_runtime_fuzz_block_ctx_create( fd_runtime_fuzz_runner_t * runner, /* Add accounts to bpf program cache */ - fd_bpf_scan_and_create_bpf_program_cache_entry( slot_ctx->bank, slot_ctx->funk, slot_ctx->funk_txn, runner->spad ); + fd_bpf_scan_and_create_bpf_program_cache_entry( slot_ctx, runner->spad ); /* Finish init epoch bank sysvars */ fd_epoch_schedule_t * epoch_schedule = fd_sysvar_epoch_schedule_read( funk, funk_txn, runner->spad ); diff --git a/src/flamenco/runtime/tests/harness/fd_instr_harness.c b/src/flamenco/runtime/tests/harness/fd_instr_harness.c index 387d693f8f..428879be2b 100644 --- a/src/flamenco/runtime/tests/harness/fd_instr_harness.c +++ b/src/flamenco/runtime/tests/harness/fd_instr_harness.c @@ -216,7 +216,7 @@ fd_runtime_fuzz_instr_ctx_create( fd_runtime_fuzz_runner_t * runner, } /* Add accounts to bpf program cache */ - fd_bpf_scan_and_create_bpf_program_cache_entry( slot_ctx->bank, slot_ctx->funk, slot_ctx->funk_txn, runner->spad ); + fd_bpf_scan_and_create_bpf_program_cache_entry( slot_ctx, runner->spad ); /* Fill missing sysvar cache values with defaults */ /* We create mock accounts for each of the sysvars and hardcode the data fields before loading it into the account manager */ diff --git a/src/flamenco/runtime/tests/harness/fd_txn_harness.c b/src/flamenco/runtime/tests/harness/fd_txn_harness.c index 984a64a7d0..8acfefd958 100644 --- a/src/flamenco/runtime/tests/harness/fd_txn_harness.c +++ b/src/flamenco/runtime/tests/harness/fd_txn_harness.c @@ -70,7 +70,7 @@ fd_runtime_fuzz_txn_ctx_create( fd_runtime_fuzz_runner_t * runner, } /* Add accounts to bpf program cache */ - fd_bpf_scan_and_create_bpf_program_cache_entry( slot_ctx->bank, slot_ctx->funk, slot_ctx->funk_txn, runner->spad ); + fd_bpf_scan_and_create_bpf_program_cache_entry( slot_ctx, runner->spad ); /* Setup Bank manager */ From 5c3699aa31272ab7a2df5224ebaffe7b50cdfe34 Mon Sep 17 00:00:00 2001 From: Ishan Bhatt Date: Tue, 8 Jul 2025 13:50:49 +0000 Subject: [PATCH 08/27] patch --- src/flamenco/runtime/fd_runtime.c | 7 +-- .../runtime/program/fd_bpf_program_util.c | 62 +++++++++---------- .../runtime/program/fd_bpf_program_util.h | 10 ++- .../runtime/program/test_program_cache.c | 3 +- .../runtime/tests/harness/fd_block_harness.c | 2 +- .../runtime/tests/harness/fd_instr_harness.c | 2 +- .../runtime/tests/harness/fd_txn_harness.c | 2 +- 7 files changed, 43 insertions(+), 45 deletions(-) diff --git a/src/flamenco/runtime/fd_runtime.c b/src/flamenco/runtime/fd_runtime.c index 0a90ff4621..11e56280ea 100644 --- a/src/flamenco/runtime/fd_runtime.c +++ b/src/flamenco/runtime/fd_runtime.c @@ -1032,12 +1032,7 @@ fd_runtime_block_execute_finalize_start( fd_bank_t * bank, /* This slot is now "frozen" and can't be changed anymore. */ fd_runtime_freeze( bank, funk, funk_txn, runtime_spad ); - fd_exec_slot_ctx_t slot_ctx[1]; - slot_ctx->bank = bank; - slot_ctx->funk = funk; - slot_ctx->funk_txn = funk_txn; - - int result = fd_bpf_scan_and_create_bpf_program_cache_entry( slot_ctx, runtime_spad ); + int result = fd_bpf_scan_and_create_bpf_program_cache_entry( bank, funk, funk_txn, runtime_spad ); if( FD_UNLIKELY( result ) ) { FD_LOG_WARNING(( "update bpf program cache failed" )); return; diff --git a/src/flamenco/runtime/program/fd_bpf_program_util.c b/src/flamenco/runtime/program/fd_bpf_program_util.c index e000dff31f..39b72293d6 100644 --- a/src/flamenco/runtime/program/fd_bpf_program_util.c +++ b/src/flamenco/runtime/program/fd_bpf_program_util.c @@ -200,12 +200,12 @@ static int fd_bpf_parse_elf_info( fd_sbpf_elf_info_t * elf_info, uchar const * program_data, ulong program_data_len, - fd_exec_slot_ctx_t const * slot_ctx ) { + fd_bank_t * bank ) { uint min_sbpf_version, max_sbpf_version; fd_bpf_get_sbpf_versions( &min_sbpf_version, &max_sbpf_version, - slot_ctx->slot, - fd_bank_features_query( slot_ctx->bank ) ); + bank->slot, + fd_bank_features_query( bank ) ); if( FD_UNLIKELY( !fd_sbpf_elf_peek( elf_info, program_data, program_data_len, /* deploy checks */ 0, min_sbpf_version, max_sbpf_version ) ) ) { FD_LOG_DEBUG(( "fd_sbpf_elf_peek() failed: %s", fd_sbpf_strerror() )); return -1; @@ -227,7 +227,7 @@ fd_bpf_parse_elf_info( fd_sbpf_elf_info_t * elf_info, On success, `validated_prog` is updated with the loaded sBPF program metadata, as well as the `last_verified_epoch` and `failed_verification` flags. */ static int -fd_bpf_validate_sbpf_program( fd_exec_slot_ctx_t const * slot_ctx, +fd_bpf_validate_sbpf_program( fd_bank_t * bank, fd_sbpf_elf_info_t const * elf_info, uchar const * program_data, ulong program_data_len, @@ -235,9 +235,9 @@ fd_bpf_validate_sbpf_program( fd_exec_slot_ctx_t const * slot_ctx, fd_sbpf_validated_program_t * validated_prog /* out */ ) { /* Mark the program as validated for this epoch. */ - fd_epoch_schedule_t const * epoch_schedule = fd_bank_epoch_schedule_query( slot_ctx->bank ); + fd_epoch_schedule_t const * epoch_schedule = fd_bank_epoch_schedule_query( bank ); validated_prog->last_epoch_verification_ran = fd_slot_to_epoch( epoch_schedule, - slot_ctx->slot, + bank->slot, NULL ); ulong prog_align = fd_sbpf_program_align(); @@ -256,8 +256,8 @@ fd_bpf_validate_sbpf_program( fd_exec_slot_ctx_t const * slot_ctx, } fd_vm_syscall_register_slot( syscalls, - slot_ctx->slot, - fd_bank_features_query( slot_ctx->bank ), + bank->slot, + fd_bank_features_query( bank ), 0 ); /* Load program. */ @@ -276,7 +276,7 @@ fd_bpf_validate_sbpf_program( fd_exec_slot_ctx_t const * slot_ctx, FD_LOG_CRIT(( "fd_vm_new() or fd_vm_join() failed" )); } - int direct_mapping = FD_FEATURE_ACTIVE( slot_ctx->slot, fd_bank_features_query( slot_ctx->bank ), bpf_account_data_direct_mapping ); + int direct_mapping = FD_FEATURE_ACTIVE( bank->slot, fd_bank_features_query( bank ), bpf_account_data_direct_mapping ); vm = fd_vm_init( vm, NULL, /* OK since unused in `fd_vm_validate()` */ @@ -357,15 +357,15 @@ fd_publish_failed_verification_rec( fd_funk_t * funk, The program will still be added to the cache even if verifications fail. This is to prevent a DOS vector where an attacker could spam invocations to programs that failed verification. */ static void -fd_bpf_create_bpf_program_cache_entry( fd_exec_slot_ctx_t * slot_ctx, +fd_bpf_create_bpf_program_cache_entry( fd_bank_t * bank, + fd_funk_t * funk, + fd_funk_txn_t * funk_txn, fd_txn_account_t const * program_acc, fd_spad_t * runtime_spad ) { FD_SPAD_FRAME_BEGIN( runtime_spad ) { /* Prepare the funk record for the program cache. */ fd_pubkey_t const * program_pubkey = program_acc->pubkey; - fd_funk_t * funk = slot_ctx->funk; - fd_funk_txn_t * funk_txn = slot_ctx->funk_txn; fd_funk_rec_key_t id = fd_acc_mgr_cache_key( program_pubkey ); /* This prepare should never fail. */ @@ -385,7 +385,7 @@ fd_bpf_create_bpf_program_cache_entry( fd_exec_slot_ctx_t * slot_ctx, } fd_sbpf_elf_info_t elf_info = {0}; - if( FD_UNLIKELY( fd_bpf_parse_elf_info( &elf_info, program_data, program_data_len, slot_ctx ) ) ) { + if( FD_UNLIKELY( fd_bpf_parse_elf_info( &elf_info, program_data, program_data_len, bank ) ) ) { fd_publish_failed_verification_rec( funk, prepare, rec ); return; } @@ -404,7 +404,7 @@ fd_bpf_create_bpf_program_cache_entry( fd_exec_slot_ctx_t * slot_ctx, /* Note that the validated program points to the funk record data and writes into the record directly to avoid an expensive memcpy. */ fd_sbpf_validated_program_t * validated_prog = fd_sbpf_validated_program_new( val, &elf_info ); - int res = fd_bpf_validate_sbpf_program( slot_ctx, &elf_info, program_data, program_data_len, runtime_spad, validated_prog ); + int res = fd_bpf_validate_sbpf_program( bank, &elf_info, program_data, program_data_len, runtime_spad, validated_prog ); if( FD_UNLIKELY( res ) ) { fd_publish_failed_verification_rec( funk, prepare, rec ); return; @@ -415,11 +415,13 @@ fd_bpf_create_bpf_program_cache_entry( fd_exec_slot_ctx_t * slot_ctx, } static int -fd_bpf_check_and_create_bpf_program_cache_entry( fd_exec_slot_ctx_t * slot_ctx, - fd_pubkey_t const * pubkey, - fd_spad_t * runtime_spad ) { +fd_bpf_check_and_create_bpf_program_cache_entry( fd_bank_t * bank, + fd_funk_t * funk, + fd_funk_txn_t * funk_txn, + fd_pubkey_t const * pubkey, + fd_spad_t * runtime_spad ) { FD_TXN_ACCOUNT_DECL( exec_rec ); - if( FD_UNLIKELY( fd_txn_account_init_from_funk_readonly( exec_rec, pubkey, slot_ctx->funk, slot_ctx->funk_txn ) != FD_ACC_MGR_SUCCESS ) ) { + if( FD_UNLIKELY( fd_txn_account_init_from_funk_readonly( exec_rec, pubkey, funk, funk_txn ) != FD_ACC_MGR_SUCCESS ) ) { return -1; } @@ -427,31 +429,29 @@ fd_bpf_check_and_create_bpf_program_cache_entry( fd_exec_slot_ctx_t * slot_ctx, return -1; } - fd_bpf_create_bpf_program_cache_entry( slot_ctx, exec_rec, runtime_spad ); + fd_bpf_create_bpf_program_cache_entry( bank, funk, funk_txn, exec_rec, runtime_spad ); return 0; } int -fd_bpf_scan_and_create_bpf_program_cache_entry( fd_exec_slot_ctx_t * slot_ctx, - fd_spad_t * runtime_spad ) { - fd_funk_t * funk = slot_ctx->funk; +fd_bpf_scan_and_create_bpf_program_cache_entry( fd_bank_t * bank, + fd_funk_t * funk, + fd_funk_txn_t * funk_txn, + fd_spad_t * runtime_spad ) { ulong cnt = 0UL; /* Use random-ish xid to avoid concurrency issues */ fd_funk_txn_xid_t cache_xid = fd_funk_generate_xid(); fd_funk_txn_start_write( funk ); - fd_funk_txn_t * cache_txn = fd_funk_txn_prepare( funk, slot_ctx->funk_txn, &cache_xid, 1 ); + fd_funk_txn_t * cache_txn = fd_funk_txn_prepare( funk, funk_txn, &cache_xid, 1 ); if( !cache_txn ) { FD_LOG_ERR(( "fd_funk_txn_prepare() failed" )); return -1; } fd_funk_txn_end_write( funk ); - fd_funk_txn_t * funk_txn = slot_ctx->funk_txn; - slot_ctx->funk_txn = cache_txn; - fd_funk_txn_start_read( funk ); for (fd_funk_rec_t const *rec = fd_funk_txn_first_rec( funk, funk_txn ); NULL != rec; @@ -462,7 +462,8 @@ fd_bpf_scan_and_create_bpf_program_cache_entry( fd_exec_slot_ctx_t * slot_ctx, fd_pubkey_t const * pubkey = fd_type_pun_const( rec->pair.key[0].uc ); - int res = fd_bpf_check_and_create_bpf_program_cache_entry( slot_ctx, pubkey, runtime_spad ); + + int res = fd_bpf_check_and_create_bpf_program_cache_entry( bank, funk, funk_txn, pubkey, runtime_spad ); if( res==0 ) { cnt++; @@ -479,7 +480,6 @@ fd_bpf_scan_and_create_bpf_program_cache_entry( fd_exec_slot_ctx_t * slot_ctx, } fd_funk_txn_end_write( funk ); - slot_ctx->funk_txn = funk_txn; return 0; } @@ -547,7 +547,7 @@ FD_SPAD_FRAME_BEGIN( runtime_spad ) { fd_sbpf_validated_program_t const * prog = NULL; int err = fd_bpf_load_cache_entry( slot_ctx->funk, slot_ctx->funk_txn, program_pubkey, &prog ); if( FD_UNLIKELY( err ) ) { - fd_bpf_create_bpf_program_cache_entry( slot_ctx, exec_rec, runtime_spad ); + fd_bpf_create_bpf_program_cache_entry( slot_ctx->bank, slot_ctx->funk, slot_ctx->funk_txn, exec_rec, runtime_spad ); return; } @@ -593,7 +593,7 @@ FD_SPAD_FRAME_BEGIN( runtime_spad ) { } /* Parse the ELF info */ - if( FD_UNLIKELY( fd_bpf_parse_elf_info( &elf_info, program_data, program_data_len, slot_ctx ) ) ) { + if( FD_UNLIKELY( fd_bpf_parse_elf_info( &elf_info, program_data, program_data_len, slot_ctx->bank ) ) ) { modified_prog->failed_verification = 1; fd_funk_rec_modify_publish( query ); return; @@ -602,7 +602,7 @@ FD_SPAD_FRAME_BEGIN( runtime_spad ) { /* Validate the sBPF program. This will set the program's flags accordingly. The return code does not matter here because we publish regardless of the return code. */ modified_prog = fd_sbpf_validated_program_new( data, &elf_info ); - fd_bpf_validate_sbpf_program( slot_ctx, &elf_info, program_data, program_data_len, runtime_spad, modified_prog ); + fd_bpf_validate_sbpf_program( slot_ctx->bank, &elf_info, program_data, program_data_len, runtime_spad, modified_prog ); if( modified_prog->failed_verification ) { FD_LOG_ERR(("program fialed veriifecation;")); diff --git a/src/flamenco/runtime/program/fd_bpf_program_util.h b/src/flamenco/runtime/program/fd_bpf_program_util.h index 3b267633d2..5257b0039c 100644 --- a/src/flamenco/runtime/program/fd_bpf_program_util.h +++ b/src/flamenco/runtime/program/fd_bpf_program_util.h @@ -62,11 +62,15 @@ fd_sbpf_validated_program_from_sbpf_program( fd_sbpf_program_t const * prog, fd_sbpf_validated_program_t * valid_prog ); int -fd_bpf_scan_and_create_bpf_program_cache_entry( fd_exec_slot_ctx_t * slot_ctx, - fd_spad_t * runtime_spad ); +fd_bpf_scan_and_create_bpf_program_cache_entry( fd_bank_t * bank, + fd_funk_t * funk, + fd_funk_txn_t * funk_txn, + fd_spad_t * runtime_spad ); int -fd_bpf_scan_and_create_bpf_program_cache_entry_para( fd_exec_slot_ctx_t * slot_ctx, +fd_bpf_scan_and_create_bpf_program_cache_entry_para( fd_bank_t * bank, + fd_funk_t * funk, + fd_funk_txn_t * funk_txn, fd_spad_t * runtime_spad, fd_exec_para_cb_ctx_t * exec_para_ctx ); diff --git a/src/flamenco/runtime/program/test_program_cache.c b/src/flamenco/runtime/program/test_program_cache.c index 4e147b5d95..b17070f69f 100644 --- a/src/flamenco/runtime/program/test_program_cache.c +++ b/src/flamenco/runtime/program/test_program_cache.c @@ -226,7 +226,7 @@ test_program_in_cache_needs_reverification( void ) { FD_TEST( valid_prog->last_epoch_verification_ran==1UL ); /* Fast forward to next epoch */ - test_slot_ctx->slot += 432000UL; + test_slot_ctx->bank->slot += 432000UL; /* This should trigger reverification */ fd_bpf_program_update_program_cache( test_slot_ctx, &test_program_pubkey, test_spad ); @@ -286,7 +286,6 @@ main( int argc, /* Set up slot context */ test_slot_ctx->funk = test_funk; - test_slot_ctx->slot = 433000UL; // Epoch 1 /* Set up bank */ ulong banks_footprint = fd_banks_footprint( 1UL ); diff --git a/src/flamenco/runtime/tests/harness/fd_block_harness.c b/src/flamenco/runtime/tests/harness/fd_block_harness.c index 5219ee2a39..6b7792336c 100644 --- a/src/flamenco/runtime/tests/harness/fd_block_harness.c +++ b/src/flamenco/runtime/tests/harness/fd_block_harness.c @@ -348,7 +348,7 @@ fd_runtime_fuzz_block_ctx_create( fd_runtime_fuzz_runner_t * runner, /* Add accounts to bpf program cache */ - fd_bpf_scan_and_create_bpf_program_cache_entry( slot_ctx, runner->spad ); + fd_bpf_scan_and_create_bpf_program_cache_entry( slot_ctx->bank, slot_ctx->funk, slot_ctx->funk_txn, runner->spad ); /* Finish init epoch bank sysvars */ fd_epoch_schedule_t * epoch_schedule = fd_sysvar_epoch_schedule_read( funk, funk_txn, runner->spad ); diff --git a/src/flamenco/runtime/tests/harness/fd_instr_harness.c b/src/flamenco/runtime/tests/harness/fd_instr_harness.c index 1db24cd11e..e378bc83ec 100644 --- a/src/flamenco/runtime/tests/harness/fd_instr_harness.c +++ b/src/flamenco/runtime/tests/harness/fd_instr_harness.c @@ -315,7 +315,7 @@ fd_runtime_fuzz_instr_ctx_create( fd_runtime_fuzz_runner_t * runner, } /* Add accounts to bpf program cache */ - fd_bpf_scan_and_create_bpf_program_cache_entry( slot_ctx, runner->spad ); + fd_bpf_scan_and_create_bpf_program_cache_entry( slot_ctx->bank, slot_ctx->funk, slot_ctx->funk_txn, runner->spad ); /* Load instruction accounts */ diff --git a/src/flamenco/runtime/tests/harness/fd_txn_harness.c b/src/flamenco/runtime/tests/harness/fd_txn_harness.c index 6772321d91..f122993fa1 100644 --- a/src/flamenco/runtime/tests/harness/fd_txn_harness.c +++ b/src/flamenco/runtime/tests/harness/fd_txn_harness.c @@ -252,7 +252,7 @@ fd_runtime_fuzz_txn_ctx_create( fd_runtime_fuzz_runner_t * runner, } /* Add accounts to bpf program cache */ - fd_bpf_scan_and_create_bpf_program_cache_entry( slot_ctx, runner->spad ); + fd_bpf_scan_and_create_bpf_program_cache_entry( slot_ctx->bank, slot_ctx->funk, slot_ctx->funk_txn, runner->spad ); /* Create the raw txn (https://solana.com/docs/core/transactions#transaction-size) */ uchar * txn_raw_begin = fd_spad_alloc( runner->spad, alignof(uchar), 1232 ); From e9c18e22605c228605dd10945055a7a36bba9707 Mon Sep 17 00:00:00 2001 From: Ishan Bhatt Date: Tue, 8 Jul 2025 14:19:40 +0000 Subject: [PATCH 09/27] patch --- src/flamenco/runtime/program/fd_bpf_program_util.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/flamenco/runtime/program/fd_bpf_program_util.c b/src/flamenco/runtime/program/fd_bpf_program_util.c index 39b72293d6..592641bd6e 100644 --- a/src/flamenco/runtime/program/fd_bpf_program_util.c +++ b/src/flamenco/runtime/program/fd_bpf_program_util.c @@ -462,8 +462,7 @@ fd_bpf_scan_and_create_bpf_program_cache_entry( fd_bank_t * bank, fd_pubkey_t const * pubkey = fd_type_pun_const( rec->pair.key[0].uc ); - - int res = fd_bpf_check_and_create_bpf_program_cache_entry( bank, funk, funk_txn, pubkey, runtime_spad ); + int res = fd_bpf_check_and_create_bpf_program_cache_entry( bank, funk, cache_txn, pubkey, runtime_spad ); if( res==0 ) { cnt++; From 41d36c480044dae662381b7bb2f0f6deceef7ab9 Mon Sep 17 00:00:00 2001 From: Ishan Bhatt Date: Tue, 8 Jul 2025 15:15:51 +0000 Subject: [PATCH 10/27] more --- src/app/ledger/main.c | 4 +- src/discof/replay/fd_replay_tile.c | 6 +- src/flamenco/rewards/fd_rewards.c | 94 ++++++++++--------- src/flamenco/rewards/fd_rewards.h | 9 +- src/flamenco/runtime/fd_runtime.c | 58 ++++++------ src/flamenco/runtime/fd_runtime.h | 20 ++-- .../runtime/sysvar/fd_sysvar_epoch_rewards.c | 22 +++-- .../runtime/sysvar/fd_sysvar_epoch_rewards.h | 14 ++- .../runtime/tests/harness/fd_block_harness.c | 2 +- 9 files changed, 126 insertions(+), 103 deletions(-) diff --git a/src/app/ledger/main.c b/src/app/ledger/main.c index 53cf905edf..b17939a703 100644 --- a/src/app/ledger/main.c +++ b/src/app/ledger/main.c @@ -312,7 +312,7 @@ runtime_replay( fd_ledger_args_t * ledger_args ) { poh_hash )); if( ledger_args->checkpt_mismatch ) { - fd_runtime_checkpt( ledger_args->capture_ctx, ledger_args->slot_ctx, ULONG_MAX ); + fd_runtime_checkpt( ledger_args->capture_ctx, ledger_args->slot_ctx->funk, ULONG_MAX ); } if( ledger_args->abort_on_mismatch ) { ret = 1; @@ -340,7 +340,7 @@ runtime_replay( fd_ledger_args_t * ledger_args ) { bank_hash )); if( ledger_args->checkpt_mismatch ) { - fd_runtime_checkpt( ledger_args->capture_ctx, ledger_args->slot_ctx, ULONG_MAX ); + fd_runtime_checkpt( ledger_args->capture_ctx, ledger_args->slot_ctx->funk, ULONG_MAX ); } if( ledger_args->abort_on_mismatch ) { ret = 1; diff --git a/src/discof/replay/fd_replay_tile.c b/src/discof/replay/fd_replay_tile.c index e0269371a2..de0263921c 100644 --- a/src/discof/replay/fd_replay_tile.c +++ b/src/discof/replay/fd_replay_tile.c @@ -636,7 +636,7 @@ funk_and_txncache_publish( fd_replay_tile_ctx_t * ctx, ulong wmk, fd_funk_txn_xi funk_publish( ctx, to_root_txn, wmk ); if( FD_UNLIKELY( ctx->capture_ctx ) ) { - fd_runtime_checkpt( ctx->capture_ctx, ctx->slot_ctx, wmk ); + fd_runtime_checkpt( ctx->capture_ctx, ctx->slot_ctx->funk, wmk ); } } @@ -906,7 +906,9 @@ prepare_new_block_execution( fd_replay_tile_ctx_t * ctx, int is_epoch_boundary = 0; /* TODO: Currently all of the epoch boundary/rewards logic is not multhreaded at the epoch boundary. */ - fd_runtime_block_pre_execute_process_new_epoch( ctx->slot_ctx, + fd_runtime_block_pre_execute_process_new_epoch( ctx->slot_ctx->bank, + ctx->slot_ctx->funk, + ctx->slot_ctx->funk_txn, NULL, ctx->exec_spads, ctx->exec_spad_cnt, diff --git a/src/flamenco/rewards/fd_rewards.c b/src/flamenco/rewards/fd_rewards.c index 97cc93c932..35e3cfae12 100644 --- a/src/flamenco/rewards/fd_rewards.c +++ b/src/flamenco/rewards/fd_rewards.c @@ -960,21 +960,23 @@ calculate_rewards_and_distribute_vote_rewards( fd_bank_t * /* Distributes a single partitioned reward to a single stake account */ static int -distribute_epoch_reward_to_stake_acc( fd_exec_slot_ctx_t * slot_ctx, - fd_pubkey_t * stake_pubkey, - ulong reward_lamports, - ulong new_credits_observed ) { +distribute_epoch_reward_to_stake_acc( fd_bank_t * bank, + fd_funk_t * funk, + fd_funk_txn_t * funk_txn, + fd_pubkey_t * stake_pubkey, + ulong reward_lamports, + ulong new_credits_observed ) { FD_TXN_ACCOUNT_DECL( stake_acc_rec ); if( FD_UNLIKELY( fd_txn_account_init_from_funk_mutable( stake_acc_rec, stake_pubkey, - slot_ctx->funk, - slot_ctx->funk_txn, + funk, + funk_txn, 0, 0UL ) != FD_ACC_MGR_SUCCESS ) ) { FD_LOG_ERR(( "Unable to modify stake account" )); } - stake_acc_rec->vt->set_slot( stake_acc_rec, slot_ctx->slot ); + stake_acc_rec->vt->set_slot( stake_acc_rec, bank->slot ); fd_stake_state_v2_t stake_state[1] = {0}; 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, FD_LOG_ERR(( "write_stake_state failed" )); } - fd_txn_account_mutable_fini( stake_acc_rec, slot_ctx->funk, slot_ctx->funk_txn ); + fd_txn_account_mutable_fini( stake_acc_rec, funk, funk_txn ); return 0; } /* Sets the epoch reward status to inactive, and destroys any allocated state associated with the active state. */ static void -set_epoch_reward_status_inactive( fd_exec_slot_ctx_t * slot_ctx ) { - fd_epoch_reward_status_global_t * epoch_reward_status = fd_bank_epoch_reward_status_locking_modify( slot_ctx->bank ); +set_epoch_reward_status_inactive( fd_bank_t * bank ) { + fd_epoch_reward_status_global_t * epoch_reward_status = fd_bank_epoch_reward_status_locking_modify( bank ); if( epoch_reward_status->discriminant == fd_epoch_reward_status_enum_Active ) { FD_LOG_NOTICE(( "Done partitioning rewards for current epoch" )); } epoch_reward_status->discriminant = fd_epoch_reward_status_enum_Inactive; - fd_bank_epoch_reward_status_end_locking_modify( slot_ctx->bank ); + fd_bank_epoch_reward_status_end_locking_modify( bank ); } /* Sets the epoch reward status to active. @@ -1061,7 +1063,9 @@ set_epoch_reward_status_active( fd_bank_t * bank, static void distribute_epoch_rewards_in_partition( fd_partitioned_stake_rewards_dlist_t * partition, fd_stake_reward_t * pool, - fd_exec_slot_ctx_t * slot_ctx, + fd_bank_t * bank, + fd_funk_t * funk, + fd_funk_txn_t * funk_txn, fd_spad_t * runtime_spad ) { ulong lamports_distributed = 0UL; @@ -1072,10 +1076,13 @@ distribute_epoch_rewards_in_partition( fd_partitioned_stake_rewards_dlist_t * pa iter = fd_partitioned_stake_rewards_dlist_iter_fwd_next( iter, partition, pool ) ) { fd_stake_reward_t * stake_reward = fd_partitioned_stake_rewards_dlist_iter_ele( iter, partition, pool ); - if( distribute_epoch_reward_to_stake_acc( slot_ctx, - &stake_reward->stake_pubkey, - stake_reward->lamports, - stake_reward->credits_observed ) == 0 ) { + if( distribute_epoch_reward_to_stake_acc( + bank, + funk, + funk_txn, + &stake_reward->stake_pubkey, + stake_reward->lamports, + stake_reward->credits_observed ) == 0 ) { lamports_distributed += stake_reward->lamports; } else { lamports_burned += stake_reward->lamports; @@ -1083,33 +1090,31 @@ distribute_epoch_rewards_in_partition( fd_partitioned_stake_rewards_dlist_t * pa } /* Update the epoch rewards sysvar with the amount distributed and burnt */ - fd_sysvar_epoch_rewards_distribute( slot_ctx, - lamports_distributed + lamports_burned, - runtime_spad ); + fd_sysvar_epoch_rewards_distribute( + bank, + funk, + funk_txn, + lamports_distributed + lamports_burned, + runtime_spad ); FD_LOG_DEBUG(( "lamports burned: %lu, lamports distributed: %lu", lamports_burned, lamports_distributed )); - fd_bank_capitalization_set( slot_ctx->bank, fd_bank_capitalization_get( slot_ctx->bank ) + lamports_distributed ); + fd_bank_capitalization_set( bank, fd_bank_capitalization_get( bank ) + lamports_distributed ); } /* Process reward distribution for the block if it is inside reward interval. https://github.com/anza-xyz/agave/blob/cbc8320d35358da14d79ebcada4dfb6756ffac79/runtime/src/bank/partitioned_epoch_rewards/distribution.rs#L42 */ void -fd_distribute_partitioned_epoch_rewards( fd_exec_slot_ctx_t * slot_ctx, - fd_tpool_t * tpool, - fd_spad_t * * exec_spads, - ulong exec_spad_cnt, - fd_spad_t * runtime_spad ) { - - (void)tpool; - (void)exec_spads; - (void)exec_spad_cnt; +fd_distribute_partitioned_epoch_rewards( fd_bank_t * bank, + fd_funk_t * funk, + fd_funk_txn_t * funk_txn, + fd_spad_t * runtime_spad ) { - fd_epoch_reward_status_global_t const * epoch_reward_status = fd_bank_epoch_reward_status_locking_query( slot_ctx->bank ); + fd_epoch_reward_status_global_t const * epoch_reward_status = fd_bank_epoch_reward_status_locking_query( bank ); if( epoch_reward_status->discriminant == fd_epoch_reward_status_enum_Inactive ) { - fd_bank_epoch_reward_status_end_locking_query( slot_ctx->bank ); + fd_bank_epoch_reward_status_end_locking_query( bank ); return; } @@ -1123,12 +1128,12 @@ fd_distribute_partitioned_epoch_rewards( fd_exec_slot_ctx_t * slot_ctx, FD_LOG_CRIT(( "Failed to join pool" )); } - ulong height = fd_bank_block_height_get( slot_ctx->bank ); + ulong height = fd_bank_block_height_get( bank ); ulong distribution_starting_block_height = status->distribution_starting_block_height; ulong distribution_end_exclusive = distribution_starting_block_height + status->partitioned_stake_rewards.partitions_len; - fd_epoch_schedule_t const * epoch_schedule = fd_bank_epoch_schedule_query( slot_ctx->bank ); - ulong epoch = fd_slot_to_epoch( epoch_schedule, slot_ctx->slot, NULL ); + fd_epoch_schedule_t const * epoch_schedule = fd_bank_epoch_schedule_query( bank ); + ulong epoch = fd_slot_to_epoch( epoch_schedule, bank->slot, NULL ); if( FD_UNLIKELY( get_slots_in_epoch( epoch, epoch_schedule ) <= status->partitioned_stake_rewards.partitions_len ) ) { FD_LOG_ERR(( "Should not be distributing rewards" )); @@ -1136,18 +1141,21 @@ fd_distribute_partitioned_epoch_rewards( fd_exec_slot_ctx_t * slot_ctx, if( (height>=distribution_starting_block_height) && (height < distribution_end_exclusive) ) { ulong partition_index = height - distribution_starting_block_height; - distribute_epoch_rewards_in_partition( &partitions[ partition_index ], - pool, - slot_ctx, - runtime_spad ); + distribute_epoch_rewards_in_partition( + &partitions[ partition_index ], + pool, + bank, + funk, + funk_txn, + runtime_spad ); } - fd_bank_epoch_reward_status_end_locking_query( slot_ctx->bank ); + fd_bank_epoch_reward_status_end_locking_query( bank ); /* If we have finished distributing rewards, set the status to inactive */ if( fd_ulong_sat_add( height, 1UL ) >= distribution_end_exclusive ) { - set_epoch_reward_status_inactive( slot_ctx ); - fd_sysvar_epoch_rewards_set_inactive( slot_ctx, runtime_spad ); + set_epoch_reward_status_inactive( bank ); + fd_sysvar_epoch_rewards_set_inactive( bank, funk, funk_txn, runtime_spad ); } } @@ -1217,7 +1225,7 @@ fd_rewards_recalculate_partitioned_rewards( fd_exec_slot_ctx_t * slot_ctx, fd_sysvar_epoch_rewards_t * epoch_rewards = fd_sysvar_epoch_rewards_read( slot_ctx->funk, slot_ctx->funk_txn, runtime_spad ); if( FD_UNLIKELY( epoch_rewards == NULL ) ) { FD_LOG_NOTICE(( "Failed to read or decode epoch rewards sysvar - may not have been created yet" )); - set_epoch_reward_status_inactive( slot_ctx ); + set_epoch_reward_status_inactive( slot_ctx->bank ); return; } @@ -1338,6 +1346,6 @@ fd_rewards_recalculate_partitioned_rewards( fd_exec_slot_ctx_t * slot_ctx, epoch_rewards->distribution_starting_block_height, &stake_rewards_by_partition->partitioned_stake_rewards ); } else { - set_epoch_reward_status_inactive( slot_ctx ); + set_epoch_reward_status_inactive( slot_ctx->bank ); } } diff --git a/src/flamenco/rewards/fd_rewards.h b/src/flamenco/rewards/fd_rewards.h index 80f66f5c4d..6ea1a587fd 100644 --- a/src/flamenco/rewards/fd_rewards.h +++ b/src/flamenco/rewards/fd_rewards.h @@ -54,11 +54,10 @@ fd_rewards_recalculate_partitioned_rewards( fd_exec_slot_ctx_t * slot_ctx, fd_spad_t * runtime_spad ); void -fd_distribute_partitioned_epoch_rewards( fd_exec_slot_ctx_t * slot_ctx, - fd_tpool_t * tpool, - fd_spad_t * * exec_spads, - ulong exec_spad_cnt, - fd_spad_t * runtime_spad ); +fd_distribute_partitioned_epoch_rewards( fd_bank_t * bank, + fd_funk_t * funk, + fd_funk_txn_t * funk_txn, + fd_spad_t * runtime_spad ); FD_PROTOTYPES_END diff --git a/src/flamenco/runtime/fd_runtime.c b/src/flamenco/runtime/fd_runtime.c index 11e56280ea..d21658747e 100644 --- a/src/flamenco/runtime/fd_runtime.c +++ b/src/flamenco/runtime/fd_runtime.c @@ -3593,7 +3593,7 @@ fd_runtime_publish_old_txns( fd_exec_slot_ctx_t * slot_ctx, fd_funk_txn_pool_t * txnpool = fd_funk_txn_pool( funk ); if( capture_ctx != NULL ) { - fd_runtime_checkpt( capture_ctx, slot_ctx, slot_ctx->slot ); + fd_runtime_checkpt( capture_ctx, slot_ctx->funk, slot_ctx->slot ); } int do_eah = 0; @@ -3748,34 +3748,36 @@ fd_runtime_block_execute_tpool( fd_exec_slot_ctx_t * slot_ctx, } void -fd_runtime_block_pre_execute_process_new_epoch( fd_exec_slot_ctx_t * slot_ctx, - fd_tpool_t * tpool, - fd_spad_t * * exec_spads, - ulong exec_spad_cnt, - fd_spad_t * runtime_spad, - int * is_epoch_boundary ) { +fd_runtime_block_pre_execute_process_new_epoch( fd_bank_t * bank, + fd_funk_t * funk, + fd_funk_txn_t * funk_txn, + fd_tpool_t * tpool, + fd_spad_t * * exec_spads, + ulong exec_spad_cnt, + fd_spad_t * runtime_spad, + int * is_epoch_boundary ) { /* Update block height. */ - fd_bank_block_height_set( slot_ctx->bank, fd_bank_block_height_get( slot_ctx->bank ) + 1UL ); + fd_bank_block_height_set( bank, fd_bank_block_height_get( bank ) + 1UL ); - if( slot_ctx->slot != 0UL ) { - fd_epoch_schedule_t const * epoch_schedule = fd_bank_epoch_schedule_query( slot_ctx->bank ); + if( bank->slot != 0UL ) { + fd_epoch_schedule_t const * epoch_schedule = fd_bank_epoch_schedule_query( bank ); ulong slot_idx; - ulong prev_epoch = fd_slot_to_epoch( epoch_schedule, fd_bank_prev_slot_get( slot_ctx->bank ), &slot_idx ); - ulong new_epoch = fd_slot_to_epoch( epoch_schedule, slot_ctx->slot, &slot_idx ); + ulong prev_epoch = fd_slot_to_epoch( epoch_schedule, fd_bank_prev_slot_get( bank ), &slot_idx ); + ulong new_epoch = fd_slot_to_epoch( epoch_schedule, bank->slot, &slot_idx ); if( FD_UNLIKELY( slot_idx==1UL && new_epoch==0UL ) ) { /* The block after genesis has a height of 1. */ - fd_bank_block_height_set( slot_ctx->bank, 1UL ); + fd_bank_block_height_set( bank, 1UL ); } if( FD_UNLIKELY( prev_epochbank, - slot_ctx->funk, - slot_ctx->funk_txn, + bank, + funk, + funk_txn, new_epoch - 1UL, tpool, exec_spads, @@ -3787,12 +3789,12 @@ fd_runtime_block_pre_execute_process_new_epoch( fd_exec_slot_ctx_t * slot_ctx, *is_epoch_boundary = 0; } - if( FD_LIKELY( slot_ctx->slot!=0UL ) ) { - fd_distribute_partitioned_epoch_rewards( slot_ctx, - tpool, - exec_spads, - exec_spad_cnt, - runtime_spad ); + if( FD_LIKELY( bank->slot!=0UL ) ) { + fd_distribute_partitioned_epoch_rewards( + bank, + funk, + funk_txn, + runtime_spad ); } } @@ -3844,7 +3846,9 @@ fd_runtime_block_eval_tpool( fd_exec_slot_ctx_t * slot_ctx, } int is_epoch_boundary = 0; - fd_runtime_block_pre_execute_process_new_epoch( slot_ctx, + fd_runtime_block_pre_execute_process_new_epoch( slot_ctx->bank, + slot_ctx->funk, + slot_ctx->funk_txn, tpool, exec_spads, exec_spad_cnt, @@ -3927,9 +3931,9 @@ fd_runtime_block_eval_tpool( fd_exec_slot_ctx_t * slot_ctx, /******************************************************************************/ void -fd_runtime_checkpt( fd_capture_ctx_t * capture_ctx, - fd_exec_slot_ctx_t * slot_ctx, - ulong slot ) { +fd_runtime_checkpt( fd_capture_ctx_t * capture_ctx, + fd_funk_t * funk, + ulong slot ) { int is_checkpt_freq = capture_ctx != NULL && slot % capture_ctx->checkpt_freq == 0; int is_abort_slot = slot == ULONG_MAX; if( !is_checkpt_freq && !is_abort_slot ) { @@ -3944,7 +3948,7 @@ fd_runtime_checkpt( fd_capture_ctx_t * capture_ctx, } unlink( capture_ctx->checkpt_path ); - int err = fd_wksp_checkpt( fd_funk_wksp( slot_ctx->funk ), capture_ctx->checkpt_path, 0666, 0, NULL ); + int err = fd_wksp_checkpt( fd_funk_wksp( funk ), capture_ctx->checkpt_path, 0666, 0, NULL ); if ( err ) { FD_LOG_ERR(( "backup failed: error %d", err )); } diff --git a/src/flamenco/runtime/fd_runtime.h b/src/flamenco/runtime/fd_runtime.h index c4873109c4..c633b961f0 100644 --- a/src/flamenco/runtime/fd_runtime.h +++ b/src/flamenco/runtime/fd_runtime.h @@ -596,12 +596,14 @@ fd_runtime_is_epoch_boundary( fd_bank_t * bank, the bank hash. */ void -fd_runtime_block_pre_execute_process_new_epoch( fd_exec_slot_ctx_t * slot_ctx, - fd_tpool_t * tpool, - fd_spad_t * * exec_spads, - ulong exec_spad_cnt, - fd_spad_t * runtime_spad, - int * is_epoch_boundary ); +fd_runtime_block_pre_execute_process_new_epoch( fd_bank_t * bank, + fd_funk_t * funk, + fd_funk_txn_t * funk_txn, + fd_tpool_t * tpool, + fd_spad_t * * exec_spads, + ulong exec_spad_cnt, + fd_spad_t * runtime_spad, + int * is_epoch_boundary ); /* This function is responsible for inserting fresh entries or updating existing entries in the program cache. 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, /* Debugging Tools ************************************************************/ void -fd_runtime_checkpt( fd_capture_ctx_t * capture_ctx, - fd_exec_slot_ctx_t * slot_ctx, - ulong slot ); +fd_runtime_checkpt( fd_capture_ctx_t * capture_ctx, + fd_funk_t * funk, + ulong slot ); /* Block Parsing **************************************************************/ diff --git a/src/flamenco/runtime/sysvar/fd_sysvar_epoch_rewards.c b/src/flamenco/runtime/sysvar/fd_sysvar_epoch_rewards.c index 944e6b9494..65d5ebe7c9 100644 --- a/src/flamenco/runtime/sysvar/fd_sysvar_epoch_rewards.c +++ b/src/flamenco/runtime/sysvar/fd_sysvar_epoch_rewards.c @@ -53,10 +53,12 @@ fd_sysvar_epoch_rewards_read( fd_funk_t * funk, we need to ensure that the cache stays updated after each change (versus with other sysvars which only get updated once per slot and then synced up after) */ void -fd_sysvar_epoch_rewards_distribute( fd_exec_slot_ctx_t * slot_ctx, - ulong distributed, - fd_spad_t * runtime_spad ) { - fd_sysvar_epoch_rewards_t * epoch_rewards = fd_sysvar_epoch_rewards_read( slot_ctx->funk, slot_ctx->funk_txn, runtime_spad ); +fd_sysvar_epoch_rewards_distribute( fd_bank_t * bank, + fd_funk_t * funk, + fd_funk_txn_t * funk_txn, + ulong distributed, + fd_spad_t * runtime_spad ) { + fd_sysvar_epoch_rewards_t * epoch_rewards = fd_sysvar_epoch_rewards_read( funk, funk_txn, runtime_spad ); if( FD_UNLIKELY( epoch_rewards == NULL ) ) { FD_LOG_ERR(( "failed to read sysvar epoch rewards" )); } @@ -71,13 +73,15 @@ fd_sysvar_epoch_rewards_distribute( fd_exec_slot_ctx_t * slot_ctx, epoch_rewards->distributed_rewards += distributed; - write_epoch_rewards( slot_ctx->bank, slot_ctx->funk, slot_ctx->funk_txn, epoch_rewards ); + write_epoch_rewards( bank, funk, funk_txn, epoch_rewards ); } void -fd_sysvar_epoch_rewards_set_inactive( fd_exec_slot_ctx_t * slot_ctx, - fd_spad_t * runtime_spad ) { - fd_sysvar_epoch_rewards_t * epoch_rewards = fd_sysvar_epoch_rewards_read( slot_ctx->funk, slot_ctx->funk_txn, runtime_spad ); +fd_sysvar_epoch_rewards_set_inactive( fd_bank_t * bank, + fd_funk_t * funk, + fd_funk_txn_t * funk_txn, + fd_spad_t * runtime_spad ) { + fd_sysvar_epoch_rewards_t * epoch_rewards = fd_sysvar_epoch_rewards_read( funk, funk_txn, runtime_spad ); if( FD_UNLIKELY( epoch_rewards == NULL ) ) { FD_LOG_ERR(( "failed to read sysvar epoch rewards" )); } @@ -88,7 +92,7 @@ fd_sysvar_epoch_rewards_set_inactive( fd_exec_slot_ctx_t * slot_ctx, epoch_rewards->active = 0; - write_epoch_rewards( slot_ctx->bank, slot_ctx->funk, slot_ctx->funk_txn, epoch_rewards ); + write_epoch_rewards( bank, funk, funk_txn, epoch_rewards ); } /* Create EpochRewards sysvar with calculated rewards diff --git a/src/flamenco/runtime/sysvar/fd_sysvar_epoch_rewards.h b/src/flamenco/runtime/sysvar/fd_sysvar_epoch_rewards.h index 24d8befaa8..af1b4bc994 100644 --- a/src/flamenco/runtime/sysvar/fd_sysvar_epoch_rewards.h +++ b/src/flamenco/runtime/sysvar/fd_sysvar_epoch_rewards.h @@ -20,16 +20,20 @@ fd_sysvar_epoch_rewards_read( fd_funk_t * funk, https://github.com/anza-xyz/agave/blob/cbc8320d35358da14d79ebcada4dfb6756ffac79/sdk/program/src/epoch_rewards.rs#L44 */ void -fd_sysvar_epoch_rewards_distribute( fd_exec_slot_ctx_t * slot_ctx, - ulong distributed, - fd_spad_t * runtime_spad ); +fd_sysvar_epoch_rewards_distribute( fd_bank_t * bank, + fd_funk_t * funk, + fd_funk_txn_t * funk_txn, + ulong distributed, + fd_spad_t * runtime_spad ); /* Set the EpochRewards sysvar to inactive https://github.com/anza-xyz/agave/blob/cbc8320d35358da14d79ebcada4dfb6756ffac79/runtime/src/bank/partitioned_epoch_rewards/sysvar.rs#L82 */ void -fd_sysvar_epoch_rewards_set_inactive( fd_exec_slot_ctx_t * slot_ctx, - fd_spad_t * runtime_spad ); +fd_sysvar_epoch_rewards_set_inactive( fd_bank_t * bank, + fd_funk_t * funk, + fd_funk_txn_t * funk_txn, + fd_spad_t * runtime_spad ); /* Initialize the EpochRewards sysvar account diff --git a/src/flamenco/runtime/tests/harness/fd_block_harness.c b/src/flamenco/runtime/tests/harness/fd_block_harness.c index 6b7792336c..77bd65e6c5 100644 --- a/src/flamenco/runtime/tests/harness/fd_block_harness.c +++ b/src/flamenco/runtime/tests/harness/fd_block_harness.c @@ -557,7 +557,7 @@ fd_runtime_fuzz_block_ctx_exec( fd_runtime_fuzz_runner_t * runner, /* Process new epoch may push a new spad frame onto the runtime spad. We should make sure this frame gets cleared (if it was allocated) before executing the block. */ int is_epoch_boundary = 0; - fd_runtime_block_pre_execute_process_new_epoch( slot_ctx, tpool, exec_spads, exec_spads_cnt, runtime_spad, &is_epoch_boundary ); + fd_runtime_block_pre_execute_process_new_epoch( slot_ctx->bank, slot_ctx->funk, slot_ctx->funk_txn, tpool, exec_spads, exec_spads_cnt, runtime_spad, &is_epoch_boundary ); res = fd_runtime_block_execute_tpool( slot_ctx, NULL, NULL, block_info, tpool, exec_spads, exec_spads_cnt, runtime_spad ); } FD_SPAD_FRAME_END; From cab237b6be512b4a93ad7d7ee96431ec8dbe64f4 Mon Sep 17 00:00:00 2001 From: Ishan Bhatt Date: Tue, 8 Jul 2025 15:30:19 +0000 Subject: [PATCH 11/27] more --- src/discof/replay/fd_replay_tile.c | 2 +- src/flamenco/runtime/fd_bank.c | 2 +- src/flamenco/runtime/fd_runtime.c | 65 +++++++++++-------- src/flamenco/runtime/fd_runtime.h | 8 ++- .../runtime/program/fd_bpf_program_util.c | 41 ++++++------ .../runtime/program/fd_bpf_program_util.h | 8 ++- .../runtime/program/test_program_cache.c | 12 ++-- 7 files changed, 78 insertions(+), 60 deletions(-) diff --git a/src/discof/replay/fd_replay_tile.c b/src/discof/replay/fd_replay_tile.c index de0263921c..e4d94d3554 100644 --- a/src/discof/replay/fd_replay_tile.c +++ b/src/discof/replay/fd_replay_tile.c @@ -1079,7 +1079,7 @@ exec_slice( fd_replay_tile_ctx_t * ctx, /* Insert or reverify invoked programs for this epoch, if needed FIXME: this should be done during txn parsing so that we don't have to loop over all accounts a second time. */ - fd_runtime_update_program_cache( ctx->slot_ctx, &txn_p, ctx->runtime_spad ); + fd_runtime_update_program_cache( ctx->slot_ctx->bank, ctx->slot_ctx->funk, ctx->slot_ctx->funk_txn, &txn_p, ctx->runtime_spad ); fd_fork_t * fork = fd_fork_frontier_ele_query( ctx->forks->frontier, &slot, diff --git a/src/flamenco/runtime/fd_bank.c b/src/flamenco/runtime/fd_bank.c index 094b216deb..3abbd31208 100644 --- a/src/flamenco/runtime/fd_bank.c +++ b/src/flamenco/runtime/fd_bank.c @@ -490,7 +490,7 @@ fd_banks_clone_from_parent( fd_banks_t * banks, /* Now acquire a new bank */ - FD_LOG_WARNING(( "fd_banks_pool_max: %lu, fd_banks_pool_free: %lu", fd_banks_pool_max( bank_pool ), fd_banks_pool_free( bank_pool ) )); + FD_LOG_DEBUG(( "fd_banks_pool_max: %lu, fd_banks_pool_free: %lu", fd_banks_pool_max( bank_pool ), fd_banks_pool_free( bank_pool ) )); fd_bank_t * new_bank = fd_banks_pool_ele_acquire( bank_pool ); if( FD_UNLIKELY( !new_bank ) ) { FD_LOG_WARNING(( "Failed to acquire bank" )); diff --git a/src/flamenco/runtime/fd_runtime.c b/src/flamenco/runtime/fd_runtime.c index d21658747e..b075133e93 100644 --- a/src/flamenco/runtime/fd_runtime.c +++ b/src/flamenco/runtime/fd_runtime.c @@ -2471,7 +2471,9 @@ fd_runtime_parse_microblock_hdr( void const * buf FD_PARAM_UNUSED, } void -fd_runtime_update_program_cache( fd_exec_slot_ctx_t * slot_ctx, +fd_runtime_update_program_cache( fd_bank_t * bank, + fd_funk_t * funk, + fd_funk_txn_t * funk_txn, fd_txn_p_t const * txn_p, fd_spad_t * runtime_spad ) { fd_txn_t const * txn_descriptor = TXN( txn_p ); @@ -2480,14 +2482,14 @@ fd_runtime_update_program_cache( fd_exec_slot_ctx_t * slot_ctx, fd_acct_addr_t const * acc_addrs = fd_txn_get_acct_addrs( txn_descriptor, txn_p ); for( ushort acc_idx=0; acc_idxacct_addr_cnt; acc_idx++ ) { fd_pubkey_t const * account = fd_type_pun_const( &acc_addrs[acc_idx] ); - fd_bpf_program_update_program_cache( slot_ctx, account, runtime_spad ); + fd_bpf_program_update_program_cache( bank, funk, funk_txn, account, runtime_spad ); } if( txn_descriptor->transaction_version==FD_TXN_V0 ) { /* Iterate over account keys referenced in ALUTs */ fd_acct_addr_t alut_accounts[256]; - fd_slot_hashes_global_t const * slot_hashes_global = fd_sysvar_slot_hashes_read( slot_ctx->funk, slot_ctx->funk_txn, runtime_spad ); + fd_slot_hashes_global_t const * slot_hashes_global = fd_sysvar_slot_hashes_read( funk, funk_txn, runtime_spad ); if( FD_UNLIKELY( !slot_hashes_global ) ) { return; } @@ -2496,9 +2498,9 @@ fd_runtime_update_program_cache( fd_exec_slot_ctx_t * slot_ctx, if( FD_UNLIKELY( fd_runtime_load_txn_address_lookup_tables( txn_descriptor, txn_p->payload, - slot_ctx->funk, - slot_ctx->funk_txn, - slot_ctx->slot, + funk, + funk_txn, + bank->slot, slot_hash, alut_accounts ) ) ) { return; @@ -2506,7 +2508,7 @@ fd_runtime_update_program_cache( fd_exec_slot_ctx_t * slot_ctx, for( ushort alut_idx=0; alut_idxaddr_table_adtl_cnt; alut_idx++ ) { fd_pubkey_t const * account = fd_type_pun_const( &alut_accounts[alut_idx] ); - fd_bpf_program_update_program_cache( slot_ctx, account, runtime_spad ); + fd_bpf_program_update_program_cache( bank, funk, funk_txn, account, runtime_spad ); } } } @@ -3583,23 +3585,25 @@ fd_runtime_block_verify_tpool( fd_exec_slot_ctx_t * slot_ctx, /* Should only be called in offline replay */ static int -fd_runtime_publish_old_txns( fd_exec_slot_ctx_t * slot_ctx, - fd_capture_ctx_t * capture_ctx, - fd_tpool_t * tpool, - fd_spad_t * runtime_spad ) { +fd_runtime_publish_old_txns( fd_banks_t * banks, + fd_bank_t * bank, + fd_funk_t * funk, + fd_funk_txn_t * funk_txn, + fd_capture_ctx_t * capture_ctx, + fd_tpool_t * tpool, + fd_spad_t * runtime_spad ) { /* Publish any transaction older than 31 slots */ - fd_funk_txn_start_write( slot_ctx->funk ); - fd_funk_t * funk = slot_ctx->funk; - fd_funk_txn_pool_t * txnpool = fd_funk_txn_pool( funk ); + fd_funk_txn_start_write( funk ); + fd_funk_txn_pool_t * txnpool = fd_funk_txn_pool( funk ); if( capture_ctx != NULL ) { - fd_runtime_checkpt( capture_ctx, slot_ctx->funk, slot_ctx->slot ); + fd_runtime_checkpt( capture_ctx, funk, bank->slot ); } int do_eah = 0; uint depth = 0; - for( fd_funk_txn_t * txn = slot_ctx->funk_txn; txn; txn = fd_funk_txn_parent(txn, txnpool) ) { + for( fd_funk_txn_t * txn = funk_txn; txn; txn = fd_funk_txn_parent(txn, txnpool) ) { if( ++depth == (FD_RUNTIME_OFFLINE_NUM_ROOT_BLOCKS - 1 ) ) { FD_LOG_DEBUG(("publishing %s (slot %lu)", FD_BASE58_ENC_32_ALLOCA( &txn->xid ), txn->xid.ul[0])); @@ -3609,20 +3613,20 @@ fd_runtime_publish_old_txns( fd_exec_slot_ctx_t * slot_ctx, /* Also publish the bank */ ulong slot = txn->xid.ul[0]; - fd_banks_publish( slot_ctx->banks, slot ); + fd_banks_publish( banks, slot ); - if( txn->xid.ul[0] >= fd_bank_eah_start_slot_get( slot_ctx->bank ) ) { - if( !FD_FEATURE_ACTIVE_BANK( slot_ctx->bank, accounts_lt_hash ) ) { + if( txn->xid.ul[0] >= fd_bank_eah_start_slot_get( bank ) ) { + if( !FD_FEATURE_ACTIVE_BANK( bank, accounts_lt_hash ) ) { do_eah = 1; } - fd_bank_eah_start_slot_set( slot_ctx->bank, ULONG_MAX ); + fd_bank_eah_start_slot_set( bank, ULONG_MAX ); } break; } } - fd_funk_txn_end_write( slot_ctx->funk ); + fd_funk_txn_end_write( funk ); /* Do the EAH calculation after we have released the Funk lock, to avoid a deadlock */ if( FD_UNLIKELY( do_eah ) ) { @@ -3632,12 +3636,12 @@ fd_runtime_publish_old_txns( fd_exec_slot_ctx_t * slot_ctx, }; - fd_hash_t * epoch_account_hash = fd_bank_epoch_account_hash_modify( slot_ctx->bank ); - fd_accounts_hash( slot_ctx->funk, - slot_ctx->slot, + fd_hash_t * epoch_account_hash = fd_bank_epoch_account_hash_modify( bank ); + fd_accounts_hash( funk, + bank->slot, epoch_account_hash, runtime_spad, - fd_bank_features_query( slot_ctx->bank ), + fd_bank_features_query( bank ), &exec_para_ctx, NULL ); } @@ -3696,7 +3700,7 @@ fd_runtime_block_execute_tpool( fd_exec_slot_ctx_t * slot_ctx, /* Reverify programs for this epoch if needed */ for( ulong txn_idx=0UL; txn_idxbank, slot_ctx->funk, slot_ctx->funk_txn, &mblock_txn_ptrs[txn_idx], runtime_spad ); } res = fd_runtime_process_txns_in_microblock_stream( slot_ctx->bank, @@ -3814,7 +3818,14 @@ fd_runtime_block_eval_tpool( fd_exec_slot_ctx_t * slot_ctx, /* offline replay */ (void)scheduler; - int err = fd_runtime_publish_old_txns( slot_ctx, capture_ctx, tpool, runtime_spad ); + int err = fd_runtime_publish_old_txns( + slot_ctx->banks, + slot_ctx->bank, + slot_ctx->funk, + slot_ctx->funk_txn, + capture_ctx, + tpool, + runtime_spad ); if( err != 0 ) { return err; } diff --git a/src/flamenco/runtime/fd_runtime.h b/src/flamenco/runtime/fd_runtime.h index c633b961f0..5b0a324903 100644 --- a/src/flamenco/runtime/fd_runtime.h +++ b/src/flamenco/runtime/fd_runtime.h @@ -621,9 +621,11 @@ fd_runtime_block_pre_execute_process_new_epoch( fd_bank_t * bank, Note that ALUTs must be resolved because programs referenced in ALUTs can be invoked via CPI. */ void -fd_runtime_update_program_cache( fd_exec_slot_ctx_t * slot_ctx, - fd_txn_p_t const * txn_p, - fd_spad_t * runtime_spad ); +fd_runtime_update_program_cache( fd_bank_t * bank, + fd_funk_t * funk, + fd_funk_txn_t * funk_txn, + fd_txn_p_t const * txn_p, + fd_spad_t * runtime_spad ); /* Debugging Tools ************************************************************/ diff --git a/src/flamenco/runtime/program/fd_bpf_program_util.c b/src/flamenco/runtime/program/fd_bpf_program_util.c index 592641bd6e..261e763f73 100644 --- a/src/flamenco/runtime/program/fd_bpf_program_util.c +++ b/src/flamenco/runtime/program/fd_bpf_program_util.c @@ -520,9 +520,11 @@ fd_bpf_load_cache_entry( fd_funk_t const * funk, } void -fd_bpf_program_update_program_cache( fd_exec_slot_ctx_t * slot_ctx, - fd_pubkey_t const * program_pubkey, - fd_spad_t * runtime_spad ) { +fd_bpf_program_update_program_cache( fd_bank_t * bank, + fd_funk_t * funk, + fd_funk_txn_t * funk_txn, + fd_pubkey_t const * program_pubkey, + fd_spad_t * runtime_spad ) { FD_SPAD_FRAME_BEGIN( runtime_spad ) { FD_TXN_ACCOUNT_DECL( exec_rec ); fd_funk_rec_key_t id = fd_acc_mgr_cache_key( program_pubkey ); @@ -530,8 +532,8 @@ FD_SPAD_FRAME_BEGIN( runtime_spad ) { /* No need to touch the cache if the account no longer exists. */ if( FD_UNLIKELY( fd_txn_account_init_from_funk_readonly( exec_rec, program_pubkey, - slot_ctx->funk, - slot_ctx->funk_txn ) ) ) { + funk, + funk_txn ) ) ) { return; } @@ -544,16 +546,16 @@ FD_SPAD_FRAME_BEGIN( runtime_spad ) { `fd_bpf_create_bpf_program_cache_entry()` will insert the program into the cache and update the entry's flags accordingly if it fails verification. */ fd_sbpf_validated_program_t const * prog = NULL; - int err = fd_bpf_load_cache_entry( slot_ctx->funk, slot_ctx->funk_txn, program_pubkey, &prog ); + int err = fd_bpf_load_cache_entry( funk, funk_txn, program_pubkey, &prog ); if( FD_UNLIKELY( err ) ) { - fd_bpf_create_bpf_program_cache_entry( slot_ctx->bank, slot_ctx->funk, slot_ctx->funk_txn, exec_rec, runtime_spad ); + fd_bpf_create_bpf_program_cache_entry( bank, funk, funk_txn, exec_rec, runtime_spad ); return; } /* At this point, the program is in the cache. We need to check the last verified epoch now to determine if it needs to be reverified. If it has already been reverified for the current epoch, then there is no need to do anything. */ - fd_epoch_schedule_t const * epoch_schedule = fd_bank_epoch_schedule_query( slot_ctx->bank ); - ulong current_epoch = fd_slot_to_epoch( epoch_schedule, slot_ctx->slot, NULL ); + fd_epoch_schedule_t const * epoch_schedule = fd_bank_epoch_schedule_query( bank ); + ulong current_epoch = fd_slot_to_epoch( epoch_schedule, bank->slot, NULL ); if( FD_LIKELY( prog->last_epoch_verification_ran==current_epoch ) ) { return; } @@ -563,28 +565,29 @@ FD_SPAD_FRAME_BEGIN( runtime_spad ) { /* Copy the record (if needed) down into the current funk txn from one of its ancestors. It is safe to pass in min_sz=0 because the record is known to exist in the cache already, and the record size will not change */ - fd_funk_rec_try_clone_safe( slot_ctx->funk, slot_ctx->funk_txn, &id, 0UL, 0UL ); + fd_funk_rec_try_clone_safe( funk, funk_txn, &id, 0UL, 0UL ); /* Modify the record within the current funk txn */ fd_funk_rec_query_t query[1]; - fd_funk_rec_t * rec = fd_funk_rec_modify( slot_ctx->funk, slot_ctx->funk_txn, &id, query ); + fd_funk_rec_t * rec = fd_funk_rec_modify( funk, funk_txn, &id, query ); if( FD_UNLIKELY( !rec ) ) { /* The record does not exist (somehow). Ideally this should never happen since this function is called in a single-threaded context. */ FD_LOG_CRIT(( "Failed to modify the BPF program cache record. Perhaps there is a race condition?" )); } - void * data = fd_funk_val( rec, fd_funk_wksp( slot_ctx->funk ) ); + void * data = fd_funk_val( rec, fd_funk_wksp( funk ) ); fd_sbpf_elf_info_t elf_info = {0}; fd_sbpf_validated_program_t * modified_prog = (fd_sbpf_validated_program_t *)data; /* Get the program data from the account */ ulong program_data_len = 0UL; - uchar const * program_data = fd_bpf_get_programdata_from_account( slot_ctx->funk, - slot_ctx->funk_txn, - exec_rec, - &program_data_len, - runtime_spad ); + uchar const * program_data = fd_bpf_get_programdata_from_account( + funk, + funk_txn, + exec_rec, + &program_data_len, + runtime_spad ); if( FD_UNLIKELY( program_data==NULL ) ) { modified_prog->failed_verification = 1; fd_funk_rec_modify_publish( query ); @@ -592,7 +595,7 @@ FD_SPAD_FRAME_BEGIN( runtime_spad ) { } /* Parse the ELF info */ - if( FD_UNLIKELY( fd_bpf_parse_elf_info( &elf_info, program_data, program_data_len, slot_ctx->bank ) ) ) { + if( FD_UNLIKELY( fd_bpf_parse_elf_info( &elf_info, program_data, program_data_len, bank ) ) ) { modified_prog->failed_verification = 1; fd_funk_rec_modify_publish( query ); return; @@ -601,7 +604,7 @@ FD_SPAD_FRAME_BEGIN( runtime_spad ) { /* Validate the sBPF program. This will set the program's flags accordingly. The return code does not matter here because we publish regardless of the return code. */ modified_prog = fd_sbpf_validated_program_new( data, &elf_info ); - fd_bpf_validate_sbpf_program( slot_ctx->bank, &elf_info, program_data, program_data_len, runtime_spad, modified_prog ); + fd_bpf_validate_sbpf_program( bank, &elf_info, program_data, program_data_len, runtime_spad, modified_prog ); if( modified_prog->failed_verification ) { FD_LOG_ERR(("program fialed veriifecation;")); diff --git a/src/flamenco/runtime/program/fd_bpf_program_util.h b/src/flamenco/runtime/program/fd_bpf_program_util.h index 5257b0039c..2373ec17ff 100644 --- a/src/flamenco/runtime/program/fd_bpf_program_util.h +++ b/src/flamenco/runtime/program/fd_bpf_program_util.h @@ -112,9 +112,11 @@ fd_bpf_get_programdata_from_account( fd_funk_t const * funk, verification, it stays in the cache so that repeated calls won't DOS the validator by forcing reverifications (since we won't be able to distinguish failed verifications from new deployments). */ void -fd_bpf_program_update_program_cache( fd_exec_slot_ctx_t * slot_ctx, - fd_pubkey_t const * program_pubkey, - fd_spad_t * runtime_spad ); +fd_bpf_program_update_program_cache( fd_bank_t * bank, + fd_funk_t * funk, + fd_funk_txn_t * funk_txn, + fd_pubkey_t const * program_pubkey, + fd_spad_t * runtime_spad ); FD_PROTOTYPES_END diff --git a/src/flamenco/runtime/program/test_program_cache.c b/src/flamenco/runtime/program/test_program_cache.c index b17070f69f..7bc135ef63 100644 --- a/src/flamenco/runtime/program/test_program_cache.c +++ b/src/flamenco/runtime/program/test_program_cache.c @@ -103,7 +103,7 @@ test_account_does_not_exist( void ) { fd_pubkey_t const non_existent_pubkey = {0}; /* This should return early without doing anything */ - fd_bpf_program_update_program_cache( test_slot_ctx, &non_existent_pubkey, test_spad ); + fd_bpf_program_update_program_cache( test_slot_ctx->bank, test_slot_ctx->funk, test_slot_ctx->funk_txn , &non_existent_pubkey, test_spad ); /* Verify no cache entry was created */ fd_sbpf_validated_program_t const * valid_prog = NULL; @@ -129,7 +129,7 @@ test_account_not_bpf_loader_owner( void ) { 1 ); /* This should return early without doing anything */ - fd_bpf_program_update_program_cache( test_slot_ctx, &test_program_pubkey, test_spad ); + fd_bpf_program_update_program_cache( test_slot_ctx->bank, test_slot_ctx->funk, test_slot_ctx->funk_txn, &test_program_pubkey, test_spad ); /* Verify no cache entry was created */ fd_sbpf_validated_program_t const * valid_prog = NULL; @@ -155,7 +155,7 @@ test_invalid_program_not_in_cache_first_time( void ) { 1 ); /* This should create a cache entry */ - fd_bpf_program_update_program_cache( test_slot_ctx, &test_program_pubkey, test_spad ); + fd_bpf_program_update_program_cache( test_slot_ctx->bank, test_slot_ctx->funk, test_slot_ctx->funk_txn, &test_program_pubkey, test_spad ); /* Verify cache entry was created */ fd_sbpf_validated_program_t const * valid_prog = NULL; @@ -184,7 +184,7 @@ test_valid_program_not_in_cache_first_time( void ) { 1 ); /* This should create a cache entry */ - fd_bpf_program_update_program_cache( test_slot_ctx, &test_program_pubkey, test_spad ); + fd_bpf_program_update_program_cache( test_slot_ctx->bank, test_slot_ctx->funk, test_slot_ctx->funk_txn, &test_program_pubkey, test_spad ); /* Verify cache entry was created */ fd_sbpf_validated_program_t const * valid_prog = NULL; @@ -214,7 +214,7 @@ test_program_in_cache_needs_reverification( void ) { 1 ); /* First call to create cache entry */ - fd_bpf_program_update_program_cache( test_slot_ctx, &test_program_pubkey, test_spad ); + fd_bpf_program_update_program_cache( test_slot_ctx->bank, test_slot_ctx->funk, test_slot_ctx->funk_txn, &test_program_pubkey, test_spad ); /* Verify cache entry was created */ fd_sbpf_validated_program_t const * valid_prog = NULL; @@ -229,7 +229,7 @@ test_program_in_cache_needs_reverification( void ) { test_slot_ctx->bank->slot += 432000UL; /* This should trigger reverification */ - fd_bpf_program_update_program_cache( test_slot_ctx, &test_program_pubkey, test_spad ); + fd_bpf_program_update_program_cache( test_slot_ctx->bank, test_slot_ctx->funk, test_slot_ctx->funk_txn, &test_program_pubkey, test_spad ); /* Verify the cache entry was updated */ err = fd_bpf_load_cache_entry( test_funk, funk_txn, &test_program_pubkey, &valid_prog ); From 4301a4cf14e3672770a29606446e981109fa8fac Mon Sep 17 00:00:00 2001 From: Ishan Bhatt Date: Tue, 8 Jul 2025 17:46:56 +0000 Subject: [PATCH 12/27] more --- src/flamenco/runtime/fd_hashes.c | 22 +++++---- src/flamenco/runtime/fd_hashes.h | 4 +- src/flamenco/runtime/fd_runtime.c | 48 +++++++++--------- .../runtime/program/fd_builtin_programs.c | 49 ++++++++++--------- .../runtime/program/fd_builtin_programs.h | 4 +- .../runtime/program/fd_stake_program.c | 13 +++-- .../runtime/program/fd_stake_program.h | 3 +- .../runtime/sysvar/fd_sysvar_epoch_schedule.c | 14 ++++-- .../runtime/sysvar/fd_sysvar_epoch_schedule.h | 8 ++- src/flamenco/runtime/sysvar/fd_sysvar_rent.c | 14 ++++-- src/flamenco/runtime/sysvar/fd_sysvar_rent.h | 12 +++-- .../runtime/sysvar/fd_sysvar_stake_history.c | 6 ++- .../runtime/sysvar/fd_sysvar_stake_history.h | 4 +- .../runtime/tests/harness/fd_instr_harness.c | 4 +- .../runtime/tests/harness/fd_txn_harness.c | 8 +-- 15 files changed, 124 insertions(+), 89 deletions(-) diff --git a/src/flamenco/runtime/fd_hashes.c b/src/flamenco/runtime/fd_hashes.c index 7907cc17e4..1b49a68263 100644 --- a/src/flamenco/runtime/fd_hashes.c +++ b/src/flamenco/runtime/fd_hashes.c @@ -589,7 +589,9 @@ fd_update_hash_bank_exec_hash( fd_bank_t * bank, } int -fd_update_hash_bank_tpool( fd_exec_slot_ctx_t * slot_ctx, +fd_update_hash_bank_tpool( fd_bank_t * bank, + fd_funk_t * funk, + fd_funk_txn_t * funk_txn, fd_capture_ctx_t * capture_ctx, fd_hash_t * hash, ulong signature_cnt, @@ -601,7 +603,7 @@ fd_update_hash_bank_tpool( fd_exec_slot_ctx_t * slot_ctx, alignof(fd_accounts_hash_task_data_t), sizeof(fd_accounts_hash_task_data_t) ); - fd_collect_modified_accounts( slot_ctx->bank, slot_ctx->funk, slot_ctx->funk_txn, task_data, runtime_spad ); + fd_collect_modified_accounts( bank, funk, funk_txn, task_data, runtime_spad ); ulong wcnt = 0UL; @@ -634,7 +636,7 @@ fd_update_hash_bank_tpool( fd_exec_slot_ctx_t * slot_ctx, } fd_tpool_exec( tpool, worker_idx, fd_account_hash_task, task_data, start_idx, end_idx, - <_hashes[worker_idx], slot_ctx, 0UL, + <_hashes[worker_idx], NULL, 0UL, 0UL, 0UL, worker_idx, 0UL, 0UL, 0UL ); } @@ -644,18 +646,18 @@ fd_update_hash_bank_tpool( fd_exec_slot_ctx_t * slot_ctx, } else { for( ulong i=0UL; iinfo_sz; i++ ) { fd_accounts_hash_task_info_t * task_info = &task_data->info[i]; - fd_account_hash( slot_ctx->funk, - slot_ctx->funk_txn, + fd_account_hash( funk, + funk_txn, task_info, <_hashes[ 0 ], - slot_ctx->slot, - fd_bank_features_query( slot_ctx->bank ) ); + bank->slot, + fd_bank_features_query( bank ) ); } } - return fd_update_hash_bank_exec_hash( slot_ctx->bank, - slot_ctx->funk, - slot_ctx->funk_txn, + return fd_update_hash_bank_exec_hash( bank, + funk, + funk_txn, hash, capture_ctx, task_data, diff --git a/src/flamenco/runtime/fd_hashes.h b/src/flamenco/runtime/fd_hashes.h index 88d0a0f9a0..fb9385c540 100644 --- a/src/flamenco/runtime/fd_hashes.h +++ b/src/flamenco/runtime/fd_hashes.h @@ -109,7 +109,9 @@ fd_account_hash( fd_funk_t * funk, fd_features_t const * features ); int -fd_update_hash_bank_tpool( fd_exec_slot_ctx_t * slot_ctx, +fd_update_hash_bank_tpool( fd_bank_t * bank, + fd_funk_t * funk, + fd_funk_txn_t * funk_txn, fd_capture_ctx_t * capture_ctx, fd_hash_t * hash, ulong signature_cnt, diff --git a/src/flamenco/runtime/fd_runtime.c b/src/flamenco/runtime/fd_runtime.c index b075133e93..843d15ed4f 100644 --- a/src/flamenco/runtime/fd_runtime.c +++ b/src/flamenco/runtime/fd_runtime.c @@ -2912,19 +2912,21 @@ fd_runtime_block_collect_txns( fd_runtime_block_info_t const * block_info, /*******************************************************************************/ static void -fd_runtime_init_program( fd_exec_slot_ctx_t * slot_ctx, - fd_spad_t * runtime_spad ) { - fd_sysvar_recent_hashes_init( slot_ctx->bank, slot_ctx->funk, slot_ctx->funk_txn, runtime_spad ); - fd_sysvar_clock_init( slot_ctx->bank, slot_ctx->funk, slot_ctx->funk_txn ); - fd_sysvar_slot_history_init( slot_ctx->bank, slot_ctx->funk, slot_ctx->funk_txn, runtime_spad ); - fd_sysvar_slot_hashes_init( slot_ctx->bank, slot_ctx->funk, slot_ctx->funk_txn, runtime_spad ); - fd_sysvar_epoch_schedule_init( slot_ctx ); - fd_sysvar_rent_init( slot_ctx ); - fd_sysvar_stake_history_init( slot_ctx ); - fd_sysvar_last_restart_slot_init( slot_ctx->bank, slot_ctx->funk, slot_ctx->funk_txn ); - - fd_builtin_programs_init( slot_ctx ); - fd_stake_program_config_init( slot_ctx ); +fd_runtime_init_program( fd_bank_t * bank, + fd_funk_t * funk, + fd_funk_txn_t * funk_txn, + fd_spad_t * runtime_spad ) { + fd_sysvar_recent_hashes_init( bank, funk, funk_txn, runtime_spad ); + fd_sysvar_clock_init( bank, funk, funk_txn ); + fd_sysvar_slot_history_init( bank, funk, funk_txn, runtime_spad ); + fd_sysvar_slot_hashes_init( bank, funk, funk_txn, runtime_spad ); + fd_sysvar_epoch_schedule_init( bank, funk, funk_txn ); + fd_sysvar_rent_init( bank, funk, funk_txn ); + fd_sysvar_stake_history_init( bank, funk, funk_txn ); + fd_sysvar_last_restart_slot_init( bank, funk, funk_txn ); + + fd_builtin_programs_init( bank, funk, funk_txn ); + fd_stake_program_config_init( funk, funk_txn ); } static void @@ -3236,7 +3238,7 @@ fd_runtime_process_genesis_block( fd_exec_slot_ctx_t * slot_ctx, fd_bank_total_compute_units_used_set( slot_ctx->bank, 0UL ); - fd_runtime_init_program( slot_ctx, runtime_spad ); + fd_runtime_init_program( slot_ctx->bank, slot_ctx->funk, slot_ctx->funk_txn, runtime_spad ); fd_sysvar_slot_history_update( slot_ctx->bank, slot_ctx->funk, slot_ctx->funk_txn, runtime_spad ); @@ -3246,7 +3248,9 @@ fd_runtime_process_genesis_block( fd_exec_slot_ctx_t * slot_ctx, /* sort and update bank hash */ fd_hash_t * bank_hash = fd_bank_bank_hash_modify( slot_ctx->bank ); - int result = fd_update_hash_bank_tpool( slot_ctx, + int result = fd_update_hash_bank_tpool( slot_ctx->bank, + slot_ctx->funk, + slot_ctx->funk_txn, capture_ctx, bank_hash, 0UL, @@ -3535,7 +3539,7 @@ fd_runtime_poh_verify_tpool( fd_poh_verification_info_t * poh_verification_info, } static int -fd_runtime_block_verify_tpool( fd_exec_slot_ctx_t * slot_ctx, +fd_runtime_block_verify_tpool( fd_bank_t * bank, fd_blockstore_t * blockstore, fd_runtime_block_info_t const * block_info, fd_hash_t const * in_poh_hash, @@ -3556,15 +3560,15 @@ fd_runtime_block_verify_tpool( fd_exec_slot_ctx_t * slot_ctx, uchar * block_data = fd_spad_alloc( runtime_spad, 128UL, FD_SHRED_DATA_PAYLOAD_MAX_PER_SLOT ); ulong tick_res = fd_runtime_block_verify_ticks( blockstore, - slot_ctx->slot, + bank->slot, block_data, FD_SHRED_DATA_PAYLOAD_MAX_PER_SLOT, - fd_bank_tick_height_get( slot_ctx->bank ), - fd_bank_max_tick_height_get( slot_ctx->bank ), - fd_bank_hashes_per_tick_get( slot_ctx->bank ) ); + fd_bank_tick_height_get( bank ), + fd_bank_max_tick_height_get( bank ), + fd_bank_hashes_per_tick_get( bank ) ); if( FD_UNLIKELY( tick_res != FD_BLOCK_OK ) ) { - FD_LOG_WARNING(( "failed to verify ticks res %lu slot %lu", tick_res, slot_ctx->slot )); + FD_LOG_WARNING(( "failed to verify ticks res %lu slot %lu", tick_res, bank->slot )); return -1; } @@ -3880,7 +3884,7 @@ fd_runtime_block_eval_tpool( fd_exec_slot_ctx_t * slot_ctx, fd_hash_t poh_out = {0}; fd_hash_t poh_in = fd_bank_poh_get( slot_ctx->bank ); - if( FD_UNLIKELY( (ret = fd_runtime_block_verify_tpool( slot_ctx, blockstore, &block_info, &poh_in, &poh_out, tpool, runtime_spad )) != FD_RUNTIME_EXECUTE_SUCCESS ) ) { + if( FD_UNLIKELY( (ret = fd_runtime_block_verify_tpool( slot_ctx->bank, blockstore, &block_info, &poh_in, &poh_out, tpool, runtime_spad )) != FD_RUNTIME_EXECUTE_SUCCESS ) ) { break; } diff --git a/src/flamenco/runtime/program/fd_builtin_programs.c b/src/flamenco/runtime/program/fd_builtin_programs.c index 91f25f17b5..fe6e7b42a7 100644 --- a/src/flamenco/runtime/program/fd_builtin_programs.c +++ b/src/flamenco/runtime/program/fd_builtin_programs.c @@ -178,7 +178,7 @@ fd_write_builtin_account( fd_bank_t * bank, /* https://github.com/solana-labs/solana/blob/8f2c8b8388a495d2728909e30460aa40dcc5d733/runtime/src/inline_spl_token.rs#L74 */ /* TODO: move this somewhere more appropiate */ static void -write_inline_spl_native_mint_program_account( fd_exec_slot_ctx_t * slot_ctx ) { +write_inline_spl_native_mint_program_account( fd_funk_t * funk, fd_funk_txn_t * funk_txn ) { if( true ) { /* FIXME: This is a hack that corresponds to the cluster type field @@ -186,9 +186,7 @@ write_inline_spl_native_mint_program_account( fd_exec_slot_ctx_t * slot_ctx ) { return; } - fd_funk_t * funk = slot_ctx->funk; - fd_funk_txn_t * txn = slot_ctx->funk_txn; - fd_pubkey_t const * key = (fd_pubkey_t const *)&fd_solana_spl_native_mint_id; + fd_pubkey_t const * key = (fd_pubkey_t const *)&fd_solana_spl_native_mint_id; FD_TXN_ACCOUNT_DECL( rec ); /* https://github.com/solana-labs/solana/blob/8f2c8b8388a495d2728909e30460aa40dcc5d733/runtime/src/inline_spl_token.rs#L86-L90 */ @@ -197,7 +195,7 @@ write_inline_spl_native_mint_program_account( fd_exec_slot_ctx_t * slot_ctx ) { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; - int err = fd_txn_account_init_from_funk_mutable( rec, key, funk, txn, 1, sizeof(data) ); + int err = fd_txn_account_init_from_funk_mutable( rec, key, funk, funk_txn, 1, sizeof(data) ); FD_TEST( !err ); rec->vt->set_lamports( rec, 1000000000UL ); @@ -206,49 +204,52 @@ write_inline_spl_native_mint_program_account( fd_exec_slot_ctx_t * slot_ctx ) { rec->vt->set_owner( rec, &fd_solana_spl_token_id ); rec->vt->set_data( rec, data, sizeof(data) ); - fd_txn_account_mutable_fini( rec, funk, txn ); + fd_txn_account_mutable_fini( rec, funk, funk_txn ); FD_TEST( !err ); } -void fd_builtin_programs_init( fd_exec_slot_ctx_t * slot_ctx ) { +void +fd_builtin_programs_init( fd_bank_t * bank, + fd_funk_t * funk, + fd_funk_txn_t * funk_txn ) { // https://github.com/anza-xyz/agave/blob/v2.0.1/runtime/src/bank/builtins/mod.rs#L33 fd_builtin_program_t const * builtins = fd_builtins(); for( ulong i=0UL; islot, fd_bank_features_get( slot_ctx->bank ), builtins[i].core_bpf_migration_config->enable_feature_offset ) ) { + if( builtins[i].core_bpf_migration_config && FD_FEATURE_ACTIVE_OFFSET( bank->slot, fd_bank_features_get( bank ), builtins[i].core_bpf_migration_config->enable_feature_offset ) ) { continue; - } else if( builtins[i].enable_feature_offset!=NO_ENABLE_FEATURE_ID && !FD_FEATURE_ACTIVE_OFFSET( slot_ctx->slot, fd_bank_features_get( slot_ctx->bank ), builtins[i].enable_feature_offset ) ) { + } else if( builtins[i].enable_feature_offset!=NO_ENABLE_FEATURE_ID && !FD_FEATURE_ACTIVE_OFFSET( bank->slot, fd_bank_features_get( bank ), builtins[i].enable_feature_offset ) ) { continue; } else { - fd_write_builtin_account( slot_ctx->bank, slot_ctx->funk, slot_ctx->funk_txn, *builtins[i].pubkey, builtins[i].data, strlen(builtins[i].data) ); + fd_write_builtin_account( bank, funk, funk_txn, *builtins[i].pubkey, builtins[i].data, strlen(builtins[i].data) ); } } //TODO: remove when no longer necessary - if( FD_FEATURE_ACTIVE_BANK( slot_ctx->bank, zk_token_sdk_enabled ) ) { - fd_write_builtin_account( slot_ctx->bank, slot_ctx->funk, slot_ctx->funk_txn, fd_solana_zk_token_proof_program_id, "zk_token_proof_program", 22UL ); + if( FD_FEATURE_ACTIVE_BANK( bank, zk_token_sdk_enabled ) ) { + fd_write_builtin_account( bank, funk, funk_txn, fd_solana_zk_token_proof_program_id, "zk_token_proof_program", 22UL ); } - if( FD_FEATURE_ACTIVE_BANK( slot_ctx->bank, zk_elgamal_proof_program_enabled ) ) { - fd_write_builtin_account( slot_ctx->bank, slot_ctx->funk, slot_ctx->funk_txn, fd_solana_zk_elgamal_proof_program_id, "zk_elgamal_proof_program", 24UL ); + if( FD_FEATURE_ACTIVE_BANK( bank, zk_elgamal_proof_program_enabled ) ) { + fd_write_builtin_account( bank, funk, funk_txn, fd_solana_zk_elgamal_proof_program_id, "zk_elgamal_proof_program", 24UL ); } /* Precompiles have empty account data */ - if( fd_bank_cluster_version_get( slot_ctx->bank ).major == 1 ) { + if( fd_bank_cluster_version_get( bank ).major == 1 ) { char data[1] = {1}; - fd_write_builtin_account( slot_ctx->bank, slot_ctx->funk, slot_ctx->funk_txn, fd_solana_keccak_secp_256k_program_id, data, 1 ); - fd_write_builtin_account( slot_ctx->bank, slot_ctx->funk, slot_ctx->funk_txn, fd_solana_ed25519_sig_verify_program_id, data, 1 ); - if( FD_FEATURE_ACTIVE_BANK( slot_ctx->bank, enable_secp256r1_precompile ) ) - fd_write_builtin_account( slot_ctx->bank, slot_ctx->funk, slot_ctx->funk_txn, fd_solana_secp256r1_program_id, data, 1 ); + fd_write_builtin_account( bank, funk, funk_txn, fd_solana_keccak_secp_256k_program_id, data, 1 ); + fd_write_builtin_account( bank, funk, funk_txn, fd_solana_ed25519_sig_verify_program_id, data, 1 ); + if( FD_FEATURE_ACTIVE_BANK( bank, enable_secp256r1_precompile ) ) + fd_write_builtin_account( bank, funk, funk_txn, fd_solana_secp256r1_program_id, data, 1 ); } else { - fd_write_builtin_account( slot_ctx->bank, slot_ctx->funk, slot_ctx->funk_txn, fd_solana_keccak_secp_256k_program_id, "", 0 ); - fd_write_builtin_account( slot_ctx->bank, slot_ctx->funk, slot_ctx->funk_txn, fd_solana_ed25519_sig_verify_program_id, "", 0 ); - if( FD_FEATURE_ACTIVE_BANK( slot_ctx->bank, enable_secp256r1_precompile ) ) - fd_write_builtin_account( slot_ctx->bank, slot_ctx->funk, slot_ctx->funk_txn, fd_solana_secp256r1_program_id, "", 0 ); + fd_write_builtin_account( bank, funk, funk_txn, fd_solana_keccak_secp_256k_program_id, "", 0 ); + fd_write_builtin_account( bank, funk, funk_txn, fd_solana_ed25519_sig_verify_program_id, "", 0 ); + if( FD_FEATURE_ACTIVE_BANK( bank, enable_secp256r1_precompile ) ) + fd_write_builtin_account( bank, funk, funk_txn, fd_solana_secp256r1_program_id, "", 0 ); } /* Inline SPL token mint program ("inlined to avoid an external dependency on the spl-token crate") */ - write_inline_spl_native_mint_program_account( slot_ctx ); + write_inline_spl_native_mint_program_account( funk, funk_txn ); } fd_builtin_program_t const * diff --git a/src/flamenco/runtime/program/fd_builtin_programs.h b/src/flamenco/runtime/program/fd_builtin_programs.h index f2a708ecb6..0c9de67055 100644 --- a/src/flamenco/runtime/program/fd_builtin_programs.h +++ b/src/flamenco/runtime/program/fd_builtin_programs.h @@ -49,7 +49,9 @@ FD_PROTOTYPES_BEGIN /* Initialize the builtin program accounts */ void -fd_builtin_programs_init( fd_exec_slot_ctx_t * slot_ctx ); +fd_builtin_programs_init( fd_bank_t * bank, + fd_funk_t * funk, + fd_funk_txn_t * funk_txn ); void fd_write_builtin_account( fd_bank_t * bank, diff --git a/src/flamenco/runtime/program/fd_stake_program.c b/src/flamenco/runtime/program/fd_stake_program.c index 4718ff66a9..43882952d3 100644 --- a/src/flamenco/runtime/program/fd_stake_program.c +++ b/src/flamenco/runtime/program/fd_stake_program.c @@ -3227,12 +3227,14 @@ fd_stake_program_execute( fd_exec_instr_ctx_t * ctx ) { /* Public API *********************************************************/ static void -write_stake_config( fd_exec_slot_ctx_t * slot_ctx, fd_stake_config_t const * stake_config ) { +write_stake_config( fd_funk_t * funk, + fd_funk_txn_t * funk_txn, + fd_stake_config_t const * stake_config ) { ulong data_sz = fd_stake_config_size( stake_config ); fd_pubkey_t const * acc_key = &fd_solana_stake_program_config_id; FD_TXN_ACCOUNT_DECL(rec); - int err = fd_txn_account_init_from_funk_mutable( rec, acc_key, slot_ctx->funk, slot_ctx->funk_txn, 1, data_sz ); + int err = fd_txn_account_init_from_funk_mutable( rec, acc_key, funk, funk_txn, 1, data_sz ); FD_TEST( !err ); rec->vt->set_lamports( rec, 960480UL ); @@ -3247,17 +3249,18 @@ write_stake_config( fd_exec_slot_ctx_t * slot_ctx, fd_stake_config_t const * sta rec->vt->set_data( rec, stake_config, data_sz ); - fd_txn_account_mutable_fini( rec, slot_ctx->funk, slot_ctx->funk_txn ); + fd_txn_account_mutable_fini( rec, funk, funk_txn ); } void -fd_stake_program_config_init( fd_exec_slot_ctx_t * slot_ctx ) { +fd_stake_program_config_init( fd_funk_t * funk, + fd_funk_txn_t * funk_txn ) { // https://github.com/anza-xyz/agave/blob/c8685ce0e1bb9b26014f1024de2cd2b8c308cbde/sdk/program/src/stake/config.rs#L26 fd_stake_config_t stake_config = { .warmup_cooldown_rate = DEFAULT_WARMUP_COOLDOWN_RATE, .slash_penalty = DEFAULT_SLASH_PENALTY, }; - write_stake_config( slot_ctx, &stake_config ); + write_stake_config( funk, funk_txn, &stake_config ); } int diff --git a/src/flamenco/runtime/program/fd_stake_program.h b/src/flamenco/runtime/program/fd_stake_program.h index 08b7ffc7c8..7f0bdb2d1d 100644 --- a/src/flamenco/runtime/program/fd_stake_program.h +++ b/src/flamenco/runtime/program/fd_stake_program.h @@ -36,7 +36,8 @@ fd_stake_program_execute( fd_exec_instr_ctx_t * ctx ); https://github.com/solana-labs/solana/blob/8f2c8b8388a495d2728909e30460aa40dcc5d733/sdk/program/src/stake/config.rs */ void -fd_stake_program_config_init( fd_exec_slot_ctx_t * global ); +fd_stake_program_config_init( fd_funk_t * funk, + fd_funk_txn_t * funk_txn ); int fd_stake_get_state( fd_txn_account_t const * self, diff --git a/src/flamenco/runtime/sysvar/fd_sysvar_epoch_schedule.c b/src/flamenco/runtime/sysvar/fd_sysvar_epoch_schedule.c index 9641313dc5..d96faf2292 100644 --- a/src/flamenco/runtime/sysvar/fd_sysvar_epoch_schedule.c +++ b/src/flamenco/runtime/sysvar/fd_sysvar_epoch_schedule.c @@ -31,7 +31,9 @@ fd_epoch_schedule_derive( fd_epoch_schedule_t * schedule, } void -fd_sysvar_epoch_schedule_write( fd_exec_slot_ctx_t * slot_ctx, +fd_sysvar_epoch_schedule_write( fd_bank_t * bank, + fd_funk_t * funk, + fd_funk_txn_t * funk_txn, fd_epoch_schedule_t const * epoch_schedule ) { ulong sz = fd_epoch_schedule_size( epoch_schedule ); FD_LOG_INFO(("Writing epoch schedule size %lu", sz)); @@ -46,7 +48,7 @@ fd_sysvar_epoch_schedule_write( fd_exec_slot_ctx_t * slot_ctx, FD_LOG_ERR(("fd_epoch_schedule_encode failed")); } - fd_sysvar_set( slot_ctx->bank, slot_ctx->funk, slot_ctx->funk_txn, &fd_sysvar_owner_id, &fd_sysvar_epoch_schedule_id, enc, sz, slot_ctx->slot ); + fd_sysvar_set( bank, funk, funk_txn, &fd_sysvar_owner_id, &fd_sysvar_epoch_schedule_id, enc, sz, bank->slot ); } fd_epoch_schedule_t * @@ -76,9 +78,11 @@ fd_sysvar_epoch_schedule_read( fd_funk_t * funk, } void -fd_sysvar_epoch_schedule_init( fd_exec_slot_ctx_t * slot_ctx ) { - fd_epoch_schedule_t const * epoch_schedule = fd_bank_epoch_schedule_query( slot_ctx->bank ); - fd_sysvar_epoch_schedule_write( slot_ctx, epoch_schedule ); +fd_sysvar_epoch_schedule_init( fd_bank_t * bank, + fd_funk_t * funk, + fd_funk_txn_t * funk_txn ) { + fd_epoch_schedule_t const * epoch_schedule = fd_bank_epoch_schedule_query( bank ); + fd_sysvar_epoch_schedule_write( bank, funk, funk_txn, epoch_schedule ); } /* https://github.com/solana-labs/solana/blob/88aeaa82a856fc807234e7da0b31b89f2dc0e091/sdk/program/src/epoch_schedule.rs#L105 */ diff --git a/src/flamenco/runtime/sysvar/fd_sysvar_epoch_schedule.h b/src/flamenco/runtime/sysvar/fd_sysvar_epoch_schedule.h index 7c47c4de10..2c460a1d23 100644 --- a/src/flamenco/runtime/sysvar/fd_sysvar_epoch_schedule.h +++ b/src/flamenco/runtime/sysvar/fd_sysvar_epoch_schedule.h @@ -58,7 +58,9 @@ FD_PROTOTYPES_BEGIN account. FIXME document what this actually does. */ void -fd_sysvar_epoch_schedule_init( fd_exec_slot_ctx_t * slot_ctx ); +fd_sysvar_epoch_schedule_init( fd_bank_t * bank, + fd_funk_t * funk, + fd_funk_txn_t * funk_txn ); /* fd_sysvar_epoch_schedule_read reads the current value of the rent sysvar from funk. If the account doesn't exist in funk or if the account @@ -73,7 +75,9 @@ fd_sysvar_epoch_schedule_read( fd_funk_t * funk, schedule sysvar to funk. */ void -fd_sysvar_epoch_schedule_write( fd_exec_slot_ctx_t * slot_ctx, +fd_sysvar_epoch_schedule_write( fd_bank_t * bank, + fd_funk_t * funk, + fd_funk_txn_t * funk_txn, fd_epoch_schedule_t const * epoch_schedule ); /* fd_epoch_schedule_derive derives an epoch schedule config from the diff --git a/src/flamenco/runtime/sysvar/fd_sysvar_rent.c b/src/flamenco/runtime/sysvar/fd_sysvar_rent.c index c312a1793d..02b357e905 100644 --- a/src/flamenco/runtime/sysvar/fd_sysvar_rent.c +++ b/src/flamenco/runtime/sysvar/fd_sysvar_rent.c @@ -5,7 +5,9 @@ #include void -fd_sysvar_rent_write( fd_exec_slot_ctx_t * slot_ctx, +fd_sysvar_rent_write( fd_bank_t * bank, + fd_funk_t * funk, + fd_funk_txn_t * funk_txn, fd_rent_t const * rent ) { uchar enc[ 32 ]; @@ -20,13 +22,15 @@ fd_sysvar_rent_write( fd_exec_slot_ctx_t * slot_ctx, if( fd_rent_encode( rent, &ctx ) ) FD_LOG_ERR(("fd_rent_encode failed")); - fd_sysvar_set( slot_ctx->bank, slot_ctx->funk, slot_ctx->funk_txn, &fd_sysvar_owner_id, &fd_sysvar_rent_id, enc, sz, slot_ctx->slot ); + fd_sysvar_set( bank, funk, funk_txn, &fd_sysvar_owner_id, &fd_sysvar_rent_id, enc, sz, bank->slot ); } void -fd_sysvar_rent_init( fd_exec_slot_ctx_t * slot_ctx ) { - fd_rent_t const * rent = fd_bank_rent_query( slot_ctx->bank ); - fd_sysvar_rent_write( slot_ctx, rent ); +fd_sysvar_rent_init( fd_bank_t * bank, + fd_funk_t * funk, + fd_funk_txn_t * funk_txn ) { + fd_rent_t const * rent = fd_bank_rent_query( bank ); + fd_sysvar_rent_write( bank, funk, funk_txn, rent ); } fd_rent_t const * diff --git a/src/flamenco/runtime/sysvar/fd_sysvar_rent.h b/src/flamenco/runtime/sysvar/fd_sysvar_rent.h index 726289c70a..1a06455edd 100644 --- a/src/flamenco/runtime/sysvar/fd_sysvar_rent.h +++ b/src/flamenco/runtime/sysvar/fd_sysvar_rent.h @@ -3,7 +3,7 @@ #include "../../fd_flamenco_base.h" #include "../../types/fd_types.h" -#include "../../../funk/fd_funk.h" +#include "../fd_bank.h" FD_PROTOTYPES_BEGIN /* fd_sysvar_rent_init copies the cached rent sysvar stored from @@ -11,13 +11,17 @@ FD_PROTOTYPES_BEGIN Note that it does NOT initialize global->bank.rent */ void -fd_sysvar_rent_init( fd_exec_slot_ctx_t * slot_ctx ); +fd_sysvar_rent_init( fd_bank_t * bank, + fd_funk_t * funk, + fd_funk_txn_t * funk_txn ); /* fd_sysvar_rent_write writes the current value of the rent sysvar to funk. */ void -fd_sysvar_rent_write( fd_exec_slot_ctx_t * slot_ctx, - fd_rent_t const * rent ); +fd_sysvar_rent_write( fd_bank_t * bank, + fd_funk_t * funk, + fd_funk_txn_t * funk_txn, + fd_rent_t const * rent ); /* fd_rent_exempt_minimum_balance returns the minimum balance needed for an account with the given data_len to be rent exempt. rent diff --git a/src/flamenco/runtime/sysvar/fd_sysvar_stake_history.c b/src/flamenco/runtime/sysvar/fd_sysvar_stake_history.c index 85e53d8593..612e4c0d2e 100644 --- a/src/flamenco/runtime/sysvar/fd_sysvar_stake_history.c +++ b/src/flamenco/runtime/sysvar/fd_sysvar_stake_history.c @@ -49,10 +49,12 @@ fd_sysvar_stake_history_read( fd_funk_t * funk, } void -fd_sysvar_stake_history_init( fd_exec_slot_ctx_t * slot_ctx ) { +fd_sysvar_stake_history_init( fd_bank_t * bank, + fd_funk_t * funk, + fd_funk_txn_t * funk_txn ) { fd_stake_history_t stake_history; fd_stake_history_new( &stake_history ); - write_stake_history( slot_ctx->bank, slot_ctx->funk, slot_ctx->funk_txn, &stake_history ); + write_stake_history( bank, funk, funk_txn, &stake_history ); } void diff --git a/src/flamenco/runtime/sysvar/fd_sysvar_stake_history.h b/src/flamenco/runtime/sysvar/fd_sysvar_stake_history.h index 358435be09..5ce29691c7 100644 --- a/src/flamenco/runtime/sysvar/fd_sysvar_stake_history.h +++ b/src/flamenco/runtime/sysvar/fd_sysvar_stake_history.h @@ -19,7 +19,9 @@ FD_PROTOTYPES_BEGIN /* Initialize the stake history sysvar account. */ void -fd_sysvar_stake_history_init( fd_exec_slot_ctx_t * slot_ctx ); +fd_sysvar_stake_history_init( fd_bank_t * bank, + fd_funk_t * funk, + fd_funk_txn_t * funk_txn ); /* fd_sysvar_stake_history_read reads the stake history sysvar from funk. If the account doesn't exist in funk or if the account has zero diff --git a/src/flamenco/runtime/tests/harness/fd_instr_harness.c b/src/flamenco/runtime/tests/harness/fd_instr_harness.c index e378bc83ec..5579126f0d 100644 --- a/src/flamenco/runtime/tests/harness/fd_instr_harness.c +++ b/src/flamenco/runtime/tests/harness/fd_instr_harness.c @@ -244,7 +244,7 @@ fd_runtime_fuzz_instr_ctx_create( fd_runtime_fuzz_runner_t * runner, .first_normal_epoch = 14UL, .first_normal_slot = 524256UL }; - fd_sysvar_epoch_schedule_write( slot_ctx, &sysvar_epoch_schedule ); + fd_sysvar_epoch_schedule_write( slot_ctx->bank, slot_ctx->funk, slot_ctx->funk_txn, &sysvar_epoch_schedule ); } /* Rent */ @@ -256,7 +256,7 @@ fd_runtime_fuzz_instr_ctx_create( fd_runtime_fuzz_runner_t * runner, .exemption_threshold = 2.0, .burn_percent = 50 }; - fd_sysvar_rent_write( slot_ctx, &sysvar_rent ); + fd_sysvar_rent_write( slot_ctx->bank, slot_ctx->funk, slot_ctx->funk_txn, &sysvar_rent ); } fd_sol_sysvar_last_restart_slot_t const * last_restart_slot = fd_sysvar_last_restart_slot_read( funk, funk_txn, runner->spad ); diff --git a/src/flamenco/runtime/tests/harness/fd_txn_harness.c b/src/flamenco/runtime/tests/harness/fd_txn_harness.c index f122993fa1..cef534de9b 100644 --- a/src/flamenco/runtime/tests/harness/fd_txn_harness.c +++ b/src/flamenco/runtime/tests/harness/fd_txn_harness.c @@ -57,7 +57,7 @@ fd_runtime_fuzz_txn_ctx_create( fd_runtime_fuzz_runner_t * runner, slot_ctx->bank->slot = slot; /* Initialize builtin accounts */ - fd_builtin_programs_init( slot_ctx ); + fd_builtin_programs_init( slot_ctx->bank, slot_ctx->funk, slot_ctx->funk_txn ); /* Load account states into funk (note this is different from the account keys): Account state = accounts to populate Funk @@ -140,7 +140,7 @@ fd_runtime_fuzz_txn_ctx_create( fd_runtime_fuzz_runner_t * runner, if( !stake_history ) { // Provide a 0-set default entry fd_epoch_stake_history_entry_pair_t entry = {0}; - fd_sysvar_stake_history_init( slot_ctx ); + fd_sysvar_stake_history_init( slot_ctx->bank, slot_ctx->funk, slot_ctx->funk_txn ); fd_sysvar_stake_history_update( slot_ctx->bank, slot_ctx->funk, slot_ctx->funk_txn, &entry, runner->spad ); } @@ -159,8 +159,8 @@ fd_runtime_fuzz_txn_ctx_create( fd_runtime_fuzz_runner_t * runner, } /* Epoch schedule and rent get set from the epoch bank */ - fd_sysvar_epoch_schedule_init( slot_ctx ); - fd_sysvar_rent_init( slot_ctx ); + fd_sysvar_epoch_schedule_init( slot_ctx->bank, slot_ctx->funk, slot_ctx->funk_txn ); + fd_sysvar_rent_init( slot_ctx->bank, slot_ctx->funk, slot_ctx->funk_txn ); /* Set the epoch rewards sysvar if partition epoch rewards feature is enabled From 636ab74a46f98e32ae721140f1f540926309e93a Mon Sep 17 00:00:00 2001 From: Ishan Bhatt Date: Tue, 8 Jul 2025 18:06:37 +0000 Subject: [PATCH 13/27] more replacement --- src/app/ledger/main.c | 4 +- src/discof/replay/fd_replay_tile.c | 13 ++- src/flamenco/runtime/fd_runtime.c | 161 +++++++++++++++-------------- src/flamenco/runtime/fd_runtime.h | 12 ++- 4 files changed, 100 insertions(+), 90 deletions(-) diff --git a/src/app/ledger/main.c b/src/app/ledger/main.c index b17939a703..3468200ae1 100644 --- a/src/app/ledger/main.c +++ b/src/app/ledger/main.c @@ -921,7 +921,7 @@ ingest( fd_ledger_args_t * args ) { } if( args->genesis ) { - fd_runtime_read_genesis( slot_ctx, args->genesis, args->snapshot != NULL, NULL, args->runtime_spad ); + fd_runtime_read_genesis( slot_ctx->bank, slot_ctx->funk, &slot_ctx->funk_txn, args->genesis, args->snapshot != NULL, NULL, args->runtime_spad ); } /* At this point the account state has been ingested into funk. Intake rocksdb */ @@ -1099,7 +1099,7 @@ replay( fd_ledger_args_t * args ) { fd_ledger_capture_setup( args ); if( args->genesis ) { - fd_runtime_read_genesis( args->slot_ctx, args->genesis, args->snapshot != NULL, args->capture_ctx, args->runtime_spad ); + fd_runtime_read_genesis( args->slot_ctx->bank, args->slot_ctx->funk, &args->slot_ctx->funk_txn, args->genesis, args->snapshot != NULL, args->capture_ctx, args->runtime_spad ); } fd_ledger_main_setup( args ); diff --git a/src/discof/replay/fd_replay_tile.c b/src/discof/replay/fd_replay_tile.c index e4d94d3554..6181b76728 100644 --- a/src/discof/replay/fd_replay_tile.c +++ b/src/discof/replay/fd_replay_tile.c @@ -1550,11 +1550,14 @@ init_snapshot( fd_replay_tile_ctx_t * ctx, replay_plugin_publish( ctx, stem, FD_PLUGIN_MSG_START_PROGRESS, msg, sizeof(msg) ); } - fd_runtime_read_genesis( ctx->slot_ctx, - ctx->genesis, - is_snapshot, - ctx->capture_ctx, - ctx->runtime_spad ); + fd_runtime_read_genesis( + ctx->slot_ctx->bank, + ctx->slot_ctx->funk, + &ctx->slot_ctx->funk_txn, + ctx->genesis, + is_snapshot, + ctx->capture_ctx, + ctx->runtime_spad ); /* We call this after fd_runtime_read_genesis, which sets up the slot_bank needed in blockstore_init. */ /* FIXME: We should really only call this once. */ diff --git a/src/flamenco/runtime/fd_runtime.c b/src/flamenco/runtime/fd_runtime.c index 4f6062184a..a0009a8f75 100644 --- a/src/flamenco/runtime/fd_runtime.c +++ b/src/flamenco/runtime/fd_runtime.c @@ -2905,29 +2905,28 @@ fd_runtime_init_program( fd_bank_t * bank, } static void -fd_runtime_init_bank_from_genesis( fd_exec_slot_ctx_t * slot_ctx, +fd_runtime_init_bank_from_genesis( fd_bank_t * bank, fd_genesis_solana_t const * genesis_block, fd_hash_t const * genesis_hash, fd_spad_t * runtime_spad ) { - slot_ctx->slot = 0UL; - fd_bank_poh_set( slot_ctx->bank, *genesis_hash ); + fd_bank_poh_set( bank, *genesis_hash ); - fd_hash_t * bank_hash = fd_bank_bank_hash_modify( slot_ctx->bank ); + fd_hash_t * bank_hash = fd_bank_bank_hash_modify( bank ); memset( bank_hash->hash, 0, FD_SHA256_HASH_SZ ); fd_poh_config_t const * poh = &genesis_block->poh_config; uint128 target_tick_duration = ((uint128)poh->target_tick_duration.seconds * 1000000000UL + (uint128)poh->target_tick_duration.nanoseconds); - fd_bank_epoch_schedule_set( slot_ctx->bank, genesis_block->epoch_schedule ); + fd_bank_epoch_schedule_set( bank, genesis_block->epoch_schedule ); - fd_bank_rent_set( slot_ctx->bank, genesis_block->rent ); + fd_bank_rent_set( bank, genesis_block->rent ); - fd_bank_block_height_set( slot_ctx->bank, 0UL ); + fd_bank_block_height_set( bank, 0UL ); - fd_bank_inflation_set( slot_ctx->bank, genesis_block->inflation ); + fd_bank_inflation_set( bank, genesis_block->inflation ); - fd_block_hash_queue_global_t * block_hash_queue = (fd_block_hash_queue_global_t *)&slot_ctx->bank->block_hash_queue[0]; + fd_block_hash_queue_global_t * block_hash_queue = fd_bank_block_hash_queue_modify( bank ); uchar * last_hash_mem = (uchar *)fd_ulong_align_up( (ulong)block_hash_queue + sizeof(fd_block_hash_queue_global_t), alignof(fd_hash_t) ); uchar * ages_pool_mem = (uchar *)fd_ulong_align_up( (ulong)last_hash_mem + sizeof(fd_hash_t), fd_hash_hash_age_pair_t_map_align() ); fd_hash_hash_age_pair_t_mapnode_t * ages_pool = fd_hash_hash_age_pair_t_map_join( fd_hash_hash_age_pair_t_map_new( ages_pool_mem, 400 ) ); @@ -2947,29 +2946,29 @@ fd_runtime_init_bank_from_genesis( fd_exec_slot_ctx_t * slot_ctx, block_hash_queue->ages_root_offset = (ulong)ages_root - (ulong)block_hash_queue; block_hash_queue->max_age = FD_BLOCKHASH_QUEUE_MAX_ENTRIES; - fd_bank_fee_rate_governor_set( slot_ctx->bank, genesis_block->fee_rate_governor ); + fd_bank_fee_rate_governor_set( bank, genesis_block->fee_rate_governor ); - fd_bank_lamports_per_signature_set( slot_ctx->bank, 0UL ); + fd_bank_lamports_per_signature_set( bank, 0UL ); - fd_bank_prev_lamports_per_signature_set( slot_ctx->bank, 0UL ); + fd_bank_prev_lamports_per_signature_set( bank, 0UL ); - fd_bank_max_tick_height_set( slot_ctx->bank, genesis_block->ticks_per_slot * (slot_ctx->slot + 1) ); + fd_bank_max_tick_height_set( bank, genesis_block->ticks_per_slot * (bank->slot + 1) ); - fd_bank_hashes_per_tick_set( slot_ctx->bank, !!poh->hashes_per_tick ? poh->hashes_per_tick : 0UL ); + fd_bank_hashes_per_tick_set( bank, !!poh->hashes_per_tick ? poh->hashes_per_tick : 0UL ); - fd_bank_ns_per_slot_set( slot_ctx->bank, target_tick_duration * genesis_block->ticks_per_slot ); + fd_bank_ns_per_slot_set( bank, target_tick_duration * genesis_block->ticks_per_slot ); - fd_bank_ticks_per_slot_set( slot_ctx->bank, genesis_block->ticks_per_slot ); + fd_bank_ticks_per_slot_set( bank, genesis_block->ticks_per_slot ); - fd_bank_genesis_creation_time_set( slot_ctx->bank, genesis_block->creation_time ); + fd_bank_genesis_creation_time_set( bank, genesis_block->creation_time ); - fd_bank_slots_per_year_set( slot_ctx->bank, SECONDS_PER_YEAR * (1000000000.0 / (double)target_tick_duration) / (double)genesis_block->ticks_per_slot ); + fd_bank_slots_per_year_set( bank, SECONDS_PER_YEAR * (1000000000.0 / (double)target_tick_duration) / (double)genesis_block->ticks_per_slot ); - fd_bank_signature_count_set( slot_ctx->bank, 0UL ); + fd_bank_signature_count_set( bank, 0UL ); /* Derive epoch stakes */ - fd_stakes_global_t * stakes_global = fd_bank_stakes_locking_modify( slot_ctx->bank ); + fd_stakes_global_t * stakes_global = fd_bank_stakes_locking_modify( bank ); uchar * vacc_pool_mem = (uchar *)fd_ulong_align_up( (ulong)stakes_global + sizeof(fd_stakes_global_t), fd_vote_accounts_pair_global_t_map_align() ); fd_vote_accounts_pair_global_t_mapnode_t * vacc_pool = fd_vote_accounts_pair_global_t_map_join( fd_vote_accounts_pair_global_t_map_new( vacc_pool_mem, 5000UL ) ); @@ -2982,7 +2981,7 @@ fd_runtime_init_bank_from_genesis( fd_exec_slot_ctx_t * slot_ctx, fd_acc_lamports_t capitalization = 0UL; - fd_features_t * features = fd_bank_features_modify( slot_ctx->bank ); + fd_features_t * features = fd_bank_features_modify( bank ); FD_FEATURE_SET_ACTIVE(features, accounts_lt_hash, 0); FD_FEATURE_SET_ACTIVE(features, remove_accounts_delta_hash, 0); @@ -3060,7 +3059,7 @@ fd_runtime_init_bank_from_genesis( fd_exec_slot_ctx_t * slot_ctx, &err ); FD_TEST( err==FD_BINCODE_SUCCESS ); - fd_features_t * features = fd_bank_features_modify( slot_ctx->bank ); + fd_features_t * features = fd_bank_features_modify( bank ); if( feature->has_activated_at ) { FD_LOG_DEBUG(( "Feature %s activated at %lu (genesis)", FD_BASE58_ENC_32_ALLOCA( acc->key.key ), feature->activated_at )); fd_features_set( features, found, feature->activated_at ); @@ -3079,14 +3078,14 @@ fd_runtime_init_bank_from_genesis( fd_exec_slot_ctx_t * slot_ctx, // slot_ctx->slot_bank.epoch_stakes.vote_accounts_root = NULL; - fd_vote_accounts_global_t * epoch_stakes = fd_bank_epoch_stakes_locking_modify( slot_ctx->bank ); + fd_vote_accounts_global_t * epoch_stakes = fd_bank_epoch_stakes_locking_modify( bank ); uchar * pool_mem = (uchar *)fd_ulong_align_up( (ulong)epoch_stakes + sizeof(fd_vote_accounts_global_t), fd_vote_accounts_pair_t_map_align() ); fd_vote_accounts_pair_global_t_mapnode_t * vote_accounts_pool = fd_vote_accounts_pair_global_t_map_join( fd_vote_accounts_pair_global_t_map_new( pool_mem, 50000UL ) ); fd_vote_accounts_pair_global_t_mapnode_t * vote_accounts_root = NULL; uchar * epoch_stakes_vote_acc_region_curr = (uchar *)fd_ulong_align_up( (ulong)vote_accounts_pool + fd_vote_accounts_pair_global_t_map_footprint( 50000UL ), 8UL ); - fd_vote_accounts_global_t * next_epoch_stakes = fd_bank_next_epoch_stakes_locking_modify( slot_ctx->bank ); + fd_vote_accounts_global_t * next_epoch_stakes = fd_bank_next_epoch_stakes_locking_modify( bank ); uchar * next_pool_mem = (uchar *)fd_ulong_align_up( (ulong)next_epoch_stakes + sizeof(fd_vote_accounts_global_t), fd_vote_accounts_pair_t_map_align() ); fd_vote_accounts_pair_global_t_mapnode_t * next_pool = fd_vote_accounts_pair_global_t_map_join( fd_vote_accounts_pair_global_t_map_new( next_pool_mem, 50000UL ) ); fd_vote_accounts_pair_global_t_mapnode_t * next_root = NULL; @@ -3162,11 +3161,9 @@ fd_runtime_init_bank_from_genesis( fd_exec_slot_ctx_t * slot_ctx, fd_vote_accounts_vote_accounts_pool_update( next_epoch_stakes, next_pool ); fd_vote_accounts_vote_accounts_root_update( next_epoch_stakes, next_root ); - fd_bank_epoch_stakes_end_locking_modify( slot_ctx->bank ); - - fd_bank_next_epoch_stakes_end_locking_modify( slot_ctx->bank ); - + fd_bank_epoch_stakes_end_locking_modify( bank ); + fd_bank_next_epoch_stakes_end_locking_modify( bank ); stakes_global->epoch = 0UL; stakes_global->unused = 0UL; @@ -3175,62 +3172,65 @@ fd_runtime_init_bank_from_genesis( fd_exec_slot_ctx_t * slot_ctx, fd_vote_accounts_vote_accounts_root_update( &stakes_global->vote_accounts, vacc_root ); fd_stakes_stake_delegations_pool_update( stakes_global, sacc_pool ); fd_stakes_stake_delegations_root_update( stakes_global, sacc_root ); - fd_bank_stakes_end_locking_modify( slot_ctx->bank ); + fd_bank_stakes_end_locking_modify( bank ); - fd_bank_capitalization_set( slot_ctx->bank, capitalization ); + fd_bank_capitalization_set( bank, capitalization ); - fd_clock_timestamp_votes_global_t * clock_timestamp_votes = fd_bank_clock_timestamp_votes_locking_modify( slot_ctx->bank ); + fd_clock_timestamp_votes_global_t * clock_timestamp_votes = fd_bank_clock_timestamp_votes_locking_modify( bank ); uchar * clock_pool_mem = (uchar *)fd_ulong_align_up( (ulong)clock_timestamp_votes + sizeof(fd_clock_timestamp_votes_global_t), fd_clock_timestamp_vote_t_map_align() ); fd_clock_timestamp_vote_t_mapnode_t * clock_pool = fd_clock_timestamp_vote_t_map_join( fd_clock_timestamp_vote_t_map_new(clock_pool_mem, 30000UL ) ); clock_timestamp_votes->votes_pool_offset = (ulong)fd_clock_timestamp_vote_t_map_leave( clock_pool) - (ulong)clock_timestamp_votes; clock_timestamp_votes->votes_root_offset = 0UL; - fd_bank_clock_timestamp_votes_end_locking_modify( slot_ctx->bank ); + fd_bank_clock_timestamp_votes_end_locking_modify( bank ); } static int -fd_runtime_process_genesis_block( fd_exec_slot_ctx_t * slot_ctx, - fd_capture_ctx_t * capture_ctx, - fd_spad_t * runtime_spad ) { +fd_runtime_process_genesis_block( fd_bank_t * bank, + fd_funk_t * funk, + fd_funk_txn_t * funk_txn, + fd_capture_ctx_t * capture_ctx, + fd_spad_t * runtime_spad ) { - fd_hash_t * poh = fd_bank_poh_modify( slot_ctx->bank ); - ulong hashcnt_per_slot = fd_bank_hashes_per_tick_get( slot_ctx->bank ) * fd_bank_ticks_per_slot_get( slot_ctx->bank ); + fd_hash_t * poh = fd_bank_poh_modify( bank ); + ulong hashcnt_per_slot = fd_bank_hashes_per_tick_get( bank ) * fd_bank_ticks_per_slot_get( bank ); while( hashcnt_per_slot-- ) { fd_sha256_hash( poh->hash, sizeof(fd_hash_t), poh->hash ); } - fd_bank_execution_fees_set( slot_ctx->bank, 0UL ); + fd_bank_execution_fees_set( bank, 0UL ); - fd_bank_priority_fees_set( slot_ctx->bank, 0UL ); + fd_bank_priority_fees_set( bank, 0UL ); - fd_bank_signature_count_set( slot_ctx->bank, 0UL ); + fd_bank_signature_count_set( bank, 0UL ); - fd_bank_txn_count_set( slot_ctx->bank, 0UL ); + fd_bank_txn_count_set( bank, 0UL ); - fd_bank_failed_txn_count_set( slot_ctx->bank, 0UL ); + fd_bank_failed_txn_count_set( bank, 0UL ); - fd_bank_nonvote_failed_txn_count_set( slot_ctx->bank, 0UL ); + fd_bank_nonvote_failed_txn_count_set( bank, 0UL ); - fd_bank_total_compute_units_used_set( slot_ctx->bank, 0UL ); + fd_bank_total_compute_units_used_set( bank, 0UL ); - fd_runtime_init_program( slot_ctx->bank, slot_ctx->funk, slot_ctx->funk_txn, runtime_spad ); + fd_runtime_init_program( bank, funk, funk_txn, runtime_spad ); - fd_sysvar_slot_history_update( slot_ctx->bank, slot_ctx->funk, slot_ctx->funk_txn, runtime_spad ); + fd_sysvar_slot_history_update( bank, funk, funk_txn, runtime_spad ); - fd_runtime_update_leaders( slot_ctx->bank, 0, runtime_spad ); + fd_runtime_update_leaders( bank, 0, runtime_spad ); - fd_runtime_freeze( slot_ctx->bank, slot_ctx->funk, slot_ctx->funk_txn, runtime_spad ); + fd_runtime_freeze( bank, funk, funk_txn, runtime_spad ); /* sort and update bank hash */ - fd_hash_t * bank_hash = fd_bank_bank_hash_modify( slot_ctx->bank ); - int result = fd_update_hash_bank_tpool( slot_ctx->bank, - slot_ctx->funk, - slot_ctx->funk_txn, - capture_ctx, - bank_hash, - 0UL, - NULL, - runtime_spad ); + fd_hash_t * bank_hash = fd_bank_bank_hash_modify( bank ); + int result = fd_update_hash_bank_tpool( + bank, + funk, + funk_txn, + capture_ctx, + bank_hash, + 0UL, + NULL, + runtime_spad ); if( FD_UNLIKELY( result != FD_EXECUTOR_INSTR_SUCCESS ) ) { FD_LOG_ERR(( "Failed to update bank hash with error=%d", result )); @@ -3240,7 +3240,9 @@ fd_runtime_process_genesis_block( fd_exec_slot_ctx_t * slot_ctx, } void -fd_runtime_read_genesis( fd_exec_slot_ctx_t * slot_ctx, +fd_runtime_read_genesis( fd_bank_t * bank, + fd_funk_t * funk, + fd_funk_txn_t * * funk_txn_out, char const * genesis_filepath, uchar is_snapshot, fd_capture_ctx_t * capture_ctx, @@ -3289,22 +3291,22 @@ fd_runtime_read_genesis( fd_exec_slot_ctx_t * slot_ctx, // The hash is generated from the raw data... don't mess with this.. fd_sha256_hash( buf, sz, genesis_hash.uc ); - fd_hash_t * genesis_hash_bm = fd_bank_genesis_hash_modify( slot_ctx->bank ); + fd_hash_t * genesis_hash_bm = fd_bank_genesis_hash_modify( bank ); fd_memcpy( genesis_hash_bm, buf, sizeof(fd_hash_t) ); if( !is_snapshot ) { /* Create a new Funk transaction for slot 0 */ - fd_funk_txn_start_write( slot_ctx->funk ); + fd_funk_txn_start_write( funk ); fd_funk_txn_xid_t xid = { 0 }; xid.ul[1] = 0UL; xid.ul[0] = 0UL; - slot_ctx->funk_txn = fd_funk_txn_prepare( slot_ctx->funk, NULL, &xid, 1 ); - fd_funk_txn_end_write( slot_ctx->funk ); + *funk_txn_out = fd_funk_txn_prepare( funk, NULL, &xid, 1 ); + fd_funk_txn_end_write( funk ); - fd_runtime_init_bank_from_genesis( slot_ctx, - genesis_block, - &genesis_hash, - runtime_spad ); + fd_runtime_init_bank_from_genesis( bank, + genesis_block, + &genesis_hash, + runtime_spad ); FD_LOG_DEBUG(( "start genesis accounts - count: %lu", genesis_block->accounts_len )); @@ -3316,8 +3318,8 @@ fd_runtime_read_genesis( fd_exec_slot_ctx_t * slot_ctx, int err = fd_txn_account_init_from_funk_mutable( rec, &a->key, - slot_ctx->funk, - slot_ctx->funk_txn, + funk, + *funk_txn_out, 1, /* do_create */ a->account.data_len ); @@ -3331,7 +3333,7 @@ fd_runtime_read_genesis( fd_exec_slot_ctx_t * slot_ctx, rec->vt->set_executable( rec, a->account.executable ); rec->vt->set_owner( rec, &a->account.owner ); - fd_txn_account_mutable_fini( rec, slot_ctx->funk, slot_ctx->funk_txn ); + fd_txn_account_mutable_fini( rec, funk, *funk_txn_out ); } FD_LOG_DEBUG(( "end genesis accounts" )); @@ -3340,30 +3342,33 @@ fd_runtime_read_genesis( fd_exec_slot_ctx_t * slot_ctx, for( ulong i=0UL; i < genesis_block->native_instruction_processors_len; i++ ) { fd_string_pubkey_pair_t * a = &genesis_block->native_instruction_processors[i]; - fd_write_builtin_account( slot_ctx->bank, slot_ctx->funk, slot_ctx->funk_txn, a->pubkey, (const char *) a->string, a->string_len ); + fd_write_builtin_account( bank, funk, *funk_txn_out, a->pubkey, (const char *) a->string, a->string_len ); } - fd_features_restore( slot_ctx->bank, slot_ctx->funk, slot_ctx->funk_txn, runtime_spad ); - - slot_ctx->slot = 0UL; + fd_features_restore( bank, funk, *funk_txn_out, runtime_spad ); - int err = fd_runtime_process_genesis_block( slot_ctx, capture_ctx, runtime_spad ); + int err = fd_runtime_process_genesis_block( + bank, + funk, + *funk_txn_out, + capture_ctx, + runtime_spad ); if( FD_UNLIKELY( err ) ) { FD_LOG_ERR(( "Genesis slot 0 execute failed with error %d", err )); } } - fd_account_keys_global_t * stake_account_keys = fd_bank_stake_account_keys_locking_modify( slot_ctx->bank ); + fd_account_keys_global_t * stake_account_keys = fd_bank_stake_account_keys_locking_modify( bank ); uchar * pool_mem = (uchar *)fd_ulong_align_up( (ulong)stake_account_keys + sizeof(fd_account_keys_global_t), fd_account_keys_pair_t_map_align() ); fd_account_keys_pair_t_mapnode_t * stake_account_keys_pool = fd_account_keys_pair_t_map_join( fd_account_keys_pair_t_map_new( pool_mem, 100000UL ) ); fd_account_keys_pair_t_mapnode_t * stake_account_keys_root = NULL; fd_account_keys_account_keys_pool_update( stake_account_keys, stake_account_keys_pool ); fd_account_keys_account_keys_root_update( stake_account_keys, stake_account_keys_root ); - fd_bank_stake_account_keys_end_locking_modify( slot_ctx->bank ); + fd_bank_stake_account_keys_end_locking_modify( bank ); - fd_account_keys_global_t * vote_account_keys = fd_bank_vote_account_keys_locking_modify( slot_ctx->bank ); + fd_account_keys_global_t * vote_account_keys = fd_bank_vote_account_keys_locking_modify( bank ); pool_mem = (uchar *)fd_ulong_align_up( (ulong)vote_account_keys + sizeof(fd_account_keys_global_t), fd_account_keys_pair_t_map_align() ); fd_account_keys_pair_t_mapnode_t * vote_account_keys_pool = fd_account_keys_pair_t_map_join( fd_account_keys_pair_t_map_new( pool_mem, 100000UL ) ); fd_account_keys_pair_t_mapnode_t * vote_account_keys_root = NULL; @@ -3371,7 +3376,7 @@ fd_runtime_read_genesis( fd_exec_slot_ctx_t * slot_ctx, fd_account_keys_account_keys_pool_update( vote_account_keys, vote_account_keys_pool ); fd_account_keys_account_keys_root_update( vote_account_keys, vote_account_keys_root ); - fd_bank_vote_account_keys_end_locking_modify( slot_ctx->bank ); + fd_bank_vote_account_keys_end_locking_modify( bank ); } /******************************************************************************/ diff --git a/src/flamenco/runtime/fd_runtime.h b/src/flamenco/runtime/fd_runtime.h index 5b0a324903..a2876dbe41 100644 --- a/src/flamenco/runtime/fd_runtime.h +++ b/src/flamenco/runtime/fd_runtime.h @@ -680,11 +680,13 @@ fd_runtime_block_execute_tpool( fd_exec_slot_ctx_t * slot_ctx, /* Genesis ********************************************************************/ void -fd_runtime_read_genesis( fd_exec_slot_ctx_t * slot_ctx, - char const * genesis_filepath, - uchar is_snapshot, - fd_capture_ctx_t * capture_ctx, - fd_spad_t * spad ); +fd_runtime_read_genesis( fd_bank_t * bank, + fd_funk_t * funk, + fd_funk_txn_t * * funk_txn_out, + char const * genesis_filepath, + uchar is_snapshot, + fd_capture_ctx_t * capture_ctx, + fd_spad_t * spad ); FD_PROTOTYPES_END From 1fc14d9b8534e588330335adcc4363f124cc54c7 Mon Sep 17 00:00:00 2001 From: Ishan Bhatt Date: Tue, 8 Jul 2025 18:22:43 +0000 Subject: [PATCH 14/27] more --- src/app/ledger/main.c | 5 +- src/flamenco/runtime/fd_runtime.c | 94 ++++++------- src/flamenco/runtime/fd_runtime.h | 13 +- src/flamenco/runtime/tests/fd_dump_pb.c | 127 ++++++++++-------- src/flamenco/runtime/tests/fd_dump_pb.h | 9 +- .../runtime/tests/harness/fd_block_harness.c | 4 +- 6 files changed, 140 insertions(+), 112 deletions(-) diff --git a/src/app/ledger/main.c b/src/app/ledger/main.c index 3468200ae1..3aae2e6f52 100644 --- a/src/app/ledger/main.c +++ b/src/app/ledger/main.c @@ -284,7 +284,10 @@ runtime_replay( fd_ledger_args_t * ledger_args ) { ulong blk_txn_cnt = 0UL; FD_LOG_NOTICE(( "Used memory in spad before slot=%lu %lu", slot, ledger_args->runtime_spad->mem_used )); - FD_TEST( fd_runtime_block_eval_tpool( ledger_args->slot_ctx, + FD_TEST( fd_runtime_block_eval_tpool( ledger_args->slot_ctx->banks, + ledger_args->slot_ctx->bank, + ledger_args->slot_ctx->funk, + &ledger_args->slot_ctx->funk_txn, slot, blk, ledger_args->capture_ctx, diff --git a/src/flamenco/runtime/fd_runtime.c b/src/flamenco/runtime/fd_runtime.c index a0009a8f75..8bb0a190dd 100644 --- a/src/flamenco/runtime/fd_runtime.c +++ b/src/flamenco/runtime/fd_runtime.c @@ -3634,7 +3634,9 @@ fd_runtime_publish_old_txns( fd_banks_t * banks, } int -fd_runtime_block_execute_tpool( fd_exec_slot_ctx_t * slot_ctx, +fd_runtime_block_execute_tpool( fd_bank_t * bank, + fd_funk_t * funk, + fd_funk_txn_t * funk_txn, fd_blockstore_t * blockstore, fd_capture_ctx_t * capture_ctx, fd_runtime_block_info_t const * block_info, @@ -3643,15 +3645,15 @@ fd_runtime_block_execute_tpool( fd_exec_slot_ctx_t * slot_ctx, ulong exec_spad_cnt, fd_spad_t * runtime_spad ) { - if ( capture_ctx != NULL && capture_ctx->capture && slot_ctx->slot>=capture_ctx->solcap_start_slot ) { - fd_solcap_writer_set_slot( capture_ctx->capture, slot_ctx->slot ); + if ( capture_ctx != NULL && capture_ctx->capture && bank->slot>=capture_ctx->solcap_start_slot ) { + fd_solcap_writer_set_slot( capture_ctx->capture, bank->slot ); } long block_execute_time = -fd_log_wallclock(); - int res = fd_runtime_block_execute_prepare( slot_ctx->bank, - slot_ctx->funk, - slot_ctx->funk_txn, + int res = fd_runtime_block_execute_prepare( bank, + funk, + funk_txn, blockstore, runtime_spad ); if( res != FD_RUNTIME_EXECUTE_SUCCESS ) { @@ -3682,12 +3684,12 @@ fd_runtime_block_execute_tpool( fd_exec_slot_ctx_t * slot_ctx, /* Reverify programs for this epoch if needed */ for( ulong txn_idx=0UL; txn_idxbank, slot_ctx->funk, slot_ctx->funk_txn, &mblock_txn_ptrs[txn_idx], runtime_spad ); + fd_runtime_update_program_cache( bank, funk, funk_txn, &mblock_txn_ptrs[txn_idx], runtime_spad ); } - res = fd_runtime_process_txns_in_microblock_stream( slot_ctx->bank, - slot_ctx->funk, - slot_ctx->funk_txn, + res = fd_runtime_process_txns_in_microblock_stream( bank, + funk, + funk_txn, capture_ctx, mblock_txn_ptrs, mblock_txn_cnt, @@ -3709,9 +3711,9 @@ fd_runtime_block_execute_tpool( fd_exec_slot_ctx_t * slot_ctx, .para_arg_1 = tpool }; - res = fd_runtime_block_execute_finalize_para( slot_ctx->bank, - slot_ctx->funk, - slot_ctx->funk_txn, + res = fd_runtime_block_execute_finalize_para( bank, + funk, + funk_txn, capture_ctx, block_info, fd_tpool_worker_cnt( tpool ), @@ -3723,12 +3725,12 @@ fd_runtime_block_execute_tpool( fd_exec_slot_ctx_t * slot_ctx, block_finalize_time += fd_log_wallclock(); double block_finalize_time_ms = (double)block_finalize_time * 1e-6; - FD_LOG_INFO(( "finalized block successfully - slot: %lu, elapsed: %6.6f ms", slot_ctx->slot, block_finalize_time_ms )); + FD_LOG_INFO(( "finalized block successfully - slot: %lu, elapsed: %6.6f ms", bank->slot, block_finalize_time_ms )); block_execute_time += fd_log_wallclock(); double block_execute_time_ms = (double)block_execute_time * 1e-6; - FD_LOG_INFO(( "executed block successfully - slot: %lu, elapsed: %6.6f ms", slot_ctx->slot, block_execute_time_ms )); + FD_LOG_INFO(( "executed block successfully - slot: %lu, elapsed: %6.6f ms", bank->slot, block_execute_time_ms )); return FD_RUNTIME_EXECUTE_SUCCESS; } @@ -3785,7 +3787,10 @@ fd_runtime_block_pre_execute_process_new_epoch( fd_bank_t * bank, } int -fd_runtime_block_eval_tpool( fd_exec_slot_ctx_t * slot_ctx, +fd_runtime_block_eval_tpool( fd_banks_t * banks, + fd_bank_t * bank, + fd_funk_t * funk, + fd_funk_txn_t * * funk_txn_out, ulong slot, fd_block_t * block, fd_capture_ctx_t * capture_ctx, @@ -3801,10 +3806,10 @@ fd_runtime_block_eval_tpool( fd_exec_slot_ctx_t * slot_ctx, (void)scheduler; int err = fd_runtime_publish_old_txns( - slot_ctx->banks, - slot_ctx->bank, - slot_ctx->funk, - slot_ctx->funk_txn, + banks, + bank, + funk, + *funk_txn_out, capture_ctx, tpool, runtime_spad ); @@ -3812,8 +3817,6 @@ fd_runtime_block_eval_tpool( fd_exec_slot_ctx_t * slot_ctx, return err; } - fd_funk_t * funk = slot_ctx->funk; - long block_eval_time = -fd_log_wallclock(); fd_runtime_block_info_t block_info; int ret = FD_RUNTIME_EXECUTE_SUCCESS; @@ -3823,11 +3826,9 @@ fd_runtime_block_eval_tpool( fd_exec_slot_ctx_t * slot_ctx, fd_funk_txn_xid_t xid = { .ul = { slot, slot } }; fd_funk_txn_start_write( funk ); - slot_ctx->funk_txn = fd_funk_txn_prepare( funk, slot_ctx->funk_txn, &xid, 1 ); + *funk_txn_out = fd_funk_txn_prepare( funk, *funk_txn_out, &xid, 1 ); fd_funk_txn_end_write( funk ); - slot_ctx->slot = slot; - /* Capturing block-agnostic state in preparation for the epoch boundary */ uchar dump_block = capture_ctx && slot >= capture_ctx->dump_proto_start_slot && capture_ctx->dump_block_to_pb; fd_exec_test_block_context_t * block_ctx = NULL; @@ -3835,13 +3836,13 @@ fd_runtime_block_eval_tpool( fd_exec_slot_ctx_t * slot_ctx, /* TODO: This probably should get allocated from a separate spad for the capture ctx */ block_ctx = fd_spad_alloc( runtime_spad, alignof(fd_exec_test_block_context_t), sizeof(fd_exec_test_block_context_t) ); fd_memset( block_ctx, 0, sizeof(fd_exec_test_block_context_t) ); - fd_dump_block_to_protobuf( slot_ctx, capture_ctx, runtime_spad, block_ctx ); + fd_dump_block_to_protobuf( bank, funk, *funk_txn_out, capture_ctx, runtime_spad, block_ctx ); } int is_epoch_boundary = 0; - fd_runtime_block_pre_execute_process_new_epoch( slot_ctx->bank, - slot_ctx->funk, - slot_ctx->funk_txn, + fd_runtime_block_pre_execute_process_new_epoch( bank, + funk, + *funk_txn_out, tpool, exec_spads, exec_spad_cnt, @@ -3861,26 +3862,29 @@ fd_runtime_block_eval_tpool( fd_exec_slot_ctx_t * slot_ctx, *txn_cnt = block_info.txn_cnt; fd_hash_t poh_out = {0}; - fd_hash_t poh_in = fd_bank_poh_get( slot_ctx->bank ); - if( FD_UNLIKELY( (ret = fd_runtime_block_verify_tpool( slot_ctx->bank, blockstore, &block_info, &poh_in, &poh_out, tpool, runtime_spad )) != FD_RUNTIME_EXECUTE_SUCCESS ) ) { + fd_hash_t poh_in = fd_bank_poh_get( bank ); + if( FD_UNLIKELY( (ret = fd_runtime_block_verify_tpool( bank, blockstore, &block_info, &poh_in, &poh_out, tpool, runtime_spad )) != FD_RUNTIME_EXECUTE_SUCCESS ) ) { break; } - fd_bank_poh_set( slot_ctx->bank, poh_out ); + fd_bank_poh_set( bank, poh_out ); /* Dump the remainder of the block after preparation, POH verification, etc */ if( FD_UNLIKELY( dump_block ) ) { - fd_dump_block_to_protobuf_tx_only( &block_info, slot_ctx, capture_ctx, runtime_spad, block_ctx ); + fd_dump_block_to_protobuf_tx_only( &block_info, bank, funk, *funk_txn_out, capture_ctx, runtime_spad, block_ctx ); } - if( FD_UNLIKELY( (ret = fd_runtime_block_execute_tpool( slot_ctx, - blockstore, - capture_ctx, - &block_info, - tpool, - exec_spads, - exec_spad_cnt, - runtime_spad )) != FD_RUNTIME_EXECUTE_SUCCESS ) ) { + if( FD_UNLIKELY( (ret = fd_runtime_block_execute_tpool( + bank, + funk, + *funk_txn_out, + blockstore, + capture_ctx, + &block_info, + tpool, + exec_spads, + exec_spad_cnt, + runtime_spad )) != FD_RUNTIME_EXECUTE_SUCCESS ) ) { break; } @@ -3899,7 +3903,7 @@ fd_runtime_block_eval_tpool( fd_exec_slot_ctx_t * slot_ctx, block_eval_time += fd_log_wallclock(); double block_eval_time_ms = (double)block_eval_time * 1e-6; double tps = (double) block_info.txn_cnt / ((double)block_eval_time * 1e-9); - fd_epoch_leaders_t const * leaders = fd_bank_epoch_leaders_locking_query( slot_ctx->bank ); + fd_epoch_leaders_t const * leaders = fd_bank_epoch_leaders_locking_query( bank ); fd_pubkey_t const * leader = fd_epoch_leaders_get( leaders, slot ); FD_LOG_INFO(( "evaluated block successfully - slot: %lu, elapsed: %6.6f ms, signatures: %lu, txns: %lu, tps: %6.6f, leader: %s", slot, @@ -3908,11 +3912,11 @@ fd_runtime_block_eval_tpool( fd_exec_slot_ctx_t * slot_ctx, block_info.txn_cnt, tps, FD_BASE58_ENC_32_ALLOCA( leader ) )); - fd_bank_epoch_leaders_end_locking_query( slot_ctx->bank ); + fd_bank_epoch_leaders_end_locking_query( bank ); - fd_bank_transaction_count_set( slot_ctx->bank, fd_bank_transaction_count_get( slot_ctx->bank ) + block_info.txn_cnt ); + fd_bank_transaction_count_set( bank, fd_bank_transaction_count_get( bank ) + block_info.txn_cnt ); - fd_bank_prev_slot_set( slot_ctx->bank, slot ); + fd_bank_prev_slot_set( bank, slot ); // FIXME: this shouldn't be doing this, it doesn't work with forking. punting changing it though // slot_ctx->slot = slot+1UL; diff --git a/src/flamenco/runtime/fd_runtime.h b/src/flamenco/runtime/fd_runtime.h index a2876dbe41..b1e856f907 100644 --- a/src/flamenco/runtime/fd_runtime.h +++ b/src/flamenco/runtime/fd_runtime.h @@ -655,20 +655,25 @@ fd_raw_block_txn_iter_ele( fd_raw_block_txn_iter_t iter, fd_txn_p_t * out_txn ); /* Offline Replay *************************************************************/ int -fd_runtime_block_eval_tpool( fd_exec_slot_ctx_t * slot_ctx, +fd_runtime_block_eval_tpool( fd_banks_t * banks, + fd_bank_t * bank, + fd_funk_t * funk, + fd_funk_txn_t * * funk_txn_out, ulong slot, fd_block_t * block, fd_capture_ctx_t * capture_ctx, fd_tpool_t * tpool, ulong scheduler, ulong * txn_cnt, - fd_spad_t * * spads, - ulong spads_cnt, + fd_spad_t * * exec_spads, + ulong exec_spad_cnt, fd_spad_t * runtime_spad, fd_blockstore_t * blockstore ); int -fd_runtime_block_execute_tpool( fd_exec_slot_ctx_t * slot_ctx, +fd_runtime_block_execute_tpool( fd_bank_t * bank, + fd_funk_t * funk, + fd_funk_txn_t * funk_txn, fd_blockstore_t * blockstore, fd_capture_ctx_t * capture_ctx, fd_runtime_block_info_t const * block_info, diff --git a/src/flamenco/runtime/tests/fd_dump_pb.c b/src/flamenco/runtime/tests/fd_dump_pb.c index 8481a9bea0..2f16c149bd 100644 --- a/src/flamenco/runtime/tests/fd_dump_pb.c +++ b/src/flamenco/runtime/tests/fd_dump_pb.c @@ -128,7 +128,8 @@ dump_account_if_not_already_dumped( fd_funk_t const * funk, /* TODO: This can be made slightly more efficient by dumping only the referenced ALUT accounts instead of all accounts */ static void -dump_lut_account_and_contained_accounts( fd_exec_slot_ctx_t const * slot_ctx, +dump_lut_account_and_contained_accounts( fd_funk_t const * funk, + fd_funk_txn_t const * funk_txn, uchar const * txn_payload, fd_txn_acct_addr_lut_t const * lookup_table, fd_spad_t * spad, @@ -136,7 +137,7 @@ dump_lut_account_and_contained_accounts( fd_exec_slot_ctx_t const * slot_ct pb_size_t * out_account_states_count ) { FD_TXN_ACCOUNT_DECL( alut_account ); fd_pubkey_t const * alut_pubkey = (fd_pubkey_t const *)((uchar *)txn_payload + lookup_table->addr_off); - uchar account_exists = dump_account_if_not_already_dumped( slot_ctx->funk, slot_ctx->funk_txn, alut_pubkey, spad, out_account_states, out_account_states_count, alut_account ); + uchar account_exists = dump_account_if_not_already_dumped( funk, funk_txn, alut_pubkey, spad, out_account_states, out_account_states_count, alut_account ); if( !account_exists || alut_account->vt->get_data_len( alut_account )vt->get_data_len( alut_account ) - FD_LOOKUP_TABLE_META_SIZE ) >> 5UL; // = (dlen - 56) / 32 for( ulong i=0UL; ifunk, slot_ctx->funk_txn, referenced_pubkey, spad, out_account_states, out_account_states_count, NULL ); + dump_account_if_not_already_dumped( funk, funk_txn, referenced_pubkey, spad, out_account_states, out_account_states_count, NULL ); } } @@ -184,7 +185,8 @@ dump_executable_account_if_exists( fd_funk_t const * funk, /** VOTE ACCOUNTS DUMPING **/ static void -dump_vote_accounts( fd_exec_slot_ctx_t const * slot_ctx, +dump_vote_accounts( fd_funk_t const * funk, + fd_funk_txn_t const * funk_txn, fd_vote_accounts_global_t const * vote_accounts, fd_spad_t * spad, fd_exec_test_vote_account_t ** out_vote_accounts, @@ -226,7 +228,7 @@ dump_vote_accounts( fd_exec_slot_ctx_t const * slot_ctx, fd_memcpy( &vote_out->vote_account.data->bytes, data, curr->elem.value.data_len ); // Dump the vote account - dump_account_if_not_already_dumped( slot_ctx->funk, slot_ctx->funk_txn, &curr->elem.key, spad, out_acct_states, out_acct_states_cnt, NULL ); + dump_account_if_not_already_dumped( funk, funk_txn, &curr->elem.key, spad, out_acct_states, out_acct_states_cnt, NULL ); } *out_vote_accounts = vote_account_out; @@ -407,7 +409,9 @@ dump_blockhash_queue( fd_block_hash_queue_global_t const * queue, static void create_block_context_protobuf_from_block( fd_exec_test_block_context_t * block_context, - fd_exec_slot_ctx_t const * slot_ctx, + fd_bank_t * bank, + fd_funk_t const * funk, + fd_funk_txn_t const * funk_txn, fd_spad_t * spad ) { /* BlockContext -> acct_states */ @@ -445,12 +449,12 @@ create_block_context_protobuf_from_block( fd_exec_test_block_context_t * block_c ulong num_sysvar_entries = (sizeof(fd_relevant_sysvar_ids) / sizeof(fd_pubkey_t)); ulong num_loaded_builtins = (sizeof(loaded_builtins) / sizeof(fd_pubkey_t)); - fd_account_keys_global_t const * stake_account_keys = fd_bank_stake_account_keys_locking_query( slot_ctx->bank ); + fd_account_keys_global_t const * stake_account_keys = fd_bank_stake_account_keys_locking_query( bank ); fd_account_keys_pair_t_mapnode_t * stake_account_keys_pool = fd_account_keys_account_keys_pool_join( stake_account_keys ); fd_account_keys_pair_t_mapnode_t * stake_account_keys_root = fd_account_keys_account_keys_root_join( stake_account_keys ); - fd_stakes_global_t const * stakes = fd_bank_stakes_locking_query( slot_ctx->bank ); + fd_stakes_global_t const * stakes = fd_bank_stakes_locking_query( bank ); fd_delegation_pair_t_mapnode_t * stake_delegations_pool = fd_stakes_stake_delegations_pool_join( stakes ); fd_delegation_pair_t_mapnode_t * stake_delegations_root = fd_stakes_stake_delegations_root_join( stakes ); @@ -464,23 +468,23 @@ create_block_context_protobuf_from_block( fd_exec_test_block_context_t * block_c ulong vote_account_t_cnt = fd_vote_accounts_pair_global_t_map_size( stakes_vote_accounts_pool, stakes_vote_accounts_root ); - fd_bank_stake_account_keys_end_locking_query( slot_ctx->bank ); - fd_bank_stakes_end_locking_query( slot_ctx->bank ); + fd_bank_stake_account_keys_end_locking_query( bank ); + fd_bank_stakes_end_locking_query( bank ); - fd_vote_accounts_global_t const * next_epoch_stakes = fd_bank_next_epoch_stakes_locking_query( slot_ctx->bank ); + fd_vote_accounts_global_t const * next_epoch_stakes = fd_bank_next_epoch_stakes_locking_query( bank ); fd_vote_accounts_pair_global_t_mapnode_t * next_epoch_stakes_pool = fd_vote_accounts_vote_accounts_pool_join( next_epoch_stakes ); fd_vote_accounts_pair_global_t_mapnode_t * next_epoch_stakes_root = fd_vote_accounts_vote_accounts_root_join( next_epoch_stakes ); ulong vote_account_t_1_cnt = fd_vote_accounts_pair_global_t_map_size( next_epoch_stakes_pool, next_epoch_stakes_root ); - fd_bank_next_epoch_stakes_end_locking_query( slot_ctx->bank ); + fd_bank_next_epoch_stakes_end_locking_query( bank ); - fd_vote_accounts_global_t const * epoch_stakes = fd_bank_epoch_stakes_locking_query( slot_ctx->bank ); + fd_vote_accounts_global_t const * epoch_stakes = fd_bank_epoch_stakes_locking_query( bank ); fd_vote_accounts_pair_global_t_mapnode_t * epoch_stakes_pool = fd_vote_accounts_vote_accounts_pool_join( epoch_stakes ); fd_vote_accounts_pair_global_t_mapnode_t * epoch_stakes_root = fd_vote_accounts_vote_accounts_root_join( epoch_stakes ); ulong vote_account_t_2_cnt = fd_vote_accounts_pair_global_t_map_size( epoch_stakes_pool, epoch_stakes_root ); - fd_bank_epoch_stakes_end_locking_query( slot_ctx->bank ); + fd_bank_epoch_stakes_end_locking_query( bank ); ulong total_num_accounts = num_sysvar_entries + num_loaded_builtins + @@ -498,11 +502,11 @@ create_block_context_protobuf_from_block( fd_exec_test_block_context_t * block_c for( ulong i=0UL; ifunk, slot_ctx->funk_txn, &fd_relevant_sysvar_ids[i], spad, block_context->acct_states, &block_context->acct_states_count, NULL ); + dump_account_if_not_already_dumped( funk, funk_txn, &fd_relevant_sysvar_ids[i], spad, block_context->acct_states, &block_context->acct_states_count, NULL ); } for( ulong i=0UL; ifunk, slot_ctx->funk_txn, &loaded_builtins[i], spad, block_context->acct_states, &block_context->acct_states_count, NULL ); + dump_account_if_not_already_dumped( funk, funk_txn, &loaded_builtins[i], spad, block_context->acct_states, &block_context->acct_states_count, NULL ); } /* BlockContext -> blockhash_queue */ @@ -511,30 +515,30 @@ create_block_context_protobuf_from_block( fd_exec_test_block_context_t * block_c PB_BYTES_ARRAY_T_ALLOCSIZE((FD_BLOCKHASH_QUEUE_MAX_ENTRIES + 1) * sizeof(pb_bytes_array_t *)) ); block_context->blockhash_queue = output_blockhash_queue; - fd_block_hash_queue_global_t * bhq = (fd_block_hash_queue_global_t *)&slot_ctx->bank->block_hash_queue[0]; + fd_block_hash_queue_global_t const * bhq = fd_bank_block_hash_queue_query( bank ); dump_blockhash_queue( bhq, spad, block_context->blockhash_queue, &block_context->blockhash_queue_count ); /* BlockContext -> SlotContext */ block_context->has_slot_ctx = true; - block_context->slot_ctx.slot = slot_ctx->slot; + block_context->slot_ctx.slot = bank->slot; // HACK FOR NOW: block height gets incremented in process_new_epoch, so we should dump block height + 1 - block_context->slot_ctx.block_height = fd_bank_block_height_get( slot_ctx->bank ) + 1UL; + block_context->slot_ctx.block_height = fd_bank_block_height_get( bank ) + 1UL; // fd_memcpy( block_context->slot_ctx.poh, &slot_ctx->slot_bank.poh, sizeof(fd_pubkey_t) ); // TODO: dump here when process epoch happens after poh verification - fd_memcpy( block_context->slot_ctx.parent_bank_hash, fd_bank_bank_hash_query( slot_ctx->bank ), sizeof(fd_pubkey_t) ); - block_context->slot_ctx.prev_slot = fd_bank_prev_slot_get( slot_ctx->bank ); - block_context->slot_ctx.prev_lps = fd_bank_prev_lamports_per_signature_get( slot_ctx->bank ); - block_context->slot_ctx.prev_epoch_capitalization = fd_bank_capitalization_get( slot_ctx->bank ); + fd_memcpy( block_context->slot_ctx.parent_bank_hash, fd_bank_bank_hash_query( bank ), sizeof(fd_pubkey_t) ); + block_context->slot_ctx.prev_slot = fd_bank_prev_slot_get( bank ); + block_context->slot_ctx.prev_lps = fd_bank_prev_lamports_per_signature_get( bank ); + block_context->slot_ctx.prev_epoch_capitalization = fd_bank_capitalization_get( bank ); /* BlockContext -> EpochContext */ block_context->has_epoch_ctx = true; block_context->epoch_ctx.has_features = true; - dump_sorted_features( fd_bank_features_query( slot_ctx->bank ), &block_context->epoch_ctx.features, spad ); - block_context->epoch_ctx.hashes_per_tick = fd_bank_hashes_per_tick_get( slot_ctx->bank ); - block_context->epoch_ctx.ticks_per_slot = fd_bank_ticks_per_slot_get( slot_ctx->bank ); - block_context->epoch_ctx.slots_per_year = fd_bank_slots_per_year_get( slot_ctx->bank ); + dump_sorted_features( fd_bank_features_query( bank ), &block_context->epoch_ctx.features, spad ); + block_context->epoch_ctx.hashes_per_tick = fd_bank_hashes_per_tick_get( bank ); + block_context->epoch_ctx.ticks_per_slot = fd_bank_ticks_per_slot_get( bank ); + block_context->epoch_ctx.slots_per_year = fd_bank_slots_per_year_get( bank ); block_context->epoch_ctx.has_inflation = true; - fd_inflation_t const * inflation = fd_bank_inflation_query( slot_ctx->bank ); + fd_inflation_t const * inflation = fd_bank_inflation_query( bank ); block_context->epoch_ctx.inflation = (fd_exec_test_inflation_t) { .initial = inflation->initial, .terminal = inflation->terminal, @@ -542,11 +546,10 @@ create_block_context_protobuf_from_block( fd_exec_test_block_context_t * block_c .foundation = inflation->foundation, .foundation_term = inflation->foundation_term, }; - block_context->epoch_ctx.genesis_creation_time = fd_bank_genesis_creation_time_get( slot_ctx->bank ); + block_context->epoch_ctx.genesis_creation_time = fd_bank_genesis_creation_time_get( bank ); /* Dumping stake accounts for this epoch */ - - stakes = fd_bank_stakes_locking_query( slot_ctx->bank ); + stakes = fd_bank_stakes_locking_query( bank ); stake_delegations_pool = fd_stakes_stake_delegations_pool_join( stakes ); stake_delegations_root = fd_stakes_stake_delegations_root_join( stakes ); @@ -556,12 +559,12 @@ create_block_context_protobuf_from_block( fd_exec_test_block_context_t * block_c stake_delegations_root ); curr; curr = fd_delegation_pair_t_map_successor_const( stake_delegations_pool, curr ) ) { - dump_account_if_not_already_dumped( slot_ctx->funk, slot_ctx->funk_txn, &curr->elem.account, spad, block_context->acct_states, &block_context->acct_states_count, NULL ); + dump_account_if_not_already_dumped( funk, funk_txn, &curr->elem.account, spad, block_context->acct_states, &block_context->acct_states_count, NULL ); } - fd_bank_stakes_end_locking_query( slot_ctx->bank ); + fd_bank_stakes_end_locking_query( bank ); - stake_account_keys = fd_bank_stake_account_keys_locking_query( slot_ctx->bank ); + stake_account_keys = fd_bank_stake_account_keys_locking_query( bank ); stake_account_keys_pool = fd_account_keys_account_keys_pool_join( stake_account_keys ); stake_account_keys_root = fd_account_keys_account_keys_root_join( stake_account_keys ); @@ -571,14 +574,14 @@ create_block_context_protobuf_from_block( fd_exec_test_block_context_t * block_c stake_account_keys_root ); curr; curr = fd_account_keys_pair_t_map_successor_const( stake_account_keys_pool, curr ) ) { - dump_account_if_not_already_dumped( slot_ctx->funk, slot_ctx->funk_txn, &curr->elem.key, spad, block_context->acct_states, &block_context->acct_states_count, NULL ); + dump_account_if_not_already_dumped( funk, funk_txn, &curr->elem.key, spad, block_context->acct_states, &block_context->acct_states_count, NULL ); } - fd_bank_stake_account_keys_end_locking_query( slot_ctx->bank ); + fd_bank_stake_account_keys_end_locking_query( bank ); /* Dumping vote accounts for this epoch */ - stakes = fd_bank_stakes_locking_query( slot_ctx->bank ); + stakes = fd_bank_stakes_locking_query( bank ); fd_vote_accounts_pair_global_t_mapnode_t * vote_accounts_pool = fd_vote_accounts_vote_accounts_pool_join( &stakes->vote_accounts ); fd_vote_accounts_pair_global_t_mapnode_t * vote_accounts_root = fd_vote_accounts_vote_accounts_root_join( &stakes->vote_accounts ); @@ -588,12 +591,12 @@ create_block_context_protobuf_from_block( fd_exec_test_block_context_t * block_c vote_accounts_root ); curr; curr = fd_vote_accounts_pair_global_t_map_successor_const( vote_accounts_pool, curr ) ) { - dump_account_if_not_already_dumped( slot_ctx->funk, slot_ctx->funk_txn, &curr->elem.key, spad, block_context->acct_states, &block_context->acct_states_count, NULL ); + dump_account_if_not_already_dumped( funk, funk_txn, &curr->elem.key, spad, block_context->acct_states, &block_context->acct_states_count, NULL ); } - fd_bank_stakes_end_locking_query( slot_ctx->bank ); + fd_bank_stakes_end_locking_query( bank ); - fd_account_keys_global_t const * vote_account_keys = fd_bank_vote_account_keys_locking_query( slot_ctx->bank ); + fd_account_keys_global_t const * vote_account_keys = fd_bank_vote_account_keys_locking_query( bank ); fd_account_keys_pair_t_mapnode_t * vote_account_keys_pool = fd_account_keys_account_keys_pool_join( vote_account_keys ); fd_account_keys_pair_t_mapnode_t * vote_account_keys_root = fd_account_keys_account_keys_root_join( vote_account_keys ); @@ -604,14 +607,15 @@ create_block_context_protobuf_from_block( fd_exec_test_block_context_t * block_c vote_account_keys_root ); curr; curr = fd_account_keys_pair_t_map_successor_const( vote_account_keys_pool, curr ) ) { - dump_account_if_not_already_dumped( slot_ctx->funk, slot_ctx->funk_txn, &curr->elem.key, spad, block_context->acct_states, &block_context->acct_states_count, NULL ); + dump_account_if_not_already_dumped( funk, funk_txn, &curr->elem.key, spad, block_context->acct_states, &block_context->acct_states_count, NULL ); } - fd_bank_vote_account_keys_end_locking_query( slot_ctx->bank ); + fd_bank_vote_account_keys_end_locking_query( bank ); // BlockContext -> EpochContext -> vote_accounts_t_1 (vote accounts at epoch T-1) - fd_vote_accounts_global_t const * next_epoch_stakes_vaccs = fd_bank_next_epoch_stakes_locking_query( slot_ctx->bank ); - dump_vote_accounts( slot_ctx, + fd_vote_accounts_global_t const * next_epoch_stakes_vaccs = fd_bank_next_epoch_stakes_locking_query( bank ); + dump_vote_accounts( funk, + funk_txn, next_epoch_stakes_vaccs, spad, &block_context->epoch_ctx.vote_accounts_t_1, @@ -620,21 +624,24 @@ create_block_context_protobuf_from_block( fd_exec_test_block_context_t * block_c &block_context->acct_states_count ); // BlockContext -> EpochContext -> vote_accounts_t_2 (vote accounts at epoch T-2) - fd_vote_accounts_global_t const * epoch_stakes_vaccs = fd_bank_epoch_stakes_locking_query( slot_ctx->bank ); - dump_vote_accounts( slot_ctx, + fd_vote_accounts_global_t const * epoch_stakes_vaccs = fd_bank_epoch_stakes_locking_query( bank ); + dump_vote_accounts( funk, + funk_txn, epoch_stakes_vaccs, spad, &block_context->epoch_ctx.vote_accounts_t_2, &block_context->epoch_ctx.vote_accounts_t_2_count, block_context->acct_states, &block_context->acct_states_count ); - fd_bank_epoch_stakes_end_locking_query( slot_ctx->bank ); + fd_bank_epoch_stakes_end_locking_query( bank ); } static void create_block_context_protobuf_from_block_tx_only( fd_exec_test_block_context_t * block_context, fd_runtime_block_info_t const * block_info, - fd_exec_slot_ctx_t const * slot_ctx, + fd_bank_t * bank, + fd_funk_t * funk, + fd_funk_txn_t * funk_txn, fd_spad_t * spad ) { /* BlockContext -> txns */ block_context->txns_count = 0U; @@ -652,7 +659,7 @@ create_block_context_protobuf_from_block_tx_only( fd_exec_test_block_context_t * /* BlockContext -> slot_ctx -> poh This currently needs to be done because POH verification is done after epoch boundary processing. That should probably be changed */ - fd_memcpy( block_context->slot_ctx.poh, fd_bank_poh_query( slot_ctx->bank )->hash, sizeof(fd_pubkey_t) ); + fd_memcpy( block_context->slot_ctx.poh, fd_bank_poh_query( bank )->hash, sizeof(fd_pubkey_t) ); /* When iterating over microblocks batches and microblocks, we flatten the batches for the output block context (essentially just one big batch with several microblocks) */ for( ulong i=0UL; imicroblock_batch_cnt; i++ ) { @@ -667,7 +674,7 @@ create_block_context_protobuf_from_block_tx_only( fd_exec_test_block_context_t * for( ulong k=0UL; ktxns[k]; fd_txn_t const * txn_descriptor = TXN( txn_ptr ); - dump_sanitized_transaction( slot_ctx->funk, slot_ctx->funk_txn, txn_descriptor, txn_ptr->payload, spad, &block_context->txns[block_context->txns_count++] ); + dump_sanitized_transaction( funk, funk_txn, txn_descriptor, txn_ptr->payload, spad, &block_context->txns[block_context->txns_count++] ); /* BlockContext -> acct_states */ /* Dump account + alut + programdata accounts (if applicable). There's a lot more brute force work since none of the borrowed accounts are set up yet. We have to: @@ -681,21 +688,21 @@ create_block_context_protobuf_from_block_tx_only( fd_exec_test_block_context_t * fd_acct_addr_t const * account_keys = fd_txn_get_acct_addrs( txn_descriptor, txn_ptr->payload ); for( ushort l=0; lacct_addr_cnt; l++ ) { fd_pubkey_t const * account_key = fd_type_pun_const( &account_keys[l] ); - dump_account_if_not_already_dumped( slot_ctx->funk, slot_ctx->funk_txn, account_key, spad, block_context->acct_states, &block_context->acct_states_count, NULL ); + dump_account_if_not_already_dumped( funk, funk_txn, account_key, spad, block_context->acct_states, &block_context->acct_states_count, NULL ); } // 2 + 3. Dump any ALUT accounts + any accounts referenced in the ALUTs fd_txn_acct_addr_lut_t const * txn_lookup_tables = fd_txn_get_address_tables_const( txn_descriptor ); for( ushort l=0; laddr_table_lookup_cnt; l++ ) { fd_txn_acct_addr_lut_t const * lookup_table = &txn_lookup_tables[l]; - dump_lut_account_and_contained_accounts( slot_ctx, txn_ptr->payload, lookup_table, spad, block_context->acct_states, &block_context->acct_states_count ); + dump_lut_account_and_contained_accounts( funk, funk_txn, txn_ptr->payload, lookup_table, spad, block_context->acct_states, &block_context->acct_states_count ); } // 4. Go through all dumped accounts and dump any executable accounts ulong dumped_accounts = block_context->acct_states_count; for( ulong l=0; lacct_states[l]; - dump_executable_account_if_exists( slot_ctx->funk, slot_ctx->funk_txn, maybe_program_account, spad, block_context->acct_states, &block_context->acct_states_count ); + dump_executable_account_if_exists( funk, funk_txn, maybe_program_account, spad, block_context->acct_states, &block_context->acct_states_count ); } } } @@ -1069,7 +1076,9 @@ fd_dump_txn_to_protobuf( fd_exec_txn_ctx_t * txn_ctx, fd_spad_t * spad ) { } void -fd_dump_block_to_protobuf( fd_exec_slot_ctx_t const * slot_ctx, +fd_dump_block_to_protobuf( fd_bank_t * bank, + fd_funk_t * funk, + fd_funk_txn_t * funk_txn, fd_capture_ctx_t const * capture_ctx, fd_spad_t * spad, fd_exec_test_block_context_t * block_context_msg /* output */ ) { @@ -1078,12 +1087,14 @@ fd_dump_block_to_protobuf( fd_exec_slot_ctx_t const * slot_ctx, FD_LOG_WARNING(( "Capture context may not be NULL when dumping blocks." )); return; } - create_block_context_protobuf_from_block( block_context_msg, slot_ctx, spad ); + create_block_context_protobuf_from_block( block_context_msg, bank, funk, funk_txn, spad ); } void fd_dump_block_to_protobuf_tx_only( fd_runtime_block_info_t const * block_info, - fd_exec_slot_ctx_t const * slot_ctx, + fd_bank_t * bank, + fd_funk_t * funk, + fd_funk_txn_t * funk_txn, fd_capture_ctx_t const * capture_ctx, fd_spad_t * spad, fd_exec_test_block_context_t * block_context_msg ) { @@ -1098,7 +1109,7 @@ fd_dump_block_to_protobuf_tx_only( fd_runtime_block_info_t const * block_info, return; } - create_block_context_protobuf_from_block_tx_only( block_context_msg, block_info, slot_ctx, spad ); + create_block_context_protobuf_from_block_tx_only( block_context_msg, block_info, bank, funk, funk_txn, spad ); /* Output to file */ ulong out_buf_size = 5UL<<30UL; /* 5 GB */ @@ -1107,7 +1118,7 @@ fd_dump_block_to_protobuf_tx_only( fd_runtime_block_info_t const * block_info, if( pb_encode( &stream, FD_EXEC_TEST_BLOCK_CONTEXT_FIELDS, block_context_msg ) ) { char output_filepath[256]; fd_memset( output_filepath, 0, sizeof(output_filepath) ); char * position = fd_cstr_init( output_filepath ); - position = fd_cstr_append_printf( position, "%s/block-%lu.blockctx", capture_ctx->dump_proto_output_dir, slot_ctx->slot ); + position = fd_cstr_append_printf( position, "%s/block-%lu.blockctx", capture_ctx->dump_proto_output_dir, bank->slot ); fd_cstr_fini( position ); FILE * file = fopen(output_filepath, "wb"); diff --git a/src/flamenco/runtime/tests/fd_dump_pb.h b/src/flamenco/runtime/tests/fd_dump_pb.h index 1a599f061d..c8f4359c3c 100644 --- a/src/flamenco/runtime/tests/fd_dump_pb.h +++ b/src/flamenco/runtime/tests/fd_dump_pb.h @@ -55,6 +55,7 @@ #include "../info/fd_instr_info.h" #include "../info/fd_runtime_block_info.h" #include "../../vm/fd_vm.h" +#include "../fd_bank.h" #include "harness/generated/block.pb.h" #include "harness/generated/elf.pb.h" @@ -86,14 +87,18 @@ fd_dump_txn_to_protobuf( fd_exec_txn_ctx_t *txn_ctx, fd_spad_t * spad ); lifetime of the partitions can exist beyond the rewards distribution period so that we don't have to push and pop spad frames in disjoint sections of the runtime. */ void -fd_dump_block_to_protobuf( fd_exec_slot_ctx_t const * slot_ctx, +fd_dump_block_to_protobuf( fd_bank_t * bank, + fd_funk_t * funk, + fd_funk_txn_t * funk_txn, fd_capture_ctx_t const * capture_ctx, fd_spad_t * spad, fd_exec_test_block_context_t * block_context_msg /* output */ ); void fd_dump_block_to_protobuf_tx_only( fd_runtime_block_info_t const * block_info, - fd_exec_slot_ctx_t const * slot_ctx, + fd_bank_t * bank, + fd_funk_t * funk, + fd_funk_txn_t * funk_txn, fd_capture_ctx_t const * capture_ctx, fd_spad_t * spad, fd_exec_test_block_context_t * block_context_msg ); diff --git a/src/flamenco/runtime/tests/harness/fd_block_harness.c b/src/flamenco/runtime/tests/harness/fd_block_harness.c index 77bd65e6c5..13c4c9df0e 100644 --- a/src/flamenco/runtime/tests/harness/fd_block_harness.c +++ b/src/flamenco/runtime/tests/harness/fd_block_harness.c @@ -556,10 +556,10 @@ fd_runtime_fuzz_block_ctx_exec( fd_runtime_fuzz_runner_t * runner, /* Process new epoch may push a new spad frame onto the runtime spad. We should make sure this frame gets cleared (if it was allocated) before executing the block. */ - int is_epoch_boundary = 0; + int is_epoch_boundary = 0; fd_runtime_block_pre_execute_process_new_epoch( slot_ctx->bank, slot_ctx->funk, slot_ctx->funk_txn, tpool, exec_spads, exec_spads_cnt, runtime_spad, &is_epoch_boundary ); - res = fd_runtime_block_execute_tpool( slot_ctx, NULL, NULL, block_info, tpool, exec_spads, exec_spads_cnt, runtime_spad ); + res = fd_runtime_block_execute_tpool( slot_ctx->bank, slot_ctx->funk, slot_ctx->funk_txn, NULL, NULL, block_info, tpool, exec_spads, exec_spads_cnt, runtime_spad ); } FD_SPAD_FRAME_END; fd_tpool_worker_pop( tpool ); From ab00aba601fc92839a16db31aaa5d7bea1304602 Mon Sep 17 00:00:00 2001 From: Ishan Bhatt Date: Tue, 8 Jul 2025 18:32:30 +0000 Subject: [PATCH 15/27] moving more --- src/flamenco/rewards/fd_rewards.c | 4 +- src/flamenco/runtime/fd_runtime.c | 48 ++++++------------- src/flamenco/stakes/fd_stakes.c | 20 ++++---- src/flamenco/stakes/fd_stakes.h | 24 ++++------ .../vm/syscall/test_vm_syscall_curve.c | 4 +- src/flamenco/vm/syscall/test_vm_syscalls.c | 4 +- src/flamenco/vm/test_vm_instr.c | 4 +- src/flamenco/vm/test_vm_interp.c | 8 +--- src/flamenco/vm/test_vm_util.c | 12 ++--- src/flamenco/vm/test_vm_util.h | 3 +- 10 files changed, 50 insertions(+), 81 deletions(-) diff --git a/src/flamenco/rewards/fd_rewards.c b/src/flamenco/rewards/fd_rewards.c index 35e3cfae12..f4048ea985 100644 --- a/src/flamenco/rewards/fd_rewards.c +++ b/src/flamenco/rewards/fd_rewards.c @@ -1304,7 +1304,9 @@ fd_rewards_recalculate_partitioned_rewards( fd_exec_slot_ctx_t * slot_ctx, fd_bank_stakes_end_locking_query( slot_ctx->bank ); /* NOTE: this is just a workaround for now to correctly populate epoch_info. */ - fd_populate_vote_accounts( slot_ctx, + fd_populate_vote_accounts( slot_ctx->bank, + slot_ctx->funk, + slot_ctx->funk_txn, stake_history, new_warmup_cooldown_rate_epoch, &epoch_info, diff --git a/src/flamenco/runtime/fd_runtime.c b/src/flamenco/runtime/fd_runtime.c index 8bb0a190dd..fab6bf59ef 100644 --- a/src/flamenco/runtime/fd_runtime.c +++ b/src/flamenco/runtime/fd_runtime.c @@ -1143,8 +1143,8 @@ fd_runtime_block_execute_finalize_para( fd_bank_t * bank, /* Transaction Level Execution Management */ /******************************************************************************/ -/* fd_runtime_prepare_txns_start is responsible for setting up the task infos, - the slot_ctx, and for setting up the accessed accounts. */ +/* fd_runtime_prepare_txns_start is responsible for setting up the + task infos and for setting up the accessed accounts. */ int fd_runtime_prepare_txns_start( fd_bank_t * bank, @@ -1339,9 +1339,6 @@ fd_runtime_finalize_txn( fd_funk_t * funk, /* for all accounts, if account->is_verified==true, propagate update to cache entry. */ - /* Store transaction info including logs */ - // fd_runtime_finalize_txns_update_blockstore_meta( slot_ctx, task_info, 1UL ); - /* Collect fees */ FD_ATOMIC_FETCH_AND_ADD( fd_bank_execution_fees_modify( bank ), task_info->txn_ctx->execution_fee ); @@ -1738,12 +1735,10 @@ fd_update_stake_delegations( fd_bank_t * bank, fd_bank_stake_account_keys_end_locking_modify( bank ); } -/* Replace the stakes in T-2 (slot_ctx->slot_bank.epoch_stakes) by the stakes at T-1 (epoch_bank->next_epoch_stakes) */ +/* Replace the stakes in T-2 by the stakes at T-1 */ static void fd_update_epoch_stakes( fd_bank_t * bank ) { - /* Copy epoch_bank->next_epoch_stakes into slot_ctx->slot_bank.epoch_stakes */ - ulong total_sz = sizeof(fd_vote_accounts_global_t) + fd_vote_accounts_pair_global_t_map_footprint( 50000UL ) + 4000 * 50000UL; @@ -1758,7 +1753,6 @@ fd_update_epoch_stakes( fd_bank_t * bank ) { } -/* Copy epoch_bank->stakes.vote_accounts into epoch_bank->next_epoch_stakes. */ static void fd_update_next_epoch_stakes( fd_bank_t * bank ) { @@ -1767,8 +1761,6 @@ fd_update_next_epoch_stakes( fd_bank_t * bank ) { The correct solution is to split out the stake delgations from the vote accounts in fd_stakes. */ - /* Copy epoch_ctx->epoch_bank->stakes.vote_accounts into epoch_bank->next_epoch_stakes */ - ulong total_sz = sizeof(fd_vote_accounts_global_t) + fd_vote_accounts_pair_global_t_map_footprint( 50000UL ) + 4000 * 50000UL; @@ -2282,13 +2274,13 @@ fd_runtime_is_epoch_boundary( fd_bank_t * bank, ulong curr_slot, ulong prev_slot Epoch before: T-2 In this function: - - stakes in T-2 (slot_ctx->slot_bank.epoch_stakes) should be replaced by T-1 (epoch_bank->next_epoch_stakes) - - stakes at T-1 (epoch_bank->next_epoch_stakes) should be replaced by updated stakes at T (stakes->vote_accounts) - - leader schedule should be calculated using new T-2 stakes (slot_ctx->slot_bank.epoch_stakes) + - stakes in T-2 should be replaced by T-1 + - stakes at T-1 should be replaced by updated stakes at T + - leader schedule should be calculated using new T-2 stakes Invariant during an epoch T: - epoch_bank->next_epoch_stakes holds the stakes at T-1 - slot_ctx->slot_bank.epoch_stakes holds the stakes at T-2 + bank's next_epoch_stakes holds the stakes at T-1 + bank's epoch_stakes holds the stakes at T-2 */ /* process for the start of a new epoch */ static void @@ -2335,9 +2327,10 @@ fd_runtime_process_new_epoch( fd_bank_t * bank, fd_epoch_info_t temp_info = {0}; fd_epoch_info_new( &temp_info ); - /* If appropiate, use the stakes at T-1 to generate the leader schedule instead of T-2. - This is due to a subtlety in how Agave's stake caches interact when loading from snapshots. - See the comment in fd_exec_slot_ctx_recover_. */ + /* If appropiate, use the stakes at T-1 to generate the leader + schedule instead of T-2. This is due to a subtlety in how Agave's + stake caches interact when loading from snapshots. See the comment + in fd_bank_recover_from_snapshot_manifest. */ if( fd_bank_use_prev_epoch_stake_get( bank ) == epoch ) { fd_update_epoch_stakes( bank ); @@ -2408,13 +2401,13 @@ fd_runtime_process_new_epoch( fd_bank_t * bank, exec_spad_cnt, runtime_spad ); - /* Replace stakes at T-2 (slot_ctx->slot_bank.epoch_stakes) by stakes at T-1 (epoch_bank->next_epoch_stakes) */ + /* Replace stakes at T-2 by stakes at T-1 */ fd_update_epoch_stakes( bank ); - /* Replace stakes at T-1 (epoch_bank->next_epoch_stakes) by updated stakes at T (stakes->vote_accounts) */ + /* Replace stakes at T-1 by updated stakes at T */ fd_update_next_epoch_stakes( bank ); - /* Update current leaders using slot_ctx->slot_bank.epoch_stakes (new T-2 stakes) */ + /* Update current leaders using new T-2 stakes */ fd_runtime_update_leaders( bank, bank->slot, runtime_spad ); FD_LOG_NOTICE(( "fd_process_new_epoch end" )); @@ -3072,12 +3065,6 @@ fd_runtime_init_bank_from_genesis( fd_bank_t * bank, } } - // uchar * pool_mem = fd_spad_alloc( runtime_spad, fd_vote_accounts_pair_t_map_align(), fd_vote_accounts_pair_t_map_footprint( FD_HASH_FOOTPRINT * 400 ) ); - - // slot_ctx->slot_bank.epoch_stakes.vote_accounts_pool = fd_vote_accounts_pair_t_map_join( fd_vote_accounts_pair_t_map_new( pool_mem, FD_HASH_FOOTPRINT * 400 ) ); - // slot_ctx->slot_bank.epoch_stakes.vote_accounts_root = NULL; - - fd_vote_accounts_global_t * epoch_stakes = fd_bank_epoch_stakes_locking_modify( bank ); uchar * pool_mem = (uchar *)fd_ulong_align_up( (ulong)epoch_stakes + sizeof(fd_vote_accounts_global_t), fd_vote_accounts_pair_t_map_align() ); fd_vote_accounts_pair_global_t_mapnode_t * vote_accounts_pool = fd_vote_accounts_pair_global_t_map_join( fd_vote_accounts_pair_global_t_map_new( pool_mem, 50000UL ) ); @@ -3892,11 +3879,8 @@ fd_runtime_block_eval_tpool( fd_banks_t * banks, } while( 0 ); - // FIXME: better way of using starting slot if( FD_UNLIKELY( FD_RUNTIME_EXECUTE_SUCCESS != ret ) ) { FD_LOG_WARNING(( "execution failure, code %d", ret )); - /* Skip over slot next time */ - // slot_ctx->slot = slot+1UL; return ret; } @@ -3917,8 +3901,6 @@ fd_runtime_block_eval_tpool( fd_banks_t * banks, fd_bank_transaction_count_set( bank, fd_bank_transaction_count_get( bank ) + block_info.txn_cnt ); fd_bank_prev_slot_set( bank, slot ); - // FIXME: this shouldn't be doing this, it doesn't work with forking. punting changing it though - // slot_ctx->slot = slot+1UL; return 0; } diff --git a/src/flamenco/stakes/fd_stakes.c b/src/flamenco/stakes/fd_stakes.c index d97c938d25..858bf33857 100644 --- a/src/flamenco/stakes/fd_stakes.c +++ b/src/flamenco/stakes/fd_stakes.c @@ -285,7 +285,9 @@ compute_stake_delegations_tpool_task( void *tpool, /* Populates vote accounts with updated delegated stake from the next cached epoch stakes into temp_info */ void -fd_populate_vote_accounts( fd_exec_slot_ctx_t * slot_ctx, +fd_populate_vote_accounts( fd_bank_t * bank, + fd_funk_t * funk, + fd_funk_txn_t * funk_txn, fd_stake_history_t const * history, ulong * new_rate_activation_epoch, fd_epoch_info_t * temp_info, @@ -296,12 +298,12 @@ fd_populate_vote_accounts( fd_exec_slot_ctx_t * slot_ctx, /* Initialize a temporary vote states cache */ - fd_account_keys_global_t * vote_account_keys = fd_bank_vote_account_keys_locking_modify( slot_ctx->bank ); + fd_account_keys_global_t * vote_account_keys = fd_bank_vote_account_keys_locking_modify( bank ); fd_account_keys_pair_t_mapnode_t * vote_account_keys_pool = fd_account_keys_account_keys_pool_join( vote_account_keys ); fd_account_keys_pair_t_mapnode_t * vote_account_keys_root = fd_account_keys_account_keys_root_join( vote_account_keys ); ulong vote_account_keys_map_sz = vote_account_keys_pool ? fd_account_keys_pair_t_map_size( vote_account_keys_pool, vote_account_keys_root ) : 0UL; - fd_stakes_global_t const * stakes = fd_bank_stakes_locking_query( slot_ctx->bank ); + fd_stakes_global_t const * stakes = fd_bank_stakes_locking_query( bank ); fd_vote_accounts_global_t const * vote_accounts = &stakes->vote_accounts; fd_vote_accounts_pair_global_t_mapnode_t * vote_accounts_pool = fd_vote_accounts_vote_accounts_pool_join( vote_accounts ); fd_vote_accounts_pair_global_t_mapnode_t * vote_accounts_root = fd_vote_accounts_vote_accounts_root_join( vote_accounts ); @@ -328,7 +330,7 @@ fd_populate_vote_accounts( fd_exec_slot_ctx_t * slot_ctx, fd_stake_weight_t_map_insert( pool, &root, entry ); } - fd_bank_stakes_end_locking_query( slot_ctx->bank ); + fd_bank_stakes_end_locking_query( bank ); for( fd_account_keys_pair_t_mapnode_t * n = fd_account_keys_pair_t_map_minimum( vote_account_keys_pool, vote_account_keys_root ); n; @@ -344,7 +346,7 @@ fd_populate_vote_accounts( fd_exec_slot_ctx_t * slot_ctx, } } - fd_bank_vote_account_keys_end_locking_modify( slot_ctx->bank ); + fd_bank_vote_account_keys_end_locking_modify( bank ); fd_compute_stake_delegations_t task_args = { .epoch = stakes->epoch, @@ -374,7 +376,7 @@ fd_populate_vote_accounts( fd_exec_slot_ctx_t * slot_ctx, https://github.com/anza-xyz/agave/blob/v2.2.14/runtime/src/bank/partitioned_epoch_rewards/calculation.rs#L309 */ ulong total_epoch_stake = 0UL; - fd_vote_accounts_global_t const * next_epoch_stakes = fd_bank_next_epoch_stakes_locking_query( slot_ctx->bank ); + fd_vote_accounts_global_t const * next_epoch_stakes = fd_bank_next_epoch_stakes_locking_query( bank ); fd_vote_accounts_pair_global_t_mapnode_t * next_epoch_stakes_pool = fd_vote_accounts_vote_accounts_pool_join( next_epoch_stakes ); fd_vote_accounts_pair_global_t_mapnode_t * next_epoch_stakes_root = fd_vote_accounts_vote_accounts_root_join( next_epoch_stakes ); @@ -383,7 +385,7 @@ fd_populate_vote_accounts( fd_exec_slot_ctx_t * slot_ctx, elem = fd_vote_accounts_pair_global_t_map_successor( next_epoch_stakes_pool, elem ) ) { fd_pubkey_t const * vote_account_pubkey = &elem->elem.key; FD_TXN_ACCOUNT_DECL( acc ); - int rc = fd_txn_account_init_from_funk_readonly( acc, vote_account_pubkey, slot_ctx->funk, slot_ctx->funk_txn ); + int rc = fd_txn_account_init_from_funk_readonly( acc, vote_account_pubkey, funk, funk_txn ); FD_TEST( rc == 0 ); uchar * data = fd_solana_account_data_join( &elem->elem.value ); ulong data_len = elem->elem.value.data_len; @@ -406,9 +408,9 @@ fd_populate_vote_accounts( fd_exec_slot_ctx_t * slot_ctx, FD_LOG_WARNING(( "Failed to deserialize vote account" )); } } - fd_bank_next_epoch_stakes_end_locking_query( slot_ctx->bank ); + fd_bank_next_epoch_stakes_end_locking_query( bank ); - fd_bank_total_epoch_stake_set( slot_ctx->bank, total_epoch_stake ); + fd_bank_total_epoch_stake_set( bank, total_epoch_stake ); } /* diff --git a/src/flamenco/stakes/fd_stakes.h b/src/flamenco/stakes/fd_stakes.h index 9f7e2ef257..78f59e279b 100644 --- a/src/flamenco/stakes/fd_stakes.h +++ b/src/flamenco/stakes/fd_stakes.h @@ -81,12 +81,6 @@ int write_stake_state( fd_txn_account_t * stake_acc_rec, fd_stake_state_v2_t * stake_state ); -void -fd_stakes_remove_stake_delegation( fd_exec_slot_ctx_t * slot_ctx, fd_borrowed_account_t * stake_account, ulong * new_rate_activation_epoch ); - -void -fd_stakes_upsert_stake_delegation( fd_exec_slot_ctx_t * slot_ctx, fd_borrowed_account_t * stake_account, ulong * new_rate_activation_epoch ); - void fd_refresh_vote_accounts( fd_bank_t * bank, fd_funk_t * funk, @@ -102,14 +96,16 @@ fd_refresh_vote_accounts( fd_bank_t * bank, /* A workaround to mimic Agave function get_epoch_reward_calculate_param_info https://github.com/anza-xyz/agave/blob/v2.2.14/runtime/src/bank/partitioned_epoch_rewards/calculation.rs#L299 */ void -fd_populate_vote_accounts( fd_exec_slot_ctx_t * slot_ctx, - fd_stake_history_t const * history, - ulong * new_rate_activation_epoch, - fd_epoch_info_t * temp_info, - fd_tpool_t * tpool, - fd_spad_t * * exec_spads, - ulong exec_spad_cnt, - fd_spad_t * runtime_spad ); +fd_populate_vote_accounts( fd_bank_t * bank, + fd_funk_t * funk, + fd_funk_txn_t * funk_txn, + fd_stake_history_t const * history, + ulong * new_rate_activation_epoch, + fd_epoch_info_t * temp_info, + fd_tpool_t * tpool, + fd_spad_t * * exec_spads, + ulong exec_spad_cnt, + fd_spad_t * runtime_spad ); void fd_accumulate_stake_infos( fd_bank_t * bank, diff --git a/src/flamenco/vm/syscall/test_vm_syscall_curve.c b/src/flamenco/vm/syscall/test_vm_syscall_curve.c index f4ab0d4761..3ca078a751 100644 --- a/src/flamenco/vm/syscall/test_vm_syscall_curve.c +++ b/src/flamenco/vm/syscall/test_vm_syscall_curve.c @@ -78,9 +78,8 @@ main( int argc, set_memory_region( rodata, rodata_sz ); fd_valloc_t valloc = fd_libc_alloc_virtual(); - fd_exec_slot_ctx_t * slot_ctx = fd_valloc_malloc( valloc, FD_EXEC_SLOT_CTX_ALIGN, FD_EXEC_SLOT_CTX_FOOTPRINT ); - fd_exec_instr_ctx_t * instr_ctx = test_vm_minimal_exec_instr_ctx( valloc, slot_ctx ); + fd_exec_instr_ctx_t * instr_ctx = test_vm_minimal_exec_instr_ctx( valloc, 0UL ); fd_features_enable_all( &((fd_exec_txn_ctx_t *)instr_ctx->txn_ctx)->features ); int vm_ok = !!fd_vm_init( @@ -394,7 +393,6 @@ main( int argc, fd_vm_delete ( fd_vm_leave ( vm ) ); fd_sha256_delete( fd_sha256_leave( sha ) ); fd_rng_delete ( fd_rng_leave ( rng ) ); - fd_valloc_free( valloc, slot_ctx ); test_vm_exec_instr_ctx_delete( instr_ctx, fd_libc_alloc_virtual() ); FD_LOG_NOTICE(( "pass" )); diff --git a/src/flamenco/vm/syscall/test_vm_syscalls.c b/src/flamenco/vm/syscall/test_vm_syscalls.c index 8e1bf15661..964187d903 100644 --- a/src/flamenco/vm/syscall/test_vm_syscalls.c +++ b/src/flamenco/vm/syscall/test_vm_syscalls.c @@ -222,9 +222,8 @@ main( int argc, input_mem_regions[3] = (fd_vm_input_region_t){ .haddr = (ulong)input + 501UL, .region_sz = 499UL, .is_writable = 1, .vaddr_offset = 501UL }; fd_valloc_t valloc = fd_libc_alloc_virtual(); - fd_exec_slot_ctx_t * slot_ctx = fd_valloc_malloc( valloc, FD_EXEC_SLOT_CTX_ALIGN, FD_EXEC_SLOT_CTX_FOOTPRINT ); - fd_exec_instr_ctx_t * instr_ctx = test_vm_minimal_exec_instr_ctx( valloc, slot_ctx ); + fd_exec_instr_ctx_t * instr_ctx = test_vm_minimal_exec_instr_ctx( valloc, 0UL ); int vm_ok = !!fd_vm_init( /* vm */ vm, @@ -764,7 +763,6 @@ main( int argc, fd_vm_delete ( fd_vm_leave ( vm ) ); fd_sha256_delete( fd_sha256_leave( sha ) ); fd_rng_delete ( fd_rng_leave ( rng ) ); - fd_valloc_free( valloc, slot_ctx ); test_vm_exec_instr_ctx_delete( instr_ctx, fd_libc_alloc_virtual() ); FD_LOG_NOTICE(( "pass" )); diff --git a/src/flamenco/vm/test_vm_instr.c b/src/flamenco/vm/test_vm_instr.c index 595b280438..1edc7fd474 100644 --- a/src/flamenco/vm/test_vm_instr.c +++ b/src/flamenco/vm/test_vm_instr.c @@ -444,9 +444,8 @@ run_input( test_input_t const * input, aligned_alloc( fd_sbpf_syscalls_align(), fd_sbpf_syscalls_footprint() ) ) ); fd_valloc_t valloc = fd_libc_alloc_virtual(); - fd_exec_slot_ctx_t * slot_ctx = fd_valloc_malloc( valloc, FD_EXEC_SLOT_CTX_ALIGN, FD_EXEC_SLOT_CTX_FOOTPRINT ); - fd_exec_instr_ctx_t * instr_ctx = test_vm_minimal_exec_instr_ctx( valloc, slot_ctx ); + fd_exec_instr_ctx_t * instr_ctx = test_vm_minimal_exec_instr_ctx( valloc, 0UL ); int vm_ok = !!fd_vm_init( /* vm */ vm, @@ -481,7 +480,6 @@ run_input( test_input_t const * input, run_input2( out, vm, force_exec ); /* Clean up */ - fd_valloc_free( valloc, slot_ctx ); test_vm_exec_instr_ctx_delete( instr_ctx, fd_libc_alloc_virtual() ); free( fd_sbpf_syscalls_delete ( fd_sbpf_syscalls_leave ( syscalls ) ) ); free( fd_sbpf_calldests_delete( fd_sbpf_calldests_leave( calldests ) ) ); diff --git a/src/flamenco/vm/test_vm_interp.c b/src/flamenco/vm/test_vm_interp.c index 529b9d6444..438c3b11d7 100644 --- a/src/flamenco/vm/test_vm_interp.c +++ b/src/flamenco/vm/test_vm_interp.c @@ -225,8 +225,7 @@ test_0cu_exit( void ) { ulong text_cnt = 3UL; fd_valloc_t valloc = fd_libc_alloc_virtual(); - fd_exec_slot_ctx_t * slot_ctx = fd_valloc_malloc( valloc, FD_EXEC_SLOT_CTX_ALIGN, FD_EXEC_SLOT_CTX_FOOTPRINT ); - fd_exec_instr_ctx_t * instr_ctx = test_vm_minimal_exec_instr_ctx( valloc, slot_ctx ); + fd_exec_instr_ctx_t * instr_ctx = test_vm_minimal_exec_instr_ctx( valloc, 0UL ); /* Ensure the VM exits with success if the CU count after the final exit instruction reaches zero. */ @@ -293,7 +292,6 @@ test_0cu_exit( void ) { FD_TEST( fd_vm_exec ( vm )==FD_VM_ERR_SIGCOST ); fd_vm_delete( fd_vm_leave( vm ) ); - fd_valloc_free( valloc, slot_ctx ); test_vm_exec_instr_ctx_delete( instr_ctx, fd_libc_alloc_virtual() ); fd_sha256_delete( fd_sha256_leave( sha ) ); } @@ -451,8 +449,7 @@ main( int argc, fd_sbpf_syscalls_t * syscalls = fd_sbpf_syscalls_join( fd_sbpf_syscalls_new( _syscalls ) ); FD_TEST( syscalls ); fd_valloc_t valloc = fd_libc_alloc_virtual(); - fd_exec_slot_ctx_t * slot_ctx = fd_valloc_malloc( valloc, FD_EXEC_SLOT_CTX_ALIGN, FD_EXEC_SLOT_CTX_FOOTPRINT ); - fd_exec_instr_ctx_t * instr_ctx = test_vm_minimal_exec_instr_ctx( valloc, slot_ctx ); + fd_exec_instr_ctx_t * instr_ctx = test_vm_minimal_exec_instr_ctx( valloc, 0UL ); FD_TEST( fd_vm_syscall_register( syscalls, "accumulator", accumulator_syscall )==FD_VM_SUCCESS ); @@ -1107,7 +1104,6 @@ main( int argc, free( text ); fd_sbpf_syscalls_delete( fd_sbpf_syscalls_leave( syscalls ) ); - fd_valloc_free( valloc, slot_ctx ); test_vm_exec_instr_ctx_delete( instr_ctx, valloc ); test_static_syscalls_list(); diff --git a/src/flamenco/vm/test_vm_util.c b/src/flamenco/vm/test_vm_util.c index e542cd743d..c476fd3fe9 100644 --- a/src/flamenco/vm/test_vm_util.c +++ b/src/flamenco/vm/test_vm_util.c @@ -5,7 +5,7 @@ /* Generates a minimal instruction context to supply to fd_vm_t. For now, we just need to setup feature flags. */ fd_exec_instr_ctx_t * -test_vm_minimal_exec_instr_ctx( fd_valloc_t valloc, fd_exec_slot_ctx_t * slot_ctx ) { +test_vm_minimal_exec_instr_ctx( fd_valloc_t valloc, ulong slot ) { void * _ctx = fd_exec_instr_ctx_new( fd_valloc_malloc( valloc, FD_EXEC_INSTR_CTX_ALIGN, FD_EXEC_INSTR_CTX_FOOTPRINT ) ); @@ -18,21 +18,19 @@ test_vm_minimal_exec_instr_ctx( fd_valloc_t valloc, fd_exec_slot_ctx_t * slot_ct /* Keep slot_ctx initialization simple. We only want features ATM. Feel free to change this to use actual init semantics (*_new and *_join), but remember to update the cleanup function below :) */ - fd_exec_txn_ctx_t * txn_ctx = fd_valloc_malloc( valloc, FD_EXEC_TXN_CTX_ALIGN, FD_EXEC_TXN_CTX_FOOTPRINT ); + fd_exec_txn_ctx_t * txn_ctx = fd_valloc_malloc( valloc, FD_EXEC_TXN_CTX_ALIGN, FD_EXEC_TXN_CTX_FOOTPRINT ); - if ( !txn_ctx ) { + if( !txn_ctx ) { return NULL; } - ctx->txn_ctx = txn_ctx; - - slot_ctx->slot = 1UL; + ctx->txn_ctx = txn_ctx; /* Setup feature flags */ fd_features_disable_all( &txn_ctx->features ); fd_features_set( &txn_ctx->features, fd_feature_id_query(TEST_VM_REJECT_CALLX_R10_FEATURE_PREFIX), 0UL ); - txn_ctx->slot = slot_ctx->slot; + txn_ctx->slot = slot; return ctx; } diff --git a/src/flamenco/vm/test_vm_util.h b/src/flamenco/vm/test_vm_util.h index 547e3edaa6..4b5c756075 100644 --- a/src/flamenco/vm/test_vm_util.h +++ b/src/flamenco/vm/test_vm_util.h @@ -10,8 +10,7 @@ #define TEST_VM_DEFAULT_SBPF_VERSION FD_SBPF_V0 fd_exec_instr_ctx_t * -test_vm_minimal_exec_instr_ctx( fd_valloc_t valloc, - fd_exec_slot_ctx_t * slot_ctx ); +test_vm_minimal_exec_instr_ctx( fd_valloc_t valloc, ulong slot ); void test_vm_exec_instr_ctx_delete( fd_exec_instr_ctx_t * ctx, From 87b16c18696251a57cb265f3a91d8c0829185526 Mon Sep 17 00:00:00 2001 From: Ishan Bhatt Date: Tue, 8 Jul 2025 18:57:41 +0000 Subject: [PATCH 16/27] more --- src/app/ledger/main.c | 4 +- src/discof/replay/fd_exec.h | 14 ++--- src/discof/replay/fd_replay_tile.c | 8 ++- src/flamenco/rewards/fd_rewards.c | 56 +++++++++--------- src/flamenco/rewards/fd_rewards.h | 12 ++-- src/flamenco/runtime/fd_runtime.h | 11 ---- .../runtime/program/fd_bpf_program_util.h | 1 - .../runtime/program/fd_builtin_programs.h | 5 +- .../runtime/program/test_program_cache.c | 57 +++++++------------ src/flamenco/runtime/sysvar/fd_sysvar_rent.h | 4 +- .../runtime/tests/harness/fd_block_harness.c | 2 +- .../runtime/tests/harness/fd_instr_harness.h | 1 - src/flamenco/stakes/fd_stakes.c | 2 - 13 files changed, 77 insertions(+), 100 deletions(-) diff --git a/src/app/ledger/main.c b/src/app/ledger/main.c index 3aae2e6f52..bf533a6d89 100644 --- a/src/app/ledger/main.c +++ b/src/app/ledger/main.c @@ -528,7 +528,9 @@ fd_ledger_main_setup( fd_ledger_args_t * args ) { /* After both snapshots have been loaded in, we can determine if we should start distributing rewards. */ - fd_rewards_recalculate_partitioned_rewards( args->slot_ctx, + fd_rewards_recalculate_partitioned_rewards( args->slot_ctx->bank, + args->slot_ctx->funk, + args->slot_ctx->funk_txn, args->tpool, args->exec_spads, args->exec_spad_cnt, diff --git a/src/discof/replay/fd_exec.h b/src/discof/replay/fd_exec.h index 8d4dd7ddc7..c97248d165 100644 --- a/src/discof/replay/fd_exec.h +++ b/src/discof/replay/fd_exec.h @@ -11,20 +11,20 @@ a dcache region and formats it as a specific message type. */ static inline ulong -generate_stake_weight_msg( fd_exec_slot_ctx_t * slot_ctx, - fd_spad_t * runtime_spad, - ulong epoch, - ulong * stake_weight_msg_out ) { +generate_stake_weight_msg( fd_bank_t * bank, + fd_spad_t * runtime_spad, + ulong epoch, + ulong * stake_weight_msg_out ) { fd_stake_weight_msg_t * stake_weight_msg = (fd_stake_weight_msg_t *)fd_type_pun( stake_weight_msg_out ); fd_stake_weight_t * stake_weights = (fd_stake_weight_t *)&stake_weight_msg_out[5]; - fd_vote_accounts_global_t const * vote_accounts = fd_bank_epoch_stakes_locking_query( slot_ctx->bank ); + fd_vote_accounts_global_t const * vote_accounts = fd_bank_epoch_stakes_locking_query( bank ); ulong stake_weight_idx = fd_stake_weights_by_node( vote_accounts, stake_weights, runtime_spad ); - fd_bank_epoch_stakes_end_locking_query( slot_ctx->bank ); + fd_bank_epoch_stakes_end_locking_query( bank ); - fd_epoch_schedule_t const * epoch_schedule = fd_bank_epoch_schedule_query( slot_ctx->bank ); + fd_epoch_schedule_t const * epoch_schedule = fd_bank_epoch_schedule_query( bank ); stake_weight_msg->epoch = epoch; stake_weight_msg->staked_cnt = stake_weight_idx; /* staked_cnt */ diff --git a/src/discof/replay/fd_replay_tile.c b/src/discof/replay/fd_replay_tile.c index 6181b76728..0afb02c91f 100644 --- a/src/discof/replay/fd_replay_tile.c +++ b/src/discof/replay/fd_replay_tile.c @@ -313,7 +313,7 @@ publish_stake_weights( fd_replay_tile_ctx_t * ctx, ulong * stake_weights_msg = fd_chunk_to_laddr( ctx->stake_out->mem, ctx->stake_out->chunk ); ulong epoch = fd_slot_to_leader_schedule_epoch( epoch_schedule, slot_ctx->slot ); - ulong stake_weights_sz = generate_stake_weight_msg( slot_ctx, ctx->runtime_spad, epoch - 1, stake_weights_msg ); + ulong stake_weights_sz = generate_stake_weight_msg( slot_ctx->bank, ctx->runtime_spad, epoch - 1, stake_weights_msg ); ulong stake_weights_sig = 4UL; fd_stem_publish( stem, 0UL, stake_weights_sig, ctx->stake_out->chunk, stake_weights_sz, 0UL, 0UL, fd_frag_meta_ts_comp( fd_tickcount() ) ); ctx->stake_out->chunk = fd_dcache_compact_next( ctx->stake_out->chunk, stake_weights_sz, ctx->stake_out->chunk0, ctx->stake_out->wmark ); @@ -329,7 +329,7 @@ publish_stake_weights( fd_replay_tile_ctx_t * ctx, ulong * stake_weights_msg = fd_chunk_to_laddr( ctx->stake_out->mem, ctx->stake_out->chunk ); ulong epoch = fd_slot_to_leader_schedule_epoch( epoch_schedule, slot_ctx->slot ); /* epoch */ - ulong stake_weights_sz = generate_stake_weight_msg( slot_ctx, ctx->runtime_spad, epoch, stake_weights_msg ); + ulong stake_weights_sz = generate_stake_weight_msg( slot_ctx->bank, ctx->runtime_spad, epoch, stake_weights_msg ); ulong stake_weights_sig = 4UL; fd_stem_publish( stem, 0UL, stake_weights_sig, ctx->stake_out->chunk, stake_weights_sz, 0UL, 0UL, fd_frag_meta_ts_comp( fd_tickcount() ) ); ctx->stake_out->chunk = fd_dcache_compact_next( ctx->stake_out->chunk, stake_weights_sz, ctx->stake_out->chunk0, ctx->stake_out->wmark ); @@ -1402,7 +1402,9 @@ init_after_snapshot( fd_replay_tile_ctx_t * ctx, /* After both snapshots have been loaded in, we can determine if we should start distributing rewards. */ - fd_rewards_recalculate_partitioned_rewards( ctx->slot_ctx, + fd_rewards_recalculate_partitioned_rewards( ctx->slot_ctx->bank, + ctx->slot_ctx->funk, + ctx->slot_ctx->funk_txn, NULL, ctx->exec_spads, ctx->exec_spad_cnt, diff --git a/src/flamenco/rewards/fd_rewards.c b/src/flamenco/rewards/fd_rewards.c index f4048ea985..36f03d8c29 100644 --- a/src/flamenco/rewards/fd_rewards.c +++ b/src/flamenco/rewards/fd_rewards.c @@ -1217,15 +1217,17 @@ fd_begin_partitioned_rewards( fd_bank_t * bank, https://github.com/anza-xyz/agave/blob/v2.2.14/runtime/src/bank/partitioned_epoch_rewards/calculation.rs#L521 */ void -fd_rewards_recalculate_partitioned_rewards( fd_exec_slot_ctx_t * slot_ctx, - fd_tpool_t * tpool, - fd_spad_t * * exec_spads, - ulong exec_spad_cnt, - fd_spad_t * runtime_spad ) { - fd_sysvar_epoch_rewards_t * epoch_rewards = fd_sysvar_epoch_rewards_read( slot_ctx->funk, slot_ctx->funk_txn, runtime_spad ); +fd_rewards_recalculate_partitioned_rewards( fd_bank_t * bank, + fd_funk_t * funk, + fd_funk_txn_t * funk_txn, + fd_tpool_t * tpool, + fd_spad_t * * exec_spads, + ulong exec_spad_cnt, + fd_spad_t * runtime_spad ) { + fd_sysvar_epoch_rewards_t * epoch_rewards = fd_sysvar_epoch_rewards_read( funk, funk_txn, runtime_spad ); if( FD_UNLIKELY( epoch_rewards == NULL ) ) { FD_LOG_NOTICE(( "Failed to read or decode epoch rewards sysvar - may not have been created yet" )); - set_epoch_reward_status_inactive( slot_ctx->bank ); + set_epoch_reward_status_inactive( bank ); return; } @@ -1245,24 +1247,24 @@ fd_rewards_recalculate_partitioned_rewards( fd_exec_slot_ctx_t * slot_ctx, https://github.com/anza-xyz/agave/blob/2316fea4c0852e59c071f72d72db020017ffd7d0/runtime/src/bank/partitioned_epoch_rewards/calculation.rs#L566 */ FD_LOG_NOTICE(( "epoch rewards is active" )); - fd_epoch_schedule_t const * epoch_schedule = fd_bank_epoch_schedule_query( slot_ctx->bank ); - ulong epoch = fd_slot_to_epoch( epoch_schedule, slot_ctx->slot, NULL ); + fd_epoch_schedule_t const * epoch_schedule = fd_bank_epoch_schedule_query( bank ); + ulong epoch = fd_slot_to_epoch( epoch_schedule, bank->slot, NULL ); ulong rewarded_epoch = fd_ulong_sat_sub( epoch, 1UL ); int _err[1] = {0}; ulong * new_warmup_cooldown_rate_epoch = fd_spad_alloc( runtime_spad, alignof(ulong), sizeof(ulong) ); - int is_some = fd_new_warmup_cooldown_rate_epoch( slot_ctx->slot, - slot_ctx->funk, - slot_ctx->funk_txn, + int is_some = fd_new_warmup_cooldown_rate_epoch( bank->slot, + funk, + funk_txn, runtime_spad, - fd_bank_features_query( slot_ctx->bank ), + fd_bank_features_query( bank ), new_warmup_cooldown_rate_epoch, _err ); if( FD_UNLIKELY( !is_some ) ) { new_warmup_cooldown_rate_epoch = NULL; } - fd_stake_history_t const * stake_history = fd_sysvar_stake_history_read( slot_ctx->funk, slot_ctx->funk_txn, runtime_spad ); + fd_stake_history_t const * stake_history = fd_sysvar_stake_history_read( funk, funk_txn, runtime_spad ); if( FD_UNLIKELY( !stake_history ) ) { FD_LOG_ERR(( "Unable to read and decode stake history sysvar" )); } @@ -1271,7 +1273,7 @@ fd_rewards_recalculate_partitioned_rewards( fd_exec_slot_ctx_t * slot_ctx, .rewards = epoch_rewards->total_rewards }; /* Populate vote and stake state info from vote and stakes cache for the stake vote rewards calculation */ - fd_stakes_global_t const * stakes = fd_bank_stakes_locking_query( slot_ctx->bank ); + fd_stakes_global_t const * stakes = fd_bank_stakes_locking_query( bank ); fd_delegation_pair_t_mapnode_t * stake_delegations_pool = fd_stakes_stake_delegations_pool_join( stakes ); fd_delegation_pair_t_mapnode_t * stake_delegations_root = fd_stakes_stake_delegations_root_join( stakes ); @@ -1288,9 +1290,9 @@ fd_rewards_recalculate_partitioned_rewards( fd_exec_slot_ctx_t * slot_ctx, .deactivating = 0UL }; - fd_accumulate_stake_infos( slot_ctx->bank, - slot_ctx->funk, - slot_ctx->funk_txn, + fd_accumulate_stake_infos( bank, + funk, + funk_txn, stakes, stake_history, new_warmup_cooldown_rate_epoch, @@ -1301,12 +1303,12 @@ fd_rewards_recalculate_partitioned_rewards( fd_exec_slot_ctx_t * slot_ctx, exec_spad_cnt, runtime_spad ); - fd_bank_stakes_end_locking_query( slot_ctx->bank ); + fd_bank_stakes_end_locking_query( bank ); /* NOTE: this is just a workaround for now to correctly populate epoch_info. */ - fd_populate_vote_accounts( slot_ctx->bank, - slot_ctx->funk, - slot_ctx->funk_txn, + fd_populate_vote_accounts( bank, + funk, + funk_txn, stake_history, new_warmup_cooldown_rate_epoch, &epoch_info, @@ -1317,9 +1319,9 @@ fd_rewards_recalculate_partitioned_rewards( fd_exec_slot_ctx_t * slot_ctx, /* In future, the calculation will be cached in the snapshot, but for now we just re-calculate it (as Agave does). */ fd_calculate_stake_vote_rewards_result_t calculate_stake_vote_rewards_result[1]; - calculate_stake_vote_rewards( slot_ctx->bank, - slot_ctx->funk, - slot_ctx->funk_txn, + calculate_stake_vote_rewards( bank, + funk, + funk_txn, stake_history, rewarded_epoch, &point_value, @@ -1344,10 +1346,10 @@ fd_rewards_recalculate_partitioned_rewards( fd_exec_slot_ctx_t * slot_ctx, runtime_spad ); /* Update the epoch reward status with the newly re-calculated partitions. */ - set_epoch_reward_status_active( slot_ctx->bank, + set_epoch_reward_status_active( bank, epoch_rewards->distribution_starting_block_height, &stake_rewards_by_partition->partitioned_stake_rewards ); } else { - set_epoch_reward_status_inactive( slot_ctx->bank ); + set_epoch_reward_status_inactive( bank ); } } diff --git a/src/flamenco/rewards/fd_rewards.h b/src/flamenco/rewards/fd_rewards.h index 6ea1a587fd..361c502b79 100644 --- a/src/flamenco/rewards/fd_rewards.h +++ b/src/flamenco/rewards/fd_rewards.h @@ -47,11 +47,13 @@ fd_begin_partitioned_rewards( fd_bank_t * bank, fd_spad_t * runtime_spad ); void -fd_rewards_recalculate_partitioned_rewards( fd_exec_slot_ctx_t * slot_ctx, - fd_tpool_t * tpool, - fd_spad_t * * exec_spads, - ulong exec_spad_cnt, - fd_spad_t * runtime_spad ); +fd_rewards_recalculate_partitioned_rewards( fd_bank_t * bank, + fd_funk_t * funk, + fd_funk_txn_t * funk_txn, + fd_tpool_t * tpool, + fd_spad_t * * exec_spads, + ulong exec_spad_cnt, + fd_spad_t * runtime_spad ); void fd_distribute_partitioned_epoch_rewards( fd_bank_t * bank, diff --git a/src/flamenco/runtime/fd_runtime.h b/src/flamenco/runtime/fd_runtime.h index b1e856f907..9ac45c796c 100644 --- a/src/flamenco/runtime/fd_runtime.h +++ b/src/flamenco/runtime/fd_runtime.h @@ -545,17 +545,6 @@ fd_runtime_prepare_txns_start( fd_bank_t * bank, void fd_runtime_pre_execute_check( fd_execute_txn_task_info_t * task_info ); -/* fd_runtime_process_txns is responsible for end-to-end preparing, executing, - and finalizing a list of transactions. It will execute all of the - transactions on a single core. */ -int -fd_runtime_process_txns( fd_exec_slot_ctx_t * slot_ctx, - fd_capture_ctx_t * capture_ctx, - fd_txn_p_t * txns, - ulong txn_cnt, - fd_spad_t * exec_spad, - fd_spad_t * runtime_spad ); - /* fd_runtime_execute_txns_in_microblock_stream is responsible for end-to-end preparing, executing and finalizng a list of transactions. It assumes that all transactions are conflict-free. */ diff --git a/src/flamenco/runtime/program/fd_bpf_program_util.h b/src/flamenco/runtime/program/fd_bpf_program_util.h index 2373ec17ff..bf5d728289 100644 --- a/src/flamenco/runtime/program/fd_bpf_program_util.h +++ b/src/flamenco/runtime/program/fd_bpf_program_util.h @@ -3,7 +3,6 @@ #include "../../fd_flamenco_base.h" #include "../fd_acc_mgr.h" -#include "../context/fd_exec_slot_ctx.h" #include "../../vm/syscall/fd_vm_syscall.h" #include "../fd_system_ids.h" diff --git a/src/flamenco/runtime/program/fd_builtin_programs.h b/src/flamenco/runtime/program/fd_builtin_programs.h index 0c9de67055..2acfc8575a 100644 --- a/src/flamenco/runtime/program/fd_builtin_programs.h +++ b/src/flamenco/runtime/program/fd_builtin_programs.h @@ -2,10 +2,7 @@ #define HEADER_fd_src_flamenco_runtime_program_fd_buildin_programs_h #include "../../fd_flamenco_base.h" -#include "../../runtime/fd_system_ids.h" -#include "../../features/fd_features.h" -#include "../context/fd_exec_slot_ctx.h" -#include "../fd_system_ids.h" +#include "../fd_bank.h" #include "../fd_system_ids_pp.h" #define NO_ENABLE_FEATURE_ID ULONG_MAX diff --git a/src/flamenco/runtime/program/test_program_cache.c b/src/flamenco/runtime/program/test_program_cache.c index 7bc135ef63..111e108608 100644 --- a/src/flamenco/runtime/program/test_program_cache.c +++ b/src/flamenco/runtime/program/test_program_cache.c @@ -19,18 +19,15 @@ static fd_pubkey_t const test_program_pubkey = { static ulong const SPAD_MEM_MAX = 100UL << 20; /* 100MB */ /* Test setup and teardown helpers */ -static fd_wksp_t * test_wksp = NULL; -static fd_funk_t * test_funk = NULL; -static fd_spad_t * test_spad = NULL; -static fd_exec_slot_ctx_t * test_slot_ctx = NULL; +static fd_wksp_t * test_wksp = NULL; +static fd_funk_t * test_funk = NULL; +static fd_spad_t * test_spad = NULL; +static fd_funk_txn_t * test_funk_txn = NULL; +static fd_bank_t * test_bank = NULL; +static fd_banks_t * test_banks = NULL; static void test_teardown( void ) { - if( test_slot_ctx ) { - fd_exec_slot_ctx_leave( test_slot_ctx ); - test_slot_ctx = NULL; - } - if( test_spad ) { fd_spad_leave( test_spad ); test_spad = NULL; @@ -69,7 +66,7 @@ create_test_account( fd_pubkey_t const * pubkey, int err = fd_txn_account_init_from_funk_mutable( /* acc */ acc, /* pubkey */ pubkey, /* funk */ test_funk, - /* txn */ test_slot_ctx->funk_txn, + /* txn */ test_funk_txn, /* do_create */ 1, /* min_data_sz */ data_len ); FD_TEST( !err ); @@ -88,7 +85,7 @@ create_test_account( fd_pubkey_t const * pubkey, /* make the account read-only by default */ acc->vt->set_readonly( acc ); - fd_txn_account_mutable_fini( acc, test_funk, test_slot_ctx->funk_txn ); + fd_txn_account_mutable_fini( acc, test_funk, test_funk_txn ); } /* Test 1: Account doesn't exist */ @@ -97,13 +94,13 @@ test_account_does_not_exist( void ) { FD_LOG_NOTICE(( "Testing: Account doesn't exist" )); fd_funk_txn_t * funk_txn = create_test_funk_txn(); - test_slot_ctx->funk_txn = funk_txn; + test_funk_txn = funk_txn; /* Call with a non-existent pubkey */ fd_pubkey_t const non_existent_pubkey = {0}; /* This should return early without doing anything */ - fd_bpf_program_update_program_cache( test_slot_ctx->bank, test_slot_ctx->funk, test_slot_ctx->funk_txn , &non_existent_pubkey, test_spad ); + fd_bpf_program_update_program_cache( test_bank, test_funk, test_funk_txn , &non_existent_pubkey, test_spad ); /* Verify no cache entry was created */ fd_sbpf_validated_program_t const * valid_prog = NULL; @@ -119,7 +116,7 @@ test_account_not_bpf_loader_owner( void ) { FD_LOG_NOTICE(( "Testing: Account exists but is not owned by a BPF loader" )); fd_funk_txn_t * funk_txn = create_test_funk_txn(); - test_slot_ctx->funk_txn = funk_txn; + test_funk_txn = funk_txn; /* Create an account owned by a non-BPF loader */ create_test_account( &test_program_pubkey, @@ -129,7 +126,7 @@ test_account_not_bpf_loader_owner( void ) { 1 ); /* This should return early without doing anything */ - fd_bpf_program_update_program_cache( test_slot_ctx->bank, test_slot_ctx->funk, test_slot_ctx->funk_txn, &test_program_pubkey, test_spad ); + fd_bpf_program_update_program_cache( test_bank, test_funk, test_funk_txn, &test_program_pubkey, test_spad ); /* Verify no cache entry was created */ fd_sbpf_validated_program_t const * valid_prog = NULL; @@ -145,7 +142,7 @@ test_invalid_program_not_in_cache_first_time( void ) { FD_LOG_NOTICE(( "Testing: Program is not in cache yet (first time), but program fails validations" )); fd_funk_txn_t * funk_txn = create_test_funk_txn(); - test_slot_ctx->funk_txn = funk_txn; + test_funk_txn = funk_txn; /* Create a BPF loader account */ create_test_account( &test_program_pubkey, @@ -155,7 +152,7 @@ test_invalid_program_not_in_cache_first_time( void ) { 1 ); /* This should create a cache entry */ - fd_bpf_program_update_program_cache( test_slot_ctx->bank, test_slot_ctx->funk, test_slot_ctx->funk_txn, &test_program_pubkey, test_spad ); + fd_bpf_program_update_program_cache( test_bank, test_funk, test_funk_txn, &test_program_pubkey, test_spad ); /* Verify cache entry was created */ fd_sbpf_validated_program_t const * valid_prog = NULL; @@ -174,7 +171,7 @@ test_valid_program_not_in_cache_first_time( void ) { FD_LOG_NOTICE(( "Testing: Program is not in cache yet (first time), but program passes validations" )); fd_funk_txn_t * funk_txn = create_test_funk_txn(); - test_slot_ctx->funk_txn = funk_txn; + test_funk_txn = funk_txn; /* Create a BPF loader account */ create_test_account( &test_program_pubkey, @@ -184,7 +181,7 @@ test_valid_program_not_in_cache_first_time( void ) { 1 ); /* This should create a cache entry */ - fd_bpf_program_update_program_cache( test_slot_ctx->bank, test_slot_ctx->funk, test_slot_ctx->funk_txn, &test_program_pubkey, test_spad ); + fd_bpf_program_update_program_cache( test_bank, test_funk, test_funk_txn, &test_program_pubkey, test_spad ); /* Verify cache entry was created */ fd_sbpf_validated_program_t const * valid_prog = NULL; @@ -204,7 +201,7 @@ test_program_in_cache_needs_reverification( void ) { FD_LOG_NOTICE(( "Testing: Program is in cache but needs reverification (different epoch)" )); fd_funk_txn_t * funk_txn = create_test_funk_txn(); - test_slot_ctx->funk_txn = funk_txn; + test_funk_txn = funk_txn; /* Create a BPF loader account */ create_test_account( &test_program_pubkey, @@ -214,7 +211,7 @@ test_program_in_cache_needs_reverification( void ) { 1 ); /* First call to create cache entry */ - fd_bpf_program_update_program_cache( test_slot_ctx->bank, test_slot_ctx->funk, test_slot_ctx->funk_txn, &test_program_pubkey, test_spad ); + fd_bpf_program_update_program_cache( test_bank, test_funk, test_funk_txn, &test_program_pubkey, test_spad ); /* Verify cache entry was created */ fd_sbpf_validated_program_t const * valid_prog = NULL; @@ -226,10 +223,10 @@ test_program_in_cache_needs_reverification( void ) { FD_TEST( valid_prog->last_epoch_verification_ran==1UL ); /* Fast forward to next epoch */ - test_slot_ctx->bank->slot += 432000UL; + test_bank->slot += 432000UL; /* This should trigger reverification */ - fd_bpf_program_update_program_cache( test_slot_ctx->bank, test_slot_ctx->funk, test_slot_ctx->funk_txn, &test_program_pubkey, test_spad ); + fd_bpf_program_update_program_cache( test_bank, test_funk, test_funk_txn, &test_program_pubkey, test_spad ); /* Verify the cache entry was updated */ err = fd_bpf_load_cache_entry( test_funk, funk_txn, &test_program_pubkey, &valid_prog ); @@ -277,16 +274,6 @@ main( int argc, FD_SPAD_FRAME_BEGIN( test_spad ) { - /* Create slot context */ - ulong slot_align = FD_EXEC_SLOT_CTX_ALIGN; - ulong slot_footprint = FD_EXEC_SLOT_CTX_FOOTPRINT; - uchar * slot_mem = fd_spad_alloc( test_spad, slot_align, slot_footprint ); - test_slot_ctx = fd_exec_slot_ctx_join( fd_exec_slot_ctx_new( slot_mem ) ); - FD_TEST( test_slot_ctx ); - - /* Set up slot context */ - test_slot_ctx->funk = test_funk; - /* Set up bank */ ulong banks_footprint = fd_banks_footprint( 1UL ); uchar * banks_mem = fd_wksp_alloc_laddr( test_wksp, fd_banks_align(), banks_footprint, TEST_WKSP_TAG ); @@ -297,8 +284,8 @@ main( int argc, fd_bank_t * bank = fd_banks_init_bank( banks, 433000UL ); FD_TEST( bank ); - test_slot_ctx->bank = bank; - test_slot_ctx->banks = banks; + test_bank = bank; + test_banks = banks; fd_epoch_schedule_t epoch_schedule = { .slots_per_epoch = 432000UL, diff --git a/src/flamenco/runtime/sysvar/fd_sysvar_rent.h b/src/flamenco/runtime/sysvar/fd_sysvar_rent.h index 1a06455edd..86f5a4b9e6 100644 --- a/src/flamenco/runtime/sysvar/fd_sysvar_rent.h +++ b/src/flamenco/runtime/sysvar/fd_sysvar_rent.h @@ -6,8 +6,8 @@ #include "../fd_bank.h" FD_PROTOTYPES_BEGIN -/* fd_sysvar_rent_init copies the cached rent sysvar stored from - fd_exec_slot_ctx_t to the corresponding account in the database. +/* fd_sysvar_rent_init copies the cached rent sysvar to the + corresponding account in the database. Note that it does NOT initialize global->bank.rent */ void diff --git a/src/flamenco/runtime/tests/harness/fd_block_harness.c b/src/flamenco/runtime/tests/harness/fd_block_harness.c index 13c4c9df0e..9d3f6dd5ad 100644 --- a/src/flamenco/runtime/tests/harness/fd_block_harness.c +++ b/src/flamenco/runtime/tests/harness/fd_block_harness.c @@ -552,7 +552,7 @@ fd_runtime_fuzz_block_ctx_exec( fd_runtime_fuzz_runner_t * runner, // Prepare. Execute. Finalize. FD_SPAD_FRAME_BEGIN( runtime_spad ) { - fd_rewards_recalculate_partitioned_rewards( slot_ctx, tpool, exec_spads, exec_spads_cnt, runtime_spad ); + fd_rewards_recalculate_partitioned_rewards( slot_ctx->bank, slot_ctx->funk, slot_ctx->funk_txn, tpool, exec_spads, exec_spads_cnt, runtime_spad ); /* Process new epoch may push a new spad frame onto the runtime spad. We should make sure this frame gets cleared (if it was allocated) before executing the block. */ diff --git a/src/flamenco/runtime/tests/harness/fd_instr_harness.h b/src/flamenco/runtime/tests/harness/fd_instr_harness.h index b007a98ed7..662dad2c92 100644 --- a/src/flamenco/runtime/tests/harness/fd_instr_harness.h +++ b/src/flamenco/runtime/tests/harness/fd_instr_harness.h @@ -8,7 +8,6 @@ #include "../../fd_executor.h" #include "../../program/fd_bpf_program_util.h" -#include "../../context/fd_exec_slot_ctx.h" #include "../../context/fd_exec_txn_ctx.h" #include "../../program/fd_bpf_loader_program.h" #include "../../../fd_flamenco.h" diff --git a/src/flamenco/stakes/fd_stakes.c b/src/flamenco/stakes/fd_stakes.c index 858bf33857..5baf97a97d 100644 --- a/src/flamenco/stakes/fd_stakes.c +++ b/src/flamenco/stakes/fd_stakes.c @@ -1,6 +1,4 @@ #include "fd_stakes.h" -#include "../runtime/fd_system_ids.h" -#include "../runtime/context/fd_exec_slot_ctx.h" #include "../runtime/program/fd_stake_program.h" #include "../runtime/sysvar/fd_sysvar_stake_history.h" From 0652e6cbe2def5e5480fbefc41ac6698d2e5e448 Mon Sep 17 00:00:00 2001 From: Ishan Bhatt Date: Tue, 8 Jul 2025 19:10:53 +0000 Subject: [PATCH 17/27] little by little --- src/discof/exec/fd_exec_tile.c | 5 -- src/discof/replay/fd_replay.c | 2 +- .../runtime/context/fd_exec_txn_ctx.h | 1 - src/flamenco/runtime/fd_executor.c | 16 ++---- src/flamenco/runtime/fd_executor.h | 1 - .../runtime/program/fd_bpf_loader_program.c | 2 - .../runtime/sysvar/fd_sysvar_slot_history.c | 5 +- .../runtime/sysvar/fd_sysvar_slot_history.h | 3 +- .../runtime/tests/harness/fd_instr_harness.c | 55 ++++++++----------- 9 files changed, 29 insertions(+), 61 deletions(-) diff --git a/src/discof/exec/fd_exec_tile.c b/src/discof/exec/fd_exec_tile.c index 5163e64385..95e93bc0dd 100644 --- a/src/discof/exec/fd_exec_tile.c +++ b/src/discof/exec/fd_exec_tile.c @@ -507,11 +507,6 @@ unprivileged_init( fd_topo_t * topo, ctx->txn_ctx = fd_exec_txn_ctx_join( fd_exec_txn_ctx_new( txn_ctx_mem ), ctx->exec_spad, ctx->exec_spad_wksp ); *ctx->txn_ctx->funk = *ctx->funk; - ctx->txn_ctx->runtime_pub_wksp = ctx->runtime_public_wksp; - if( FD_UNLIKELY( !ctx->txn_ctx->runtime_pub_wksp ) ) { - FD_LOG_ERR(( "Failed to find public wksp" )); - } - ctx->txn_ctx->bank_hash_cmp = ctx->bank_hash_cmp; /********************************************************************/ diff --git a/src/discof/replay/fd_replay.c b/src/discof/replay/fd_replay.c index b1733a737c..18c03a5431 100644 --- a/src/discof/replay/fd_replay.c +++ b/src/discof/replay/fd_replay.c @@ -119,7 +119,7 @@ leader_pipeline( void ) { // for( fd_fork_frontier_iter_t iter = fd_fork_frontier_iter_init( ctx->forks->frontier, ctx->forks->pool ); // !fd_fork_frontier_iter_done( iter, ctx->forks->frontier, ctx->forks->pool ); // iter = fd_fork_frontier_iter_next( iter, ctx->forks->frontier, ctx->forks->pool ) ) { - // fd_exec_slot_ctx_t * ele = &fd_fork_frontier_iter_ele( iter, ctx->forks->frontier, ctx->forks->pool )->slot_ctx; + // * ele = &fd_fork_frontier_iter_ele( iter, ctx->forks->frontier, ctx->forks->pool )->slot_ctx; // if ( max_slot < ele->slot_bank.slot ) { // max_slot = ele->slot_bank.slot; // } diff --git a/src/flamenco/runtime/context/fd_exec_txn_ctx.h b/src/flamenco/runtime/context/fd_exec_txn_ctx.h index 32203efd47..f7d895b17f 100644 --- a/src/flamenco/runtime/context/fd_exec_txn_ctx.h +++ b/src/flamenco/runtime/context/fd_exec_txn_ctx.h @@ -76,7 +76,6 @@ struct fd_exec_txn_ctx { fd_bank_hash_cmp_t * bank_hash_cmp; fd_funk_txn_t * funk_txn; fd_funk_t funk[1]; - fd_wksp_t * runtime_pub_wksp; ulong slot; fd_spad_t * spad; /* Sized out to handle the worst case footprint of single transaction execution. */ diff --git a/src/flamenco/runtime/fd_executor.c b/src/flamenco/runtime/fd_executor.c index 65c9166eab..f1b009c27a 100644 --- a/src/flamenco/runtime/fd_executor.c +++ b/src/flamenco/runtime/fd_executor.c @@ -324,9 +324,7 @@ status_check_tower( ulong slot, void * _ctx ) { FD_LOG_ERR(( "Unable to read and decode slot history sysvar" )); } - if( fd_sysvar_slot_history_find_slot( slot_history, - slot, - ctx->runtime_pub_wksp ) == FD_SLOT_HISTORY_SLOT_FOUND ) { + if( fd_sysvar_slot_history_find_slot( slot_history, slot ) == FD_SLOT_HISTORY_SLOT_FOUND ) { return 1; } @@ -1231,13 +1229,10 @@ void fd_exec_txn_ctx_from_exec_slot_ctx( fd_bank_t * bank, fd_exec_txn_ctx_t * ctx, fd_wksp_t const * funk_wksp, - fd_wksp_t const * runtime_pub_wksp, ulong funk_txn_gaddr, ulong funk_gaddr, fd_bank_hash_cmp_t * bank_hash_cmp ) { - ctx->runtime_pub_wksp = (fd_wksp_t *)runtime_pub_wksp; - ctx->funk_txn = fd_wksp_laddr( funk_wksp, funk_txn_gaddr ); if( FD_UNLIKELY( !ctx->funk_txn ) ) { FD_LOG_ERR(( "Could not find valid funk transaction" )); @@ -1368,18 +1363,15 @@ fd_execute_txn_prepare_start( fd_bank_t * bank, fd_txn_t const * txn_descriptor, fd_rawtxn_b_t const * txn_raw ) { - fd_wksp_t * funk_wksp = fd_funk_wksp( funk ); - /* FIXME: just pass in the runtime workspace, instead of getting it from fd_wksp_containing */ - fd_wksp_t * runtime_pub_wksp = fd_wksp_containing( bank ); - ulong funk_txn_gaddr = fd_wksp_gaddr( funk_wksp, funk_txn ); - ulong funk_gaddr = fd_wksp_gaddr( funk_wksp, funk->shmem ); + fd_wksp_t * funk_wksp = fd_funk_wksp( funk ); + ulong funk_txn_gaddr = fd_wksp_gaddr( funk_wksp, funk_txn ); + ulong funk_gaddr = fd_wksp_gaddr( funk_wksp, funk->shmem ); /* Init txn ctx */ fd_exec_txn_ctx_new( txn_ctx ); fd_exec_txn_ctx_from_exec_slot_ctx( bank, txn_ctx, funk_wksp, - runtime_pub_wksp, funk_txn_gaddr, funk_gaddr, NULL ); diff --git a/src/flamenco/runtime/fd_executor.h b/src/flamenco/runtime/fd_executor.h index 5b5dc97d8c..b401a3832d 100644 --- a/src/flamenco/runtime/fd_executor.h +++ b/src/flamenco/runtime/fd_executor.h @@ -152,7 +152,6 @@ void fd_exec_txn_ctx_from_exec_slot_ctx( fd_bank_t * bank, fd_exec_txn_ctx_t * ctx, fd_wksp_t const * funk_wksp, - fd_wksp_t const * runtime_pub_wksp, ulong funk_txn_gaddr, ulong funk_gaddr, fd_bank_hash_cmp_t * bank_hash_cmp ); diff --git a/src/flamenco/runtime/program/fd_bpf_loader_program.c b/src/flamenco/runtime/program/fd_bpf_loader_program.c index 262d51adfc..d528447f56 100644 --- a/src/flamenco/runtime/program/fd_bpf_loader_program.c +++ b/src/flamenco/runtime/program/fd_bpf_loader_program.c @@ -2497,7 +2497,6 @@ fd_directly_invoke_loader_v3_deploy( fd_bank_t * bank, /* Set up a dummy instr and txn context */ fd_exec_txn_ctx_t * txn_ctx = fd_exec_txn_ctx_join( fd_exec_txn_ctx_new( fd_spad_alloc( runtime_spad, FD_EXEC_TXN_CTX_ALIGN, FD_EXEC_TXN_CTX_FOOTPRINT ) ), runtime_spad, fd_wksp_containing( runtime_spad ) ); fd_wksp_t * funk_wksp = fd_funk_wksp( funk ); - fd_wksp_t * runtime_wksp = fd_wksp_containing( runtime_spad ); ulong funk_txn_gaddr = fd_wksp_gaddr( funk_wksp, funk_txn ); ulong funk_gaddr = fd_wksp_gaddr( funk_wksp, funk->shmem ); @@ -2505,7 +2504,6 @@ fd_directly_invoke_loader_v3_deploy( fd_bank_t * bank, bank, txn_ctx, funk_wksp, - runtime_wksp, funk_txn_gaddr, funk_gaddr, NULL ); diff --git a/src/flamenco/runtime/sysvar/fd_sysvar_slot_history.c b/src/flamenco/runtime/sysvar/fd_sysvar_slot_history.c index c621ac211d..6186e93b30 100644 --- a/src/flamenco/runtime/sysvar/fd_sysvar_slot_history.c +++ b/src/flamenco/runtime/sysvar/fd_sysvar_slot_history.c @@ -191,10 +191,7 @@ fd_sysvar_slot_history_read( fd_funk_t * funk, } int -fd_sysvar_slot_history_find_slot( fd_slot_history_global_t const * history, - ulong slot, - fd_wksp_t * wksp ) { - (void)wksp; +fd_sysvar_slot_history_find_slot( fd_slot_history_global_t const * history, ulong slot ) { ulong * blocks = (ulong *)((uchar*)history + history->bits_bitvec_offset); if( FD_UNLIKELY( !blocks ) ) { FD_LOG_ERR(( "Unable to find slot history blocks" )); diff --git a/src/flamenco/runtime/sysvar/fd_sysvar_slot_history.h b/src/flamenco/runtime/sysvar/fd_sysvar_slot_history.h index 2b71105bb4..3e09a3f23c 100644 --- a/src/flamenco/runtime/sysvar/fd_sysvar_slot_history.h +++ b/src/flamenco/runtime/sysvar/fd_sysvar_slot_history.h @@ -37,6 +37,5 @@ fd_sysvar_slot_history_read( fd_funk_t * funk, int fd_sysvar_slot_history_find_slot( fd_slot_history_global_t const * history, - ulong slot, - fd_wksp_t * wksp ); + ulong slot ); #endif /* HEADER_fd_src_flamenco_runtime_sysvar_fd_slot_history_h */ diff --git a/src/flamenco/runtime/tests/harness/fd_instr_harness.c b/src/flamenco/runtime/tests/harness/fd_instr_harness.c index 5579126f0d..6a4cd9ca23 100644 --- a/src/flamenco/runtime/tests/harness/fd_instr_harness.c +++ b/src/flamenco/runtime/tests/harness/fd_instr_harness.c @@ -32,27 +32,20 @@ fd_runtime_fuzz_instr_ctx_create( fd_runtime_fuzz_runner_t * runner, fd_funk_txn_end_write( funk ); /* Allocate contexts */ - uchar * slot_ctx_mem = fd_spad_alloc( runner->spad,FD_EXEC_SLOT_CTX_ALIGN, FD_EXEC_SLOT_CTX_FOOTPRINT ); - uchar * txn_ctx_mem = fd_spad_alloc( runner->spad,FD_EXEC_TXN_CTX_ALIGN, FD_EXEC_TXN_CTX_FOOTPRINT ); + uchar * txn_ctx_mem = fd_spad_alloc( runner->spad,FD_EXEC_TXN_CTX_ALIGN, FD_EXEC_TXN_CTX_FOOTPRINT ); - fd_exec_slot_ctx_t * slot_ctx = fd_exec_slot_ctx_join ( fd_exec_slot_ctx_new ( slot_ctx_mem ) ); - fd_exec_txn_ctx_t * txn_ctx = fd_exec_txn_ctx_join ( fd_exec_txn_ctx_new ( txn_ctx_mem ), runner->spad, fd_wksp_containing( runner->spad ) ); - - assert( slot_ctx ); + fd_exec_txn_ctx_t * txn_ctx = fd_exec_txn_ctx_join( fd_exec_txn_ctx_new( txn_ctx_mem ), runner->spad, fd_wksp_containing( runner->spad ) ); ctx->txn_ctx = txn_ctx; /* Set up slot context */ - slot_ctx->funk_txn = funk_txn; - slot_ctx->funk = funk; /* Bank manager */ - slot_ctx->bank = runner->bank; - fd_bank_clear_bank( slot_ctx->bank ); + fd_bank_clear_bank( runner->bank ); - fd_features_t * features = fd_bank_features_modify( slot_ctx->bank ); + fd_features_t * features = fd_bank_features_modify( runner->bank ); fd_exec_test_feature_set_t const * feature_set = &test_ctx->epoch_context.features; if( !fd_runtime_fuzz_restore_features( features, feature_set ) ) { return 0; @@ -60,14 +53,14 @@ fd_runtime_fuzz_instr_ctx_create( fd_runtime_fuzz_runner_t * runner, /* Set up epoch context. Defaults obtained from GenesisConfig::Default() */ - fd_rent_t * rent_bm = fd_bank_rent_modify( slot_ctx->bank ); + fd_rent_t * rent_bm = fd_bank_rent_modify( runner->bank ); rent_bm->lamports_per_uint8_year = 3480; rent_bm->exemption_threshold = 2; rent_bm->burn_percent = 50; /* Blockhash queue init */ - fd_block_hash_queue_global_t * block_hash_queue = fd_bank_block_hash_queue_modify( slot_ctx->bank ); + fd_block_hash_queue_global_t * block_hash_queue = fd_bank_block_hash_queue_modify( runner->bank ); uchar * last_hash_mem = (uchar *)fd_ulong_align_up( (ulong)block_hash_queue + sizeof(fd_block_hash_queue_global_t), alignof(fd_hash_t) ); uchar * ages_pool_mem = (uchar *)fd_ulong_align_up( (ulong)last_hash_mem + sizeof(fd_hash_t), fd_hash_hash_age_pair_t_map_align() ); @@ -84,7 +77,6 @@ fd_runtime_fuzz_instr_ctx_create( fd_runtime_fuzz_runner_t * runner, /* Set up txn context */ fd_wksp_t * funk_wksp = fd_funk_wksp( funk ); - fd_wksp_t * runtime_wksp = fd_wksp_containing( slot_ctx ); ulong funk_txn_gaddr = fd_wksp_gaddr( funk_wksp, funk_txn ); ulong funk_gaddr = fd_wksp_gaddr( funk_wksp, funk->shmem ); @@ -94,10 +86,9 @@ fd_runtime_fuzz_instr_ctx_create( fd_runtime_fuzz_runner_t * runner, txn_descriptor->acct_addr_cnt = (ushort)test_ctx->accounts_count; fd_exec_txn_ctx_from_exec_slot_ctx( - slot_ctx->bank, + runner->bank, txn_ctx, funk_wksp, - runtime_wksp, funk_txn_gaddr, funk_gaddr, NULL ); @@ -230,7 +221,7 @@ fd_runtime_fuzz_instr_ctx_create( fd_runtime_fuzz_runner_t * runner, .leader_schedule_epoch = 0UL, .unix_timestamp = 0L }; - fd_sysvar_clock_write( slot_ctx->bank, slot_ctx->funk, slot_ctx->funk_txn, &sysvar_clock ); + fd_sysvar_clock_write( runner->bank, funk, funk_txn, &sysvar_clock ); } /* Epoch schedule */ @@ -244,7 +235,7 @@ fd_runtime_fuzz_instr_ctx_create( fd_runtime_fuzz_runner_t * runner, .first_normal_epoch = 14UL, .first_normal_slot = 524256UL }; - fd_sysvar_epoch_schedule_write( slot_ctx->bank, slot_ctx->funk, slot_ctx->funk_txn, &sysvar_epoch_schedule ); + fd_sysvar_epoch_schedule_write( runner->bank, funk, funk_txn, &sysvar_epoch_schedule ); } /* Rent */ @@ -256,7 +247,7 @@ fd_runtime_fuzz_instr_ctx_create( fd_runtime_fuzz_runner_t * runner, .exemption_threshold = 2.0, .burn_percent = 50 }; - fd_sysvar_rent_write( slot_ctx->bank, slot_ctx->funk, slot_ctx->funk_txn, &sysvar_rent ); + fd_sysvar_rent_write( runner->bank, funk, funk_txn, &sysvar_rent ); } fd_sol_sysvar_last_restart_slot_t const * last_restart_slot = fd_sysvar_last_restart_slot_read( funk, funk_txn, runner->spad ); @@ -264,34 +255,33 @@ fd_runtime_fuzz_instr_ctx_create( fd_runtime_fuzz_runner_t * runner, fd_sol_sysvar_last_restart_slot_t restart = { .slot = 5000UL }; - fd_sysvar_set( slot_ctx->bank, - slot_ctx->funk, - slot_ctx->funk_txn, + fd_sysvar_set( runner->bank, + funk, + funk_txn, &fd_sysvar_owner_id, &fd_sysvar_last_restart_slot_id, &restart.slot, sizeof(ulong), - slot_ctx->slot ); + runner->bank->slot ); } /* Set slot bank variables */ clock = fd_sysvar_clock_read( funk, funk_txn, runner->spad ); - slot_ctx->slot = clock->slot; - slot_ctx->bank->slot = clock->slot; + runner->bank->slot = clock->slot; /* Handle undefined behavior if sysvars are malicious (!!!) */ epoch_schedule = fd_sysvar_epoch_schedule_read( funk, funk_txn, runner->spad ); if( epoch_schedule ) { - fd_bank_epoch_schedule_set( slot_ctx->bank, *epoch_schedule ); + fd_bank_epoch_schedule_set( runner->bank, *epoch_schedule ); } /* Override epoch bank rent setting */ rent = fd_sysvar_rent_read( funk, funk_txn, runner->spad ); if( rent ) { - fd_bank_rent_set( slot_ctx->bank, *rent ); + fd_bank_rent_set( runner->bank, *rent ); } /* Override most recent blockhash if given */ @@ -304,18 +294,18 @@ fd_runtime_fuzz_instr_ctx_create( fd_runtime_fuzz_runner_t * runner, if( rbh_global && !deq_fd_block_block_hash_entry_t_empty( rbh->hashes ) ) { fd_block_block_hash_entry_t const * last = deq_fd_block_block_hash_entry_t_peek_tail_const( rbh->hashes ); if( last ) { - block_hash_queue = (fd_block_hash_queue_global_t *)&slot_ctx->bank->block_hash_queue[0]; + block_hash_queue = fd_bank_block_hash_queue_modify( runner->bank ); fd_hash_t * last_hash = fd_block_hash_queue_last_hash_join( block_hash_queue ); fd_memcpy( last_hash, &last->blockhash, sizeof(fd_hash_t) ); - fd_bank_lamports_per_signature_set( slot_ctx->bank, last->fee_calculator.lamports_per_signature ); + fd_bank_lamports_per_signature_set( runner->bank, last->fee_calculator.lamports_per_signature ); - fd_bank_prev_lamports_per_signature_set( slot_ctx->bank, last->fee_calculator.lamports_per_signature ); + fd_bank_prev_lamports_per_signature_set( runner->bank, last->fee_calculator.lamports_per_signature ); } } /* Add accounts to bpf program cache */ - fd_bpf_scan_and_create_bpf_program_cache_entry( slot_ctx->bank, slot_ctx->funk, slot_ctx->funk_txn, runner->spad ); + fd_bpf_scan_and_create_bpf_program_cache_entry( runner->bank, funk, funk_txn, runner->spad ); /* Load instruction accounts */ @@ -369,10 +359,9 @@ fd_runtime_fuzz_instr_ctx_create( fd_runtime_fuzz_runner_t * runner, /* Refresh the setup from the updated slot and epoch ctx. */ fd_exec_txn_ctx_from_exec_slot_ctx( - slot_ctx->bank, + runner->bank, txn_ctx, funk_wksp, - runtime_wksp, funk_txn_gaddr, funk_gaddr, NULL ); From 2e23895ade4c10cb3d4b9b558e0c029dd6226b9b Mon Sep 17 00:00:00 2001 From: Ishan Bhatt Date: Tue, 8 Jul 2025 19:21:47 +0000 Subject: [PATCH 18/27] more --- src/app/ledger/main.c | 4 +- src/discof/consensus/test_consensus.c | 2 +- src/flamenco/runtime/fd_hashes.c | 53 ++++---- src/flamenco/runtime/fd_hashes.h | 13 +- .../runtime/tests/harness/fd_block_harness.c | 2 +- .../runtime/tests/harness/fd_txn_harness.c | 113 ++++++++---------- src/flamenco/snapshot/fd_snapshot.c | 6 +- 7 files changed, 91 insertions(+), 102 deletions(-) diff --git a/src/app/ledger/main.c b/src/app/ledger/main.c index bf533a6d89..8080e560be 100644 --- a/src/app/ledger/main.c +++ b/src/app/ledger/main.c @@ -166,7 +166,7 @@ runtime_replay( fd_ledger_args_t * ledger_args ) { fd_runtime_update_leaders( ledger_args->slot_ctx->bank, ledger_args->slot_ctx->slot, ledger_args->runtime_spad ); - fd_calculate_epoch_accounts_hash_values( ledger_args->slot_ctx ); + fd_calculate_epoch_accounts_hash_values( ledger_args->slot_ctx->bank ); long replay_time = -fd_log_wallclock(); ulong txn_cnt = 0; @@ -523,7 +523,7 @@ fd_ledger_main_setup( fd_ledger_args_t * args ) { /* Finish other runtime setup steps */ fd_features_restore( args->slot_ctx->bank, args->slot_ctx->funk, args->slot_ctx->funk_txn, args->runtime_spad ); fd_runtime_update_leaders( args->slot_ctx->bank, args->slot_ctx->slot, args->runtime_spad ); - fd_calculate_epoch_accounts_hash_values( args->slot_ctx ); + fd_calculate_epoch_accounts_hash_values( args->slot_ctx->bank ); /* After both snapshots have been loaded in, we can determine if we should start distributing rewards. */ diff --git a/src/discof/consensus/test_consensus.c b/src/discof/consensus/test_consensus.c index 045a921743..d762d8bdc4 100644 --- a/src/discof/consensus/test_consensus.c +++ b/src/discof/consensus/test_consensus.c @@ -536,7 +536,7 @@ main( void ) { // /**********************************************************************/ // fd_fork_t * snapshot_fork = fd_fork_pool_ele_acquire( forks->pool ); -// fd_exec_slot_ctx_t * snapshot_slot_ctx = +// * snapshot_slot_ctx = // fd_exec_slot_ctx_join( fd_exec_slot_ctx_new( &snapshot_fork->slot_ctx, valloc ) ); // FD_TEST( snapshot_slot_ctx ); diff --git a/src/flamenco/runtime/fd_hashes.c b/src/flamenco/runtime/fd_hashes.c index 1b49a68263..d52185dfb6 100644 --- a/src/flamenco/runtime/fd_hashes.c +++ b/src/flamenco/runtime/fd_hashes.c @@ -150,15 +150,15 @@ fd_hash_account_deltas( fd_pubkey_hash_pair_list_t * lists, ulong lists_len, fd_ void -fd_calculate_epoch_accounts_hash_values( fd_exec_slot_ctx_t * slot_ctx ) { +fd_calculate_epoch_accounts_hash_values( fd_bank_t * bank ) { ulong slot_idx = 0; - fd_epoch_schedule_t const * epoch_schedule = fd_bank_epoch_schedule_query( slot_ctx->bank ); - ulong epoch = fd_slot_to_epoch( epoch_schedule, slot_ctx->slot, &slot_idx ); + fd_epoch_schedule_t const * epoch_schedule = fd_bank_epoch_schedule_query( bank ); + ulong epoch = fd_slot_to_epoch( epoch_schedule, bank->slot, &slot_idx ); - if( FD_FEATURE_ACTIVE_BANK( slot_ctx->bank, accounts_lt_hash) ) { - fd_bank_eah_start_slot_set( slot_ctx->bank, ULONG_MAX ); - fd_bank_eah_stop_slot_set( slot_ctx->bank, ULONG_MAX ); - fd_bank_eah_interval_set( slot_ctx->bank, ULONG_MAX ); + if( FD_FEATURE_ACTIVE_BANK( bank, accounts_lt_hash) ) { + fd_bank_eah_start_slot_set( bank, ULONG_MAX ); + fd_bank_eah_stop_slot_set( bank, ULONG_MAX ); + fd_bank_eah_interval_set( bank, ULONG_MAX ); return; } @@ -175,23 +175,23 @@ fd_calculate_epoch_accounts_hash_values( fd_exec_slot_ctx_t * slot_ctx ) { const ulong MINIMUM_CALCULATION_INTERVAL = MAX_LOCKOUT_HISTORY + CALCULATION_INTERVAL_BUFFER; if( calculation_interval < MINIMUM_CALCULATION_INTERVAL ) { - fd_bank_eah_start_slot_set( slot_ctx->bank, ULONG_MAX ); - fd_bank_eah_stop_slot_set( slot_ctx->bank, ULONG_MAX ); - fd_bank_eah_interval_set( slot_ctx->bank, ULONG_MAX ); + fd_bank_eah_start_slot_set( bank, ULONG_MAX ); + fd_bank_eah_stop_slot_set( bank, ULONG_MAX ); + fd_bank_eah_interval_set( bank, ULONG_MAX ); return; } - fd_bank_eah_start_slot_set( slot_ctx->bank, first_slot_in_epoch + calculation_offset_start ); - if( slot_ctx->slot > fd_bank_eah_start_slot_get( slot_ctx->bank ) ) { - fd_bank_eah_start_slot_set( slot_ctx->bank, ULONG_MAX ); + fd_bank_eah_start_slot_set( bank, first_slot_in_epoch + calculation_offset_start ); + if( bank->slot > fd_bank_eah_start_slot_get( bank ) ) { + fd_bank_eah_start_slot_set( bank, ULONG_MAX ); } - fd_bank_eah_stop_slot_set( slot_ctx->bank, first_slot_in_epoch + calculation_offset_stop ); - if( slot_ctx->slot > fd_bank_eah_stop_slot_get( slot_ctx->bank ) ) { - fd_bank_eah_stop_slot_set( slot_ctx->bank, ULONG_MAX ); + fd_bank_eah_stop_slot_set( bank, first_slot_in_epoch + calculation_offset_stop ); + if( bank->slot > fd_bank_eah_stop_slot_get( bank ) ) { + fd_bank_eah_stop_slot_set( bank, ULONG_MAX ); } - fd_bank_eah_interval_set( slot_ctx->bank, calculation_interval ); + fd_bank_eah_interval_set( bank, calculation_interval ); } @@ -1017,16 +1017,16 @@ fd_accounts_hash( fd_funk_t * funk, } int -fd_accounts_hash_inc_only( fd_exec_slot_ctx_t * slot_ctx, - fd_hash_t * accounts_hash, - fd_funk_txn_t * child_txn, - ulong do_hash_verify, - fd_spad_t * spad ) { +fd_accounts_hash_inc_only( fd_bank_t * bank, + fd_funk_t * funk, + fd_hash_t * accounts_hash, + fd_funk_txn_t * child_txn, + ulong do_hash_verify, + fd_spad_t * spad ) { FD_LOG_NOTICE(( "accounts_hash_inc_only start for txn %p, do_hash_verify=%s", (void *)child_txn, do_hash_verify ? "true" : "false" )); FD_SPAD_FRAME_BEGIN( spad ) { - fd_funk_t * funk = slot_ctx->funk; fd_wksp_t * wksp = fd_funk_wksp( funk ); // How many total records are we dealing with? @@ -1070,13 +1070,10 @@ fd_accounts_hash_inc_only( fd_exec_slot_ctx_t * slot_ctx, fd_hash_t *h = (fd_hash_t *) metadata->hash; if ((h->ul[0] | h->ul[1] | h->ul[2] | h->ul[3]) == 0) { // By the time we fall into this case, we can assume the ignore_slot feature is enabled... - fd_hash_account_current( (uchar *) metadata->hash, NULL, metadata, fd_type_pun_const(rec->pair.key->uc), fd_account_meta_get_data(metadata), FD_HASH_JUST_ACCOUNT_HASH, fd_bank_features_query( slot_ctx->bank ) ); + fd_hash_account_current( (uchar *) metadata->hash, NULL, metadata, fd_type_pun_const(rec->pair.key->uc), fd_account_meta_get_data(metadata), FD_HASH_JUST_ACCOUNT_HASH, fd_bank_features_query( bank ) ); } else if( do_hash_verify ) { uchar hash[32]; - // ulong old_slot = slot_ctx->slot; - // slot_ctx->slot = metadata->slot; - fd_hash_account_current( (uchar *) &hash, NULL, metadata, fd_type_pun_const(rec->pair.key->uc), fd_account_meta_get_data(metadata), FD_HASH_JUST_ACCOUNT_HASH, fd_bank_features_query( slot_ctx->bank ) ); - // slot_ctx->slot = old_slot; + fd_hash_account_current( (uchar *) &hash, NULL, metadata, fd_type_pun_const(rec->pair.key->uc), fd_account_meta_get_data(metadata), FD_HASH_JUST_ACCOUNT_HASH, fd_bank_features_query( bank ) ); if ( fd_account_meta_exists( metadata ) && memcmp( metadata->hash, &hash, 32 ) != 0 ) { FD_LOG_WARNING(( "snapshot hash (%s) doesn't match calculated hash (%s)", FD_BASE58_ENC_32_ALLOCA( metadata->hash ), FD_BASE58_ENC_32_ALLOCA( &hash ) )); } diff --git a/src/flamenco/runtime/fd_hashes.h b/src/flamenco/runtime/fd_hashes.h index fb9385c540..542646e02d 100644 --- a/src/flamenco/runtime/fd_hashes.h +++ b/src/flamenco/runtime/fd_hashes.h @@ -200,14 +200,15 @@ fd_accounts_check_lthash( fd_funk_t * funk, fd_features_t * features ); void -fd_calculate_epoch_accounts_hash_values(fd_exec_slot_ctx_t * slot_ctx); +fd_calculate_epoch_accounts_hash_values( fd_bank_t * bank ); int -fd_accounts_hash_inc_only( fd_exec_slot_ctx_t * slot_ctx, - fd_hash_t * accounts_hash, - fd_funk_txn_t * child_txn, - ulong do_hash_verify, - fd_spad_t * spad ); +fd_accounts_hash_inc_only( fd_bank_t * bank, + fd_funk_t * funk, + fd_hash_t * accounts_hash, + fd_funk_txn_t * child_txn, + ulong do_hash_verify, + fd_spad_t * spad ); void fd_account_hash_task( void * tpool, diff --git a/src/flamenco/runtime/tests/harness/fd_block_harness.c b/src/flamenco/runtime/tests/harness/fd_block_harness.c index 9d3f6dd5ad..5706fe7a25 100644 --- a/src/flamenco/runtime/tests/harness/fd_block_harness.c +++ b/src/flamenco/runtime/tests/harness/fd_block_harness.c @@ -455,7 +455,7 @@ fd_runtime_fuzz_block_ctx_create( fd_runtime_fuzz_runner_t * runner, fd_funk_txn_end_write( funk ); /* Calculate epoch account hash values. This sets epoch_bank.eah_{start_slot, stop_slot, interval} */ - fd_calculate_epoch_accounts_hash_values( slot_ctx ); + fd_calculate_epoch_accounts_hash_values( slot_ctx->bank ); /* Prepare raw transaction pointers and block / microblock infos */ ulong txn_cnt = test_ctx->txns_count; diff --git a/src/flamenco/runtime/tests/harness/fd_txn_harness.c b/src/flamenco/runtime/tests/harness/fd_txn_harness.c index cef534de9b..7eb917168b 100644 --- a/src/flamenco/runtime/tests/harness/fd_txn_harness.c +++ b/src/flamenco/runtime/tests/harness/fd_txn_harness.c @@ -3,9 +3,11 @@ static void fd_runtime_fuzz_txn_ctx_destroy( fd_runtime_fuzz_runner_t * runner, - fd_exec_slot_ctx_t * slot_ctx ) { - if( !slot_ctx ) return; // This shouldn't be false either - fd_funk_txn_t * funk_txn = slot_ctx->funk_txn; + fd_funk_txn_t * funk_txn ) { + + if( FD_UNLIKELY( !funk_txn ) ) { + return; + } fd_funk_txn_cancel( runner->funk, funk_txn, 1 ); } @@ -14,7 +16,7 @@ fd_runtime_fuzz_txn_ctx_destroy( fd_runtime_fuzz_runner_t * runner, a parsed txn descriptor on success and NULL on failure. */ static fd_txn_p_t * fd_runtime_fuzz_txn_ctx_create( fd_runtime_fuzz_runner_t * runner, - fd_exec_slot_ctx_t * slot_ctx, + fd_funk_txn_t * * funk_txn_out, fd_exec_test_txn_context_t const * test_ctx ) { const uchar empty_bytes[64] = { 0 }; fd_funk_t * funk = runner->funk; @@ -28,23 +30,16 @@ fd_runtime_fuzz_txn_ctx_create( fd_runtime_fuzz_runner_t * runner, fd_funk_txn_start_write( funk ); fd_funk_txn_t * funk_txn = fd_funk_txn_prepare( funk, NULL, xid, 1 ); + *funk_txn_out = funk_txn; fd_funk_txn_end_write( funk ); - /* Allocate contexts */ - assert( slot_ctx ); - - /* Set up slot context */ - slot_ctx->funk_txn = funk_txn; - slot_ctx->funk = funk; - - slot_ctx->bank = runner->bank; - fd_bank_clear_bank( slot_ctx->bank ); + fd_bank_clear_bank( runner->bank ); /* Restore feature flags */ fd_exec_test_feature_set_t const * feature_set = &test_ctx->epoch_ctx.features; - fd_features_t * features_bm = fd_bank_features_modify( slot_ctx->bank ); + fd_features_t * features_bm = fd_bank_features_modify( runner->bank ); if( !fd_runtime_fuzz_restore_features( features_bm, feature_set ) ) { return NULL; } @@ -53,11 +48,10 @@ fd_runtime_fuzz_txn_ctx_create( fd_runtime_fuzz_runner_t * runner, ulong slot = test_ctx->slot_ctx.slot ? test_ctx->slot_ctx.slot : 10; // Arbitrary default > 0 /* Set slot bank variables (defaults obtained from GenesisConfig::default() in Agave) */ - slot_ctx->slot = slot; - slot_ctx->bank->slot = slot; + runner->bank->slot = slot; /* Initialize builtin accounts */ - fd_builtin_programs_init( slot_ctx->bank, slot_ctx->funk, slot_ctx->funk_txn ); + fd_builtin_programs_init( runner->bank, funk, funk_txn ); /* Load account states into funk (note this is different from the account keys): Account state = accounts to populate Funk @@ -71,20 +65,20 @@ fd_runtime_fuzz_txn_ctx_create( fd_runtime_fuzz_runner_t * runner, /* Setup Bank manager */ - fd_bank_prev_slot_set( slot_ctx->bank, slot_ctx->slot - 1UL ); + fd_bank_prev_slot_set( runner->bank, slot - 1UL ); - fd_bank_lamports_per_signature_set( slot_ctx->bank, 5000UL ); + fd_bank_lamports_per_signature_set( runner->bank, 5000UL ); - fd_bank_prev_lamports_per_signature_set( slot_ctx->bank, 5000UL ); + fd_bank_prev_lamports_per_signature_set( runner->bank, 5000UL ); - fd_fee_rate_governor_t * fee_rate_governor = fd_bank_fee_rate_governor_modify( slot_ctx->bank ); + fd_fee_rate_governor_t * fee_rate_governor = fd_bank_fee_rate_governor_modify( runner->bank ); fee_rate_governor->burn_percent = 50; fee_rate_governor->min_lamports_per_signature = 0; fee_rate_governor->max_lamports_per_signature = 0; fee_rate_governor->target_lamports_per_signature = 10000; fee_rate_governor->target_signatures_per_slot = 20000; - fd_bank_ticks_per_slot_set( slot_ctx->bank, 64 ); + fd_bank_ticks_per_slot_set( runner->bank, 64 ); /* Set epoch bank variables if not present (defaults obtained from GenesisConfig::default() in Agave) */ fd_epoch_schedule_t default_epoch_schedule = { @@ -99,21 +93,21 @@ fd_runtime_fuzz_txn_ctx_create( fd_runtime_fuzz_runner_t * runner, .exemption_threshold = 2.0, .burn_percent = 50 }; - fd_bank_epoch_schedule_set( slot_ctx->bank, default_epoch_schedule ); + fd_bank_epoch_schedule_set( runner->bank, default_epoch_schedule ); - fd_bank_rent_set( slot_ctx->bank, default_rent ); + fd_bank_rent_set( runner->bank, default_rent ); - fd_bank_slots_per_year_set( slot_ctx->bank, SECONDS_PER_YEAR * (1000000000.0 / (double)6250000) / (double)(fd_bank_ticks_per_slot_get( slot_ctx->bank )) ); + fd_bank_slots_per_year_set( runner->bank, SECONDS_PER_YEAR * (1000000000.0 / (double)6250000) / (double)(fd_bank_ticks_per_slot_get( runner->bank )) ); // Override default values if provided fd_epoch_schedule_t * epoch_schedule = fd_sysvar_epoch_schedule_read( funk, funk_txn, runner->spad ); if( epoch_schedule ) { - fd_bank_epoch_schedule_set( slot_ctx->bank, *epoch_schedule ); + fd_bank_epoch_schedule_set( runner->bank, *epoch_schedule ); } fd_rent_t const * rent = fd_sysvar_rent_read( funk, funk_txn, runner->spad ); if( rent ) { - fd_bank_rent_set( slot_ctx->bank, *rent ); + fd_bank_rent_set( runner->bank, *rent ); } /* Provide default slot hashes of size 1 if not provided */ @@ -129,7 +123,7 @@ fd_runtime_fuzz_txn_ctx_create( fd_runtime_fuzz_runner_t * runner, fd_slot_hash_t * dummy_elem = deq_fd_slot_hash_t_push_tail_nocopy( slot_hashes ); memset( dummy_elem, 0, sizeof(fd_slot_hash_t) ); - fd_sysvar_slot_hashes_write( slot_ctx->bank, slot_ctx->funk, slot_ctx->funk_txn, default_slot_hashes_global ); + fd_sysvar_slot_hashes_write( runner->bank, funk, funk_txn, default_slot_hashes_global ); fd_sysvar_slot_hashes_delete( fd_sysvar_slot_hashes_leave( default_slot_hashes_global, slot_hashes ) ); } FD_SPAD_FRAME_END; @@ -140,27 +134,27 @@ fd_runtime_fuzz_txn_ctx_create( fd_runtime_fuzz_runner_t * runner, if( !stake_history ) { // Provide a 0-set default entry fd_epoch_stake_history_entry_pair_t entry = {0}; - fd_sysvar_stake_history_init( slot_ctx->bank, slot_ctx->funk, slot_ctx->funk_txn ); - fd_sysvar_stake_history_update( slot_ctx->bank, slot_ctx->funk, slot_ctx->funk_txn, &entry, runner->spad ); + fd_sysvar_stake_history_init( runner->bank, funk, funk_txn ); + fd_sysvar_stake_history_update( runner->bank, funk, funk_txn, &entry, runner->spad ); } /* Provide default last restart slot sysvar if not provided */ FD_TXN_ACCOUNT_DECL( acc ); int err = fd_txn_account_init_from_funk_readonly( acc, &fd_sysvar_last_restart_slot_id, funk, funk_txn ); if( err==FD_ACC_MGR_ERR_UNKNOWN_ACCOUNT ) { - fd_sysvar_last_restart_slot_init( slot_ctx->bank, slot_ctx->funk, slot_ctx->funk_txn ); + fd_sysvar_last_restart_slot_init( runner->bank, funk, funk_txn ); } /* Provide a default clock if not present */ fd_sol_sysvar_clock_t const * clock = fd_sysvar_clock_read( funk, funk_txn, runner->spad ); if( !clock ) { - fd_sysvar_clock_init( slot_ctx->bank, slot_ctx->funk, slot_ctx->funk_txn ); - fd_sysvar_clock_update( slot_ctx->bank, slot_ctx->funk, slot_ctx->funk_txn, runner->spad ); + fd_sysvar_clock_init( runner->bank, funk, funk_txn ); + fd_sysvar_clock_update( runner->bank, funk, funk_txn, runner->spad ); } /* Epoch schedule and rent get set from the epoch bank */ - fd_sysvar_epoch_schedule_init( slot_ctx->bank, slot_ctx->funk, slot_ctx->funk_txn ); - fd_sysvar_rent_init( slot_ctx->bank, slot_ctx->funk, slot_ctx->funk_txn ); + fd_sysvar_epoch_schedule_init( runner->bank, funk, funk_txn ); + fd_sysvar_rent_init( runner->bank, funk, funk_txn ); /* Set the epoch rewards sysvar if partition epoch rewards feature is enabled @@ -175,9 +169,9 @@ fd_runtime_fuzz_txn_ctx_create( fd_runtime_fuzz_runner_t * runner, fd_point_value_t point_value = {0}; fd_hash_t const * last_hash = test_ctx->blockhash_queue_count > 0 ? (fd_hash_t const *)test_ctx->blockhash_queue[0]->bytes : (fd_hash_t const *)empty_bytes; fd_sysvar_epoch_rewards_init( - slot_ctx->bank, - slot_ctx->funk, - slot_ctx->funk_txn, + runner->bank, + funk, + funk_txn, 0UL, 2UL, 1UL, @@ -201,7 +195,7 @@ fd_runtime_fuzz_txn_ctx_create( fd_runtime_fuzz_runner_t * runner, ulong num_blockhashes = test_ctx->blockhash_queue_count; /* Blockhash queue init */ - fd_block_hash_queue_global_t * block_hash_queue = fd_bank_block_hash_queue_modify( slot_ctx->bank ); + fd_block_hash_queue_global_t * block_hash_queue = fd_bank_block_hash_queue_modify( runner->bank ); uchar * last_hash_mem = (uchar *)fd_ulong_align_up( (ulong)block_hash_queue + sizeof(fd_block_hash_queue_global_t), alignof(fd_hash_t) ); uchar * ages_pool_mem = (uchar *)fd_ulong_align_up( (ulong)last_hash_mem + sizeof(fd_hash_t), fd_hash_hash_age_pair_t_map_align() ); fd_hash_hash_age_pair_t_mapnode_t * ages_pool = fd_hash_hash_age_pair_t_map_join( fd_hash_hash_age_pair_t_map_new( ages_pool_mem, 400 ) ); @@ -222,37 +216,37 @@ fd_runtime_fuzz_txn_ctx_create( fd_runtime_fuzz_runner_t * runner, if( rbh_global && !deq_fd_block_block_hash_entry_t_empty( rbh->hashes ) ) { fd_block_block_hash_entry_t const * last = deq_fd_block_block_hash_entry_t_peek_head_const( rbh->hashes ); if( last && last->fee_calculator.lamports_per_signature!=0UL ) { - fd_bank_lamports_per_signature_set( slot_ctx->bank, last->fee_calculator.lamports_per_signature ); - fd_bank_prev_lamports_per_signature_set( slot_ctx->bank, last->fee_calculator.lamports_per_signature ); + fd_bank_lamports_per_signature_set( runner->bank, last->fee_calculator.lamports_per_signature ); + fd_bank_prev_lamports_per_signature_set( runner->bank, last->fee_calculator.lamports_per_signature ); } } // Blockhash_queue[end] = last (latest) hash // Blockhash_queue[0] = genesis hash if( num_blockhashes > 0 ) { - fd_hash_t * genesis_hash = fd_bank_genesis_hash_modify( slot_ctx->bank ); + fd_hash_t * genesis_hash = fd_bank_genesis_hash_modify( runner->bank ); memcpy( genesis_hash->hash, test_ctx->blockhash_queue[0]->bytes, sizeof(fd_hash_t) ); for( ulong i = 0; i < num_blockhashes; ++i ) { // Recent block hashes cap is 150 (actually 151), while blockhash queue capacity is 300 (actually 301) fd_block_block_hash_entry_t blockhash_entry; memcpy( &blockhash_entry.blockhash, test_ctx->blockhash_queue[i]->bytes, sizeof(fd_hash_t) ); - fd_bank_poh_set( slot_ctx->bank, blockhash_entry.blockhash ); - fd_sysvar_recent_hashes_update( slot_ctx->bank, slot_ctx->funk, slot_ctx->funk_txn, runner->spad ); + fd_bank_poh_set( runner->bank, blockhash_entry.blockhash ); + fd_sysvar_recent_hashes_update( runner->bank, funk, funk_txn, runner->spad ); } } else { // Add a default empty blockhash and use it as genesis num_blockhashes = 1; - fd_hash_t * genesis_hash = fd_bank_genesis_hash_modify( slot_ctx->bank ); + fd_hash_t * genesis_hash = fd_bank_genesis_hash_modify( runner->bank ); memcpy( genesis_hash->hash, empty_bytes, sizeof(fd_hash_t) ); fd_block_block_hash_entry_t blockhash_entry; memcpy( &blockhash_entry.blockhash, empty_bytes, sizeof(fd_hash_t) ); - fd_bank_poh_set( slot_ctx->bank, blockhash_entry.blockhash ); - fd_sysvar_recent_hashes_update( slot_ctx->bank, slot_ctx->funk, slot_ctx->funk_txn, runner->spad ); + fd_bank_poh_set( runner->bank, blockhash_entry.blockhash ); + fd_sysvar_recent_hashes_update( runner->bank, funk, funk_txn, runner->spad ); } /* Add accounts to bpf program cache */ - fd_bpf_scan_and_create_bpf_program_cache_entry( slot_ctx->bank, slot_ctx->funk, slot_ctx->funk_txn, runner->spad ); + fd_bpf_scan_and_create_bpf_program_cache_entry( runner->bank, funk, funk_txn, runner->spad ); /* Create the raw txn (https://solana.com/docs/core/transactions#transaction-size) */ uchar * txn_raw_begin = fd_spad_alloc( runner->spad, alignof(uchar), 1232 ); @@ -283,7 +277,7 @@ fd_runtime_fuzz_txn_ctx_create( fd_runtime_fuzz_runner_t * runner, Returns the task info. */ static fd_execute_txn_task_info_t * fd_runtime_fuzz_txn_ctx_exec( fd_runtime_fuzz_runner_t * runner, - fd_exec_slot_ctx_t * slot_ctx, + fd_funk_txn_t * funk_txn, fd_txn_p_t * txn ) { fd_execute_txn_task_info_t * task_info = fd_spad_alloc( runner->spad, alignof(fd_execute_txn_task_info_t), sizeof(fd_execute_txn_task_info_t) ); memset( task_info, 0, sizeof(fd_execute_txn_task_info_t) ); @@ -294,7 +288,7 @@ fd_runtime_fuzz_txn_ctx_exec( fd_runtime_fuzz_runner_t * runner, tpool->worker_cnt = 1; tpool->worker_max = 1; - fd_runtime_prepare_txns_start( slot_ctx->bank, slot_ctx->funk, slot_ctx->funk_txn, task_info, txn, 1UL, runner->spad ); + fd_runtime_prepare_txns_start( runner->bank, runner->funk, funk_txn, task_info, txn, 1UL, runner->spad ); /* Setup the spad for account allocation */ task_info->txn_ctx->spad = runner->spad; @@ -307,9 +301,9 @@ fd_runtime_fuzz_txn_ctx_exec( fd_runtime_fuzz_runner_t * runner, task_info->exec_res = fd_execute_txn( task_info ); } - fd_bank_execution_fees_set( slot_ctx->bank, fd_bank_execution_fees_get( slot_ctx->bank ) + task_info->txn_ctx->execution_fee ); + fd_bank_execution_fees_set( runner->bank, fd_bank_execution_fees_get( runner->bank ) + task_info->txn_ctx->execution_fee ); - fd_bank_priority_fees_set( slot_ctx->bank, fd_bank_priority_fees_get( slot_ctx->bank ) + task_info->txn_ctx->priority_fee ); + fd_bank_priority_fees_set( runner->bank, fd_bank_priority_fees_get( runner->bank ) + task_info->txn_ctx->priority_fee ); return task_info; } @@ -437,19 +431,16 @@ fd_runtime_fuzz_txn_run( fd_runtime_fuzz_runner_t * runner, FD_SPAD_FRAME_BEGIN( runner->spad ) { - /* Initialize memory */ - uchar * slot_ctx_mem = fd_spad_alloc( runner->spad, FD_EXEC_SLOT_CTX_ALIGN, FD_EXEC_SLOT_CTX_FOOTPRINT ); - fd_exec_slot_ctx_t * slot_ctx = fd_exec_slot_ctx_join( fd_exec_slot_ctx_new( slot_ctx_mem ) ); - /* Setup the transaction context */ - fd_txn_p_t * txn = fd_runtime_fuzz_txn_ctx_create( runner, slot_ctx, input ); + fd_funk_txn_t * funk_txn = NULL; + fd_txn_p_t * txn = fd_runtime_fuzz_txn_ctx_create( runner, &funk_txn, input ); if( txn==NULL ) { - fd_runtime_fuzz_txn_ctx_destroy( runner, slot_ctx ); + fd_runtime_fuzz_txn_ctx_destroy( runner, funk_txn ); return 0; } /* Execute the transaction against the runtime */ - fd_execute_txn_task_info_t * task_info = fd_runtime_fuzz_txn_ctx_exec( runner, slot_ctx, txn ); + fd_execute_txn_task_info_t * task_info = fd_runtime_fuzz_txn_ctx_exec( runner, funk_txn, txn ); fd_exec_txn_ctx_t * txn_ctx = task_info->txn_ctx; int exec_res = task_info->exec_res; @@ -505,7 +496,7 @@ fd_runtime_fuzz_txn_run( fd_runtime_fuzz_runner_t * runner, } ulong actual_end = FD_SCRATCH_ALLOC_FINI( l, 1UL ); - fd_runtime_fuzz_txn_ctx_destroy( runner, slot_ctx ); + fd_runtime_fuzz_txn_ctx_destroy( runner, funk_txn ); *output = txn_result; return actual_end - (ulong)output_buf; @@ -609,7 +600,7 @@ fd_runtime_fuzz_txn_run( fd_runtime_fuzz_runner_t * runner, } ulong actual_end = FD_SCRATCH_ALLOC_FINI( l, 1UL ); - fd_runtime_fuzz_txn_ctx_destroy( runner, slot_ctx ); + fd_runtime_fuzz_txn_ctx_destroy( runner, funk_txn ); *output = txn_result; return actual_end - (ulong)output_buf; diff --git a/src/flamenco/snapshot/fd_snapshot.c b/src/flamenco/snapshot/fd_snapshot.c index 7235650723..5efad33f29 100644 --- a/src/flamenco/snapshot/fd_snapshot.c +++ b/src/flamenco/snapshot/fd_snapshot.c @@ -234,7 +234,7 @@ fd_snapshot_load_fini( fd_snapshot_load_ctx_t * ctx ) { ctx->slot_ctx->funk, ctx->slot_ctx->funk_txn, ctx->runtime_spad ); - fd_calculate_epoch_accounts_hash_values( ctx->slot_ctx ); + fd_calculate_epoch_accounts_hash_values( ctx->slot_ctx->bank ); int snapshots_lt_hash = FD_FEATURE_ACTIVE_BANK( ctx->slot_ctx->bank, snapshots_lt_hash ); int accounts_lt_hash = FD_FEATURE_ACTIVE_BANK( ctx->slot_ctx->bank, accounts_lt_hash ); @@ -502,7 +502,7 @@ fd_snapshot_inc_hash( fd_exec_slot_ctx_t * slot_ctx, if( fd_should_snapshot_include_epoch_accounts_hash( slot_ctx ) ) { fd_sha256_t h; fd_hash_t hash; - fd_accounts_hash_inc_only( slot_ctx, &hash, child_txn, do_hash_verify, spad ); + fd_accounts_hash_inc_only( slot_ctx->bank, slot_ctx->funk, &hash, child_txn, do_hash_verify, spad ); fd_sha256_init( &h ); fd_sha256_append( &h, (uchar const *) hash.hash, sizeof( fd_hash_t ) ); @@ -511,5 +511,5 @@ fd_snapshot_inc_hash( fd_exec_slot_ctx_t * slot_ctx, return 0; } - return fd_accounts_hash_inc_only( slot_ctx, accounts_hash, child_txn, do_hash_verify, spad ); + return fd_accounts_hash_inc_only( slot_ctx->bank, slot_ctx->funk, accounts_hash, child_txn, do_hash_verify, spad ); } From 987337fe56c27e1ca66d8acee64ac5bff573041f Mon Sep 17 00:00:00 2001 From: Ishan Bhatt Date: Tue, 8 Jul 2025 20:42:27 +0000 Subject: [PATCH 19/27] asdf --- src/app/ledger/main.c | 7 +- .../runtime/context/fd_exec_slot_ctx.c | 125 ++++++++------- .../runtime/context/fd_exec_slot_ctx.h | 5 +- src/flamenco/runtime/fd_runtime.c | 12 +- src/flamenco/snapshot/fd_snapshot.c | 145 ++++++++++-------- src/flamenco/snapshot/fd_snapshot.h | 11 +- 6 files changed, 165 insertions(+), 140 deletions(-) diff --git a/src/app/ledger/main.c b/src/app/ledger/main.c index 8080e560be..a23f51a201 100644 --- a/src/app/ledger/main.c +++ b/src/app/ledger/main.c @@ -162,6 +162,10 @@ int runtime_replay( fd_ledger_args_t * ledger_args ) { int ret = 0; + ledger_args->slot_ctx->slot = ledger_args->slot_ctx->bank->slot; + ulong prev_slot = ledger_args->slot_ctx->slot; + ulong start_slot = ledger_args->slot_ctx->slot + 1; + fd_features_restore( ledger_args->slot_ctx->bank, ledger_args->slot_ctx->funk, ledger_args->slot_ctx->funk_txn, ledger_args->runtime_spad ); fd_runtime_update_leaders( ledger_args->slot_ctx->bank, ledger_args->slot_ctx->slot, ledger_args->runtime_spad ); @@ -173,9 +177,6 @@ runtime_replay( fd_ledger_args_t * ledger_args ) { ulong slot_cnt = 0; fd_blockstore_t * blockstore = ledger_args->blockstore; - ulong prev_slot = ledger_args->slot_ctx->slot; - ulong start_slot = ledger_args->slot_ctx->slot + 1; - /* On demand rocksdb ingest */ fd_rocksdb_t rocks_db = {0}; fd_rocksdb_root_iter_t iter = {0}; diff --git a/src/flamenco/runtime/context/fd_exec_slot_ctx.c b/src/flamenco/runtime/context/fd_exec_slot_ctx.c index aa811b0456..dda9b1a1de 100644 --- a/src/flamenco/runtime/context/fd_exec_slot_ctx.c +++ b/src/flamenco/runtime/context/fd_exec_slot_ctx.c @@ -91,12 +91,12 @@ fd_exec_slot_ctx_delete( void * mem ) { accounts in current epoch stakes. */ static int -recover_clock( fd_exec_slot_ctx_t * slot_ctx, fd_spad_t * runtime_spad ) { +recover_clock( fd_bank_t * bank, fd_spad_t * runtime_spad ) { - fd_stakes_global_t const * stakes = fd_bank_stakes_locking_query( slot_ctx->bank ); + fd_stakes_global_t const * stakes = fd_bank_stakes_locking_query( bank ); if( FD_UNLIKELY( stakes==NULL ) ) { FD_LOG_WARNING(( "stakes is NULL" )); - fd_bank_stakes_end_locking_query( slot_ctx->bank ); + fd_bank_stakes_end_locking_query( bank ); return 0; } @@ -130,7 +130,7 @@ recover_clock( fd_exec_slot_ctx_t * slot_ctx, fd_spad_t * runtime_spad ) { &err ); if( FD_UNLIKELY( err ) ) { FD_LOG_WARNING(( "vote state decode failed" )); - fd_bank_stakes_end_locking_query( slot_ctx->bank ); + fd_bank_stakes_end_locking_query( bank ); return 0; } @@ -155,39 +155,41 @@ recover_clock( fd_exec_slot_ctx_t * slot_ctx, fd_spad_t * runtime_spad ) { /* Record timestamp */ if( slot != 0 || n->elem.stake != 0 ) { - fd_vote_record_timestamp_vote_with_slot( &n->elem.key, timestamp, slot, slot_ctx->bank ); + fd_vote_record_timestamp_vote_with_slot( &n->elem.key, timestamp, slot, bank ); } } FD_SPAD_FRAME_END; } - fd_bank_stakes_end_locking_query( slot_ctx->bank ); + fd_bank_stakes_end_locking_query( bank ); return 1; } -fd_exec_slot_ctx_t * -fd_exec_slot_ctx_recover( fd_exec_slot_ctx_t * slot_ctx, +int +fd_exec_slot_ctx_recover( fd_banks_t * banks, + fd_bank_t * * bank_out, fd_solana_manifest_global_t const * manifest, fd_spad_t * runtime_spad ) { - slot_ctx->bank = fd_banks_clone_from_parent( slot_ctx->banks, manifest->bank.slot, 0UL ); - if( FD_UNLIKELY( !slot_ctx->bank ) ) { + fd_bank_t * bank = fd_banks_clone_from_parent( banks, manifest->bank.slot, 0UL ); + if( FD_UNLIKELY( !bank ) ) { FD_LOG_CRIT(( "fd_banks_clone_from_parent failed" )); } + *bank_out = bank; fd_versioned_bank_global_t const * old_bank = &manifest->bank; ulong stakes_sz = fd_stakes_size_global( &manifest->bank.stakes ); - fd_stakes_global_t * stakes = fd_bank_stakes_locking_modify( slot_ctx->bank ); + fd_stakes_global_t * stakes = fd_bank_stakes_locking_modify( bank ); fd_memcpy( stakes, &manifest->bank.stakes, stakes_sz ); /* Verify stakes */ - fd_bank_stakes_end_locking_modify( slot_ctx->bank ); + fd_bank_stakes_end_locking_modify( bank ); /* Index vote accounts */ /* Block Hash Queue */ - fd_block_hash_queue_global_t * bhq = (fd_block_hash_queue_global_t *)&slot_ctx->bank->block_hash_queue[0]; + fd_block_hash_queue_global_t * bhq = fd_bank_block_hash_queue_modify( bank ); uchar * last_hash_mem = (uchar *)fd_ulong_align_up( (ulong)bhq + sizeof(fd_block_hash_queue_global_t), alignof(fd_hash_t) ); uchar * ages_pool_mem = (uchar *)fd_ulong_align_up( (ulong)last_hash_mem + sizeof(fd_hash_t), fd_hash_hash_age_pair_t_map_align() ); @@ -221,112 +223,117 @@ fd_exec_slot_ctx_recover( fd_exec_slot_ctx_t * slot_ctx, /* Bank Hash */ - fd_bank_bank_hash_set( slot_ctx->bank, old_bank->hash ); - - /* Slot */ - - slot_ctx->slot = old_bank->slot; + fd_bank_bank_hash_set( bank, old_bank->hash ); /* Fee Rate Governor */ - fd_fee_rate_governor_t * fee_rate_governor = fd_bank_fee_rate_governor_modify( slot_ctx->bank ); + fd_fee_rate_governor_t * fee_rate_governor = fd_bank_fee_rate_governor_modify( bank ); *fee_rate_governor = old_bank->fee_rate_governor; /* Capitalization */ - fd_bank_capitalization_set( slot_ctx->bank, old_bank->capitalization ); + fd_bank_capitalization_set( bank, old_bank->capitalization ); /* Lamports Per Signature */ - fd_bank_lamports_per_signature_set( slot_ctx->bank, manifest->lamports_per_signature ); + fd_bank_lamports_per_signature_set( bank, manifest->lamports_per_signature ); /* Previous Lamports Per Signature */ - fd_bank_prev_lamports_per_signature_set( slot_ctx->bank, manifest->lamports_per_signature ); + fd_bank_prev_lamports_per_signature_set( bank, manifest->lamports_per_signature ); /* Transaction Count */ - fd_bank_transaction_count_set( slot_ctx->bank, old_bank->transaction_count ); + fd_bank_transaction_count_set( bank, old_bank->transaction_count ); /* Parent Signature Count */ - fd_bank_parent_signature_cnt_set( slot_ctx->bank, old_bank->signature_count ); + fd_bank_parent_signature_cnt_set( bank, old_bank->signature_count ); /* Tick Height */ - fd_bank_tick_height_set( slot_ctx->bank, old_bank->tick_height ); + fd_bank_tick_height_set( bank, old_bank->tick_height ); /* Max Tick Height */ - fd_bank_max_tick_height_set( slot_ctx->bank, old_bank->max_tick_height ); + fd_bank_max_tick_height_set( bank, old_bank->max_tick_height ); /* Hashes Per Tick */ ulong * hashes_per_tick = fd_versioned_bank_hashes_per_tick_join( old_bank ); - fd_bank_hashes_per_tick_set( slot_ctx->bank, !!hashes_per_tick ? *hashes_per_tick : 0UL ); + fd_bank_hashes_per_tick_set( bank, !!hashes_per_tick ? *hashes_per_tick : 0UL ); /* NS Per Slot */ - fd_bank_ns_per_slot_set( slot_ctx->bank, old_bank->ns_per_slot ); + fd_bank_ns_per_slot_set( bank, old_bank->ns_per_slot ); /* Ticks Per Slot */ - fd_bank_ticks_per_slot_set( slot_ctx->bank, old_bank->ticks_per_slot ); + fd_bank_ticks_per_slot_set( bank, old_bank->ticks_per_slot ); /* Genesis Creation Time */ - fd_bank_genesis_creation_time_set( slot_ctx->bank, old_bank->genesis_creation_time ); + fd_bank_genesis_creation_time_set( bank, old_bank->genesis_creation_time ); /* Slots Per Year */ - fd_bank_slots_per_year_set( slot_ctx->bank, old_bank->slots_per_year ); + fd_bank_slots_per_year_set( bank, old_bank->slots_per_year ); /* Inflation */ - fd_bank_inflation_set( slot_ctx->bank, old_bank->inflation ); + fd_bank_inflation_set( bank, old_bank->inflation ); /* Block Height */ - fd_bank_block_height_set( slot_ctx->bank, old_bank->block_height ); + fd_bank_block_height_set( bank, old_bank->block_height ); /* Epoch Account Hash */ fd_hash_t * epoch_account_hash = fd_solana_manifest_epoch_account_hash_join( manifest ); if( !!epoch_account_hash ) { - fd_bank_epoch_account_hash_set( slot_ctx->bank, *epoch_account_hash ); + fd_bank_epoch_account_hash_set( bank, *epoch_account_hash ); } else { - fd_bank_epoch_account_hash_set( slot_ctx->bank, (fd_hash_t){0} ); + fd_bank_epoch_account_hash_set( bank, (fd_hash_t){0} ); } /* Prev Slot */ - fd_bank_prev_slot_set( slot_ctx->bank, old_bank->parent_slot ); + fd_bank_prev_slot_set( bank, old_bank->parent_slot ); /* Execution Fees */ - fd_bank_execution_fees_set( slot_ctx->bank, old_bank->collector_fees ); + fd_bank_execution_fees_set( bank, old_bank->collector_fees ); /* Priority Fees */ - fd_bank_priority_fees_set( slot_ctx->bank, 0UL ); + fd_bank_priority_fees_set( bank, 0UL ); /* PoH */ if( last_hash ) { - fd_bank_poh_set( slot_ctx->bank, *last_hash ); + fd_bank_poh_set( bank, *last_hash ); } /* Prev Bank Hash */ - fd_bank_prev_bank_hash_set( slot_ctx->bank, old_bank->parent_hash ); + fd_bank_prev_bank_hash_set( bank, old_bank->parent_hash ); /* Epoch Schedule */ - fd_bank_epoch_schedule_set( slot_ctx->bank, old_bank->epoch_schedule ); + fd_bank_epoch_schedule_set( bank, old_bank->epoch_schedule ); + + fd_epoch_schedule_t const * epoch_schedule = fd_bank_epoch_schedule_query( bank ); + FD_LOG_WARNING(( "schedule->slots_per_epoch = %lu", epoch_schedule->slots_per_epoch )); + FD_LOG_WARNING(( "schedule->leader_schedule_slot_offset = %lu", epoch_schedule->leader_schedule_slot_offset )); + FD_LOG_WARNING(( "schedule->warmup = %d", epoch_schedule->warmup )); + FD_LOG_WARNING(( "schedule->first_normal_epoch = %lu", epoch_schedule->first_normal_epoch )); + FD_LOG_WARNING(( "schedule->first_normal_slot = %lu", epoch_schedule->first_normal_slot )); + + /* Rent */ - fd_bank_rent_set( slot_ctx->bank, old_bank->rent_collector.rent ); + fd_bank_rent_set( bank, old_bank->rent_collector.rent ); /* Last Restart Slot */ @@ -338,7 +345,7 @@ fd_exec_slot_ctx_recover( fd_exec_slot_ctx_t * slot_ctx, number that is less or equal than the current slot number. (There might be some hard forks in the future, ignore these) */ do { - fd_sol_sysvar_last_restart_slot_t * last_restart_slot = fd_bank_last_restart_slot_modify( slot_ctx->bank ); + fd_sol_sysvar_last_restart_slot_t * last_restart_slot = fd_bank_last_restart_slot_modify( bank ); last_restart_slot->slot = 0UL; if( FD_UNLIKELY( old_bank->hard_forks.hard_forks_len == 0 ) ) { @@ -350,8 +357,8 @@ fd_exec_slot_ctx_recover( fd_exec_slot_ctx_t * slot_ctx, fd_slot_pair_t const * tail = head + old_bank->hard_forks.hard_forks_len - 1UL; for( fd_slot_pair_t const *pair = tail; pair >= head; pair-- ) { - if( pair->slot <= slot_ctx->slot ) { - fd_sol_sysvar_last_restart_slot_t * last_restart_slot = fd_bank_last_restart_slot_modify( slot_ctx->bank ); + if( pair->slot <= bank->slot ) { + fd_sol_sysvar_last_restart_slot_t * last_restart_slot = fd_bank_last_restart_slot_modify( bank ); last_restart_slot->slot = pair->slot; break; } @@ -359,21 +366,21 @@ fd_exec_slot_ctx_recover( fd_exec_slot_ctx_t * slot_ctx, } while (0); /* FIXME: Remove the magic number here. */ - fd_clock_timestamp_votes_global_t * clock_timestamp_votes = fd_bank_clock_timestamp_votes_locking_modify( slot_ctx->bank ); + fd_clock_timestamp_votes_global_t * clock_timestamp_votes = fd_bank_clock_timestamp_votes_locking_modify( bank ); uchar * clock_pool_mem = (uchar *)fd_ulong_align_up( (ulong)clock_timestamp_votes + sizeof(fd_clock_timestamp_votes_global_t), fd_clock_timestamp_vote_t_map_align() ); fd_clock_timestamp_vote_t_mapnode_t * clock_pool = fd_clock_timestamp_vote_t_map_join( fd_clock_timestamp_vote_t_map_new(clock_pool_mem, 30000UL ) ); clock_timestamp_votes->votes_pool_offset = (ulong)fd_clock_timestamp_vote_t_map_leave( clock_pool) - (ulong)clock_timestamp_votes; clock_timestamp_votes->votes_root_offset = 0UL; - fd_bank_clock_timestamp_votes_end_locking_modify( slot_ctx->bank ); + fd_bank_clock_timestamp_votes_end_locking_modify( bank ); - recover_clock( slot_ctx, runtime_spad ); + recover_clock( bank, runtime_spad ); /* Move EpochStakes */ do { - fd_epoch_schedule_t const * epoch_schedule = fd_bank_epoch_schedule_query( slot_ctx->bank ); - ulong epoch = fd_slot_to_epoch( epoch_schedule, slot_ctx->slot, NULL ); + fd_epoch_schedule_t const * epoch_schedule = fd_bank_epoch_schedule_query( bank ); + ulong epoch = fd_slot_to_epoch( epoch_schedule, bank->slot, NULL ); /* We need to save the vote accounts for the current epoch and the next epoch as it is used to calculate the leader schedule at the epoch @@ -426,11 +433,11 @@ fd_exec_slot_ctx_recover( fd_exec_slot_ctx_t * slot_ctx, the leader schedule for epoch 8 is determined based on the stakes at the end of epoch 6. Therefore, we save the total epoch stake by querying for epoch+1. */ - fd_bank_total_epoch_stake_set( slot_ctx->bank, versioned_epoch_stakes[i].val.inner.Current.total_stake ); + fd_bank_total_epoch_stake_set( bank, versioned_epoch_stakes[i].val.inner.Current.total_stake ); } } - fd_bank_use_prev_epoch_stake_set( slot_ctx->bank, epoch + 2UL ); + fd_bank_use_prev_epoch_stake_set( bank, epoch + 2UL ); fd_vote_accounts_pair_global_t_mapnode_t * vote_accounts_curr_stakes_pool = fd_vote_accounts_vote_accounts_pool_join( vote_accounts_curr_stakes ); fd_vote_accounts_pair_global_t_mapnode_t * vote_accounts_curr_stakes_root = fd_vote_accounts_vote_accounts_root_join( vote_accounts_curr_stakes ); @@ -445,7 +452,7 @@ fd_exec_slot_ctx_recover( fd_exec_slot_ctx_t * slot_ctx, /* Move current EpochStakes */ - fd_vote_accounts_global_t * epoch_stakes = fd_bank_epoch_stakes_locking_modify( slot_ctx->bank ); + fd_vote_accounts_global_t * epoch_stakes = fd_bank_epoch_stakes_locking_modify( bank ); uchar * epoch_stakes_pool_mem = (uchar *)fd_ulong_align_up( (ulong)epoch_stakes + sizeof(fd_vote_accounts_global_t), fd_vote_accounts_pair_global_t_map_align() ); fd_vote_accounts_pair_global_t_mapnode_t * epoch_stakes_pool = fd_vote_accounts_pair_global_t_map_join( fd_vote_accounts_pair_global_t_map_new( epoch_stakes_pool_mem, 50000UL ) ); fd_vote_accounts_pair_global_t_mapnode_t * epoch_stakes_root = NULL; @@ -487,11 +494,11 @@ fd_exec_slot_ctx_recover( fd_exec_slot_ctx_t * slot_ctx, fd_vote_accounts_vote_accounts_pool_update( epoch_stakes, epoch_stakes_pool ); fd_vote_accounts_vote_accounts_root_update( epoch_stakes, epoch_stakes_root ); - fd_bank_epoch_stakes_end_locking_modify( slot_ctx->bank ); + fd_bank_epoch_stakes_end_locking_modify( bank ); /* Move next EpochStakes */ - fd_vote_accounts_global_t * next_epoch_stakes = fd_bank_next_epoch_stakes_locking_modify( slot_ctx->bank ); + fd_vote_accounts_global_t * next_epoch_stakes = fd_bank_next_epoch_stakes_locking_modify( bank ); uchar * next_epoch_stakes_pool_mem = (uchar *)fd_ulong_align_up( (ulong)next_epoch_stakes + sizeof(fd_vote_accounts_global_t), fd_vote_accounts_pair_global_t_map_align() ); fd_vote_accounts_pair_global_t_mapnode_t * next_epoch_stakes_pool = fd_vote_accounts_pair_global_t_map_join( fd_vote_accounts_pair_global_t_map_new( next_epoch_stakes_pool_mem, 50000UL ) ); fd_vote_accounts_pair_global_t_mapnode_t * next_epoch_stakes_root = NULL; @@ -533,11 +540,11 @@ fd_exec_slot_ctx_recover( fd_exec_slot_ctx_t * slot_ctx, } fd_vote_accounts_vote_accounts_pool_update( next_epoch_stakes, next_epoch_stakes_pool ); fd_vote_accounts_vote_accounts_root_update( next_epoch_stakes, next_epoch_stakes_root ); - fd_bank_next_epoch_stakes_end_locking_modify( slot_ctx->bank ); + fd_bank_next_epoch_stakes_end_locking_modify( bank ); } while(0); - fd_slot_lthash_t * lthash = fd_bank_lthash_modify( slot_ctx->bank ); + fd_slot_lthash_t * lthash = fd_bank_lthash_modify( bank ); fd_slot_lthash_t * lthash_value = fd_solana_manifest_lthash_join( manifest ); if( !!lthash_value ) { @@ -547,7 +554,7 @@ fd_exec_slot_ctx_recover( fd_exec_slot_ctx_t * slot_ctx, } /* Setup next epoch stakes */ - return slot_ctx; + return 1; } fd_exec_slot_ctx_t * @@ -555,6 +562,8 @@ fd_exec_slot_ctx_recover_status_cache( fd_exec_slot_ctx_t * ctx, fd_bank_slot_deltas_t * slot_deltas, fd_spad_t * runtime_spad ) { + return ctx; + fd_txncache_t * status_cache = ctx->status_cache; if( !status_cache ) { FD_LOG_WARNING(("No status cache in slot ctx")); diff --git a/src/flamenco/runtime/context/fd_exec_slot_ctx.h b/src/flamenco/runtime/context/fd_exec_slot_ctx.h index 9a0eab558f..e67a28b784 100644 --- a/src/flamenco/runtime/context/fd_exec_slot_ctx.h +++ b/src/flamenco/runtime/context/fd_exec_slot_ctx.h @@ -61,8 +61,9 @@ fd_exec_slot_ctx_delete( void * mem ); epoch context use same allocator. Returns ctx on success. On failure, logs reason for error and returns NULL. */ -fd_exec_slot_ctx_t * -fd_exec_slot_ctx_recover( fd_exec_slot_ctx_t * ctx, +int +fd_exec_slot_ctx_recover( fd_banks_t * banks, + fd_bank_t * * bank_out, fd_solana_manifest_global_t const * manifest_global, fd_spad_t * spad ); diff --git a/src/flamenco/runtime/fd_runtime.c b/src/flamenco/runtime/fd_runtime.c index fab6bf59ef..b285929624 100644 --- a/src/flamenco/runtime/fd_runtime.c +++ b/src/flamenco/runtime/fd_runtime.c @@ -113,11 +113,13 @@ fd_runtime_update_leaders( fd_bank_t * bank, fd_epoch_schedule_t const * epoch_schedule = fd_bank_epoch_schedule_query( bank ); - FD_LOG_INFO(( "schedule->slots_per_epoch = %lu", epoch_schedule->slots_per_epoch )); - FD_LOG_INFO(( "schedule->leader_schedule_slot_offset = %lu", epoch_schedule->leader_schedule_slot_offset )); - FD_LOG_INFO(( "schedule->warmup = %d", epoch_schedule->warmup )); - FD_LOG_INFO(( "schedule->first_normal_epoch = %lu", epoch_schedule->first_normal_epoch )); - FD_LOG_INFO(( "schedule->first_normal_slot = %lu", epoch_schedule->first_normal_slot )); + FD_LOG_WARNING(("SLOT %lu", bank->slot )); + + FD_LOG_WARNING(( "schedule->slots_per_epoch = %lu", epoch_schedule->slots_per_epoch )); + FD_LOG_WARNING(( "schedule->leader_schedule_slot_offset = %lu", epoch_schedule->leader_schedule_slot_offset )); + FD_LOG_WARNING(( "schedule->warmup = %d", epoch_schedule->warmup )); + FD_LOG_WARNING(( "schedule->first_normal_epoch = %lu", epoch_schedule->first_normal_epoch )); + FD_LOG_WARNING(( "schedule->first_normal_slot = %lu", epoch_schedule->first_normal_slot )); fd_vote_accounts_global_t const * epoch_vaccs = fd_bank_epoch_stakes_locking_query( bank ); fd_vote_accounts_pair_global_t_mapnode_t * vote_acc_pool = fd_vote_accounts_vote_accounts_pool_join( epoch_vaccs ); diff --git a/src/flamenco/snapshot/fd_snapshot.c b/src/flamenco/snapshot/fd_snapshot.c index 5efad33f29..3e83295909 100644 --- a/src/flamenco/snapshot/fd_snapshot.c +++ b/src/flamenco/snapshot/fd_snapshot.c @@ -20,11 +20,15 @@ struct fd_snapshot_load_ctx { const char * snapshot_dir; const char * snapshot_src; int snapshot_src_type; - fd_exec_slot_ctx_t * slot_ctx; uint verify_hash; uint check_hash; int snapshot_type; + fd_banks_t * banks; + fd_bank_t * bank; + fd_funk_t * funk; + fd_funk_txn_t * funk_txn; + /* Internal state. */ fd_funk_txn_t * par_txn; fd_funk_txn_t * child_txn; @@ -39,22 +43,28 @@ struct fd_snapshot_load_ctx { typedef struct fd_snapshot_load_ctx fd_snapshot_load_ctx_t; static void -fd_hashes_load( fd_exec_slot_ctx_t * slot_ctx ) { +fd_hashes_load( fd_bank_t * bank, fd_funk_t * funk, fd_funk_txn_t * funk_txn ) { FD_TXN_ACCOUNT_DECL( block_hashes_rec ); - int err = fd_txn_account_init_from_funk_readonly( block_hashes_rec, &fd_sysvar_recent_block_hashes_id, slot_ctx->funk, slot_ctx->funk_txn ); + int err = fd_txn_account_init_from_funk_readonly( block_hashes_rec, &fd_sysvar_recent_block_hashes_id, funk, funk_txn ); if( err != FD_ACC_MGR_SUCCESS ) { FD_LOG_ERR(( "missing recent block hashes account" )); } - fd_bank_execution_fees_set( slot_ctx->bank, 0UL ); + fd_bank_execution_fees_set( bank, 0UL ); } static int restore_manifest( void * ctx, fd_solana_manifest_global_t const * manifest, fd_spad_t * spad ) { - return (!!fd_exec_slot_ctx_recover( ctx, manifest, spad ) ? 0 : EINVAL); + fd_snapshot_load_ctx_t * load_ctx = (fd_snapshot_load_ctx_t *)ctx; + + fd_bank_t * bank = NULL; + int err = (!!fd_exec_slot_ctx_recover( load_ctx->banks, &bank, manifest, spad ) ? 0 : EINVAL); + FD_LOG_WARNING(("P %p", (void*)load_ctx)); + load_ctx->bank = bank; + return err; } static int @@ -96,7 +106,12 @@ fd_snapshot_load_new( uchar * mem, ctx->snapshot_dir = snapshot_dir; ctx->snapshot_src = snapshot_src; ctx->snapshot_src_type = snapshot_src_type; - ctx->slot_ctx = slot_ctx; + + ctx->banks = slot_ctx->banks; + ctx->bank = slot_ctx->bank; + ctx->funk = slot_ctx->funk; + ctx->funk_txn = slot_ctx->funk_txn; + ctx->verify_hash = verify_hash; ctx->check_hash = check_hash; ctx->snapshot_type = snapshot_type; @@ -123,19 +138,19 @@ fd_snapshot_load_init( fd_snapshot_load_ctx_t * ctx ) { break; } - ctx->par_txn = ctx->slot_ctx->funk_txn; - ctx->child_txn = ctx->slot_ctx->funk_txn; + ctx->par_txn = ctx->funk_txn; + ctx->child_txn = ctx->funk_txn; // the hash in the incremental snapshot of an lt_hash contains all the accounts. This means we don't need a sub-txn for the incremental if( ctx->verify_hash && - (FD_FEATURE_ACTIVE_BANK( ctx->slot_ctx->bank, incremental_snapshot_only_incremental_hash_calculation ) - && !FD_FEATURE_ACTIVE_BANK( ctx->slot_ctx->bank, snapshots_lt_hash ) )) { + (FD_FEATURE_ACTIVE_BANK( ctx->bank, incremental_snapshot_only_incremental_hash_calculation ) + && !FD_FEATURE_ACTIVE_BANK( ctx->bank, snapshots_lt_hash ) )) { fd_funk_txn_xid_t xid; memset( &xid, 0xc3, sizeof(xid) ); - fd_funk_txn_start_write( ctx->slot_ctx->funk ); - ctx->child_txn = fd_funk_txn_prepare( ctx->slot_ctx->funk, ctx->child_txn, &xid, 0 ); - fd_funk_txn_end_write( ctx->slot_ctx->funk ); - ctx->slot_ctx->funk_txn = ctx->child_txn; + fd_funk_txn_start_write( ctx->funk ); + ctx->child_txn = fd_funk_txn_prepare( ctx->funk, ctx->child_txn, &xid, 0 ); + fd_funk_txn_end_write( ctx->funk ); + ctx->funk_txn = ctx->child_txn; } } @@ -154,8 +169,8 @@ fd_snapshot_load_manifest_and_status_cache( fd_snapshot_load_ctx_t * ctx, } src->snapshot_dir = ctx->snapshot_dir; - fd_funk_t * funk = ctx->slot_ctx->funk; - fd_funk_txn_t * funk_txn = ctx->slot_ctx->funk_txn; + fd_funk_t * funk = ctx->funk; + fd_funk_txn_t * funk_txn = ctx->funk_txn; void * restore_mem = fd_spad_alloc( ctx->runtime_spad, fd_snapshot_restore_align(), fd_snapshot_restore_footprint() ); void * loader_mem = fd_spad_alloc( ctx->runtime_spad, fd_snapshot_loader_align(), fd_snapshot_loader_footprint( ZSTD_WINDOW_SZ ) ); @@ -164,7 +179,7 @@ fd_snapshot_load_manifest_and_status_cache( fd_snapshot_load_ctx_t * ctx, funk, funk_txn, ctx->runtime_spad, - ctx->slot_ctx, + ctx, (restore_manifest_flags & FD_SNAPSHOT_RESTORE_MANIFEST) ? restore_manifest : NULL, (restore_manifest_flags & FD_SNAPSHOT_RESTORE_STATUS_CACHE) ? restore_status_cache : NULL ); if( FD_UNLIKELY( !ctx->restore ) ) { @@ -180,7 +195,7 @@ fd_snapshot_load_manifest_and_status_cache( fd_snapshot_load_ctx_t * ctx, if( FD_UNLIKELY( !fd_snapshot_loader_init( ctx->loader, ctx->restore, src, - base_slot_override ? *base_slot_override : ctx->slot_ctx->slot, + base_slot_override ? *base_slot_override : ctx->bank->slot, 1 ) ) ) { FD_LOG_ERR(( "Failed to init snapshot loader" )); } @@ -230,20 +245,20 @@ fd_snapshot_load_fini( fd_snapshot_load_ctx_t * ctx ) { // In order to calculate the snapshot hash, we need to know what features are active... fd_features_restore( - ctx->slot_ctx->bank, - ctx->slot_ctx->funk, - ctx->slot_ctx->funk_txn, + ctx->bank, + ctx->funk, + ctx->funk_txn, ctx->runtime_spad ); - fd_calculate_epoch_accounts_hash_values( ctx->slot_ctx->bank ); + fd_calculate_epoch_accounts_hash_values( ctx->bank ); - int snapshots_lt_hash = FD_FEATURE_ACTIVE_BANK( ctx->slot_ctx->bank, snapshots_lt_hash ); - int accounts_lt_hash = FD_FEATURE_ACTIVE_BANK( ctx->slot_ctx->bank, accounts_lt_hash ); - int incremental_snapshot_only_incremental_hash_calculation = FD_FEATURE_ACTIVE_BANK( ctx->slot_ctx->bank, + int snapshots_lt_hash = FD_FEATURE_ACTIVE_BANK( ctx->bank, snapshots_lt_hash ); + int accounts_lt_hash = FD_FEATURE_ACTIVE_BANK( ctx->bank, accounts_lt_hash ); + int incremental_snapshot_only_incremental_hash_calculation = FD_FEATURE_ACTIVE_BANK( ctx->bank, incremental_snapshot_only_incremental_hash_calculation ); // https://github.com/anza-xyz/agave/blob/766cd682423b8049ddeac3c0ec6cebe0a1356e9e/runtime/src/bank.rs#L1831 if( accounts_lt_hash ) { - fd_slot_lthash_t const * lthash = fd_bank_lthash_query( ctx->slot_ctx->bank ); + fd_slot_lthash_t const * lthash = fd_bank_lthash_query( ctx->bank ); ulong *p = (ulong *) lthash->lthash; ulong *e = (ulong *) <hash->lthash[sizeof(lthash->lthash)]; while (p < e) { @@ -256,8 +271,8 @@ fd_snapshot_load_fini( fd_snapshot_load_ctx_t * ctx ) { fd_lthash_value_t lthash_buf; fd_lthash_zero(<hash_buf); fd_hash_t accounts_hash; - fd_snapshot_hash( ctx->slot_ctx, &accounts_hash, ctx->check_hash, ctx->runtime_spad, ctx->exec_para_ctx, <hash_buf ); - fd_slot_lthash_t * lthash_val = fd_bank_lthash_modify( ctx->slot_ctx->bank ); + fd_snapshot_hash( ctx->bank, ctx->funk, &accounts_hash, ctx->runtime_spad, ctx->exec_para_ctx, <hash_buf ); + fd_slot_lthash_t * lthash_val = fd_bank_lthash_modify( ctx->bank ); fd_memcpy( (fd_lthash_value_t *)fd_type_pun(lthash_val->lthash), <hash_buf, sizeof(lthash_buf) ); FD_LOG_NOTICE(( "re-calculated accounts_lthash for full snapshot %s", FD_LTHASH_ENC_32_ALLOCA( (fd_lthash_value_t *)fd_type_pun(lthash_val->lthash) ) )); } @@ -277,11 +292,11 @@ fd_snapshot_load_fini( fd_snapshot_load_ctx_t * ctx ) { if( ctx->snapshot_type==FD_SNAPSHOT_TYPE_FULL ) { FD_SPAD_FRAME_BEGIN( ctx->runtime_spad ) { - fd_snapshot_hash( ctx->slot_ctx, &accounts_hash, ctx->check_hash, ctx->runtime_spad, ctx->exec_para_ctx, lthash ); + fd_snapshot_hash( ctx->bank, ctx->funk, &accounts_hash, ctx->runtime_spad, ctx->exec_para_ctx, lthash ); } FD_SPAD_FRAME_END; if ( snapshots_lt_hash ) { - fd_slot_lthash_t const * lthash_val = fd_bank_lthash_query( ctx->slot_ctx->bank ); + fd_slot_lthash_t const * lthash_val = fd_bank_lthash_query( ctx->bank ); if( memcmp( (fd_lthash_value_t *)lthash_val->lthash, lthash, sizeof(lthash_buf) ) ) { FD_LOG_ERR(( "snapshot accounts_hash (calculated) %s != (expected) %s", FD_LTHASH_ENC_32_ALLOCA( (fd_lthash_value_t *)lthash_val->lthash ), FD_LTHASH_ENC_32_ALLOCA( lthash ) )); @@ -300,14 +315,14 @@ fd_snapshot_load_fini( fd_snapshot_load_ctx_t * ctx ) { if( incremental_snapshot_only_incremental_hash_calculation && !snapshots_lt_hash ) { FD_LOG_NOTICE(( "hashing incremental snapshot with only deltas" )); - fd_snapshot_inc_hash( ctx->slot_ctx, &accounts_hash, ctx->child_txn, ctx->check_hash, ctx->runtime_spad, NULL); + fd_snapshot_inc_hash( ctx->bank, ctx->funk, &accounts_hash, ctx->child_txn, ctx->check_hash, ctx->runtime_spad ); } else { FD_LOG_NOTICE(( "hashing incremental snapshot with all accounts" )); - fd_snapshot_hash( ctx->slot_ctx, &accounts_hash, ctx->check_hash, ctx->runtime_spad, ctx->exec_para_ctx, lthash ); + fd_snapshot_hash( ctx->bank, ctx->funk, &accounts_hash, ctx->runtime_spad, ctx->exec_para_ctx, lthash ); } if ( snapshots_lt_hash ) { - fd_slot_lthash_t const * lthash_val = fd_bank_lthash_query( ctx->slot_ctx->bank ); + fd_slot_lthash_t const * lthash_val = fd_bank_lthash_query( ctx->bank ); if( memcmp( (fd_lthash_value_t *)lthash_val->lthash, lthash, sizeof(lthash_buf) ) ) { FD_LOG_ERR(( "snapshot accounts_hash (calculated) %s != (expected) %s", FD_LTHASH_ENC_32_ALLOCA( (fd_lthash_value_t *)lthash_val->lthash ), FD_LTHASH_ENC_32_ALLOCA( lthash ) )); @@ -327,13 +342,13 @@ fd_snapshot_load_fini( fd_snapshot_load_ctx_t * ctx ) { } if( ctx->child_txn != ctx->par_txn ) { - fd_funk_txn_start_write( ctx->slot_ctx->funk ); - fd_funk_txn_publish( ctx->slot_ctx->funk, ctx->child_txn, 0 ); - fd_funk_txn_end_write( ctx->slot_ctx->funk ); - ctx->slot_ctx->funk_txn = ctx->par_txn; + fd_funk_txn_start_write( ctx->funk ); + fd_funk_txn_publish( ctx->funk, ctx->child_txn, 0 ); + fd_funk_txn_end_write( ctx->funk ); + ctx->funk_txn = ctx->par_txn; } - fd_hashes_load( ctx->slot_ctx ); + fd_hashes_load( ctx->bank, ctx->funk, ctx->funk_txn ); /* We don't need to free any of the loader memory since it is allocated from a spad. */ @@ -380,8 +395,9 @@ fd_snapshot_load_all( const char * source_cstr, fd_snapshot_load_accounts( ctx ); fd_snapshot_load_fini( ctx ); - } FD_SPAD_FRAME_END; + slot_ctx->bank = ctx->bank; + } FD_SPAD_FRAME_END; } void @@ -397,13 +413,10 @@ fd_snapshot_load_prefetch_manifest( fd_snapshot_load_ctx_t * ctx ) { } src->snapshot_dir = ctx->snapshot_dir; - fd_funk_t * funk = ctx->slot_ctx->funk; - fd_funk_txn_t * funk_txn = ctx->slot_ctx->funk_txn; - void * restore_mem = fd_spad_alloc( ctx->runtime_spad, fd_snapshot_restore_align(), fd_snapshot_restore_footprint() ); void * loader_mem = fd_spad_alloc( ctx->runtime_spad, fd_snapshot_loader_align(), fd_snapshot_loader_footprint( ZSTD_WINDOW_SZ ) ); - ctx->restore = fd_snapshot_restore_new( restore_mem, funk, funk_txn, ctx->runtime_spad, ctx->slot_ctx, restore_manifest, restore_status_cache ); + ctx->restore = fd_snapshot_restore_new( restore_mem, ctx->funk, ctx->funk_txn, ctx->runtime_spad, ctx, restore_manifest, restore_status_cache ); if( FD_UNLIKELY( !ctx->restore ) ) { FD_LOG_ERR(( "Failed to fd_snapshot_restore_new" )); } @@ -432,16 +445,16 @@ fd_snapshot_load_prefetch_manifest( fd_snapshot_load_ctx_t * ctx ) { } static int -fd_should_snapshot_include_epoch_accounts_hash(fd_exec_slot_ctx_t * slot_ctx) { - if( FD_FEATURE_ACTIVE_BANK( slot_ctx->bank, snapshots_lt_hash ) ) { +fd_should_snapshot_include_epoch_accounts_hash( fd_bank_t * bank ) { + if( FD_FEATURE_ACTIVE_BANK( bank, snapshots_lt_hash ) ) { return 0; } // We need to find the correct logic - if( fd_bank_eah_start_slot_get( slot_ctx->bank ) != ULONG_MAX ) { + if( fd_bank_eah_start_slot_get( bank ) != ULONG_MAX ) { return 0; } - if( fd_bank_eah_stop_slot_get( slot_ctx->bank ) == ULONG_MAX ) { + if( fd_bank_eah_stop_slot_get( bank ) == ULONG_MAX ) { return 0; } return 1; @@ -453,63 +466,61 @@ fd_snapshot_get_slot( fd_snapshot_load_ctx_t * ctx ) { } int -fd_snapshot_hash( fd_exec_slot_ctx_t * slot_ctx, +fd_snapshot_hash( fd_bank_t * bank, + fd_funk_t * funk, fd_hash_t * accounts_hash, - uint check_hash, fd_spad_t * runtime_spad, fd_exec_para_cb_ctx_t * exec_para_ctx, fd_lthash_value_t * lt_hash ) { - (void)check_hash; - if( fd_should_snapshot_include_epoch_accounts_hash( slot_ctx ) ) { + if( fd_should_snapshot_include_epoch_accounts_hash( bank ) ) { FD_LOG_NOTICE(( "snapshot is including epoch account hash" )); fd_sha256_t h; fd_hash_t hash; - fd_accounts_hash( slot_ctx->funk, - slot_ctx->slot, + fd_accounts_hash( funk, + bank->slot, &hash, runtime_spad, - fd_bank_features_query( slot_ctx->bank ), + fd_bank_features_query( bank ), exec_para_ctx, lt_hash ); fd_sha256_init( &h ); fd_sha256_append( &h, (uchar const *) hash.hash, sizeof( fd_hash_t ) ); - fd_sha256_append( &h, (uchar const *) fd_bank_epoch_account_hash_query( slot_ctx->bank ), sizeof( fd_hash_t ) ); + fd_sha256_append( &h, (uchar const *) fd_bank_epoch_account_hash_query( bank ), sizeof( fd_hash_t ) ); fd_sha256_fini( &h, accounts_hash ); return 0; } - return fd_accounts_hash( slot_ctx->funk, - slot_ctx->slot, + return fd_accounts_hash( funk, + bank->slot, accounts_hash, runtime_spad, - fd_bank_features_query( slot_ctx->bank ), + fd_bank_features_query( bank ), exec_para_ctx, lt_hash ); } int -fd_snapshot_inc_hash( fd_exec_slot_ctx_t * slot_ctx, +fd_snapshot_inc_hash( fd_bank_t * bank, + fd_funk_t * funk, fd_hash_t * accounts_hash, fd_funk_txn_t * child_txn, uint do_hash_verify, - fd_spad_t * spad, - fd_lthash_value_t * lt_hash ) { - - (void) lt_hash; + fd_spad_t * spad ) { - if( fd_should_snapshot_include_epoch_accounts_hash( slot_ctx ) ) { + if( fd_should_snapshot_include_epoch_accounts_hash( bank ) ) { fd_sha256_t h; fd_hash_t hash; - fd_accounts_hash_inc_only( slot_ctx->bank, slot_ctx->funk, &hash, child_txn, do_hash_verify, spad ); + fd_accounts_hash_inc_only( bank, funk, &hash, child_txn, do_hash_verify, spad ); fd_sha256_init( &h ); fd_sha256_append( &h, (uchar const *) hash.hash, sizeof( fd_hash_t ) ); - //fd_sha256_append( &h, (uchar const *) slot_ctx->slot_bank.epoch_account_hash.hash, sizeof( fd_hash_t ) ); + fd_hash_t const * epoch_account_hash = fd_bank_epoch_account_hash_query( bank ); + fd_sha256_append( &h, (uchar const *) epoch_account_hash, sizeof( fd_hash_t ) ); fd_sha256_fini( &h, accounts_hash ); return 0; } - return fd_accounts_hash_inc_only( slot_ctx->bank, slot_ctx->funk, accounts_hash, child_txn, do_hash_verify, spad ); + return fd_accounts_hash_inc_only( bank, funk, accounts_hash, child_txn, do_hash_verify, spad ); } diff --git a/src/flamenco/snapshot/fd_snapshot.h b/src/flamenco/snapshot/fd_snapshot.h index 9f325d2a94..52e99bd250 100644 --- a/src/flamenco/snapshot/fd_snapshot.h +++ b/src/flamenco/snapshot/fd_snapshot.h @@ -7,6 +7,7 @@ #include "fd_snapshot_base.h" #include "../runtime/fd_runtime_public.h" +#include "../runtime/fd_bank.h" #include "../../funk/fd_funk_txn.h" #include "../../ballet/lthash/fd_lthash.h" @@ -116,21 +117,21 @@ fd_snapshot_get_slot( fd_snapshot_load_ctx_t * ctx ); /* Generate a non-incremental hash of the entire account database, conditionally including in the epoch account hash. */ int -fd_snapshot_hash( fd_exec_slot_ctx_t * slot_ctx, +fd_snapshot_hash( fd_bank_t * bank, + fd_funk_t * funk, fd_hash_t * accounts_hash, - uint check_hash, fd_spad_t * runtime_spad, fd_exec_para_cb_ctx_t * exec_para_ctx, fd_lthash_value_t * lt_hash ); /* Generate an incremental hash of the entire account database, conditionally including in the epoch account hash. */ int -fd_snapshot_inc_hash( fd_exec_slot_ctx_t * slot_ctx, +fd_snapshot_inc_hash( fd_bank_t * bank, + fd_funk_t * funk, fd_hash_t * accounts_hash, fd_funk_txn_t * child_txn, uint check_hash, - fd_spad_t * spad, - fd_lthash_value_t * lt_hash ); + fd_spad_t * spad ); FD_PROTOTYPES_END From c9b202913df78e0ef22ab5ca1d28fe1b02185f7d Mon Sep 17 00:00:00 2001 From: Ishan Bhatt Date: Tue, 8 Jul 2025 22:07:43 +0000 Subject: [PATCH 20/27] asdf --- src/app/ledger/main.c | 14 ++++++--- src/discof/replay/fd_replay_tile.c | 31 ++++++++++--------- .../runtime/context/fd_exec_slot_ctx.c | 9 ------ src/flamenco/snapshot/fd_snapshot.c | 15 ++++----- src/flamenco/snapshot/fd_snapshot.h | 6 ++-- 5 files changed, 38 insertions(+), 37 deletions(-) diff --git a/src/app/ledger/main.c b/src/app/ledger/main.c index a23f51a201..f842c349c6 100644 --- a/src/app/ledger/main.c +++ b/src/app/ledger/main.c @@ -896,7 +896,7 @@ ingest( fd_ledger_args_t * args ) { /* Load in snapshot(s) */ if( args->snapshot ) { - fd_snapshot_load_all( args->snapshot, + args->slot_ctx->bank = fd_snapshot_load_all( args->snapshot, FD_SNAPSHOT_SRC_FILE, NULL, slot_ctx, @@ -908,10 +908,13 @@ ingest( fd_ledger_args_t * args ) { args->exec_spads, args->exec_spad_cnt, args->runtime_spad ); + if( FD_UNLIKELY( !args->slot_ctx->bank ) ) { + FD_LOG_ERR(( "Failed to load snapshot" )); + } FD_LOG_NOTICE(( "imported records from snapshot" )); } if( args->incremental ) { - fd_snapshot_load_all( args->incremental, + args->slot_ctx->bank = fd_snapshot_load_all( args->incremental, FD_SNAPSHOT_SRC_FILE, NULL, slot_ctx, @@ -923,6 +926,9 @@ ingest( fd_ledger_args_t * args ) { args->exec_spads, args->exec_spad_cnt, args->runtime_spad ); + if( FD_UNLIKELY( !args->slot_ctx->bank ) ) { + FD_LOG_ERR(( "Failed to load incremental snapshot" )); + } FD_LOG_NOTICE(( "imported records from incremental snapshot" )); } @@ -1070,7 +1076,7 @@ replay( fd_ledger_args_t * args ) { /* Load in snapshot(s) */ if( args->snapshot ) { - fd_snapshot_load_all( args->snapshot, + args->slot_ctx->bank = fd_snapshot_load_all( args->snapshot, FD_SNAPSHOT_SRC_FILE, NULL, args->slot_ctx, @@ -1084,7 +1090,7 @@ replay( fd_ledger_args_t * args ) { args->runtime_spad ); FD_LOG_NOTICE(( "imported from snapshot" )); if( args->incremental ) { - fd_snapshot_load_all( args->incremental, + args->slot_ctx->bank = fd_snapshot_load_all( args->incremental, FD_SNAPSHOT_SRC_FILE, NULL, args->slot_ctx, diff --git a/src/discof/replay/fd_replay_tile.c b/src/discof/replay/fd_replay_tile.c index 0afb02c91f..ecbc1a7bd9 100644 --- a/src/discof/replay/fd_replay_tile.c +++ b/src/discof/replay/fd_replay_tile.c @@ -1353,8 +1353,9 @@ read_snapshot( void * _ctx, /* If we don't have an incremental snapshot, load the manifest and the status cache and initialize the objects because we don't have these from the incremental snapshot. */ if( strlen( incremental )<=0UL ) { - fd_snapshot_load_manifest_and_status_cache( snap_ctx, NULL, + ctx->slot_ctx->bank = fd_snapshot_load_manifest_and_status_cache( snap_ctx, NULL, FD_SNAPSHOT_RESTORE_MANIFEST | FD_SNAPSHOT_RESTORE_STATUS_CACHE ); + ctx->slot_ctx->slot = ctx->slot_ctx->bank->slot; ctx->curr_slot = ctx->slot_ctx->slot; kickoff_repair_orphans( ctx, stem ); /* If we don't have an incremental snapshot, we can still kick off @@ -1366,25 +1367,27 @@ read_snapshot( void * _ctx, } base_slot = fd_snapshot_get_slot( snap_ctx ); fd_snapshot_load_accounts( snap_ctx ); - fd_snapshot_load_fini( snap_ctx ); + ctx->slot_ctx->bank = fd_snapshot_load_fini( snap_ctx ); + ctx->slot_ctx->slot = ctx->slot_ctx->bank->slot; } if( strlen( incremental ) > 0 && strcmp( snapshot, "funk" ) != 0 ) { /* The slot of the full snapshot should be used as the base slot to verify the incremental snapshot, not the slot context's slot - which is the slot of the incremental, not the full snapshot. */ - fd_snapshot_load_all( incremental, - ctx->incremental_src_type, - NULL, - ctx->slot_ctx, - &base_slot, - NULL, - false, - false, - FD_SNAPSHOT_TYPE_INCREMENTAL, - ctx->exec_spads, - ctx->exec_spad_cnt, - ctx->runtime_spad ); + ctx->slot_ctx->bank = fd_snapshot_load_all( incremental, + ctx->incremental_src_type, + NULL, + ctx->slot_ctx, + &base_slot, + NULL, + false, + false, + FD_SNAPSHOT_TYPE_INCREMENTAL, + ctx->exec_spads, + ctx->exec_spad_cnt, + ctx->runtime_spad ); + ctx->slot_ctx->slot = ctx->slot_ctx->bank->slot; ctx->curr_slot = ctx->slot_ctx->slot; kickoff_repair_orphans( ctx, stem ); } diff --git a/src/flamenco/runtime/context/fd_exec_slot_ctx.c b/src/flamenco/runtime/context/fd_exec_slot_ctx.c index dda9b1a1de..f01484bbc0 100644 --- a/src/flamenco/runtime/context/fd_exec_slot_ctx.c +++ b/src/flamenco/runtime/context/fd_exec_slot_ctx.c @@ -322,15 +322,6 @@ fd_exec_slot_ctx_recover( fd_banks_t * banks, fd_bank_epoch_schedule_set( bank, old_bank->epoch_schedule ); - fd_epoch_schedule_t const * epoch_schedule = fd_bank_epoch_schedule_query( bank ); - FD_LOG_WARNING(( "schedule->slots_per_epoch = %lu", epoch_schedule->slots_per_epoch )); - FD_LOG_WARNING(( "schedule->leader_schedule_slot_offset = %lu", epoch_schedule->leader_schedule_slot_offset )); - FD_LOG_WARNING(( "schedule->warmup = %d", epoch_schedule->warmup )); - FD_LOG_WARNING(( "schedule->first_normal_epoch = %lu", epoch_schedule->first_normal_epoch )); - FD_LOG_WARNING(( "schedule->first_normal_slot = %lu", epoch_schedule->first_normal_slot )); - - - /* Rent */ fd_bank_rent_set( bank, old_bank->rent_collector.rent ); diff --git a/src/flamenco/snapshot/fd_snapshot.c b/src/flamenco/snapshot/fd_snapshot.c index 3e83295909..b3993053f9 100644 --- a/src/flamenco/snapshot/fd_snapshot.c +++ b/src/flamenco/snapshot/fd_snapshot.c @@ -154,7 +154,7 @@ fd_snapshot_load_init( fd_snapshot_load_ctx_t * ctx ) { } } -void +fd_bank_t * fd_snapshot_load_manifest_and_status_cache( fd_snapshot_load_ctx_t * ctx, ulong * base_slot_override, int restore_manifest_flags ) { @@ -211,6 +211,7 @@ fd_snapshot_load_manifest_and_status_cache( fd_snapshot_load_ctx_t * ctx, FD_LOG_ERR(( "Failed to load snapshot (%d-%s)", err, fd_io_strerror( err ) )); } + return ctx->bank; } void @@ -234,7 +235,7 @@ fd_snapshot_load_accounts( fd_snapshot_load_ctx_t * ctx ) { } #define FD_LTHASH_SNAPSHOT_HACK -void +fd_bank_t * fd_snapshot_load_fini( fd_snapshot_load_ctx_t * ctx ) { fd_snapshot_name_t const * name = fd_snapshot_loader_get_name( ctx->loader ); fd_hash_t const * fhash = &name->fhash; @@ -350,11 +351,13 @@ fd_snapshot_load_fini( fd_snapshot_load_ctx_t * ctx ) { fd_hashes_load( ctx->bank, ctx->funk, ctx->funk_txn ); + return ctx->bank; + /* We don't need to free any of the loader memory since it is allocated from a spad. */ } -void +fd_bank_t * fd_snapshot_load_all( const char * source_cstr, int source_type, const char * snapshot_dir, @@ -393,10 +396,8 @@ fd_snapshot_load_all( const char * source_cstr, fd_snapshot_load_manifest_and_status_cache( ctx, base_slot_override, FD_SNAPSHOT_RESTORE_STATUS_CACHE | FD_SNAPSHOT_RESTORE_MANIFEST ); fd_snapshot_load_accounts( ctx ); - fd_snapshot_load_fini( ctx ); - - slot_ctx->bank = ctx->bank; - + fd_bank_t * bank = fd_snapshot_load_fini( ctx ); + return bank; } FD_SPAD_FRAME_END; } diff --git a/src/flamenco/snapshot/fd_snapshot.h b/src/flamenco/snapshot/fd_snapshot.h index 52e99bd250..b0b2ab0a1f 100644 --- a/src/flamenco/snapshot/fd_snapshot.h +++ b/src/flamenco/snapshot/fd_snapshot.h @@ -84,7 +84,7 @@ void fd_snapshot_load_init( fd_snapshot_load_ctx_t * ctx ); /* restore_manifest_flags controls if the manifest and status cache objects are initialized or not. */ -void +fd_bank_t * fd_snapshot_load_manifest_and_status_cache( fd_snapshot_load_ctx_t * ctx, ulong * base_slot_override, int restore_manifest_flags ); @@ -92,10 +92,10 @@ fd_snapshot_load_manifest_and_status_cache( fd_snapshot_load_ctx_t * ctx, void fd_snapshot_load_accounts( fd_snapshot_load_ctx_t * ctx ); -void +fd_bank_t * fd_snapshot_load_fini( fd_snapshot_load_ctx_t * ctx ); -void +fd_bank_t * fd_snapshot_load_all( const char * source_cstr, int source_type, const char * snapshot_dir, From e620a9533bf9a27f3967ae195ec2b37c7fcd21d9 Mon Sep 17 00:00:00 2001 From: Ishan Bhatt Date: Tue, 8 Jul 2025 22:29:14 +0000 Subject: [PATCH 21/27] no more slot ctx --- src/app/ledger/main.c | 229 ++++++++++++++-------------- src/discof/replay/fd_replay_tile.c | 15 +- src/flamenco/snapshot/fd_snapshot.c | 28 ++-- src/flamenco/snapshot/fd_snapshot.h | 10 +- 4 files changed, 151 insertions(+), 131 deletions(-) diff --git a/src/app/ledger/main.c b/src/app/ledger/main.c index f842c349c6..0b4ac3486b 100644 --- a/src/app/ledger/main.c +++ b/src/app/ledger/main.c @@ -20,7 +20,6 @@ struct fd_ledger_args { fd_wksp_t * status_cache_wksp; /* wksp for status cache. */ fd_blockstore_t blockstore_ljoin; fd_blockstore_t * blockstore; /* blockstore for replay */ - fd_funk_t funk[1]; /* handle to funk */ fd_alloc_t * alloc; /* handle to alloc */ char const * cmd; /* user passed command to fd_ledger */ ulong start_slot; /* start slot for offline replay */ @@ -79,7 +78,13 @@ struct fd_ledger_args { /* These values are setup and maintained before replay */ fd_capture_ctx_t * capture_ctx; /* capture_ctx is used in runtime_replay for various debugging tasks */ - fd_exec_slot_ctx_t * slot_ctx; /* slot_ctx */ + + /* Everything needed for replay */ + fd_banks_t * banks; + fd_bank_t * bank; + fd_funk_t funk[1]; + fd_funk_txn_t * funk_txn; + fd_tpool_t * tpool; /* thread pool for execution */ uchar tpool_mem[FD_TPOOL_FOOTPRINT( FD_TILE_MAX )] __attribute__( ( aligned( FD_TPOOL_ALIGN ) ) ); @@ -162,15 +167,14 @@ int runtime_replay( fd_ledger_args_t * ledger_args ) { int ret = 0; - ledger_args->slot_ctx->slot = ledger_args->slot_ctx->bank->slot; - ulong prev_slot = ledger_args->slot_ctx->slot; - ulong start_slot = ledger_args->slot_ctx->slot + 1; + ulong prev_slot = ledger_args->bank->slot; + ulong start_slot = ledger_args->bank->slot + 1; - fd_features_restore( ledger_args->slot_ctx->bank, ledger_args->slot_ctx->funk, ledger_args->slot_ctx->funk_txn, ledger_args->runtime_spad ); + fd_features_restore( ledger_args->bank, ledger_args->funk, ledger_args->funk_txn, ledger_args->runtime_spad ); - fd_runtime_update_leaders( ledger_args->slot_ctx->bank, ledger_args->slot_ctx->slot, ledger_args->runtime_spad ); + fd_runtime_update_leaders( ledger_args->bank, ledger_args->bank->slot, ledger_args->runtime_spad ); - fd_calculate_epoch_accounts_hash_values( ledger_args->slot_ctx->bank ); + fd_calculate_epoch_accounts_hash_values( ledger_args->bank ); long replay_time = -fd_log_wallclock(); ulong txn_cnt = 0; @@ -219,7 +223,7 @@ runtime_replay( fd_ledger_args_t * ledger_args ) { for( ulong slot = start_slot; slot<=ledger_args->end_slot && !aborted; ++slot ) { - fd_bank_prev_slot_set( ledger_args->slot_ctx->bank, prev_slot ); + fd_bank_prev_slot_set( ledger_args->bank, prev_slot ); FD_LOG_DEBUG(( "reading slot %lu", slot )); @@ -273,22 +277,22 @@ runtime_replay( fd_ledger_args_t * ledger_args ) { continue; } - fd_bank_tick_height_set( ledger_args->slot_ctx->bank, fd_bank_max_tick_height_get( ledger_args->slot_ctx->bank ) ); + fd_bank_tick_height_set( ledger_args->bank, fd_bank_max_tick_height_get( ledger_args->bank ) ); - ulong * max_tick_height = fd_bank_max_tick_height_modify( ledger_args->slot_ctx->bank ); - ulong ticks_per_slot = fd_bank_ticks_per_slot_get( ledger_args->slot_ctx->bank ); + ulong * max_tick_height = fd_bank_max_tick_height_modify( ledger_args->bank ); + ulong ticks_per_slot = fd_bank_ticks_per_slot_get( ledger_args->bank ); if( FD_UNLIKELY( FD_RUNTIME_EXECUTE_SUCCESS != fd_runtime_compute_max_tick_height( ticks_per_slot, slot, max_tick_height ) ) ) { FD_LOG_ERR(( "couldn't compute max tick height slot %lu ticks_per_slot %lu", slot, ticks_per_slot )); } - ledger_args->slot_ctx->bank = fd_banks_clone_from_parent( ledger_args->slot_ctx->banks, slot, prev_slot ); + ledger_args->bank = fd_banks_clone_from_parent( ledger_args->banks, slot, prev_slot ); ulong blk_txn_cnt = 0UL; FD_LOG_NOTICE(( "Used memory in spad before slot=%lu %lu", slot, ledger_args->runtime_spad->mem_used )); - FD_TEST( fd_runtime_block_eval_tpool( ledger_args->slot_ctx->banks, - ledger_args->slot_ctx->bank, - ledger_args->slot_ctx->funk, - &ledger_args->slot_ctx->funk_txn, + FD_TEST( fd_runtime_block_eval_tpool( ledger_args->banks, + ledger_args->bank, + ledger_args->funk, + &ledger_args->funk_txn, slot, blk, ledger_args->capture_ctx, @@ -305,18 +309,18 @@ runtime_replay( fd_ledger_args_t * ledger_args ) { fd_hash_t expected; int err = fd_blockstore_block_hash_query( blockstore, slot, &expected ); if( FD_UNLIKELY( err ) ) FD_LOG_ERR( ( "slot %lu is missing its hash", slot ) ); - else if( FD_UNLIKELY( 0 != memcmp( fd_bank_poh_query( ledger_args->slot_ctx->bank ), expected.hash, sizeof(fd_hash_t) ) ) ) { + else if( FD_UNLIKELY( 0 != memcmp( fd_bank_poh_query( ledger_args->bank ), expected.hash, sizeof(fd_hash_t) ) ) ) { char expected_hash[ FD_BASE58_ENCODED_32_SZ ]; fd_acct_addr_cstr( expected_hash, expected.hash ); char poh_hash[ FD_BASE58_ENCODED_32_SZ ]; - fd_acct_addr_cstr( poh_hash, fd_bank_poh_query( ledger_args->slot_ctx->bank )->hash ); + fd_acct_addr_cstr( poh_hash, fd_bank_poh_query( ledger_args->bank )->hash ); FD_LOG_WARNING(( "PoH hash mismatch! slot=%lu expected=%s, got=%s", slot, expected_hash, poh_hash )); if( ledger_args->checkpt_mismatch ) { - fd_runtime_checkpt( ledger_args->capture_ctx, ledger_args->slot_ctx->funk, ULONG_MAX ); + fd_runtime_checkpt( ledger_args->capture_ctx, ledger_args->funk, ULONG_MAX ); } if( ledger_args->abort_on_mismatch ) { ret = 1; @@ -325,7 +329,7 @@ runtime_replay( fd_ledger_args_t * ledger_args ) { } } - fd_hash_t const * bank_hash_bm = fd_bank_bank_hash_query( ledger_args->slot_ctx->bank ); + fd_hash_t const * bank_hash_bm = fd_bank_bank_hash_query( ledger_args->bank ); err = fd_blockstore_bank_hash_query( blockstore, slot, &expected ); if( FD_UNLIKELY( err) ) { FD_LOG_ERR(( "slot %lu is missing its bank hash", slot )); @@ -344,7 +348,7 @@ runtime_replay( fd_ledger_args_t * ledger_args ) { bank_hash )); if( ledger_args->checkpt_mismatch ) { - fd_runtime_checkpt( ledger_args->capture_ctx, ledger_args->slot_ctx->funk, ULONG_MAX ); + fd_runtime_checkpt( ledger_args->capture_ctx, ledger_args->funk, ULONG_MAX ); } if( ledger_args->abort_on_mismatch ) { ret = 1; @@ -522,16 +526,16 @@ fd_ledger_main_setup( fd_ledger_args_t * args ) { fd_flamenco_boot( NULL, NULL ); /* Finish other runtime setup steps */ - fd_features_restore( args->slot_ctx->bank, args->slot_ctx->funk, args->slot_ctx->funk_txn, args->runtime_spad ); - fd_runtime_update_leaders( args->slot_ctx->bank, args->slot_ctx->slot, args->runtime_spad ); - fd_calculate_epoch_accounts_hash_values( args->slot_ctx->bank ); + fd_features_restore( args->bank, args->funk, args->funk_txn, args->runtime_spad ); + fd_runtime_update_leaders( args->bank, args->bank->slot, args->runtime_spad ); + fd_calculate_epoch_accounts_hash_values( args->bank ); /* After both snapshots have been loaded in, we can determine if we should start distributing rewards. */ - fd_rewards_recalculate_partitioned_rewards( args->slot_ctx->bank, - args->slot_ctx->funk, - args->slot_ctx->funk_txn, + fd_rewards_recalculate_partitioned_rewards( args->bank, + args->funk, + args->funk_txn, args->tpool, args->exec_spads, args->exec_spad_cnt, @@ -546,8 +550,6 @@ fd_ledger_main_teardown( fd_ledger_args_t * args ) { fd_solcap_writer_flush( args->capture_ctx->capture ); fd_solcap_writer_delete( args->capture_ctx->capture ); } - - fd_exec_slot_ctx_delete( fd_exec_slot_ctx_leave( args->slot_ctx ) ); } void @@ -860,7 +862,7 @@ minify( fd_ledger_args_t * args ) { void ingest( fd_ledger_args_t * args ) { - /* Setup funk, blockstore, and slot_ctx */ + /* Setup funk and blockstore */ wksp_restore( args ); init_funk( args ); if( !args->funk_only ) { @@ -870,16 +872,8 @@ ingest( fd_ledger_args_t * args ) { init_tpool( args ); init_exec_spads( args, 1 ); - fd_funk_t * funk = args->funk; - args->valloc = allocator_setup( args->wksp ); - uchar slot_ctx_mem[FD_EXEC_SLOT_CTX_FOOTPRINT] __attribute__((aligned(FD_EXEC_SLOT_CTX_ALIGN))); - fd_exec_slot_ctx_t * slot_ctx = fd_exec_slot_ctx_join( fd_exec_slot_ctx_new( slot_ctx_mem ) ); - args->slot_ctx = slot_ctx; - - slot_ctx->funk = funk; - // if( args->status_cache_wksp ) { // void * status_cache_mem = fd_spad_alloc_check( spad, // fd_txncache_align(), @@ -896,53 +890,59 @@ ingest( fd_ledger_args_t * args ) { /* Load in snapshot(s) */ if( args->snapshot ) { - args->slot_ctx->bank = fd_snapshot_load_all( args->snapshot, - FD_SNAPSHOT_SRC_FILE, - NULL, - slot_ctx, - NULL, - args->tpool, - args->verify_acc_hash, - args->check_acc_hash , - FD_SNAPSHOT_TYPE_FULL, - args->exec_spads, - args->exec_spad_cnt, - args->runtime_spad ); - if( FD_UNLIKELY( !args->slot_ctx->bank ) ) { + args->bank = fd_snapshot_load_all( args->snapshot, + FD_SNAPSHOT_SRC_FILE, + NULL, + args->banks, + args->bank, + args->funk, + args->funk_txn, + NULL, + args->tpool, + args->verify_acc_hash, + args->check_acc_hash , + FD_SNAPSHOT_TYPE_FULL, + args->exec_spads, + args->exec_spad_cnt, + args->runtime_spad ); + if( FD_UNLIKELY( !args->bank ) ) { FD_LOG_ERR(( "Failed to load snapshot" )); } FD_LOG_NOTICE(( "imported records from snapshot" )); } if( args->incremental ) { - args->slot_ctx->bank = fd_snapshot_load_all( args->incremental, - FD_SNAPSHOT_SRC_FILE, - NULL, - slot_ctx, - NULL, - args->tpool, - args->verify_acc_hash, - args->check_acc_hash, - FD_SNAPSHOT_TYPE_INCREMENTAL, - args->exec_spads, - args->exec_spad_cnt, - args->runtime_spad ); - if( FD_UNLIKELY( !args->slot_ctx->bank ) ) { + args->bank = fd_snapshot_load_all( args->incremental, + FD_SNAPSHOT_SRC_FILE, + NULL, + args->banks, + args->bank, + args->funk, + args->funk_txn, + NULL, + args->tpool, + args->verify_acc_hash, + args->check_acc_hash, + FD_SNAPSHOT_TYPE_INCREMENTAL, + args->exec_spads, + args->exec_spad_cnt, + args->runtime_spad ); + if( FD_UNLIKELY( !args->bank ) ) { FD_LOG_ERR(( "Failed to load incremental snapshot" )); } FD_LOG_NOTICE(( "imported records from incremental snapshot" )); } if( args->genesis ) { - fd_runtime_read_genesis( slot_ctx->bank, slot_ctx->funk, &slot_ctx->funk_txn, args->genesis, args->snapshot != NULL, NULL, args->runtime_spad ); + fd_runtime_read_genesis( args->bank, args->funk, &args->funk_txn, args->genesis, args->snapshot != NULL, NULL, args->runtime_spad ); } /* At this point the account state has been ingested into funk. Intake rocksdb */ if( args->start_slot == 0 ) { - args->start_slot = slot_ctx->slot + 1; + args->start_slot = args->bank->slot + 1; } fd_blockstore_t * blockstore = args->blockstore; if( blockstore ) { - blockstore->shmem->lps = blockstore->shmem->hcs = blockstore->shmem->wmk = slot_ctx->slot; + blockstore->shmem->lps = blockstore->shmem->hcs = blockstore->shmem->wmk = args->bank->slot; } if( args->funk_only ) { @@ -951,8 +951,8 @@ ingest( fd_ledger_args_t * args ) { FD_LOG_NOTICE(( "using shredcap" )); fd_shredcap_populate_blockstore( args->shredcap, blockstore, args->start_slot, args->end_slot ); } else if( args->rocksdb_list[ 0UL ] ) { - if( args->end_slot >= slot_ctx->slot + args->slot_history_max ) { - args->end_slot = slot_ctx->slot + args->slot_history_max - 1; + if( args->end_slot >= args->bank->slot + args->slot_history_max ) { + args->end_slot = args->bank->slot + args->slot_history_max - 1; } ingest_rocksdb( args->rocksdb_list[ 0UL ], args->start_slot, args->end_slot, blockstore, args->trash_hash, args->valloc ); @@ -1012,9 +1012,12 @@ replay( fd_ledger_args_t * args ) { init_tpool( args ); /* Sets up tpool */ init_exec_spads( args, 1 ); /* Sets up spad */ - uchar * banks_mem = fd_wksp_alloc_laddr( args->wksp, fd_banks_align(), fd_banks_footprint( 8UL ), 0xABCABC123 ); - fd_banks_t * banks = fd_banks_join( fd_banks_new( banks_mem, 8UL ) ); - FD_TEST( banks ); + uchar * banks_mem = fd_wksp_alloc_laddr( args->wksp, fd_banks_align(), fd_banks_footprint( 8UL ), 0xABCABC123 ); + args->banks = fd_banks_join( fd_banks_new( banks_mem, 8UL ) ); + FD_TEST( args->banks ); + + args->bank = fd_banks_init_bank( args->banks, 0UL ); + FD_TEST( args->bank ); void * runtime_public_mem = fd_wksp_alloc_laddr( args->wksp, fd_runtime_public_align(), @@ -1033,28 +1036,14 @@ replay( fd_ledger_args_t * args ) { FD_SPAD_FRAME_BEGIN( spad ) { - /* Setup slot_ctx */ - fd_funk_t * funk = args->funk; - - /* TODO: This is very hacky, needs to be cleaned up */ - - void * slot_ctx_mem = fd_spad_alloc_check( spad, FD_EXEC_SLOT_CTX_ALIGN, FD_EXEC_SLOT_CTX_FOOTPRINT ); - args->slot_ctx = fd_exec_slot_ctx_join( fd_exec_slot_ctx_new( slot_ctx_mem ) ); - args->slot_ctx->funk = funk; - - args->slot_ctx->banks = banks; - FD_TEST( args->slot_ctx->banks ); - - args->slot_ctx->bank = fd_banks_init_bank( args->slot_ctx->banks, 0UL ); - - fd_cluster_version_t * cluster_version = fd_bank_cluster_version_modify( args->slot_ctx->bank ); + fd_cluster_version_t * cluster_version = fd_bank_cluster_version_modify( args->bank ); cluster_version->major = args->cluster_version[0]; cluster_version->minor = args->cluster_version[1]; cluster_version->patch = args->cluster_version[2]; - fd_features_t * features = fd_bank_features_modify( args->slot_ctx->bank ); + fd_features_t * features = fd_bank_features_modify( args->bank ); - fd_features_enable_cleaned_up( features, fd_bank_cluster_version_query( args->slot_ctx->bank ) ); + fd_features_enable_cleaned_up( features, fd_bank_cluster_version_query( args->bank ) ); fd_features_enable_one_offs( features, args->one_off_features, args->one_off_features_cnt, 0UL ); // void * status_cache_mem = fd_spad_alloc_check( spad, @@ -1075,33 +1064,41 @@ replay( fd_ledger_args_t * args ) { that you need to load in snapshot(s). */ /* Load in snapshot(s) */ + + FD_LOG_WARNING(("%p funk %p funk_txn", (void*)args->funk, (void *)args->funk_txn )); if( args->snapshot ) { - args->slot_ctx->bank = fd_snapshot_load_all( args->snapshot, - FD_SNAPSHOT_SRC_FILE, - NULL, - args->slot_ctx, - NULL, - args->tpool, - args->verify_acc_hash, - args->check_acc_hash, - FD_SNAPSHOT_TYPE_FULL, - args->exec_spads, - args->exec_spad_cnt, - args->runtime_spad ); + args->bank = fd_snapshot_load_all( args->snapshot, + FD_SNAPSHOT_SRC_FILE, + NULL, + args->banks, + args->bank, + args->funk, + args->funk_txn, + NULL, + args->tpool, + args->verify_acc_hash, + args->check_acc_hash, + FD_SNAPSHOT_TYPE_FULL, + args->exec_spads, + args->exec_spad_cnt, + args->runtime_spad ); FD_LOG_NOTICE(( "imported from snapshot" )); if( args->incremental ) { - args->slot_ctx->bank = fd_snapshot_load_all( args->incremental, - FD_SNAPSHOT_SRC_FILE, - NULL, - args->slot_ctx, - NULL, - args->tpool, - args->verify_acc_hash, - args->check_acc_hash, - FD_SNAPSHOT_TYPE_INCREMENTAL, - args->exec_spads, - args->exec_spad_cnt, - args->runtime_spad ); + args->bank = fd_snapshot_load_all( args->incremental, + FD_SNAPSHOT_SRC_FILE, + NULL, + args->banks, + args->bank, + args->funk, + args->funk_txn, + NULL, + args->tpool, + args->verify_acc_hash, + args->check_acc_hash, + FD_SNAPSHOT_TYPE_INCREMENTAL, + args->exec_spads, + args->exec_spad_cnt, + args->runtime_spad ); FD_LOG_NOTICE(( "imported from snapshot" )); } } @@ -1111,7 +1108,7 @@ replay( fd_ledger_args_t * args ) { fd_ledger_capture_setup( args ); if( args->genesis ) { - fd_runtime_read_genesis( args->slot_ctx->bank, args->slot_ctx->funk, &args->slot_ctx->funk_txn, args->genesis, args->snapshot != NULL, args->capture_ctx, args->runtime_spad ); + fd_runtime_read_genesis( args->bank, args->funk, &args->funk_txn, args->genesis, args->snapshot != NULL, args->capture_ctx, args->runtime_spad ); } fd_ledger_main_setup( args ); @@ -1119,7 +1116,7 @@ replay( fd_ledger_args_t * args ) { fd_blockstore_init( args->blockstore, -1, FD_BLOCKSTORE_ARCHIVE_MIN_SIZE, - args->slot_ctx->slot ); + args->bank->slot ); fd_buf_shred_pool_reset( args->blockstore->shred_pool, 0 ); FD_LOG_WARNING(( "setup done" )); diff --git a/src/discof/replay/fd_replay_tile.c b/src/discof/replay/fd_replay_tile.c index ecbc1a7bd9..e92f2f9957 100644 --- a/src/discof/replay/fd_replay_tile.c +++ b/src/discof/replay/fd_replay_tile.c @@ -1317,7 +1317,10 @@ read_snapshot( void * _ctx, incremental, ctx->incremental_src_type, NULL, - ctx->slot_ctx, + ctx->slot_ctx->banks, + ctx->slot_ctx->bank, + ctx->slot_ctx->funk, + ctx->slot_ctx->funk_txn, false, false, FD_SNAPSHOT_TYPE_INCREMENTAL, @@ -1339,7 +1342,10 @@ read_snapshot( void * _ctx, snapshot, ctx->snapshot_src_type, snapshot_dir, - ctx->slot_ctx, + ctx->slot_ctx->banks, + ctx->slot_ctx->bank, + ctx->slot_ctx->funk, + ctx->slot_ctx->funk_txn, false, false, FD_SNAPSHOT_TYPE_FULL, @@ -1378,7 +1384,10 @@ read_snapshot( void * _ctx, ctx->slot_ctx->bank = fd_snapshot_load_all( incremental, ctx->incremental_src_type, NULL, - ctx->slot_ctx, + ctx->slot_ctx->banks, + ctx->slot_ctx->bank, + ctx->slot_ctx->funk, + ctx->slot_ctx->funk_txn, &base_slot, NULL, false, diff --git a/src/flamenco/snapshot/fd_snapshot.c b/src/flamenco/snapshot/fd_snapshot.c index b3993053f9..8b0022e1dd 100644 --- a/src/flamenco/snapshot/fd_snapshot.c +++ b/src/flamenco/snapshot/fd_snapshot.c @@ -89,7 +89,10 @@ fd_snapshot_load_new( uchar * mem, const char * snapshot_src, int snapshot_src_type, const char * snapshot_dir, - fd_exec_slot_ctx_t * slot_ctx, + fd_banks_t * banks, + fd_bank_t * bank, + fd_funk_t * funk, + fd_funk_txn_t * funk_txn, uint verify_hash, uint check_hash, int snapshot_type, @@ -107,10 +110,10 @@ fd_snapshot_load_new( uchar * mem, ctx->snapshot_src = snapshot_src; ctx->snapshot_src_type = snapshot_src_type; - ctx->banks = slot_ctx->banks; - ctx->bank = slot_ctx->bank; - ctx->funk = slot_ctx->funk; - ctx->funk_txn = slot_ctx->funk_txn; + ctx->banks = banks; + ctx->bank = bank; + ctx->funk = funk; + ctx->funk_txn = funk_txn; ctx->verify_hash = verify_hash; ctx->check_hash = check_hash; @@ -361,7 +364,10 @@ fd_bank_t * fd_snapshot_load_all( const char * source_cstr, int source_type, const char * snapshot_dir, - fd_exec_slot_ctx_t * slot_ctx, + fd_banks_t * banks, + fd_bank_t * bank, + fd_funk_t * funk, + fd_funk_txn_t * funk_txn, ulong * base_slot_override, fd_tpool_t * tpool, uint verify_hash, @@ -382,7 +388,10 @@ fd_snapshot_load_all( const char * source_cstr, source_cstr, source_type, snapshot_dir, - slot_ctx, + banks, + bank, + funk, + funk_txn, verify_hash, check_hash, snapshot_type, @@ -392,12 +401,11 @@ fd_snapshot_load_all( const char * source_cstr, &exec_para_ctx ); fd_snapshot_load_init( ctx ); - fd_runtime_update_slots_per_epoch( slot_ctx->bank, FD_DEFAULT_SLOTS_PER_EPOCH ); + fd_runtime_update_slots_per_epoch( bank, FD_DEFAULT_SLOTS_PER_EPOCH ); fd_snapshot_load_manifest_and_status_cache( ctx, base_slot_override, FD_SNAPSHOT_RESTORE_STATUS_CACHE | FD_SNAPSHOT_RESTORE_MANIFEST ); fd_snapshot_load_accounts( ctx ); - fd_bank_t * bank = fd_snapshot_load_fini( ctx ); - return bank; + return fd_snapshot_load_fini( ctx ); } FD_SPAD_FRAME_END; } diff --git a/src/flamenco/snapshot/fd_snapshot.h b/src/flamenco/snapshot/fd_snapshot.h index b0b2ab0a1f..e54ead9ecc 100644 --- a/src/flamenco/snapshot/fd_snapshot.h +++ b/src/flamenco/snapshot/fd_snapshot.h @@ -71,7 +71,10 @@ fd_snapshot_load_new( uchar * mem, const char * snapshot_src, int snapshot_src_type, const char * snapshot_dir, - fd_exec_slot_ctx_t * slot_ctx, + fd_banks_t * banks, + fd_bank_t * bank, + fd_funk_t * funk, + fd_funk_txn_t * funk_txn, uint verify_hash, uint check_hash, int snapshot_type, @@ -99,7 +102,10 @@ fd_bank_t * fd_snapshot_load_all( const char * source_cstr, int source_type, const char * snapshot_dir, - fd_exec_slot_ctx_t * slot_ctx, + fd_banks_t * banks, + fd_bank_t * bank, + fd_funk_t * funk, + fd_funk_txn_t * funk_txn, ulong * base_slot_override, fd_tpool_t * tpool, uint verify_hash, From b088d01444d9df0c697729dc0aff05dfd28a8622 Mon Sep 17 00:00:00 2001 From: Ishan Bhatt Date: Tue, 8 Jul 2025 22:31:58 +0000 Subject: [PATCH 22/27] nit --- src/app/ledger/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/ledger/main.c b/src/app/ledger/main.c index 0b4ac3486b..49772a3767 100644 --- a/src/app/ledger/main.c +++ b/src/app/ledger/main.c @@ -961,7 +961,7 @@ ingest( fd_ledger_args_t * args ) { #ifdef FD_FUNK_HANDHOLDING if( args->verify_funk ) { FD_LOG_NOTICE(( "fd_funk_verify() start" )); - if( fd_funk_verify( funk ) ) { + if( fd_funk_verify( args->funk ) ) { FD_LOG_ERR(( "fd_funk_verify() failed" )); } } From 72e8d00b4834ff12c91417383ac123fd235024e6 Mon Sep 17 00:00:00 2001 From: Ishan Bhatt Date: Tue, 8 Jul 2025 22:54:01 +0000 Subject: [PATCH 23/27] even less slot ctx --- .../runtime/tests/harness/fd_block_harness.c | 142 +++++++++--------- src/flamenco/snapshot/fd_snapshot_main.c | 19 +-- 2 files changed, 76 insertions(+), 85 deletions(-) diff --git a/src/flamenco/runtime/tests/harness/fd_block_harness.c b/src/flamenco/runtime/tests/harness/fd_block_harness.c index 5706fe7a25..c2a83d5505 100644 --- a/src/flamenco/runtime/tests/harness/fd_block_harness.c +++ b/src/flamenco/runtime/tests/harness/fd_block_harness.c @@ -27,13 +27,15 @@ fd_runtime_fuzz_block_refresh_vote_accounts( fd_vote_accounts_pair_global_t_mapn from the current present account state. This function also registers a vote timestamp for the vote account */ static void -fd_runtime_fuzz_block_register_vote_account( fd_exec_slot_ctx_t * slot_ctx, +fd_runtime_fuzz_block_register_vote_account( fd_bank_t * bank, + fd_funk_t * funk, + fd_funk_txn_t * funk_txn, fd_vote_accounts_pair_global_t_mapnode_t * pool, fd_vote_accounts_pair_global_t_mapnode_t ** root, fd_pubkey_t * pubkey, fd_spad_t * spad ) { FD_TXN_ACCOUNT_DECL( acc ); - if( FD_UNLIKELY( fd_txn_account_init_from_funk_readonly( acc, pubkey, slot_ctx->funk, slot_ctx->funk_txn ) ) ) { + if( FD_UNLIKELY( fd_txn_account_init_from_funk_readonly( acc, pubkey, funk, funk_txn ) ) ) { return; } @@ -99,18 +101,19 @@ fd_runtime_fuzz_block_register_vote_account( fd_exec_slot_ctx_t * __builtin_unreachable(); } - fd_vote_record_timestamp_vote_with_slot( pubkey, ts->timestamp, ts->slot, slot_ctx->bank ); + fd_vote_record_timestamp_vote_with_slot( pubkey, ts->timestamp, ts->slot, bank ); } /* Stores an entry in the stake delegations cache for the given vote account. Deserializes and uses the present account state to derive delegation information. */ static void -fd_runtime_fuzz_block_register_stake_delegation( fd_exec_slot_ctx_t * slot_ctx, +fd_runtime_fuzz_block_register_stake_delegation( fd_funk_t * funk, + fd_funk_txn_t * funk_txn, fd_delegation_pair_t_mapnode_t * pool, fd_delegation_pair_t_mapnode_t ** root, fd_pubkey_t * pubkey ) { FD_TXN_ACCOUNT_DECL( acc ); - if( FD_UNLIKELY( fd_txn_account_init_from_funk_readonly( acc, pubkey, slot_ctx->funk, slot_ctx->funk_txn ) ) ) { + if( FD_UNLIKELY( fd_txn_account_init_from_funk_readonly( acc, pubkey, funk, funk_txn ) ) ) { return; } @@ -182,10 +185,8 @@ fd_runtime_fuzz_block_update_prev_epoch_votes_cache( fd_vote_accounts_pair_globa static void FD_FN_UNUSED fd_runtime_fuzz_block_ctx_destroy( fd_runtime_fuzz_runner_t * runner, - fd_exec_slot_ctx_t * slot_ctx, fd_wksp_t * wksp, fd_alloc_t * alloc ) { - if( !slot_ctx ) return; // This shouldn't be false either fd_wksp_free_laddr( fd_alloc_delete( fd_alloc_leave( alloc ) ) ); fd_wksp_detach( wksp ); @@ -197,12 +198,11 @@ fd_runtime_fuzz_block_ctx_destroy( fd_runtime_fuzz_runner_t * runner, Returns block_info on success and NULL on failure. */ static fd_runtime_block_info_t * fd_runtime_fuzz_block_ctx_create( fd_runtime_fuzz_runner_t * runner, - fd_exec_slot_ctx_t * slot_ctx, - fd_exec_test_block_context_t const * test_ctx ) { + fd_exec_test_block_context_t const * test_ctx, + fd_funk_txn_t * * funk_txn_out ) { fd_funk_t * funk = runner->funk; - slot_ctx->bank = runner->bank; - fd_bank_clear_bank( slot_ctx->bank ); + fd_bank_clear_bank( runner->bank ); /* Generate unique ID for funk txn */ fd_funk_txn_xid_t xid[1] = {0}; @@ -221,91 +221,91 @@ fd_runtime_fuzz_block_ctx_create( fd_runtime_fuzz_runner_t * runner, if( !fd_runtime_fuzz_restore_features( &features, &test_ctx->epoch_ctx.features ) ) { return NULL; } - fd_bank_features_set( slot_ctx->bank, features ); + fd_bank_features_set( runner->bank, features ); /* Set up slot context */ ulong slot = test_ctx->slot_ctx.slot; - slot_ctx->funk_txn = funk_txn; - slot_ctx->funk = funk; - slot_ctx->slot = slot; + runner->bank->slot = slot; - fd_hash_t * bank_hash = fd_bank_bank_hash_modify( slot_ctx->bank ); + *funk_txn_out = funk_txn; + + fd_hash_t * bank_hash = fd_bank_bank_hash_modify( runner->bank ); fd_memcpy( bank_hash, test_ctx->slot_ctx.parent_bank_hash, sizeof(fd_hash_t) ); /* All bank mgr stuff here. */ /* Initialize vote timestamps cache */ - fd_clock_timestamp_votes_global_t * clock_timestamp_votes = fd_bank_clock_timestamp_votes_locking_modify( slot_ctx->bank ); + fd_clock_timestamp_votes_global_t * clock_timestamp_votes = fd_bank_clock_timestamp_votes_locking_modify( runner->bank ); uchar * pool_mem = (uchar *)fd_ulong_align_up( (ulong)clock_timestamp_votes + sizeof(fd_clock_timestamp_votes_global_t), fd_clock_timestamp_vote_t_map_align() ); fd_clock_timestamp_vote_t_mapnode_t * clock_pool = fd_clock_timestamp_vote_t_map_join( fd_clock_timestamp_vote_t_map_new( pool_mem, 15000UL ) ); fd_clock_timestamp_vote_t_mapnode_t * clock_root = NULL; fd_clock_timestamp_votes_votes_pool_update( clock_timestamp_votes, clock_pool ); fd_clock_timestamp_votes_votes_root_update( clock_timestamp_votes, clock_root ); - fd_bank_clock_timestamp_votes_end_locking_modify( slot_ctx->bank ); + fd_bank_clock_timestamp_votes_end_locking_modify( runner->bank ); - slot_ctx->bank->slot = slot; + runner->bank->slot = slot; - fd_bank_block_height_set( slot_ctx->bank, test_ctx->slot_ctx.block_height ); + fd_bank_block_height_set( runner->bank, test_ctx->slot_ctx.block_height ); - fd_bank_prev_slot_set( slot_ctx->bank, test_ctx->slot_ctx.prev_slot ); + fd_bank_prev_slot_set( runner->bank, test_ctx->slot_ctx.prev_slot ); - fd_bank_capitalization_set( slot_ctx->bank, test_ctx->slot_ctx.prev_epoch_capitalization ); + fd_bank_capitalization_set( runner->bank, test_ctx->slot_ctx.prev_epoch_capitalization ); - fd_bank_lamports_per_signature_set( slot_ctx->bank, 5000UL ); + fd_bank_lamports_per_signature_set( runner->bank, 5000UL ); - fd_bank_prev_lamports_per_signature_set( slot_ctx->bank, test_ctx->slot_ctx.prev_lps ); + fd_bank_prev_lamports_per_signature_set( runner->bank, test_ctx->slot_ctx.prev_lps ); // self.max_tick_height = (self.slot + 1) * self.ticks_per_slot; - fd_bank_hashes_per_tick_set( slot_ctx->bank, test_ctx->epoch_ctx.hashes_per_tick ); + fd_bank_hashes_per_tick_set( runner->bank, test_ctx->epoch_ctx.hashes_per_tick ); - fd_bank_ticks_per_slot_set( slot_ctx->bank, test_ctx->epoch_ctx.ticks_per_slot ); + fd_bank_ticks_per_slot_set( runner->bank, test_ctx->epoch_ctx.ticks_per_slot ); - fd_bank_ns_per_slot_set( slot_ctx->bank, 400000000 ); // TODO: restore from input + fd_bank_ns_per_slot_set( runner->bank, 400000000 ); // TODO: restore from input - fd_bank_genesis_creation_time_set( slot_ctx->bank, test_ctx->epoch_ctx.genesis_creation_time ); + fd_bank_genesis_creation_time_set( runner->bank, test_ctx->epoch_ctx.genesis_creation_time ); - fd_bank_slots_per_year_set( slot_ctx->bank, test_ctx->epoch_ctx.slots_per_year ); + fd_bank_slots_per_year_set( runner->bank, test_ctx->epoch_ctx.slots_per_year ); - fd_fee_rate_governor_t * fee_rate_governor = fd_bank_fee_rate_governor_modify( slot_ctx->bank ); + fd_fee_rate_governor_t * fee_rate_governor = fd_bank_fee_rate_governor_modify( runner->bank ); fee_rate_governor->target_lamports_per_signature = 10000UL; fee_rate_governor->target_signatures_per_slot = 20000UL; fee_rate_governor->min_lamports_per_signature = 5000UL; fee_rate_governor->max_lamports_per_signature = 100000UL; fee_rate_governor->burn_percent = 50; - fd_inflation_t * inflation = fd_bank_inflation_modify( slot_ctx->bank ); + fd_inflation_t * inflation = fd_bank_inflation_modify( runner->bank ); inflation->initial = test_ctx->epoch_ctx.inflation.initial; inflation->terminal = test_ctx->epoch_ctx.inflation.terminal; inflation->taper = test_ctx->epoch_ctx.inflation.taper; inflation->foundation = test_ctx->epoch_ctx.inflation.foundation; inflation->foundation_term = test_ctx->epoch_ctx.inflation.foundation_term; - fd_bank_block_height_set( slot_ctx->bank, test_ctx->slot_ctx.block_height ); + fd_bank_block_height_set( runner->bank, test_ctx->slot_ctx.block_height ); // /* Initialize the current running epoch stake and vote accounts */ /* TODO: should be stake account max */ - fd_account_keys_global_t * stake_account_keys = fd_bank_stake_account_keys_locking_modify( slot_ctx->bank ); + fd_account_keys_global_t * stake_account_keys = fd_bank_stake_account_keys_locking_modify( runner->bank ); pool_mem = (uchar *)fd_ulong_align_up( (ulong)stake_account_keys + sizeof(fd_account_keys_global_t), fd_account_keys_pair_t_map_align() ); fd_account_keys_pair_t_mapnode_t * account_keys_pool = fd_account_keys_pair_t_map_join( fd_account_keys_pair_t_map_new( pool_mem, vote_acct_max ) ); fd_account_keys_pair_t_mapnode_t * account_keys_root = NULL; fd_account_keys_account_keys_pool_update( stake_account_keys, account_keys_pool ); fd_account_keys_account_keys_root_update( stake_account_keys, account_keys_root ); - fd_bank_stake_account_keys_end_locking_modify( slot_ctx->bank ); + fd_bank_stake_account_keys_end_locking_modify( runner->bank ); - fd_account_keys_global_t * vote_account_keys = fd_bank_vote_account_keys_locking_modify( slot_ctx->bank ); + fd_account_keys_global_t * vote_account_keys = fd_bank_vote_account_keys_locking_modify( runner->bank ); pool_mem = (uchar *)fd_ulong_align_up( (ulong)vote_account_keys + sizeof(fd_account_keys_global_t), fd_account_keys_pair_t_map_align() ); fd_account_keys_pair_t_mapnode_t * vote_account_keys_pool = fd_account_keys_pair_t_map_join( fd_account_keys_pair_t_map_new( pool_mem, vote_acct_max ) ); fd_account_keys_pair_t_mapnode_t * vote_account_keys_root = NULL; fd_account_keys_account_keys_pool_update( vote_account_keys, vote_account_keys_pool ); fd_account_keys_account_keys_root_update( vote_account_keys, vote_account_keys_root ); - fd_bank_vote_account_keys_end_locking_modify( slot_ctx->bank ); + fd_bank_vote_account_keys_end_locking_modify( runner->bank ); /* SETUP STAKES HERE */ - fd_stakes_global_t * stakes = fd_bank_stakes_locking_modify( slot_ctx->bank ); + fd_stakes_global_t * stakes = fd_bank_stakes_locking_modify( runner->bank ); pool_mem = (uchar *)fd_ulong_align_up( (ulong)stakes + sizeof(fd_stakes_global_t), fd_vote_accounts_pair_t_map_align() ); fd_vote_accounts_pair_global_t_mapnode_t * vote_accounts_pool = fd_vote_accounts_pair_global_t_map_join( fd_vote_accounts_pair_global_t_map_new( pool_mem, vote_acct_max ) ); fd_vote_accounts_pair_global_t_mapnode_t * vote_accounts_root = NULL; @@ -321,14 +321,17 @@ fd_runtime_fuzz_block_ctx_create( fd_runtime_fuzz_runner_t * runner, /* Update vote accounts cache for epoch T */ fd_pubkey_t pubkey; memcpy( &pubkey, test_ctx->acct_states[i].address, sizeof(fd_pubkey_t) ); - fd_runtime_fuzz_block_register_vote_account( slot_ctx, + fd_runtime_fuzz_block_register_vote_account( runner->bank, + runner->funk, + funk_txn, vote_accounts_pool, &vote_accounts_root, &pubkey, runner->spad ); /* Update the stake delegations cache for epoch T */ - fd_runtime_fuzz_block_register_stake_delegation( slot_ctx, + fd_runtime_fuzz_block_register_stake_delegation( runner->funk, + funk_txn, stake_delegations_pool, &stake_delegations_root, &pubkey ); @@ -348,20 +351,20 @@ fd_runtime_fuzz_block_ctx_create( fd_runtime_fuzz_runner_t * runner, /* Add accounts to bpf program cache */ - fd_bpf_scan_and_create_bpf_program_cache_entry( slot_ctx->bank, slot_ctx->funk, slot_ctx->funk_txn, runner->spad ); + fd_bpf_scan_and_create_bpf_program_cache_entry( runner->bank, runner->funk, funk_txn, runner->spad ); /* Finish init epoch bank sysvars */ fd_epoch_schedule_t * epoch_schedule = fd_sysvar_epoch_schedule_read( funk, funk_txn, runner->spad ); - fd_bank_epoch_schedule_set( slot_ctx->bank, *epoch_schedule ); + fd_bank_epoch_schedule_set( runner->bank, *epoch_schedule ); fd_rent_t const * rent = fd_sysvar_rent_read( funk, funk_txn, runner->spad ); - fd_bank_rent_set( slot_ctx->bank, *rent ); + fd_bank_rent_set( runner->bank, *rent ); stakes->epoch = fd_slot_to_epoch( epoch_schedule, test_ctx->slot_ctx.prev_slot, NULL ); - fd_bank_stakes_end_locking_modify( slot_ctx->bank ); + fd_bank_stakes_end_locking_modify( runner->bank ); - fd_vote_accounts_global_t * vote_accounts = fd_bank_next_epoch_stakes_locking_modify( slot_ctx->bank ); + fd_vote_accounts_global_t * vote_accounts = fd_bank_next_epoch_stakes_locking_modify( runner->bank ); pool_mem = (uchar *)fd_ulong_align_up( (ulong)vote_accounts + sizeof(fd_vote_accounts_global_t), fd_vote_accounts_pair_global_t_map_align() ); vote_accounts_pool = fd_vote_accounts_pair_global_t_map_join( fd_vote_accounts_pair_global_t_map_new( pool_mem, vote_acct_max ) ); vote_accounts_root = NULL; @@ -376,10 +379,10 @@ fd_runtime_fuzz_block_ctx_create( fd_runtime_fuzz_runner_t * runner, fd_vote_accounts_vote_accounts_pool_update( vote_accounts, vote_accounts_pool ); fd_vote_accounts_vote_accounts_root_update( vote_accounts, vote_accounts_root ); - fd_bank_next_epoch_stakes_end_locking_modify( slot_ctx->bank ); + fd_bank_next_epoch_stakes_end_locking_modify( runner->bank ); /* Update vote cache for epoch T-2 */ - vote_accounts = fd_bank_epoch_stakes_locking_modify( slot_ctx->bank ); + vote_accounts = fd_bank_epoch_stakes_locking_modify( runner->bank ); pool_mem = (uchar *)fd_ulong_align_up( (ulong)vote_accounts + sizeof(fd_vote_accounts_global_t), fd_vote_accounts_pair_global_t_map_align() ); vote_accounts_pool = fd_vote_accounts_pair_global_t_map_join( fd_vote_accounts_pair_global_t_map_new( pool_mem, vote_acct_max ) ); vote_accounts_root = NULL; @@ -392,13 +395,13 @@ fd_runtime_fuzz_block_ctx_create( fd_runtime_fuzz_runner_t * runner, fd_vote_accounts_vote_accounts_pool_update( vote_accounts, vote_accounts_pool ); fd_vote_accounts_vote_accounts_root_update( vote_accounts, vote_accounts_root ); - fd_bank_epoch_stakes_end_locking_modify( slot_ctx->bank ); + fd_bank_epoch_stakes_end_locking_modify( runner->bank ); /* Update leader schedule */ - fd_runtime_update_leaders( slot_ctx->bank, slot_ctx->slot, runner->spad ); + fd_runtime_update_leaders( runner->bank, runner->bank->slot, runner->spad ); /* Initialize the blockhash queue and recent blockhashes sysvar from the input blockhash queue */ - fd_block_hash_queue_global_t * block_hash_queue = (fd_block_hash_queue_global_t *)&slot_ctx->bank->block_hash_queue[0]; + fd_block_hash_queue_global_t * block_hash_queue = fd_bank_block_hash_queue_modify( runner->bank ); uchar * last_hash_mem = (uchar *)fd_ulong_align_up( (ulong)block_hash_queue + sizeof(fd_block_hash_queue_global_t), alignof(fd_hash_t) ); uchar * ages_pool_mem = (uchar *)fd_ulong_align_up( (ulong)last_hash_mem + sizeof(fd_hash_t), fd_hash_hash_age_pair_t_map_align() ); fd_hash_hash_age_pair_t_mapnode_t * ages_pool = fd_hash_hash_age_pair_t_map_join( fd_hash_hash_age_pair_t_map_new( ages_pool_mem, FD_BLOCKHASH_QUEUE_MAX_ENTRIES ) ); @@ -417,7 +420,7 @@ fd_runtime_fuzz_block_ctx_create( fd_runtime_fuzz_runner_t * runner, /* Allocate all the memory for the rent fresh accounts list */ // Set genesis hash to {0} - fd_hash_t * genesis_hash = fd_bank_genesis_hash_modify( slot_ctx->bank ); + fd_hash_t * genesis_hash = fd_bank_genesis_hash_modify( runner->bank ); fd_memset( genesis_hash->hash, 0, sizeof(fd_hash_t) ); // Use the latest lamports per signature @@ -430,8 +433,8 @@ fd_runtime_fuzz_block_ctx_create( fd_runtime_fuzz_runner_t * runner, if( rbh_global && !deq_fd_block_block_hash_entry_t_empty( rbh->hashes ) ) { fd_block_block_hash_entry_t const * last = deq_fd_block_block_hash_entry_t_peek_head_const( rbh->hashes ); if( last && last->fee_calculator.lamports_per_signature!=0UL ) { - fd_bank_lamports_per_signature_set( slot_ctx->bank, last->fee_calculator.lamports_per_signature ); - fd_bank_prev_lamports_per_signature_set( slot_ctx->bank, last->fee_calculator.lamports_per_signature ); + fd_bank_lamports_per_signature_set( runner->bank, last->fee_calculator.lamports_per_signature ); + fd_bank_prev_lamports_per_signature_set( runner->bank, last->fee_calculator.lamports_per_signature ); } } @@ -439,23 +442,24 @@ fd_runtime_fuzz_block_ctx_create( fd_runtime_fuzz_runner_t * runner, for( ushort i=0; iblockhash_queue_count; ++i ) { fd_block_block_hash_entry_t blockhash_entry; memcpy( &blockhash_entry.blockhash, test_ctx->blockhash_queue[i]->bytes, sizeof(fd_hash_t) ); - fd_bank_poh_set( slot_ctx->bank, blockhash_entry.blockhash ); - fd_sysvar_recent_hashes_update( slot_ctx->bank, slot_ctx->funk, slot_ctx->funk_txn, runner->spad ); + fd_bank_poh_set( runner->bank, blockhash_entry.blockhash ); + fd_sysvar_recent_hashes_update( runner->bank, runner->funk, funk_txn, runner->spad ); } // Set the current poh from the input (we skip POH verification in this fuzzing target) - fd_hash_t * poh = fd_bank_poh_modify( slot_ctx->bank ); + fd_hash_t * poh = fd_bank_poh_modify( runner->bank ); fd_memcpy( poh->hash, test_ctx->slot_ctx.poh, sizeof(fd_hash_t) ); /* Make a new funk transaction since we're done loading in accounts for context */ fd_funk_txn_xid_t fork_xid[1] = {0}; fork_xid[0] = fd_funk_generate_xid(); fd_funk_txn_start_write( funk ); - slot_ctx->funk_txn = fd_funk_txn_prepare( funk, slot_ctx->funk_txn, fork_xid, 1 ); + funk_txn = fd_funk_txn_prepare( funk, funk_txn, fork_xid, 1 ); + *funk_txn_out = funk_txn; fd_funk_txn_end_write( funk ); /* Calculate epoch account hash values. This sets epoch_bank.eah_{start_slot, stop_slot, interval} */ - fd_calculate_epoch_accounts_hash_values( slot_ctx->bank ); + fd_calculate_epoch_accounts_hash_values( runner->bank ); /* Prepare raw transaction pointers and block / microblock infos */ ulong txn_cnt = test_ctx->txns_count; @@ -528,7 +532,7 @@ fd_runtime_fuzz_block_ctx_create( fd_runtime_fuzz_runner_t * runner, and executes it against the runtime. Returns the execution result. */ static int fd_runtime_fuzz_block_ctx_exec( fd_runtime_fuzz_runner_t * runner, - fd_exec_slot_ctx_t * slot_ctx, + fd_funk_txn_t * funk_txn, fd_runtime_block_info_t * block_info ) { int res = 0; @@ -552,14 +556,14 @@ fd_runtime_fuzz_block_ctx_exec( fd_runtime_fuzz_runner_t * runner, // Prepare. Execute. Finalize. FD_SPAD_FRAME_BEGIN( runtime_spad ) { - fd_rewards_recalculate_partitioned_rewards( slot_ctx->bank, slot_ctx->funk, slot_ctx->funk_txn, tpool, exec_spads, exec_spads_cnt, runtime_spad ); + fd_rewards_recalculate_partitioned_rewards( runner->bank, runner->funk, funk_txn, tpool, exec_spads, exec_spads_cnt, runtime_spad ); /* Process new epoch may push a new spad frame onto the runtime spad. We should make sure this frame gets cleared (if it was allocated) before executing the block. */ int is_epoch_boundary = 0; - fd_runtime_block_pre_execute_process_new_epoch( slot_ctx->bank, slot_ctx->funk, slot_ctx->funk_txn, tpool, exec_spads, exec_spads_cnt, runtime_spad, &is_epoch_boundary ); + fd_runtime_block_pre_execute_process_new_epoch( runner->bank, runner->funk, funk_txn, tpool, exec_spads, exec_spads_cnt, runtime_spad, &is_epoch_boundary ); - res = fd_runtime_block_execute_tpool( slot_ctx->bank, slot_ctx->funk, slot_ctx->funk_txn, NULL, NULL, block_info, tpool, exec_spads, exec_spads_cnt, runtime_spad ); + res = fd_runtime_block_execute_tpool( runner->bank, runner->funk, funk_txn, NULL, NULL, block_info, tpool, exec_spads, exec_spads_cnt, runtime_spad ); } FD_SPAD_FRAME_END; fd_tpool_worker_pop( tpool ); @@ -580,18 +584,16 @@ fd_runtime_fuzz_block_run( fd_runtime_fuzz_runner_t * runner, /* Initialize memory */ fd_wksp_t * wksp = fd_wksp_attach( "wksp" ); fd_alloc_t * alloc = fd_alloc_join( fd_alloc_new( fd_wksp_alloc_laddr( wksp, fd_alloc_align(), fd_alloc_footprint(), 2 ), 2 ), 0 ); - uchar * slot_ctx_mem = fd_spad_alloc( runner->spad, FD_EXEC_SLOT_CTX_ALIGN, FD_EXEC_SLOT_CTX_FOOTPRINT ); - fd_exec_slot_ctx_t * slot_ctx = fd_exec_slot_ctx_join ( fd_exec_slot_ctx_new ( slot_ctx_mem ) ); - /* Set up the block execution context */ - fd_runtime_block_info_t * block_info = fd_runtime_fuzz_block_ctx_create( runner, slot_ctx, input ); + fd_funk_txn_t * funk_txn = NULL; + fd_runtime_block_info_t * block_info = fd_runtime_fuzz_block_ctx_create( runner, input, &funk_txn ); if( block_info==NULL ) { - fd_runtime_fuzz_block_ctx_destroy( runner, slot_ctx, wksp, alloc ); + fd_runtime_fuzz_block_ctx_destroy( runner, wksp, alloc ); return 0; } /* Execute the constructed block against the runtime. */ - int res = fd_runtime_fuzz_block_ctx_exec( runner, slot_ctx, block_info); + int res = fd_runtime_fuzz_block_ctx_exec( runner, funk_txn, block_info ); /* Start saving block exec results */ FD_SCRATCH_ALLOC_INIT( l, output_buf ); @@ -609,14 +611,14 @@ fd_runtime_fuzz_block_run( fd_runtime_fuzz_runner_t * runner, effects->has_error = !!( res ); /* Capture capitalization */ - effects->slot_capitalization = fd_bank_capitalization_get( slot_ctx->bank ); + effects->slot_capitalization = fd_bank_capitalization_get( runner->bank ); /* Capture hashes */ - fd_hash_t bank_hash = fd_bank_bank_hash_get( slot_ctx->bank ); + fd_hash_t bank_hash = fd_bank_bank_hash_get( runner->bank ); fd_memcpy( effects->bank_hash, bank_hash.hash, sizeof(fd_hash_t) ); ulong actual_end = FD_SCRATCH_ALLOC_FINI( l, 1UL ); - fd_runtime_fuzz_block_ctx_destroy( runner, slot_ctx, wksp, alloc ); + fd_runtime_fuzz_block_ctx_destroy( runner, wksp, alloc ); *output = effects; return actual_end - (ulong)output_buf; diff --git a/src/flamenco/snapshot/fd_snapshot_main.c b/src/flamenco/snapshot/fd_snapshot_main.c index 3a79908d7f..6eb2bb7854 100644 --- a/src/flamenco/snapshot/fd_snapshot_main.c +++ b/src/flamenco/snapshot/fd_snapshot_main.c @@ -22,10 +22,9 @@ #define OSTREAM_BUFSZ (32768UL) struct fd_snapshot_dumper { - fd_alloc_t * alloc; - fd_funk_t funk[1]; - - fd_exec_slot_ctx_t * slot_ctx; + fd_alloc_t * alloc; + fd_funk_t funk[1]; + fd_funk_txn_t * funk_txn; int snapshot_fd; @@ -65,11 +64,6 @@ fd_snapshot_dumper_delete( fd_snapshot_dumper_t * dumper ) { dumper->restore = NULL; } - if( dumper->slot_ctx ) { - fd_exec_slot_ctx_delete( fd_exec_slot_ctx_leave( dumper->slot_ctx ) ); - dumper->slot_ctx = NULL; - } - if( dumper->funk->shmem ) { void * shfunk = NULL; fd_funk_leave( dumper->funk, &shfunk ); @@ -271,16 +265,11 @@ do_dump( fd_snapshot_dumper_t * d, int funk_ok = !!fd_funk_join( d->funk, fd_funk_new( fd_wksp_alloc_laddr( wksp, fd_funk_align(), fd_funk_footprint(txn_max, rec_max), funk_tag ), funk_tag, funk_seed, txn_max, rec_max ) ); if( FD_UNLIKELY( !funk_ok ) ) { FD_LOG_WARNING(( "Failed to create fd_funk_t" )); return EXIT_FAILURE; } - /* Create a new processing context */ - - d->slot_ctx = fd_exec_slot_ctx_join( fd_exec_slot_ctx_new( fd_spad_alloc( spad, FD_EXEC_SLOT_CTX_ALIGN, FD_EXEC_SLOT_CTX_FOOTPRINT ) ) ); - if( FD_UNLIKELY( !d->slot_ctx ) ) { FD_LOG_WARNING(( "Failed to create fd_exec_slot_ctx_t" )); return EXIT_FAILURE; } - /* funk_txn is destroyed automatically when deleting fd_funk_t. */ fd_funk_txn_xid_t funk_txn_xid = { .ul = { 1UL } }; fd_funk_txn_t * funk_txn = fd_funk_txn_prepare( d->funk, NULL, &funk_txn_xid, 1 ); - d->slot_ctx->funk_txn = funk_txn; + d->funk_txn = funk_txn; void * restore_mem = fd_spad_alloc( spad, fd_snapshot_restore_align(), fd_snapshot_restore_footprint() ); if( FD_UNLIKELY( !restore_mem ) ) FD_LOG_ERR(( "Failed to allocate restore buffer" )); /* unreachable */ From 86f0c4749e2cb190542b0253ffa3ea2f2bedfd95 Mon Sep 17 00:00:00 2001 From: Ishan Bhatt Date: Wed, 9 Jul 2025 15:06:58 +0000 Subject: [PATCH 24/27] some more tweaks --- src/app/ledger/main.c | 4 +- src/discof/replay/fd_replay_tile.c | 123 ++++++++---------- src/flamenco/runtime/fd_runtime.c | 18 +-- src/flamenco/runtime/fd_runtime.h | 4 +- .../runtime/tests/harness/fd_block_harness.c | 2 +- 5 files changed, 62 insertions(+), 89 deletions(-) diff --git a/src/app/ledger/main.c b/src/app/ledger/main.c index 49772a3767..aedf2303fa 100644 --- a/src/app/ledger/main.c +++ b/src/app/ledger/main.c @@ -172,7 +172,7 @@ runtime_replay( fd_ledger_args_t * ledger_args ) { fd_features_restore( ledger_args->bank, ledger_args->funk, ledger_args->funk_txn, ledger_args->runtime_spad ); - fd_runtime_update_leaders( ledger_args->bank, ledger_args->bank->slot, ledger_args->runtime_spad ); + fd_runtime_update_leaders( ledger_args->bank, ledger_args->runtime_spad ); fd_calculate_epoch_accounts_hash_values( ledger_args->bank ); @@ -527,7 +527,7 @@ fd_ledger_main_setup( fd_ledger_args_t * args ) { /* Finish other runtime setup steps */ fd_features_restore( args->bank, args->funk, args->funk_txn, args->runtime_spad ); - fd_runtime_update_leaders( args->bank, args->bank->slot, args->runtime_spad ); + fd_runtime_update_leaders( args->bank, args->runtime_spad ); fd_calculate_epoch_accounts_hash_values( args->bank ); /* After both snapshots have been loaded in, we can determine if we should diff --git a/src/discof/replay/fd_replay_tile.c b/src/discof/replay/fd_replay_tile.c index e92f2f9957..c82d865951 100644 --- a/src/discof/replay/fd_replay_tile.c +++ b/src/discof/replay/fd_replay_tile.c @@ -166,7 +166,6 @@ struct fd_replay_tile_ctx { /* Metadata updated during execution */ - ulong curr_slot; ulong parent_slot; ulong snapshot_slot; ulong * turbine_slot0; @@ -468,7 +467,7 @@ block_finalize_tiles_cb( void * para_arg_1, fd_replay_out_link_t * exec_out = &ctx->exec_out[ worker_idx ]; fd_runtime_public_hash_bank_msg_t * hash_msg = (fd_runtime_public_hash_bank_msg_t *)fd_chunk_to_laddr( exec_out->mem, exec_out->chunk ); - generate_hash_bank_msg( task_infos_gaddr, lt_hash_gaddr, start_idx, end_idx, ctx->curr_slot, hash_msg ); + generate_hash_bank_msg( task_infos_gaddr, lt_hash_gaddr, start_idx, end_idx, ctx->slot_ctx->bank->slot, hash_msg ); ulong tspub = fd_frag_meta_ts_comp( fd_tickcount() ); fd_stem_publish( stem, @@ -493,7 +492,7 @@ block_finalize_tiles_cb( void * para_arg_1, /* We need to compare the state and a unique identifier (slot) in the case where the last thing the exec tile did is to hash accounts. */ - if( state==FD_EXEC_STATE_HASH_DONE && slot==ctx->curr_slot ) { + if( state==FD_EXEC_STATE_HASH_DONE && slot==ctx->slot_ctx->bank->slot ) { hash_done[ i ] = 1; } else { wait_cnt++; @@ -682,8 +681,7 @@ replay_plugin_publish( fd_replay_tile_ctx_t * ctx, static void publish_slot_notifications( fd_replay_tile_ctx_t * ctx, fd_stem_context_t * stem, - ulong block_entry_block_height, - ulong curr_slot ) { + ulong block_entry_block_height ) { if( FD_LIKELY( !ctx->notif_out->mcache ) ) return; long notify_time_ns = -fd_log_wallclock(); @@ -702,7 +700,7 @@ publish_slot_notifications( fd_replay_tile_ctx_t * ctx, { NOTIFY_START; msg->type = FD_REPLAY_SLOT_TYPE; - msg->slot_exec.slot = curr_slot; + msg->slot_exec.slot = ctx->slot_ctx->bank->slot; msg->slot_exec.parent = ctx->parent_slot; msg->slot_exec.root = fd_fseq_query( ctx->published_wmark ); msg->slot_exec.height = block_entry_block_height; @@ -721,12 +719,10 @@ publish_slot_notifications( fd_replay_tile_ctx_t * ctx, } fd_bank_shred_cnt_set( ctx->slot_ctx->bank, 0UL ); - FD_TEST( curr_slot == ctx->slot_ctx->bank->slot ); - #undef NOTIFY_START #undef NOTIFY_END notify_time_ns += fd_log_wallclock(); - FD_LOG_DEBUG(("TIMING: notify_slot_time - slot: %lu, elapsed: %6.6f ms", curr_slot, (double)notify_time_ns * 1e-6)); + FD_LOG_DEBUG(("TIMING: notify_slot_time - slot: %lu, elapsed: %6.6f ms", ctx->slot_ctx->bank->slot, (double)notify_time_ns * 1e-6)); if( ctx->plugin_out->mem ) { /* @@ -744,7 +740,7 @@ publish_slot_notifications( fd_replay_tile_ctx_t * ctx, */ ulong msg[11]; - msg[ 0 ] = ctx->curr_slot; + msg[ 0 ] = ctx->slot_ctx->bank->slot; msg[ 1 ] = fd_bank_txn_count_get( ctx->slot_ctx->bank ); msg[ 2 ] = fd_bank_nonvote_txn_count_get( ctx->slot_ctx->bank ); msg[ 3 ] = fd_bank_failed_txn_count_get( ctx->slot_ctx->bank ); @@ -812,7 +808,7 @@ publish_slot_notifications( fd_replay_tile_ctx_t * ctx, static fd_fork_t * prepare_new_block_execution( fd_replay_tile_ctx_t * ctx, fd_stem_context_t * stem, - ulong curr_slot, + ulong slot, ulong flags ) { long prepare_time_ns = -fd_log_wallclock(); @@ -826,25 +822,25 @@ prepare_new_block_execution( fd_replay_tile_ctx_t * ctx, /* Remove previous slot ctx from frontier */ fd_fork_t * child = fd_fork_frontier_ele_remove( ctx->forks->frontier, &fork->slot, NULL, ctx->forks->pool ); - child->slot = curr_slot; + child->slot = slot; child->end_idx = UINT_MAX; // reset end_idx from whatever was previously executed on this fork /* Insert new slot onto fork frontier */ if( FD_UNLIKELY( fd_fork_frontier_ele_query( - ctx->forks->frontier, &curr_slot, NULL, ctx->forks->pool ) ) ) { - FD_LOG_ERR( ( "invariant violation: child slot %lu was already in the frontier", curr_slot ) ); + ctx->forks->frontier, &slot, NULL, ctx->forks->pool ) ) ) { + FD_LOG_ERR( ( "invariant violation: child slot %lu was already in the frontier", slot ) ); } fd_fork_frontier_ele_insert( ctx->forks->frontier, child, ctx->forks->pool ); fork->lock = 1; FD_TEST( fork == child ); - FD_LOG_NOTICE(( "new block execution - slot: %lu, parent_slot: %lu", curr_slot, ctx->parent_slot )); + FD_LOG_NOTICE(( "new block execution - slot: %lu, parent_slot: %lu", slot, ctx->parent_slot )); ctx->slot_ctx->banks = ctx->banks; if( FD_UNLIKELY( !ctx->banks ) ) { FD_LOG_CRIT(( "invariant violation: banks is NULL" )); } - ctx->slot_ctx->bank = fd_banks_clone_from_parent( ctx->banks, curr_slot, ctx->parent_slot ); + ctx->slot_ctx->bank = fd_banks_clone_from_parent( ctx->banks, slot, ctx->parent_slot ); if( FD_UNLIKELY( !ctx->slot_ctx->bank ) ) { FD_LOG_CRIT(( "invariant violation: bank is NULL" )); } @@ -857,24 +853,24 @@ prepare_new_block_execution( fd_replay_tile_ctx_t * ctx, /* Update starting PoH hash for the new slot for tick verification later */ fd_block_map_query_t query[1] = { 0 }; - int err = fd_block_map_prepare( ctx->blockstore->block_map, &curr_slot, NULL, query, FD_MAP_FLAG_BLOCKING ); + int err = fd_block_map_prepare( ctx->blockstore->block_map, &slot, NULL, query, FD_MAP_FLAG_BLOCKING ); fd_block_info_t * curr_block_info = fd_block_map_query_ele( query ); if( FD_UNLIKELY( err == FD_MAP_ERR_FULL ) ) FD_LOG_ERR(("Block map prepare failed, likely corrupt.")); - if( FD_UNLIKELY( curr_slot != curr_block_info->slot ) ) FD_LOG_ERR(("Block map prepare failed, likely corrupt.")); + if( FD_UNLIKELY( slot != curr_block_info->slot ) ) FD_LOG_ERR(("Block map prepare failed, likely corrupt.")); fd_block_map_publish( query ); fd_bank_prev_slot_set( ctx->slot_ctx->bank, ctx->slot_ctx->slot ); - ctx->slot_ctx->slot = curr_slot; + ctx->slot_ctx->slot = slot; fd_bank_tick_height_set( ctx->slot_ctx->bank, fd_bank_max_tick_height_get( ctx->slot_ctx->bank ) ); ulong * max_tick_height = fd_bank_max_tick_height_modify( ctx->slot_ctx->bank ); ulong ticks_per_slot = fd_bank_ticks_per_slot_get( ctx->slot_ctx->bank ); if( FD_UNLIKELY( FD_RUNTIME_EXECUTE_SUCCESS != fd_runtime_compute_max_tick_height( ticks_per_slot, - curr_slot, + slot, max_tick_height ) ) ) { - FD_LOG_ERR(( "couldn't compute tick height/max tick height slot %lu ticks_per_slot %lu", curr_slot, ticks_per_slot )); + FD_LOG_ERR(( "couldn't compute tick height/max tick height slot %lu ticks_per_slot %lu", slot, ticks_per_slot )); } fd_bank_enable_exec_recording_set( ctx->slot_ctx->bank, ctx->tx_metadata_storage ); @@ -947,7 +943,7 @@ prepare_new_block_execution( fd_replay_tile_ctx_t * ctx, } prepare_time_ns += fd_log_wallclock(); - FD_LOG_DEBUG(("TIMING: prepare_time - slot: %lu, elapsed: %6.6f ms", curr_slot, (double)prepare_time_ns * 1e-6)); + FD_LOG_DEBUG(("TIMING: prepare_time - slot: %lu, elapsed: %6.6f ms", slot, (double)prepare_time_ns * 1e-6)); return fork; } @@ -983,10 +979,11 @@ init_poh( fd_replay_tile_ctx_t * ctx ) { } static void -prepare_first_batch_execution( fd_replay_tile_ctx_t * ctx, fd_stem_context_t * stem ) { +prepare_first_batch_execution( fd_replay_tile_ctx_t * ctx, + fd_stem_context_t * stem, + ulong slot ) { - ulong curr_slot = ctx->curr_slot; - ulong flags = ctx->flags; + ulong flags = ctx->flags; /**********************************************************************/ /* Prepare the fork in ctx->forks for replaying curr_slot */ @@ -998,28 +995,28 @@ prepare_first_batch_execution( fd_replay_tile_ctx_t * ctx, fd_stem_context_t * s already be in the frontier and currently executing (ie. fork->frozen = 0). */ FD_LOG_ERR(( "parent slot is frozen in frontier. cannot execute. slot: %lu, parent_slot: %lu", - curr_slot, + slot, ctx->parent_slot )); } - fd_fork_t * fork = fd_fork_frontier_ele_query( ctx->forks->frontier, &curr_slot, NULL, ctx->forks->pool ); + fd_fork_t * fork = fd_fork_frontier_ele_query( ctx->forks->frontier, &slot, NULL, ctx->forks->pool ); if( fork==NULL ) { - fork = prepare_new_block_execution( ctx, stem, curr_slot, flags ); + fork = prepare_new_block_execution( ctx, stem, slot, flags ); } else { - FD_LOG_WARNING(("Fork for slot %lu already exists, so we don't make a new one. Restarting execution from batch %u", curr_slot, fork->end_idx )); - ctx->slot_ctx->bank = fd_banks_get_bank( ctx->banks, curr_slot ); + FD_LOG_WARNING(("Fork for slot %lu already exists, so we don't make a new one. Restarting execution from batch %u", slot, fork->end_idx )); + ctx->slot_ctx->bank = fd_banks_get_bank( ctx->banks, slot ); if( FD_UNLIKELY( !ctx->slot_ctx->bank ) ) { - FD_LOG_CRIT(( "Unable to get bank for slot %lu", curr_slot )); + FD_LOG_CRIT(( "Unable to get bank for slot %lu", slot )); } fd_funk_txn_map_t * txn_map = fd_funk_txn_map( ctx->funk ); - fd_funk_txn_xid_t xid = { .ul = { curr_slot, curr_slot } }; + fd_funk_txn_xid_t xid = { .ul = { slot, slot } }; ctx->slot_ctx->funk_txn = fd_funk_txn_query( &xid, txn_map ); if( FD_UNLIKELY( !ctx->slot_ctx->funk_txn ) ) { - FD_LOG_CRIT(( "Unable to get funk transaction for slot %lu", curr_slot )); + FD_LOG_CRIT(( "Unable to get funk transaction for slot %lu", slot )); } - ctx->slot_ctx->slot = curr_slot; + ctx->slot_ctx->slot = slot; } /**********************************************************************/ @@ -1145,7 +1142,7 @@ exec_slice( fd_replay_tile_ctx_t * ctx, // Copy block hash to slot_bank poh for updating the sysvars fd_block_map_query_t query[1] = { 0 }; - fd_block_map_prepare( ctx->blockstore->block_map, &ctx->curr_slot, NULL, query, FD_MAP_FLAG_BLOCKING ); + fd_block_map_prepare( ctx->blockstore->block_map, &ctx->slot_ctx->bank->slot, NULL, query, FD_MAP_FLAG_BLOCKING ); fd_block_info_t * block_info = fd_block_map_query_ele( query ); fd_hash_t * poh = fd_bank_poh_modify( ctx->slot_ctx->bank ); @@ -1208,7 +1205,7 @@ handle_slice( fd_replay_tile_ctx_t * ctx, return; } - if( FD_UNLIKELY( slot != ctx->curr_slot ) ) { + if( FD_UNLIKELY( slot != ctx->slot_ctx->bank->slot ) ) { /* We need to switch forks and execution contexts. Either we completed execution of the previous slot and are now executing @@ -1219,9 +1216,8 @@ handle_slice( fd_replay_tile_ctx_t * ctx, if its not on the frontier. I think prepare_first_batch_execution already handles this logic. */ - ctx->curr_slot = slot; ctx->parent_slot = parent_slot; - prepare_first_batch_execution( ctx, stem ); + prepare_first_batch_execution( ctx, stem, slot ); ulong turbine_slot = fd_fseq_query( ctx->turbine_slot ); @@ -1261,7 +1257,6 @@ handle_slice( fd_replay_tile_ctx_t * ctx, static void kickoff_repair_orphans( fd_replay_tile_ctx_t * ctx, fd_stem_context_t * stem ) { - ctx->slot_ctx->slot = ctx->curr_slot; fd_blockstore_init( ctx->blockstore, ctx->blockstore_fd, FD_BLOCKSTORE_ARCHIVE_MIN_SIZE, @@ -1331,7 +1326,6 @@ read_snapshot( void * _ctx, /* Load the prefetch manifest, and initialize the status cache and slot context, so that we can use these to kick off repair. */ fd_snapshot_load_prefetch_manifest( tmp_snap_ctx ); - ctx->curr_slot = ctx->slot_ctx->slot; kickoff_repair_orphans( ctx, stem ); } @@ -1362,7 +1356,6 @@ read_snapshot( void * _ctx, ctx->slot_ctx->bank = fd_snapshot_load_manifest_and_status_cache( snap_ctx, NULL, FD_SNAPSHOT_RESTORE_MANIFEST | FD_SNAPSHOT_RESTORE_STATUS_CACHE ); ctx->slot_ctx->slot = ctx->slot_ctx->bank->slot; - ctx->curr_slot = ctx->slot_ctx->slot; kickoff_repair_orphans( ctx, stem ); /* If we don't have an incremental snapshot, we can still kick off sending the stake weights and snapshot slot to repair. */ @@ -1397,13 +1390,10 @@ read_snapshot( void * _ctx, ctx->exec_spad_cnt, ctx->runtime_spad ); ctx->slot_ctx->slot = ctx->slot_ctx->bank->slot; - ctx->curr_slot = ctx->slot_ctx->slot; kickoff_repair_orphans( ctx, stem ); } - fd_runtime_update_leaders( ctx->slot_ctx->bank, - ctx->slot_ctx->slot, - ctx->runtime_spad ); + fd_runtime_update_leaders( ctx->slot_ctx->bank, ctx->runtime_spad ); } static void @@ -1428,9 +1418,7 @@ init_after_snapshot( fd_replay_tile_ctx_t * ctx, /* FIXME: This branch does not set up a new block exec ctx properly. Needs to do whatever prepare_new_block_execution does, but just hacking that in breaks stuff. */ - fd_runtime_update_leaders( ctx->slot_ctx->bank, - ctx->slot_ctx->slot, - ctx->runtime_spad ); + fd_runtime_update_leaders( ctx->slot_ctx->bank, ctx->runtime_spad ); fd_bank_prev_slot_set( ctx->slot_ctx->bank, 0UL ); ctx->slot_ctx->slot = 1UL; @@ -1468,7 +1456,6 @@ init_after_snapshot( fd_replay_tile_ctx_t * ctx, } } - ctx->curr_slot = snapshot_slot; ctx->parent_slot = fd_bank_prev_slot_get( ctx->slot_ctx->bank ); ctx->snapshot_slot = snapshot_slot; ctx->flags = EXEC_FLAG_READY_NEW; @@ -1578,7 +1565,7 @@ init_snapshot( fd_replay_tile_ctx_t * ctx, fd_blockstore_init( ctx->blockstore, ctx->blockstore_fd, FD_BLOCKSTORE_ARCHIVE_MIN_SIZE, - ctx->curr_slot ); + ctx->slot_ctx->bank->slot ); init_after_snapshot( ctx, stem ); if( ctx->plugin_out->mem && strlen( ctx->genesis ) > 0 ) { @@ -1590,17 +1577,16 @@ init_snapshot( fd_replay_tile_ctx_t * ctx, fd_memcpy( &ctx->runtime_public->features, features, sizeof(ctx->runtime_public->features) ); /* Publish slot notifs */ - ulong curr_slot = ctx->curr_slot; ulong block_entry_height = 0; if( is_snapshot ) { for(;;){ fd_block_map_query_t query[1] = { 0 }; - int err = fd_block_map_query_try( ctx->blockstore->block_map, &curr_slot, NULL, query, 0 ); + int err = fd_block_map_query_try( ctx->blockstore->block_map, &ctx->slot_ctx->bank->slot, NULL, query, 0 ); fd_block_info_t * block_info = fd_block_map_query_ele( query ); if( FD_UNLIKELY( err == FD_MAP_ERR_KEY ) ) continue; /* FIXME: eventually need an error condition here.*/ if( FD_UNLIKELY( err == FD_MAP_ERR_AGAIN ) ) { - FD_LOG_WARNING(( "Waiting for block map query for slot %lu", curr_slot )); + FD_LOG_WARNING(( "Waiting for block map query for slot %lu", ctx->slot_ctx->bank->slot )); continue; }; block_entry_height = block_info->block_height; @@ -1615,7 +1601,7 @@ init_snapshot( fd_replay_tile_ctx_t * ctx, init_poh( ctx ); } - publish_slot_notifications( ctx, stem, block_entry_height, curr_slot ); + publish_slot_notifications( ctx, stem, block_entry_height ); FD_TEST( ctx->slot_ctx ); @@ -1626,7 +1612,7 @@ publish_votes_to_plugin( fd_replay_tile_ctx_t * ctx, fd_stem_context_t * stem ) { uchar * dst = (uchar *)fd_chunk_to_laddr( ctx->votes_plugin_out->mem, ctx->votes_plugin_out->chunk ); - fd_fork_t * fork = fd_fork_frontier_ele_query( ctx->forks->frontier, &ctx->curr_slot, NULL, ctx->forks->pool ); + fd_fork_t * fork = fd_fork_frontier_ele_query( ctx->forks->frontier, &ctx->slot_ctx->bank->slot, NULL, ctx->forks->pool ); if( FD_UNLIKELY ( !fork ) ) return; fd_vote_accounts_global_t const * epoch_stakes = fd_bank_epoch_stakes_locking_query( ctx->slot_ctx->bank ); @@ -1702,7 +1688,7 @@ publish_votes_to_plugin( fd_replay_tile_ctx_t * ctx, msg->root_slot = root_slot; msg->epoch_credits = epoch_credits; msg->commission = (uchar)commission; - msg->is_delinquent = (uchar)fd_int_if(ctx->curr_slot >= 128UL, msg->last_vote <= ctx->curr_slot - 128UL, msg->last_vote == 0); + msg->is_delinquent = (uchar)fd_int_if(ctx->slot_ctx->bank->slot >= 128UL, msg->last_vote <= ctx->slot_ctx->bank->slot - 128UL, msg->last_vote == 0); ++i; fd_bank_clock_timestamp_votes_end_locking_query( ctx->slot_ctx->bank ); } @@ -1785,10 +1771,9 @@ after_credit( fd_replay_tile_ctx_t * ctx, /* If we are currently executing a slice, proceed. */ if( ctx->flags & EXEC_FLAG_EXECUTING_SLICE ) { - exec_slice( ctx, stem, ctx->curr_slot ); + exec_slice( ctx, stem, ctx->slot_ctx->bank->slot ); } - ulong curr_slot = ctx->curr_slot; ulong flags = ctx->flags; /* Finished replaying a slot in this after_credit iteration. */ @@ -1798,13 +1783,13 @@ after_credit( fd_replay_tile_ctx_t * ctx, as read-only. This happens when it has replayed through turbine_slot0. */ - if( FD_UNLIKELY( ctx->read_only && ctx->curr_slot >= fd_fseq_query( ctx->turbine_slot0 ) ) ) { + if( FD_UNLIKELY( ctx->read_only && ctx->slot_ctx->bank->slot >= fd_fseq_query( ctx->turbine_slot0 ) ) ) { ctx->read_only = 0; } - fd_fork_t * fork = fd_fork_frontier_ele_query( ctx->forks->frontier, &ctx->curr_slot, NULL, ctx->forks->pool ); + fd_fork_t * fork = fd_fork_frontier_ele_query( ctx->forks->frontier, &ctx->slot_ctx->bank->slot, NULL, ctx->forks->pool ); - FD_LOG_NOTICE(( "finished block - slot: %lu, parent_slot: %lu", curr_slot, ctx->parent_slot )); + FD_LOG_NOTICE(( "finished block - slot: %lu, parent_slot: %lu", ctx->slot_ctx->bank->slot, ctx->parent_slot )); /**************************************************************************************************/ /* Call fd_runtime_block_execute_finalize_tpool which updates sysvar and cleanup some other stuff */ @@ -1832,7 +1817,7 @@ after_credit( fd_replay_tile_ctx_t * ctx, /* Update blockstore with the freshly computed bank hash */ fd_block_map_query_t query[1] = { 0 }; - fd_block_map_prepare( ctx->blockstore->block_map, &curr_slot, NULL, query, FD_MAP_FLAG_BLOCKING ); + fd_block_map_prepare( ctx->blockstore->block_map, &ctx->slot_ctx->bank->slot, NULL, query, FD_MAP_FLAG_BLOCKING ); fd_block_info_t * block_info = fd_block_map_query_ele( query ); block_info->bank_hash = fd_bank_bank_hash_get( ctx->slot_ctx->bank ); fd_block_map_publish( query ); @@ -1844,12 +1829,12 @@ after_credit( fd_replay_tile_ctx_t * ctx, /* Push notifications for slot updates and reset block_info flag */ /**********************************************************************/ - ulong block_entry_height = fd_blockstore_block_height_query( ctx->blockstore, curr_slot ); - publish_slot_notifications( ctx, stem, block_entry_height, curr_slot ); + ulong block_entry_height = fd_blockstore_block_height_query( ctx->blockstore, ctx->slot_ctx->bank->slot ); + publish_slot_notifications( ctx, stem, block_entry_height ); - ctx->blockstore->shmem->lps = curr_slot; + ctx->blockstore->shmem->lps = ctx->slot_ctx->bank->slot; - FD_TEST(fork->slot == curr_slot); + FD_TEST(fork->slot == ctx->slot_ctx->bank->slot); fork->lock = 0; // FD_LOG_NOTICE(( "ulong_max? %d", ctx->tower_out_idx==ULONG_MAX )); @@ -1861,7 +1846,7 @@ after_credit( fd_replay_tile_ctx_t * ctx, memcpy( chunk_laddr, bank_hash, sizeof(fd_hash_t) ); memcpy( chunk_laddr+sizeof(fd_hash_t), last_hash, sizeof(fd_hash_t) ); - fd_stem_publish( stem, ctx->tower_out_idx, ctx->curr_slot << 32UL | ctx->parent_slot, ctx->tower_out_chunk, sizeof(fd_hash_t) * 2, 0UL, fd_frag_meta_ts_comp( fd_tickcount() ), fd_frag_meta_ts_comp( fd_tickcount() ) ); + fd_stem_publish( stem, ctx->tower_out_idx, ctx->slot_ctx->bank->slot << 32UL | ctx->parent_slot, ctx->tower_out_chunk, sizeof(fd_hash_t) * 2, 0UL, fd_frag_meta_ts_comp( fd_tickcount() ), fd_frag_meta_ts_comp( fd_tickcount() ) ); } // if (FD_UNLIKELY( prev_confirmed!=ctx->forks->confirmed && ctx->plugin_out->mem ) ) { @@ -1901,10 +1886,10 @@ after_credit( fd_replay_tile_ctx_t * ctx, fd_hash_t const * bank_hash = fd_bank_bank_hash_query( ctx->slot_ctx->bank ); fd_bank_hash_cmp_t * bank_hash_cmp = ctx->bank_hash_cmp; fd_bank_hash_cmp_lock( bank_hash_cmp ); - fd_bank_hash_cmp_insert( bank_hash_cmp, curr_slot, bank_hash, 1, 0 ); + fd_bank_hash_cmp_insert( bank_hash_cmp, ctx->slot_ctx->bank->slot, bank_hash, 1, 0 ); /* Try to move the bank hash comparison watermark forward */ - for( ulong cmp_slot = bank_hash_cmp->watermark + 1; cmp_slot < curr_slot; cmp_slot++ ) { + for( ulong cmp_slot = bank_hash_cmp->watermark + 1; cmp_slot < ctx->slot_ctx->bank->slot; cmp_slot++ ) { if( FD_UNLIKELY( !ctx->enable_bank_hash_cmp ) ) { bank_hash_cmp->watermark = cmp_slot; break; diff --git a/src/flamenco/runtime/fd_runtime.c b/src/flamenco/runtime/fd_runtime.c index b285929624..ba2e7e009a 100644 --- a/src/flamenco/runtime/fd_runtime.c +++ b/src/flamenco/runtime/fd_runtime.c @@ -105,27 +105,17 @@ fd_runtime_update_slots_per_epoch( fd_bank_t * bank, } void -fd_runtime_update_leaders( fd_bank_t * bank, - ulong slot, - fd_spad_t * runtime_spad ) { +fd_runtime_update_leaders( fd_bank_t * bank, fd_spad_t * runtime_spad ) { FD_SPAD_FRAME_BEGIN( runtime_spad ) { fd_epoch_schedule_t const * epoch_schedule = fd_bank_epoch_schedule_query( bank ); - FD_LOG_WARNING(("SLOT %lu", bank->slot )); - - FD_LOG_WARNING(( "schedule->slots_per_epoch = %lu", epoch_schedule->slots_per_epoch )); - FD_LOG_WARNING(( "schedule->leader_schedule_slot_offset = %lu", epoch_schedule->leader_schedule_slot_offset )); - FD_LOG_WARNING(( "schedule->warmup = %d", epoch_schedule->warmup )); - FD_LOG_WARNING(( "schedule->first_normal_epoch = %lu", epoch_schedule->first_normal_epoch )); - FD_LOG_WARNING(( "schedule->first_normal_slot = %lu", epoch_schedule->first_normal_slot )); - fd_vote_accounts_global_t const * epoch_vaccs = fd_bank_epoch_stakes_locking_query( bank ); fd_vote_accounts_pair_global_t_mapnode_t * vote_acc_pool = fd_vote_accounts_vote_accounts_pool_join( epoch_vaccs ); fd_vote_accounts_pair_global_t_mapnode_t * vote_acc_root = fd_vote_accounts_vote_accounts_root_join( epoch_vaccs ); - ulong epoch = fd_slot_to_epoch( epoch_schedule, slot, NULL ); + ulong epoch = fd_slot_to_epoch( epoch_schedule, bank->slot, NULL ); ulong slot0 = fd_epoch_slot0( epoch_schedule, epoch ); ulong slot_cnt = fd_epoch_slot_cnt( epoch_schedule, epoch ); @@ -2410,7 +2400,7 @@ fd_runtime_process_new_epoch( fd_bank_t * bank, fd_update_next_epoch_stakes( bank ); /* Update current leaders using new T-2 stakes */ - fd_runtime_update_leaders( bank, bank->slot, runtime_spad ); + fd_runtime_update_leaders( bank, runtime_spad ); FD_LOG_NOTICE(( "fd_process_new_epoch end" )); @@ -3205,7 +3195,7 @@ fd_runtime_process_genesis_block( fd_bank_t * bank, fd_sysvar_slot_history_update( bank, funk, funk_txn, runtime_spad ); - fd_runtime_update_leaders( bank, 0, runtime_spad ); + fd_runtime_update_leaders( bank, runtime_spad ); fd_runtime_freeze( bank, funk, funk_txn, runtime_spad ); diff --git a/src/flamenco/runtime/fd_runtime.h b/src/flamenco/runtime/fd_runtime.h index 9ac45c796c..8cbae70e5b 100644 --- a/src/flamenco/runtime/fd_runtime.h +++ b/src/flamenco/runtime/fd_runtime.h @@ -312,9 +312,7 @@ fd_runtime_compute_max_tick_height( ulong ticks_per_slot, ulong * out_max_tick_height /* out */ ); void -fd_runtime_update_leaders( fd_bank_t * bank, - ulong slot, - fd_spad_t * runtime_spad ); +fd_runtime_update_leaders( fd_bank_t * bank, fd_spad_t * runtime_spad ); /* TODO: Invoked by fd_executor: layering violation. Rent logic is deprecated and will be torn out entirely very soon. */ diff --git a/src/flamenco/runtime/tests/harness/fd_block_harness.c b/src/flamenco/runtime/tests/harness/fd_block_harness.c index c2a83d5505..e172331909 100644 --- a/src/flamenco/runtime/tests/harness/fd_block_harness.c +++ b/src/flamenco/runtime/tests/harness/fd_block_harness.c @@ -398,7 +398,7 @@ fd_runtime_fuzz_block_ctx_create( fd_runtime_fuzz_runner_t * runner, fd_bank_epoch_stakes_end_locking_modify( runner->bank ); /* Update leader schedule */ - fd_runtime_update_leaders( runner->bank, runner->bank->slot, runner->spad ); + fd_runtime_update_leaders( runner->bank, runner->spad ); /* Initialize the blockhash queue and recent blockhashes sysvar from the input blockhash queue */ fd_block_hash_queue_global_t * block_hash_queue = fd_bank_block_hash_queue_modify( runner->bank ); From cca1b3c581172fa2d674b6158401267c0055530d Mon Sep 17 00:00:00 2001 From: Ishan Bhatt Date: Wed, 9 Jul 2025 18:19:36 +0000 Subject: [PATCH 25/27] removing from replay tile --- src/discof/replay/fd_replay_tile.c | 348 +++++++++++++--------------- src/flamenco/snapshot/fd_snapshot.c | 1 - 2 files changed, 165 insertions(+), 184 deletions(-) diff --git a/src/discof/replay/fd_replay_tile.c b/src/discof/replay/fd_replay_tile.c index c82d865951..7eeb1236e3 100644 --- a/src/discof/replay/fd_replay_tile.c +++ b/src/discof/replay/fd_replay_tile.c @@ -128,8 +128,7 @@ struct fd_replay_tile_ctx { /* Do not modify order! This is join-order in unprivileged_init. */ - fd_funk_t funk[1]; - fd_forks_t * forks; + fd_forks_t * forks; fd_pubkey_t validator_identity[1]; fd_pubkey_t vote_authority[1]; @@ -150,8 +149,13 @@ struct fd_replay_tile_ctx { /* Updated during execution */ - fd_exec_slot_ctx_t * slot_ctx; - fd_slice_exec_t slice_exec_ctx; + fd_banks_t * banks; + fd_bank_t * bank; + fd_funk_t funk[1]; + fd_funk_txn_t * funk_txn; + fd_txncache_t * status_cache; + + fd_slice_exec_t slice_exec_ctx; /* TODO: Some of these arrays should be bitvecs that get masked into. */ ulong exec_cnt; @@ -211,7 +215,6 @@ struct fd_replay_tile_ctx { int vote; fd_pubkey_t validator_identity_pubkey[ 1 ]; - fd_txncache_t * status_cache; void * bmtree[ FD_PACK_MAX_BANK_TILES ]; /* The spad allocators used by the executor tiles are NOT the same as the @@ -247,7 +250,6 @@ struct fd_replay_tile_ctx { ulong enable_bank_hash_cmp; - fd_banks_t * banks; int is_booted; }; typedef struct fd_replay_tile_ctx fd_replay_tile_ctx_t; @@ -302,39 +304,39 @@ before_frag( fd_replay_tile_ctx_t * ctx, static void publish_stake_weights( fd_replay_tile_ctx_t * ctx, fd_stem_context_t * stem, - fd_exec_slot_ctx_t * slot_ctx ) { - fd_epoch_schedule_t const * epoch_schedule = fd_bank_epoch_schedule_query( slot_ctx->bank ); + fd_bank_t * bank ) { + fd_epoch_schedule_t const * epoch_schedule = fd_bank_epoch_schedule_query( bank ); - fd_vote_accounts_global_t const * epoch_stakes = fd_bank_epoch_stakes_locking_query( slot_ctx->bank ); + fd_vote_accounts_global_t const * epoch_stakes = fd_bank_epoch_stakes_locking_query( bank ); fd_vote_accounts_pair_global_t_mapnode_t * epoch_stakes_root = fd_vote_accounts_vote_accounts_root_join( epoch_stakes ); if( epoch_stakes_root!=NULL ) { ulong * stake_weights_msg = fd_chunk_to_laddr( ctx->stake_out->mem, ctx->stake_out->chunk ); - ulong epoch = fd_slot_to_leader_schedule_epoch( epoch_schedule, slot_ctx->slot ); - ulong stake_weights_sz = generate_stake_weight_msg( slot_ctx->bank, ctx->runtime_spad, epoch - 1, stake_weights_msg ); + ulong epoch = fd_slot_to_leader_schedule_epoch( epoch_schedule, bank->slot ); + ulong stake_weights_sz = generate_stake_weight_msg( bank, ctx->runtime_spad, epoch - 1, stake_weights_msg ); ulong stake_weights_sig = 4UL; fd_stem_publish( stem, 0UL, stake_weights_sig, ctx->stake_out->chunk, stake_weights_sz, 0UL, 0UL, fd_frag_meta_ts_comp( fd_tickcount() ) ); ctx->stake_out->chunk = fd_dcache_compact_next( ctx->stake_out->chunk, stake_weights_sz, ctx->stake_out->chunk0, ctx->stake_out->wmark ); FD_LOG_NOTICE(("sending current epoch stake weights - epoch: %lu, stake_weight_cnt: %lu, start_slot: %lu, slot_cnt: %lu", stake_weights_msg[0], stake_weights_msg[1], stake_weights_msg[2], stake_weights_msg[3])); } - fd_bank_epoch_stakes_end_locking_query( slot_ctx->bank ); + fd_bank_epoch_stakes_end_locking_query( bank ); - fd_vote_accounts_global_t const * next_epoch_stakes = fd_bank_next_epoch_stakes_locking_query( slot_ctx->bank ); + fd_vote_accounts_global_t const * next_epoch_stakes = fd_bank_next_epoch_stakes_locking_query( bank ); fd_vote_accounts_pair_global_t_mapnode_t * next_epoch_stakes_root = fd_vote_accounts_vote_accounts_root_join( next_epoch_stakes ); if( next_epoch_stakes_root!=NULL ) { ulong * stake_weights_msg = fd_chunk_to_laddr( ctx->stake_out->mem, ctx->stake_out->chunk ); ulong epoch = fd_slot_to_leader_schedule_epoch( epoch_schedule, - slot_ctx->slot ); /* epoch */ - ulong stake_weights_sz = generate_stake_weight_msg( slot_ctx->bank, ctx->runtime_spad, epoch, stake_weights_msg ); + ctx->bank->slot ); /* epoch */ + ulong stake_weights_sz = generate_stake_weight_msg( bank, ctx->runtime_spad, epoch, stake_weights_msg ); ulong stake_weights_sig = 4UL; fd_stem_publish( stem, 0UL, stake_weights_sig, ctx->stake_out->chunk, stake_weights_sz, 0UL, 0UL, fd_frag_meta_ts_comp( fd_tickcount() ) ); ctx->stake_out->chunk = fd_dcache_compact_next( ctx->stake_out->chunk, stake_weights_sz, ctx->stake_out->chunk0, ctx->stake_out->wmark ); FD_LOG_NOTICE(("sending next epoch stake weights - epoch: %lu, stake_weight_cnt: %lu, start_slot: %lu, slot_cnt: %lu", stake_weights_msg[0], stake_weights_msg[1], stake_weights_msg[2], stake_weights_msg[3])); } - fd_bank_next_epoch_stakes_end_locking_query( slot_ctx->bank ); + fd_bank_next_epoch_stakes_end_locking_query( bank ); } static void @@ -467,7 +469,7 @@ block_finalize_tiles_cb( void * para_arg_1, fd_replay_out_link_t * exec_out = &ctx->exec_out[ worker_idx ]; fd_runtime_public_hash_bank_msg_t * hash_msg = (fd_runtime_public_hash_bank_msg_t *)fd_chunk_to_laddr( exec_out->mem, exec_out->chunk ); - generate_hash_bank_msg( task_infos_gaddr, lt_hash_gaddr, start_idx, end_idx, ctx->slot_ctx->bank->slot, hash_msg ); + generate_hash_bank_msg( task_infos_gaddr, lt_hash_gaddr, start_idx, end_idx, ctx->bank->slot, hash_msg ); ulong tspub = fd_frag_meta_ts_comp( fd_tickcount() ); fd_stem_publish( stem, @@ -492,7 +494,7 @@ block_finalize_tiles_cb( void * para_arg_1, /* We need to compare the state and a unique identifier (slot) in the case where the last thing the exec tile did is to hash accounts. */ - if( state==FD_EXEC_STATE_HASH_DONE && slot==ctx->slot_ctx->bank->slot ) { + if( state==FD_EXEC_STATE_HASH_DONE && slot==ctx->bank->slot ) { hash_done[ i ] = 1; } else { wait_cnt++; @@ -546,7 +548,7 @@ txncache_publish( fd_replay_tile_ctx_t * ctx, one exists. */ - if( FD_UNLIKELY( !ctx->slot_ctx->status_cache ) ) { + if( FD_UNLIKELY( !ctx->status_cache ) ) { return; } @@ -558,7 +560,7 @@ txncache_publish( fd_replay_tile_ctx_t * ctx, ulong slot = txn->xid.ul[0]; FD_LOG_INFO(( "Registering slot %lu", slot )); - fd_txncache_register_root_slot( ctx->slot_ctx->status_cache, slot ); + fd_txncache_register_root_slot( ctx->status_cache, slot ); txn = fd_funk_txn_parent( txn, txn_pool ); } @@ -582,10 +584,10 @@ funk_publish( fd_replay_tile_ctx_t * ctx, } fd_funk_txn_end_write( ctx->funk ); - if( FD_LIKELY( FD_FEATURE_ACTIVE_BANK( ctx->slot_ctx->bank, epoch_accounts_hash ) && - !FD_FEATURE_ACTIVE_BANK( ctx->slot_ctx->bank, accounts_lt_hash ) ) ) { + if( FD_LIKELY( FD_FEATURE_ACTIVE_BANK( ctx->bank, epoch_accounts_hash ) && + !FD_FEATURE_ACTIVE_BANK( ctx->bank, accounts_lt_hash ) ) ) { - if( wmk>=fd_bank_eah_start_slot_get( ctx->slot_ctx->bank ) ) { + if( wmk>=fd_bank_eah_start_slot_get( ctx->bank ) ) { fd_exec_para_cb_ctx_t exec_para_ctx = { .func = fd_accounts_hash_counter_and_gather_tpool_cb, .para_arg_1 = NULL, @@ -593,18 +595,18 @@ funk_publish( fd_replay_tile_ctx_t * ctx, }; fd_hash_t out_hash = {0}; - fd_accounts_hash( ctx->slot_ctx->funk, - ctx->slot_ctx->slot, + fd_accounts_hash( ctx->funk, + ctx->bank->slot, &out_hash, ctx->runtime_spad, - fd_bank_features_query( ctx->slot_ctx->bank ), + fd_bank_features_query( ctx->bank ), &exec_para_ctx, NULL ); FD_LOG_NOTICE(( "Done computing epoch account hash (%s)", FD_BASE58_ENC_32_ALLOCA( &out_hash ) )); - fd_bank_epoch_account_hash_set( ctx->slot_ctx->bank, out_hash ); + fd_bank_epoch_account_hash_set( ctx->bank, out_hash ); - fd_bank_eah_start_slot_set( ctx->slot_ctx->bank, FD_SLOT_NULL ); + fd_bank_eah_start_slot_set( ctx->bank, FD_SLOT_NULL ); } } @@ -635,7 +637,7 @@ funk_and_txncache_publish( fd_replay_tile_ctx_t * ctx, ulong wmk, fd_funk_txn_xi funk_publish( ctx, to_root_txn, wmk ); if( FD_UNLIKELY( ctx->capture_ctx ) ) { - fd_runtime_checkpt( ctx->capture_ctx, ctx->slot_ctx->funk, wmk ); + fd_runtime_checkpt( ctx->capture_ctx, ctx->funk, wmk ); } } @@ -700,16 +702,16 @@ publish_slot_notifications( fd_replay_tile_ctx_t * ctx, { NOTIFY_START; msg->type = FD_REPLAY_SLOT_TYPE; - msg->slot_exec.slot = ctx->slot_ctx->bank->slot; + msg->slot_exec.slot = ctx->bank->slot; msg->slot_exec.parent = ctx->parent_slot; msg->slot_exec.root = fd_fseq_query( ctx->published_wmark ); msg->slot_exec.height = block_entry_block_height; - msg->slot_exec.transaction_count = fd_bank_txn_count_get( ctx->slot_ctx->bank ); - msg->slot_exec.shred_cnt = fd_bank_shred_cnt_get( ctx->slot_ctx->bank ); + msg->slot_exec.transaction_count = fd_bank_txn_count_get( ctx->bank ); + msg->slot_exec.shred_cnt = fd_bank_shred_cnt_get( ctx->bank ); - msg->slot_exec.bank_hash = fd_bank_bank_hash_get( ctx->slot_ctx->bank ); + msg->slot_exec.bank_hash = fd_bank_bank_hash_get( ctx->bank ); - fd_block_hash_queue_global_t const * block_hash_queue = fd_bank_block_hash_queue_query( ctx->slot_ctx->bank ); + fd_block_hash_queue_global_t const * block_hash_queue = fd_bank_block_hash_queue_query( ctx->bank ); fd_hash_t * last_hash = fd_block_hash_queue_last_hash_join( block_hash_queue ); msg->slot_exec.block_hash = *last_hash; @@ -717,12 +719,12 @@ publish_slot_notifications( fd_replay_tile_ctx_t * ctx, msg->slot_exec.ts = tsorig; NOTIFY_END; } - fd_bank_shred_cnt_set( ctx->slot_ctx->bank, 0UL ); + fd_bank_shred_cnt_set( ctx->bank, 0UL ); #undef NOTIFY_START #undef NOTIFY_END notify_time_ns += fd_log_wallclock(); - FD_LOG_DEBUG(("TIMING: notify_slot_time - slot: %lu, elapsed: %6.6f ms", ctx->slot_ctx->bank->slot, (double)notify_time_ns * 1e-6)); + FD_LOG_DEBUG(("TIMING: notify_slot_time - slot: %lu, elapsed: %6.6f ms", ctx->bank->slot, (double)notify_time_ns * 1e-6)); if( ctx->plugin_out->mem ) { /* @@ -740,14 +742,14 @@ publish_slot_notifications( fd_replay_tile_ctx_t * ctx, */ ulong msg[11]; - msg[ 0 ] = ctx->slot_ctx->bank->slot; - msg[ 1 ] = fd_bank_txn_count_get( ctx->slot_ctx->bank ); - msg[ 2 ] = fd_bank_nonvote_txn_count_get( ctx->slot_ctx->bank ); - msg[ 3 ] = fd_bank_failed_txn_count_get( ctx->slot_ctx->bank ); - msg[ 4 ] = fd_bank_nonvote_failed_txn_count_get( ctx->slot_ctx->bank ); - msg[ 5 ] = fd_bank_total_compute_units_used_get( ctx->slot_ctx->bank ); - msg[ 6 ] = fd_bank_execution_fees_get( ctx->slot_ctx->bank ); - msg[ 7 ] = fd_bank_priority_fees_get( ctx->slot_ctx->bank ); + msg[ 0 ] = ctx->bank->slot; + msg[ 1 ] = fd_bank_txn_count_get( ctx->bank ); + msg[ 2 ] = fd_bank_nonvote_txn_count_get( ctx->bank ); + msg[ 3 ] = fd_bank_failed_txn_count_get( ctx->bank ); + msg[ 4 ] = fd_bank_nonvote_failed_txn_count_get( ctx->bank ); + msg[ 5 ] = fd_bank_total_compute_units_used_get( ctx->bank ); + msg[ 6 ] = fd_bank_execution_fees_get( ctx->bank ); + msg[ 7 ] = fd_bank_priority_fees_get( ctx->bank ); msg[ 8 ] = 0UL; /* todo ... track tips */ msg[ 9 ] = ctx->parent_slot; msg[ 10 ] = 0UL; /* todo ... max compute units */ @@ -835,20 +837,20 @@ prepare_new_block_execution( fd_replay_tile_ctx_t * ctx, FD_TEST( fork == child ); FD_LOG_NOTICE(( "new block execution - slot: %lu, parent_slot: %lu", slot, ctx->parent_slot )); - ctx->slot_ctx->banks = ctx->banks; if( FD_UNLIKELY( !ctx->banks ) ) { FD_LOG_CRIT(( "invariant violation: banks is NULL" )); } - ctx->slot_ctx->bank = fd_banks_clone_from_parent( ctx->banks, slot, ctx->parent_slot ); - if( FD_UNLIKELY( !ctx->slot_ctx->bank ) ) { + fd_bank_t * prev_bank = ctx->bank; + ctx->bank = fd_banks_clone_from_parent( ctx->banks, slot, ctx->parent_slot ); + if( FD_UNLIKELY( !ctx->bank ) ) { FD_LOG_CRIT(( "invariant violation: bank is NULL" )); } /* if it is an epoch boundary, push out stake weights */ - if( ctx->slot_ctx->slot != 0 ) { - is_new_epoch_in_new_block = (int)fd_runtime_is_epoch_boundary( ctx->slot_ctx->bank, ctx->slot_ctx->slot, fd_bank_prev_slot_get( ctx->slot_ctx->bank ) ); + if( ctx->bank->slot != 0 ) { + is_new_epoch_in_new_block = (int)fd_runtime_is_epoch_boundary( ctx->bank, ctx->bank->slot, fd_bank_prev_slot_get( ctx->bank ) ); } /* Update starting PoH hash for the new slot for tick verification later */ @@ -859,32 +861,30 @@ prepare_new_block_execution( fd_replay_tile_ctx_t * ctx, if( FD_UNLIKELY( slot != curr_block_info->slot ) ) FD_LOG_ERR(("Block map prepare failed, likely corrupt.")); fd_block_map_publish( query ); - fd_bank_prev_slot_set( ctx->slot_ctx->bank, ctx->slot_ctx->slot ); + fd_bank_prev_slot_set( ctx->bank, prev_bank->slot ); - ctx->slot_ctx->slot = slot; + fd_bank_tick_height_set( ctx->bank, fd_bank_max_tick_height_get( ctx->bank ) ); - fd_bank_tick_height_set( ctx->slot_ctx->bank, fd_bank_max_tick_height_get( ctx->slot_ctx->bank ) ); - - ulong * max_tick_height = fd_bank_max_tick_height_modify( ctx->slot_ctx->bank ); - ulong ticks_per_slot = fd_bank_ticks_per_slot_get( ctx->slot_ctx->bank ); + ulong * max_tick_height = fd_bank_max_tick_height_modify( ctx->bank ); + ulong ticks_per_slot = fd_bank_ticks_per_slot_get( ctx->bank ); if( FD_UNLIKELY( FD_RUNTIME_EXECUTE_SUCCESS != fd_runtime_compute_max_tick_height( ticks_per_slot, slot, max_tick_height ) ) ) { FD_LOG_ERR(( "couldn't compute tick height/max tick height slot %lu ticks_per_slot %lu", slot, ticks_per_slot )); } - fd_bank_enable_exec_recording_set( ctx->slot_ctx->bank, ctx->tx_metadata_storage ); + fd_bank_enable_exec_recording_set( ctx->bank, ctx->tx_metadata_storage ); - ctx->slot_ctx->status_cache = ctx->status_cache; + ctx->status_cache = ctx->status_cache; fd_funk_txn_xid_t xid = { 0 }; if( flags & REPLAY_FLAG_PACKED_MICROBLOCK ) { memset( xid.uc, 0, sizeof(fd_funk_txn_xid_t) ); } else { - xid.ul[1] = ctx->slot_ctx->slot; + xid.ul[1] = ctx->bank->slot; } - xid.ul[0] = ctx->slot_ctx->slot; + xid.ul[0] = ctx->bank->slot; /* push a new transaction on the stack */ fd_funk_txn_start_write( ctx->funk ); @@ -895,16 +895,16 @@ prepare_new_block_execution( fd_replay_tile_ctx_t * ctx, fd_funk_txn_xid_t parent_xid = { .ul = { ctx->parent_slot, ctx->parent_slot } }; fd_funk_txn_t * parent_txn = fd_funk_txn_query( &parent_xid, txn_map ); - ctx->slot_ctx->funk_txn = fd_funk_txn_prepare(ctx->funk, parent_txn, &xid, 1 ); + ctx->funk_txn = fd_funk_txn_prepare(ctx->funk, parent_txn, &xid, 1 ); fd_funk_txn_end_write( ctx->funk ); int is_epoch_boundary = 0; /* TODO: Currently all of the epoch boundary/rewards logic is not multhreaded at the epoch boundary. */ - fd_runtime_block_pre_execute_process_new_epoch( ctx->slot_ctx->bank, - ctx->slot_ctx->funk, - ctx->slot_ctx->funk_txn, + fd_runtime_block_pre_execute_process_new_epoch( ctx->bank, + ctx->funk, + ctx->funk_txn, NULL, ctx->exec_spads, ctx->exec_spad_cnt, @@ -929,9 +929,9 @@ prepare_new_block_execution( fd_replay_tile_ctx_t * ctx, an epoch). We pop a frame when rewards are done being distributed. */ fd_spad_push( ctx->runtime_spad ); - int res = fd_runtime_block_execute_prepare( ctx->slot_ctx->bank, - ctx->slot_ctx->funk, - ctx->slot_ctx->funk_txn, + int res = fd_runtime_block_execute_prepare( ctx->bank, + ctx->funk, + ctx->funk_txn, ctx->blockstore, ctx->runtime_spad ); if( res != FD_RUNTIME_EXECUTE_SUCCESS ) { @@ -939,7 +939,7 @@ prepare_new_block_execution( fd_replay_tile_ctx_t * ctx, } if( is_new_epoch_in_new_block ) { - publish_stake_weights( ctx, stem, ctx->slot_ctx ); + publish_stake_weights( ctx, stem, ctx->bank ); } prepare_time_ns += fd_log_wallclock(); @@ -953,25 +953,25 @@ init_poh( fd_replay_tile_ctx_t * ctx ) { FD_LOG_INFO(( "sending init msg" )); FD_LOG_WARNING(( "hashes_per_tick: %lu, ticks_per_slot: %lu", - fd_bank_hashes_per_tick_get( ctx->slot_ctx->bank ), - fd_bank_ticks_per_slot_get( ctx->slot_ctx->bank ) )); + fd_bank_hashes_per_tick_get( ctx->bank ), + fd_bank_ticks_per_slot_get( ctx->bank ) )); fd_replay_out_link_t * bank_out = &ctx->bank_out[ 0UL ]; fd_poh_init_msg_t * msg = fd_chunk_to_laddr( bank_out->mem, bank_out->chunk ); // FIXME: msg is NULL - msg->hashcnt_per_tick = fd_bank_hashes_per_tick_get( ctx->slot_ctx->bank ); - msg->ticks_per_slot = fd_bank_ticks_per_slot_get( ctx->slot_ctx->bank ); - msg->tick_duration_ns = (ulong)(fd_bank_ns_per_slot_get( ctx->slot_ctx->bank )) / fd_bank_ticks_per_slot_get( ctx->slot_ctx->bank ); + msg->hashcnt_per_tick = fd_bank_hashes_per_tick_get( ctx->bank ); + msg->ticks_per_slot = fd_bank_ticks_per_slot_get( ctx->bank ); + msg->tick_duration_ns = (ulong)(fd_bank_ns_per_slot_get( ctx->bank )) / fd_bank_ticks_per_slot_get( ctx->bank ); - fd_block_hash_queue_global_t * bhq = (fd_block_hash_queue_global_t *)&ctx->slot_ctx->bank->block_hash_queue[0]; + fd_block_hash_queue_global_t * bhq = fd_bank_block_hash_queue_modify( ctx->bank ); fd_hash_t * last_hash = fd_block_hash_queue_last_hash_join( bhq ); if( last_hash ) { memcpy(msg->last_entry_hash, last_hash, sizeof(fd_hash_t)); } else { memset(msg->last_entry_hash, 0UL, sizeof(fd_hash_t)); } - msg->tick_height = ctx->slot_ctx->slot * msg->ticks_per_slot; + msg->tick_height = ctx->bank->slot * msg->ticks_per_slot; - ulong sig = fd_disco_replay_old_sig( ctx->slot_ctx->slot, REPLAY_FLAG_INIT ); + ulong sig = fd_disco_replay_old_sig( ctx->bank->slot, REPLAY_FLAG_INIT ); fd_mcache_publish( bank_out->mcache, bank_out->depth, bank_out->seq, sig, bank_out->chunk, sizeof(fd_poh_init_msg_t), 0UL, 0UL, 0UL ); bank_out->chunk = fd_dcache_compact_next( bank_out->chunk, sizeof(fd_poh_init_msg_t), bank_out->chunk0, bank_out->wmark ); bank_out->seq = fd_seq_inc( bank_out->seq, 1UL ); @@ -1004,19 +1004,17 @@ prepare_first_batch_execution( fd_replay_tile_ctx_t * ctx, fork = prepare_new_block_execution( ctx, stem, slot, flags ); } else { FD_LOG_WARNING(("Fork for slot %lu already exists, so we don't make a new one. Restarting execution from batch %u", slot, fork->end_idx )); - ctx->slot_ctx->bank = fd_banks_get_bank( ctx->banks, slot ); - if( FD_UNLIKELY( !ctx->slot_ctx->bank ) ) { + ctx->bank = fd_banks_get_bank( ctx->banks, slot ); + if( FD_UNLIKELY( !ctx->bank ) ) { FD_LOG_CRIT(( "Unable to get bank for slot %lu", slot )); } fd_funk_txn_map_t * txn_map = fd_funk_txn_map( ctx->funk ); fd_funk_txn_xid_t xid = { .ul = { slot, slot } }; - ctx->slot_ctx->funk_txn = fd_funk_txn_query( &xid, txn_map ); - if( FD_UNLIKELY( !ctx->slot_ctx->funk_txn ) ) { + ctx->funk_txn = fd_funk_txn_query( &xid, txn_map ); + if( FD_UNLIKELY( !ctx->funk_txn ) ) { FD_LOG_CRIT(( "Unable to get funk transaction for slot %lu", slot )); } - - ctx->slot_ctx->slot = slot; } /**********************************************************************/ @@ -1024,7 +1022,7 @@ prepare_first_batch_execution( fd_replay_tile_ctx_t * ctx, /**********************************************************************/ if( ctx->capture_ctx ) { - fd_solcap_writer_set_slot( ctx->capture_ctx->capture, ctx->slot_ctx->slot ); + fd_solcap_writer_set_slot( ctx->capture_ctx->capture, ctx->bank->slot ); } } @@ -1076,7 +1074,7 @@ exec_slice( fd_replay_tile_ctx_t * ctx, /* Insert or reverify invoked programs for this epoch, if needed FIXME: this should be done during txn parsing so that we don't have to loop over all accounts a second time. */ - fd_runtime_update_program_cache( ctx->slot_ctx->bank, ctx->slot_ctx->funk, ctx->slot_ctx->funk_txn, &txn_p, ctx->runtime_spad ); + fd_runtime_update_program_cache( ctx->bank, ctx->funk, ctx->funk_txn, &txn_p, ctx->runtime_spad ); fd_fork_t * fork = fd_fork_frontier_ele_query( ctx->forks->frontier, &slot, @@ -1085,12 +1083,12 @@ exec_slice( fd_replay_tile_ctx_t * ctx, if( FD_UNLIKELY( !fork ) ) FD_LOG_ERR(( "Unable to select a fork" )); - fd_bank_txn_count_set( ctx->slot_ctx->bank, fd_bank_txn_count_get( ctx->slot_ctx->bank ) + 1 ); + fd_bank_txn_count_set( ctx->bank, fd_bank_txn_count_get( ctx->bank ) + 1 ); /* dispatch dcache */ fd_runtime_public_txn_msg_t * exec_msg = (fd_runtime_public_txn_msg_t *)fd_chunk_to_laddr( exec_out->mem, exec_out->chunk ); memcpy( &exec_msg->txn, &txn_p, sizeof(fd_txn_p_t) ); - exec_msg->slot = ctx->slot_ctx->slot; + exec_msg->slot = ctx->bank->slot; ctx->exec_ready[ exec_idx ] = EXEC_TXN_BUSY; ulong tspub = fd_frag_meta_ts_comp( fd_tickcount() ); @@ -1142,17 +1140,17 @@ exec_slice( fd_replay_tile_ctx_t * ctx, // Copy block hash to slot_bank poh for updating the sysvars fd_block_map_query_t query[1] = { 0 }; - fd_block_map_prepare( ctx->blockstore->block_map, &ctx->slot_ctx->bank->slot, NULL, query, FD_MAP_FLAG_BLOCKING ); + fd_block_map_prepare( ctx->blockstore->block_map, &ctx->bank->slot, NULL, query, FD_MAP_FLAG_BLOCKING ); fd_block_info_t * block_info = fd_block_map_query_ele( query ); - fd_hash_t * poh = fd_bank_poh_modify( ctx->slot_ctx->bank ); + fd_hash_t * poh = fd_bank_poh_modify( ctx->bank ); memcpy( poh, hdr->hash, sizeof(fd_hash_t) ); block_info->flags = fd_uchar_set_bit( block_info->flags, FD_BLOCK_FLAG_PROCESSED ); FD_COMPILER_MFENCE(); block_info->flags = fd_uchar_clear_bit( block_info->flags, FD_BLOCK_FLAG_REPLAYING ); memcpy( &block_info->block_hash, hdr->hash, sizeof(fd_hash_t) ); - fd_hash_t const * bank_hash = fd_bank_bank_hash_query( ctx->slot_ctx->bank ); + fd_hash_t const * bank_hash = fd_bank_bank_hash_query( ctx->bank ); memcpy( &block_info->bank_hash, bank_hash, sizeof(fd_hash_t) ); fd_block_map_publish( query ); @@ -1205,7 +1203,7 @@ handle_slice( fd_replay_tile_ctx_t * ctx, return; } - if( FD_UNLIKELY( slot != ctx->slot_ctx->bank->slot ) ) { + if( FD_UNLIKELY( slot != ctx->bank->slot ) ) { /* We need to switch forks and execution contexts. Either we completed execution of the previous slot and are now executing @@ -1248,7 +1246,7 @@ handle_slice( fd_replay_tile_ctx_t * ctx, &slice_sz ); fork->end_idx += data_cnt; fd_slice_exec_begin( &ctx->slice_exec_ctx, slice_sz, slot_complete ); - fd_bank_shred_cnt_set( ctx->slot_ctx->bank, fd_bank_shred_cnt_get( ctx->slot_ctx->bank ) + data_cnt ); + fd_bank_shred_cnt_set( ctx->bank, fd_bank_shred_cnt_get( ctx->bank ) + data_cnt ); if( FD_UNLIKELY( err ) ) { FD_LOG_ERR(( "Failed to query blockstore for slot %lu", slot )); @@ -1260,10 +1258,10 @@ kickoff_repair_orphans( fd_replay_tile_ctx_t * ctx, fd_stem_context_t * stem ) { fd_blockstore_init( ctx->blockstore, ctx->blockstore_fd, FD_BLOCKSTORE_ARCHIVE_MIN_SIZE, - ctx->slot_ctx->slot ); + ctx->bank->slot ); - fd_fseq_update( ctx->published_wmark, ctx->slot_ctx->slot ); - publish_stake_weights( ctx, stem, ctx->slot_ctx ); + fd_fseq_update( ctx->published_wmark, ctx->bank->slot ); + publish_stake_weights( ctx, stem, ctx->bank ); } @@ -1289,7 +1287,7 @@ read_snapshot( void * _ctx, ulong base_slot = 0UL; if( strcmp( snapshot, "funk" )==0 || strncmp( snapshot, "wksp:", 5 )==0 ) { /* Funk already has a snapshot loaded */ - base_slot = ctx->slot_ctx->slot; + base_slot = ctx->bank->slot; kickoff_repair_orphans( ctx, stem ); } else { @@ -1312,10 +1310,10 @@ read_snapshot( void * _ctx, incremental, ctx->incremental_src_type, NULL, - ctx->slot_ctx->banks, - ctx->slot_ctx->bank, - ctx->slot_ctx->funk, - ctx->slot_ctx->funk_txn, + ctx->banks, + ctx->bank, + ctx->funk, + ctx->funk_txn, false, false, FD_SNAPSHOT_TYPE_INCREMENTAL, @@ -1336,10 +1334,10 @@ read_snapshot( void * _ctx, snapshot, ctx->snapshot_src_type, snapshot_dir, - ctx->slot_ctx->banks, - ctx->slot_ctx->bank, - ctx->slot_ctx->funk, - ctx->slot_ctx->funk_txn, + ctx->banks, + ctx->bank, + ctx->funk, + ctx->funk_txn, false, false, FD_SNAPSHOT_TYPE_FULL, @@ -1353,9 +1351,8 @@ read_snapshot( void * _ctx, /* If we don't have an incremental snapshot, load the manifest and the status cache and initialize the objects because we don't have these from the incremental snapshot. */ if( strlen( incremental )<=0UL ) { - ctx->slot_ctx->bank = fd_snapshot_load_manifest_and_status_cache( snap_ctx, NULL, + ctx->bank = fd_snapshot_load_manifest_and_status_cache( snap_ctx, NULL, FD_SNAPSHOT_RESTORE_MANIFEST | FD_SNAPSHOT_RESTORE_STATUS_CACHE ); - ctx->slot_ctx->slot = ctx->slot_ctx->bank->slot; kickoff_repair_orphans( ctx, stem ); /* If we don't have an incremental snapshot, we can still kick off sending the stake weights and snapshot slot to repair. */ @@ -1366,21 +1363,20 @@ read_snapshot( void * _ctx, } base_slot = fd_snapshot_get_slot( snap_ctx ); fd_snapshot_load_accounts( snap_ctx ); - ctx->slot_ctx->bank = fd_snapshot_load_fini( snap_ctx ); - ctx->slot_ctx->slot = ctx->slot_ctx->bank->slot; + ctx->bank = fd_snapshot_load_fini( snap_ctx ); } if( strlen( incremental ) > 0 && strcmp( snapshot, "funk" ) != 0 ) { /* The slot of the full snapshot should be used as the base slot to verify the incremental snapshot, not the slot context's slot - which is the slot of the incremental, not the full snapshot. */ - ctx->slot_ctx->bank = fd_snapshot_load_all( incremental, + ctx->bank = fd_snapshot_load_all( incremental, ctx->incremental_src_type, NULL, - ctx->slot_ctx->banks, - ctx->slot_ctx->bank, - ctx->slot_ctx->funk, - ctx->slot_ctx->funk_txn, + ctx->banks, + ctx->bank, + ctx->funk, + ctx->funk_txn, &base_slot, NULL, false, @@ -1389,11 +1385,10 @@ read_snapshot( void * _ctx, ctx->exec_spads, ctx->exec_spad_cnt, ctx->runtime_spad ); - ctx->slot_ctx->slot = ctx->slot_ctx->bank->slot; kickoff_repair_orphans( ctx, stem ); } - fd_runtime_update_leaders( ctx->slot_ctx->bank, ctx->runtime_spad ); + fd_runtime_update_leaders( ctx->bank, ctx->runtime_spad ); } static void @@ -1404,32 +1399,31 @@ init_after_snapshot( fd_replay_tile_ctx_t * ctx, /* After both snapshots have been loaded in, we can determine if we should start distributing rewards. */ - fd_rewards_recalculate_partitioned_rewards( ctx->slot_ctx->bank, - ctx->slot_ctx->funk, - ctx->slot_ctx->funk_txn, + fd_rewards_recalculate_partitioned_rewards( ctx->bank, + ctx->funk, + ctx->funk_txn, NULL, ctx->exec_spads, ctx->exec_spad_cnt, ctx->runtime_spad ); - ulong snapshot_slot = ctx->slot_ctx->slot; + ulong snapshot_slot = ctx->bank->slot; if( FD_UNLIKELY( !snapshot_slot ) ) { /* Genesis-specific setup. */ /* FIXME: This branch does not set up a new block exec ctx properly. Needs to do whatever prepare_new_block_execution does, but just hacking that in breaks stuff. */ - fd_runtime_update_leaders( ctx->slot_ctx->bank, ctx->runtime_spad ); + fd_runtime_update_leaders( ctx->bank, ctx->runtime_spad ); - fd_bank_prev_slot_set( ctx->slot_ctx->bank, 0UL ); - ctx->slot_ctx->slot = 1UL; + fd_bank_prev_slot_set( ctx->bank, 0UL ); - ulong hashcnt_per_slot = fd_bank_hashes_per_tick_get( ctx->slot_ctx->bank ) * fd_bank_ticks_per_slot_get( ctx->slot_ctx->bank ); - fd_hash_t * poh = fd_bank_poh_modify( ctx->slot_ctx->bank ); + ulong hashcnt_per_slot = fd_bank_hashes_per_tick_get( ctx->bank ) * fd_bank_ticks_per_slot_get( ctx->bank ); + fd_hash_t * poh = fd_bank_poh_modify( ctx->bank ); while(hashcnt_per_slot--) { fd_sha256_hash( poh->hash, 32UL, poh->hash ); } - FD_TEST( fd_runtime_block_execute_prepare( ctx->slot_ctx->bank, ctx->slot_ctx->funk, ctx->slot_ctx->funk_txn, ctx->blockstore, ctx->runtime_spad ) == 0 ); + FD_TEST( fd_runtime_block_execute_prepare( ctx->bank, ctx->funk, ctx->funk_txn, ctx->blockstore, ctx->runtime_spad ) == 0 ); fd_runtime_block_info_t info = { .signature_cnt = 0 }; fd_exec_para_cb_ctx_t exec_para_ctx_block_finalize = { @@ -1438,17 +1432,16 @@ init_after_snapshot( fd_replay_tile_ctx_t * ctx, .para_arg_2 = stem, }; - fd_runtime_block_execute_finalize_para( ctx->slot_ctx->bank, - ctx->slot_ctx->funk, - ctx->slot_ctx->funk_txn, + fd_runtime_block_execute_finalize_para( ctx->bank, + ctx->funk, + ctx->funk_txn, ctx->capture_ctx, &info, ctx->exec_cnt, ctx->runtime_spad, &exec_para_ctx_block_finalize ); - ctx->slot_ctx->slot = 1UL; - snapshot_slot = 1UL; + snapshot_slot = 1UL; /* Now setup exec tiles for execution */ for( ulong i=0UL; iexec_cnt; i++ ) { @@ -1456,18 +1449,18 @@ init_after_snapshot( fd_replay_tile_ctx_t * ctx, } } - ctx->parent_slot = fd_bank_prev_slot_get( ctx->slot_ctx->bank ); + ctx->parent_slot = fd_bank_prev_slot_get( ctx->bank ); ctx->snapshot_slot = snapshot_slot; ctx->flags = EXEC_FLAG_READY_NEW; /* Initialize consensus structures post-snapshot */ - fd_fork_t * snapshot_fork = fd_forks_init( ctx->forks, ctx->slot_ctx->slot ); + fd_fork_t * snapshot_fork = fd_forks_init( ctx->forks, ctx->bank->slot ); if( FD_UNLIKELY( !snapshot_fork ) ) { FD_LOG_CRIT(( "Failed to initialize snapshot fork" )); } - fd_stakes_global_t const * stakes = fd_bank_stakes_locking_query( ctx->slot_ctx->bank ); + fd_stakes_global_t const * stakes = fd_bank_stakes_locking_query( ctx->bank ); fd_vote_accounts_global_t const * vote_accounts = &stakes->vote_accounts; fd_vote_accounts_pair_global_t_mapnode_t * vote_accounts_pool = fd_vote_accounts_vote_accounts_pool_join( vote_accounts ); @@ -1501,7 +1494,7 @@ init_after_snapshot( fd_replay_tile_ctx_t * ctx, } bank_hash_cmp->watermark = snapshot_slot; - fd_bank_stakes_end_locking_query( ctx->slot_ctx->bank ); + fd_bank_stakes_end_locking_query( ctx->bank ); ulong root = snapshot_slot; if( FD_LIKELY( root > fd_fseq_query( ctx->published_wmark ) ) ) { @@ -1528,16 +1521,9 @@ init_after_snapshot( fd_replay_tile_ctx_t * ctx, void init_snapshot( fd_replay_tile_ctx_t * ctx, fd_stem_context_t * stem ) { - /* Init slot_ctx */ - uchar * slot_ctx_mem = fd_spad_alloc_check( ctx->runtime_spad, FD_EXEC_SLOT_CTX_ALIGN, FD_EXEC_SLOT_CTX_FOOTPRINT ); - ctx->slot_ctx = fd_exec_slot_ctx_join( fd_exec_slot_ctx_new( slot_ctx_mem ) ); - ctx->slot_ctx->banks = ctx->banks; - ctx->slot_ctx->bank = fd_banks_get_bank( ctx->banks, 0UL ); - - ctx->slot_ctx->funk = ctx->funk; - ctx->slot_ctx->status_cache = ctx->status_cache; - fd_runtime_update_slots_per_epoch( ctx->slot_ctx->bank, FD_DEFAULT_SLOTS_PER_EPOCH ); + ctx->bank = fd_banks_get_bank( ctx->banks, 0UL ); + fd_runtime_update_slots_per_epoch( ctx->bank, FD_DEFAULT_SLOTS_PER_EPOCH ); uchar is_snapshot = strlen( ctx->snapshot ) > 0; if( is_snapshot ) { @@ -1552,9 +1538,9 @@ init_snapshot( fd_replay_tile_ctx_t * ctx, } fd_runtime_read_genesis( - ctx->slot_ctx->bank, - ctx->slot_ctx->funk, - &ctx->slot_ctx->funk_txn, + ctx->bank, + ctx->funk, + &ctx->funk_txn, ctx->genesis, is_snapshot, ctx->capture_ctx, @@ -1565,15 +1551,15 @@ init_snapshot( fd_replay_tile_ctx_t * ctx, fd_blockstore_init( ctx->blockstore, ctx->blockstore_fd, FD_BLOCKSTORE_ARCHIVE_MIN_SIZE, - ctx->slot_ctx->bank->slot ); + ctx->bank->slot ); init_after_snapshot( ctx, stem ); if( ctx->plugin_out->mem && strlen( ctx->genesis ) > 0 ) { - replay_plugin_publish( ctx, stem, FD_PLUGIN_MSG_GENESIS_HASH_KNOWN, fd_bank_genesis_hash_query( ctx->slot_ctx->bank )->hash, sizeof(fd_hash_t) ); + replay_plugin_publish( ctx, stem, FD_PLUGIN_MSG_GENESIS_HASH_KNOWN, fd_bank_genesis_hash_query( ctx->bank )->hash, sizeof(fd_hash_t) ); } // Tell the world about the current activate features - fd_features_t const * features = fd_bank_features_query( ctx->slot_ctx->bank ); + fd_features_t const * features = fd_bank_features_query( ctx->bank ); fd_memcpy( &ctx->runtime_public->features, features, sizeof(ctx->runtime_public->features) ); /* Publish slot notifs */ @@ -1582,11 +1568,11 @@ init_snapshot( fd_replay_tile_ctx_t * ctx, if( is_snapshot ) { for(;;){ fd_block_map_query_t query[1] = { 0 }; - int err = fd_block_map_query_try( ctx->blockstore->block_map, &ctx->slot_ctx->bank->slot, NULL, query, 0 ); + int err = fd_block_map_query_try( ctx->blockstore->block_map, &ctx->bank->slot, NULL, query, 0 ); fd_block_info_t * block_info = fd_block_map_query_ele( query ); if( FD_UNLIKELY( err == FD_MAP_ERR_KEY ) ) continue; /* FIXME: eventually need an error condition here.*/ if( FD_UNLIKELY( err == FD_MAP_ERR_AGAIN ) ) { - FD_LOG_WARNING(( "Waiting for block map query for slot %lu", ctx->slot_ctx->bank->slot )); + FD_LOG_WARNING(( "Waiting for block map query for slot %lu", ctx->bank->slot )); continue; }; block_entry_height = block_info->block_height; @@ -1602,9 +1588,6 @@ init_snapshot( fd_replay_tile_ctx_t * ctx, } publish_slot_notifications( ctx, stem, block_entry_height ); - - - FD_TEST( ctx->slot_ctx ); } static void @@ -1612,10 +1595,10 @@ publish_votes_to_plugin( fd_replay_tile_ctx_t * ctx, fd_stem_context_t * stem ) { uchar * dst = (uchar *)fd_chunk_to_laddr( ctx->votes_plugin_out->mem, ctx->votes_plugin_out->chunk ); - fd_fork_t * fork = fd_fork_frontier_ele_query( ctx->forks->frontier, &ctx->slot_ctx->bank->slot, NULL, ctx->forks->pool ); + fd_fork_t * fork = fd_fork_frontier_ele_query( ctx->forks->frontier, &ctx->bank->slot, NULL, ctx->forks->pool ); if( FD_UNLIKELY ( !fork ) ) return; - fd_vote_accounts_global_t const * epoch_stakes = fd_bank_epoch_stakes_locking_query( ctx->slot_ctx->bank ); + fd_vote_accounts_global_t const * epoch_stakes = fd_bank_epoch_stakes_locking_query( ctx->bank ); fd_vote_accounts_pair_global_t_mapnode_t * epoch_stakes_pool = fd_vote_accounts_vote_accounts_pool_join( epoch_stakes ); fd_vote_accounts_pair_global_t_mapnode_t * epoch_stakes_root = fd_vote_accounts_vote_accounts_root_join( epoch_stakes ); @@ -1673,7 +1656,7 @@ publish_votes_to_plugin( fd_replay_tile_ctx_t * ctx, fd_clock_timestamp_vote_t_mapnode_t query; memcpy( query.elem.pubkey.uc, n->elem.key.uc, 32UL ); - fd_clock_timestamp_votes_global_t const * clock_timestamp_votes = fd_bank_clock_timestamp_votes_locking_query( ctx->slot_ctx->bank ); + fd_clock_timestamp_votes_global_t const * clock_timestamp_votes = fd_bank_clock_timestamp_votes_locking_query( ctx->bank ); fd_clock_timestamp_vote_t_mapnode_t * timestamp_votes_root = fd_clock_timestamp_votes_votes_root_join( clock_timestamp_votes ); fd_clock_timestamp_vote_t_mapnode_t * timestamp_votes_pool = fd_clock_timestamp_votes_votes_pool_join( clock_timestamp_votes ); @@ -1688,13 +1671,13 @@ publish_votes_to_plugin( fd_replay_tile_ctx_t * ctx, msg->root_slot = root_slot; msg->epoch_credits = epoch_credits; msg->commission = (uchar)commission; - msg->is_delinquent = (uchar)fd_int_if(ctx->slot_ctx->bank->slot >= 128UL, msg->last_vote <= ctx->slot_ctx->bank->slot - 128UL, msg->last_vote == 0); + msg->is_delinquent = (uchar)fd_int_if(ctx->bank->slot >= 128UL, msg->last_vote <= ctx->bank->slot - 128UL, msg->last_vote == 0); ++i; - fd_bank_clock_timestamp_votes_end_locking_query( ctx->slot_ctx->bank ); + fd_bank_clock_timestamp_votes_end_locking_query( ctx->bank ); } } FD_SPAD_FRAME_END; - fd_bank_epoch_stakes_end_locking_query( ctx->slot_ctx->bank ); + fd_bank_epoch_stakes_end_locking_query( ctx->bank ); *(ulong *)dst = i; @@ -1771,7 +1754,7 @@ after_credit( fd_replay_tile_ctx_t * ctx, /* If we are currently executing a slice, proceed. */ if( ctx->flags & EXEC_FLAG_EXECUTING_SLICE ) { - exec_slice( ctx, stem, ctx->slot_ctx->bank->slot ); + exec_slice( ctx, stem, ctx->bank->slot ); } ulong flags = ctx->flags; @@ -1783,20 +1766,20 @@ after_credit( fd_replay_tile_ctx_t * ctx, as read-only. This happens when it has replayed through turbine_slot0. */ - if( FD_UNLIKELY( ctx->read_only && ctx->slot_ctx->bank->slot >= fd_fseq_query( ctx->turbine_slot0 ) ) ) { + if( FD_UNLIKELY( ctx->read_only && ctx->bank->slot >= fd_fseq_query( ctx->turbine_slot0 ) ) ) { ctx->read_only = 0; } - fd_fork_t * fork = fd_fork_frontier_ele_query( ctx->forks->frontier, &ctx->slot_ctx->bank->slot, NULL, ctx->forks->pool ); + fd_fork_t * fork = fd_fork_frontier_ele_query( ctx->forks->frontier, &ctx->bank->slot, NULL, ctx->forks->pool ); - FD_LOG_NOTICE(( "finished block - slot: %lu, parent_slot: %lu", ctx->slot_ctx->bank->slot, ctx->parent_slot )); + FD_LOG_NOTICE(( "finished block - slot: %lu, parent_slot: %lu", ctx->bank->slot, ctx->parent_slot )); /**************************************************************************************************/ /* Call fd_runtime_block_execute_finalize_tpool which updates sysvar and cleanup some other stuff */ /**************************************************************************************************/ fd_runtime_block_info_t runtime_block_info[1]; - runtime_block_info->signature_cnt = fd_bank_signature_count_get( ctx->slot_ctx->bank ); + runtime_block_info->signature_cnt = fd_bank_signature_count_get( ctx->bank ); ctx->block_finalizing = 0; @@ -1806,9 +1789,10 @@ after_credit( fd_replay_tile_ctx_t * ctx, .para_arg_2 = stem, }; - fd_runtime_block_execute_finalize_para( ctx->slot_ctx->bank, - ctx->slot_ctx->funk, - ctx->slot_ctx->funk_txn, + fd_runtime_block_execute_finalize_para( + ctx->bank, + ctx->funk, + ctx->funk_txn, ctx->capture_ctx, runtime_block_info, ctx->exec_cnt, @@ -1817,9 +1801,9 @@ after_credit( fd_replay_tile_ctx_t * ctx, /* Update blockstore with the freshly computed bank hash */ fd_block_map_query_t query[1] = { 0 }; - fd_block_map_prepare( ctx->blockstore->block_map, &ctx->slot_ctx->bank->slot, NULL, query, FD_MAP_FLAG_BLOCKING ); + fd_block_map_prepare( ctx->blockstore->block_map, &ctx->bank->slot, NULL, query, FD_MAP_FLAG_BLOCKING ); fd_block_info_t * block_info = fd_block_map_query_ele( query ); - block_info->bank_hash = fd_bank_bank_hash_get( ctx->slot_ctx->bank ); + block_info->bank_hash = fd_bank_bank_hash_get( ctx->bank ); fd_block_map_publish( query ); fd_spad_pop( ctx->runtime_spad ); @@ -1829,24 +1813,24 @@ after_credit( fd_replay_tile_ctx_t * ctx, /* Push notifications for slot updates and reset block_info flag */ /**********************************************************************/ - ulong block_entry_height = fd_blockstore_block_height_query( ctx->blockstore, ctx->slot_ctx->bank->slot ); + ulong block_entry_height = fd_blockstore_block_height_query( ctx->blockstore, ctx->bank->slot ); publish_slot_notifications( ctx, stem, block_entry_height ); - ctx->blockstore->shmem->lps = ctx->slot_ctx->bank->slot; + ctx->blockstore->shmem->lps = ctx->bank->slot; - FD_TEST(fork->slot == ctx->slot_ctx->bank->slot); + FD_TEST(fork->slot == ctx->bank->slot); fork->lock = 0; // FD_LOG_NOTICE(( "ulong_max? %d", ctx->tower_out_idx==ULONG_MAX )); if( FD_LIKELY( ctx->tower_out_idx!=ULONG_MAX && !ctx->read_only ) ) { uchar * chunk_laddr = fd_chunk_to_laddr( ctx->tower_out_mem, ctx->tower_out_chunk ); - fd_hash_t const * bank_hash = fd_bank_bank_hash_query( ctx->slot_ctx->bank ); - fd_block_hash_queue_global_t * block_hash_queue = (fd_block_hash_queue_global_t *)&ctx->slot_ctx->bank->block_hash_queue[0]; + fd_hash_t const * bank_hash = fd_bank_bank_hash_query( ctx->bank ); + fd_block_hash_queue_global_t * block_hash_queue = (fd_block_hash_queue_global_t *)&ctx->bank->block_hash_queue[0]; fd_hash_t * last_hash = fd_block_hash_queue_last_hash_join( block_hash_queue ); memcpy( chunk_laddr, bank_hash, sizeof(fd_hash_t) ); memcpy( chunk_laddr+sizeof(fd_hash_t), last_hash, sizeof(fd_hash_t) ); - fd_stem_publish( stem, ctx->tower_out_idx, ctx->slot_ctx->bank->slot << 32UL | ctx->parent_slot, ctx->tower_out_chunk, sizeof(fd_hash_t) * 2, 0UL, fd_frag_meta_ts_comp( fd_tickcount() ), fd_frag_meta_ts_comp( fd_tickcount() ) ); + fd_stem_publish( stem, ctx->tower_out_idx, ctx->bank->slot << 32UL | ctx->parent_slot, ctx->tower_out_chunk, sizeof(fd_hash_t) * 2, 0UL, fd_frag_meta_ts_comp( fd_tickcount() ), fd_frag_meta_ts_comp( fd_tickcount() ) ); } // if (FD_UNLIKELY( prev_confirmed!=ctx->forks->confirmed && ctx->plugin_out->mem ) ) { @@ -1863,15 +1847,13 @@ after_credit( fd_replay_tile_ctx_t * ctx, /* Prepare bank for the next execution and write to debugging files */ /**********************************************************************/ - ulong prev_slot = ctx->slot_ctx->slot; - - fd_bank_execution_fees_set( ctx->slot_ctx->bank, 0UL ); + fd_bank_execution_fees_set( ctx->bank, 0UL ); - fd_bank_priority_fees_set( ctx->slot_ctx->bank, 0UL ); + fd_bank_priority_fees_set( ctx->bank, 0UL ); if( FD_UNLIKELY( ctx->slots_replayed_file ) ) { - FD_LOG_DEBUG(( "writing %lu to slots file", prev_slot )); - fprintf( ctx->slots_replayed_file, "%lu\n", prev_slot ); + FD_LOG_DEBUG(( "writing %lu to slots file", ctx->bank->slot )); + fprintf( ctx->slots_replayed_file, "%lu\n", ctx->bank->slot ); fflush( ctx->slots_replayed_file ); } @@ -1883,13 +1865,13 @@ after_credit( fd_replay_tile_ctx_t * ctx, /* Bank hash comparison, and halt if there's a mismatch after replay */ /**********************************************************************/ - fd_hash_t const * bank_hash = fd_bank_bank_hash_query( ctx->slot_ctx->bank ); + fd_hash_t const * bank_hash = fd_bank_bank_hash_query( ctx->bank ); fd_bank_hash_cmp_t * bank_hash_cmp = ctx->bank_hash_cmp; fd_bank_hash_cmp_lock( bank_hash_cmp ); - fd_bank_hash_cmp_insert( bank_hash_cmp, ctx->slot_ctx->bank->slot, bank_hash, 1, 0 ); + fd_bank_hash_cmp_insert( bank_hash_cmp, ctx->bank->slot, bank_hash, 1, 0 ); /* Try to move the bank hash comparison watermark forward */ - for( ulong cmp_slot = bank_hash_cmp->watermark + 1; cmp_slot < ctx->slot_ctx->bank->slot; cmp_slot++ ) { + for( ulong cmp_slot = bank_hash_cmp->watermark + 1; cmp_slot < ctx->bank->slot; cmp_slot++ ) { if( FD_UNLIKELY( !ctx->enable_bank_hash_cmp ) ) { bank_hash_cmp->watermark = cmp_slot; break; diff --git a/src/flamenco/snapshot/fd_snapshot.c b/src/flamenco/snapshot/fd_snapshot.c index 8b0022e1dd..97e69490ed 100644 --- a/src/flamenco/snapshot/fd_snapshot.c +++ b/src/flamenco/snapshot/fd_snapshot.c @@ -62,7 +62,6 @@ restore_manifest( void * ctx, fd_bank_t * bank = NULL; int err = (!!fd_exec_slot_ctx_recover( load_ctx->banks, &bank, manifest, spad ) ? 0 : EINVAL); - FD_LOG_WARNING(("P %p", (void*)load_ctx)); load_ctx->bank = bank; return err; } From e64d0eed9ba69d4d29e8013a3664f6311890f411 Mon Sep 17 00:00:00 2001 From: Ishan Bhatt Date: Wed, 9 Jul 2025 19:52:54 +0000 Subject: [PATCH 26/27] decouple from snapshot loading totally --- src/app/ledger/main.c | 1 - src/discof/replay/fd_replay_tile.c | 10 +- .../runtime/context/fd_exec_slot_ctx.c | 545 ------------------ .../runtime/context/fd_exec_slot_ctx.h | 26 - src/flamenco/runtime/fd_runtime.c | 540 +++++++++++++++++ src/flamenco/runtime/fd_runtime.h | 25 + src/flamenco/snapshot/fd_snapshot.c | 8 +- 7 files changed, 572 insertions(+), 583 deletions(-) diff --git a/src/app/ledger/main.c b/src/app/ledger/main.c index aedf2303fa..dec6a3c804 100644 --- a/src/app/ledger/main.c +++ b/src/app/ledger/main.c @@ -1065,7 +1065,6 @@ replay( fd_ledger_args_t * args ) { /* Load in snapshot(s) */ - FD_LOG_WARNING(("%p funk %p funk_txn", (void*)args->funk, (void *)args->funk_txn )); if( args->snapshot ) { args->bank = fd_snapshot_load_all( args->snapshot, FD_SNAPSHOT_SRC_FILE, diff --git a/src/discof/replay/fd_replay_tile.c b/src/discof/replay/fd_replay_tile.c index e3adc924e7..fd80efef4b 100644 --- a/src/discof/replay/fd_replay_tile.c +++ b/src/discof/replay/fd_replay_tile.c @@ -656,18 +656,14 @@ restore_slot_ctx( fd_replay_tile_ctx_t * ctx, fd_solana_manifest_global_t * manifest_global = (fd_solana_manifest_global_t *)fd_chunk_to_laddr( fd_wksp_containing( ctx->manifest_dcache ), chunk ); - - fd_bank_t * manifest_bank = NULL; - int err = fd_exec_slot_ctx_recover( + ctx->bank = fd_runtime_recover_bank( ctx->banks, - &manifest_bank, manifest_global, ctx->runtime_spad ); - if( FD_UNLIKELY( !err ) ) { + + if( FD_UNLIKELY( !ctx->bank ) ) { FD_LOG_CRIT(( "Failed to restore slot context from snapshot manifest!" )); } - - ctx->bank = manifest_bank; } static void diff --git a/src/flamenco/runtime/context/fd_exec_slot_ctx.c b/src/flamenco/runtime/context/fd_exec_slot_ctx.c index c6f1a3f4cd..7dca96b265 100644 --- a/src/flamenco/runtime/context/fd_exec_slot_ctx.c +++ b/src/flamenco/runtime/context/fd_exec_slot_ctx.c @@ -86,548 +86,3 @@ fd_exec_slot_ctx_delete( void * mem ) { return mem; } - -/* recover_clock recovers PoH/wallclock synchronization. Walks all vote - accounts in current epoch stakes. */ - -static int -recover_clock( fd_bank_t * bank, fd_spad_t * runtime_spad ) { - - fd_stakes_global_t const * stakes = fd_bank_stakes_locking_query( bank ); - if( FD_UNLIKELY( stakes==NULL ) ) { - FD_LOG_WARNING(( "stakes is NULL" )); - fd_bank_stakes_end_locking_query( bank ); - return 0; - } - - fd_vote_accounts_global_t const * vote_accounts = &stakes->vote_accounts; - fd_vote_accounts_pair_global_t_mapnode_t * vote_accounts_pool = fd_vote_accounts_vote_accounts_pool_join( vote_accounts ); - fd_vote_accounts_pair_global_t_mapnode_t * vote_accounts_root = fd_vote_accounts_vote_accounts_root_join( vote_accounts ); - - if( FD_UNLIKELY( !vote_accounts_pool ) ) { - FD_LOG_CRIT(( "vote_accounts_pool is NULL" )); - } - if( FD_UNLIKELY( !vote_accounts_root ) ) { - FD_LOG_CRIT(( "vote_accounts_root is NULL" )); - } - - for( fd_vote_accounts_pair_global_t_mapnode_t * n = fd_vote_accounts_pair_global_t_map_minimum(vote_accounts_pool, vote_accounts_root); - n; - n = fd_vote_accounts_pair_global_t_map_successor( vote_accounts_pool, n ) ) { - - FD_SPAD_FRAME_BEGIN( runtime_spad ) { - - /* Extract vote timestamp of account */ - int err; - - uchar * data = fd_solana_account_data_join( &n->elem.value ); - ulong data_len = n->elem.value.data_len; - - fd_vote_state_versioned_t * vsv = fd_bincode_decode_spad( - vote_state_versioned, runtime_spad, - data, - data_len, - &err ); - if( FD_UNLIKELY( err ) ) { - FD_LOG_WARNING(( "vote state decode failed" )); - fd_bank_stakes_end_locking_query( bank ); - return 0; - } - - long timestamp = 0; - ulong slot = 0; - switch( vsv->discriminant ) { - case fd_vote_state_versioned_enum_v0_23_5: - timestamp = vsv->inner.v0_23_5.last_timestamp.timestamp; - slot = vsv->inner.v0_23_5.last_timestamp.slot; - break; - case fd_vote_state_versioned_enum_v1_14_11: - timestamp = vsv->inner.v1_14_11.last_timestamp.timestamp; - slot = vsv->inner.v1_14_11.last_timestamp.slot; - break; - case fd_vote_state_versioned_enum_current: - timestamp = vsv->inner.current.last_timestamp.timestamp; - slot = vsv->inner.current.last_timestamp.slot; - break; - default: - __builtin_unreachable(); - } - - /* Record timestamp */ - if( slot != 0 || n->elem.stake != 0 ) { - fd_vote_record_timestamp_vote_with_slot( &n->elem.key, timestamp, slot, bank ); - } - } FD_SPAD_FRAME_END; - } - - fd_bank_stakes_end_locking_query( bank ); - return 1; -} - -int -fd_exec_slot_ctx_recover( fd_banks_t * banks, - fd_bank_t * * bank_out, - fd_solana_manifest_global_t const * manifest, - fd_spad_t * runtime_spad ) { - - fd_bank_t * bank = fd_banks_clone_from_parent( banks, manifest->bank.slot, 0UL ); - if( FD_UNLIKELY( !bank ) ) { - FD_LOG_CRIT(( "fd_banks_clone_from_parent failed" )); - } - *bank_out = bank; - - fd_versioned_bank_global_t const * old_bank = &manifest->bank; - - ulong stakes_sz = fd_stakes_size_global( &manifest->bank.stakes ); - fd_stakes_global_t * stakes = fd_bank_stakes_locking_modify( bank ); - fd_memcpy( stakes, &manifest->bank.stakes, stakes_sz ); - /* Verify stakes */ - - fd_bank_stakes_end_locking_modify( bank ); - - /* Index vote accounts */ - - /* Block Hash Queue */ - - fd_block_hash_queue_global_t * bhq = fd_bank_block_hash_queue_modify( bank ); - uchar * last_hash_mem = (uchar *)fd_ulong_align_up( (ulong)bhq + sizeof(fd_block_hash_queue_global_t), alignof(fd_hash_t) ); - uchar * ages_pool_mem = (uchar *)fd_ulong_align_up( (ulong)last_hash_mem + sizeof(fd_hash_t), fd_hash_hash_age_pair_t_map_align() ); - - fd_hash_hash_age_pair_t_mapnode_t * ages_pool = fd_hash_hash_age_pair_t_map_join( fd_hash_hash_age_pair_t_map_new( ages_pool_mem, 301 ) ); - fd_hash_hash_age_pair_t_mapnode_t * ages_root = NULL; - - bhq->last_hash_index = old_bank->blockhash_queue.last_hash_index; - - fd_hash_t const * last_hash = fd_block_hash_vec_last_hash_join( &old_bank->blockhash_queue ); - - if( last_hash ) { - fd_memcpy( last_hash_mem, last_hash, sizeof(fd_hash_t) ); - } else { - fd_memset( last_hash_mem, 0, sizeof(fd_hash_t) ); - } - bhq->last_hash_offset = (ulong)last_hash_mem - (ulong)bhq; - - fd_hash_hash_age_pair_t const * ages = fd_block_hash_vec_ages_join( &old_bank->blockhash_queue ); - - for( ulong i=0UL; iblockhash_queue.ages_len; i++ ) { - fd_hash_hash_age_pair_t const * elem = &ages[i]; - fd_hash_hash_age_pair_t_mapnode_t * node = fd_hash_hash_age_pair_t_map_acquire( ages_pool ); - node->elem = *elem; - fd_hash_hash_age_pair_t_map_insert( ages_pool, &ages_root, node ); - } - - fd_block_hash_queue_ages_pool_update( bhq, ages_pool ); - fd_block_hash_queue_ages_root_update( bhq, ages_root ); - - bhq->max_age = old_bank->blockhash_queue.max_age; - - /* Bank Hash */ - - fd_bank_bank_hash_set( bank, old_bank->hash ); - - /* Fee Rate Governor */ - - fd_fee_rate_governor_t * fee_rate_governor = fd_bank_fee_rate_governor_modify( bank ); - *fee_rate_governor = old_bank->fee_rate_governor; - - /* Capitalization */ - - fd_bank_capitalization_set( bank, old_bank->capitalization ); - - /* Lamports Per Signature */ - - fd_bank_lamports_per_signature_set( bank, manifest->lamports_per_signature ); - - /* Previous Lamports Per Signature */ - - fd_bank_prev_lamports_per_signature_set( bank, manifest->lamports_per_signature ); - - /* Transaction Count */ - - fd_bank_transaction_count_set( bank, old_bank->transaction_count ); - - /* Parent Signature Count */ - - fd_bank_parent_signature_cnt_set( bank, old_bank->signature_count ); - - /* Tick Height */ - - fd_bank_tick_height_set( bank, old_bank->tick_height ); - - /* Max Tick Height */ - - fd_bank_max_tick_height_set( bank, old_bank->max_tick_height ); - - /* Hashes Per Tick */ - - ulong * hashes_per_tick = fd_versioned_bank_hashes_per_tick_join( old_bank ); - fd_bank_hashes_per_tick_set( bank, !!hashes_per_tick ? *hashes_per_tick : 0UL ); - - /* NS Per Slot */ - - fd_bank_ns_per_slot_set( bank, old_bank->ns_per_slot ); - - /* Ticks Per Slot */ - - fd_bank_ticks_per_slot_set( bank, old_bank->ticks_per_slot ); - - /* Genesis Creation Time */ - - fd_bank_genesis_creation_time_set( bank, old_bank->genesis_creation_time ); - - /* Slots Per Year */ - - fd_bank_slots_per_year_set( bank, old_bank->slots_per_year ); - - /* Inflation */ - - fd_bank_inflation_set( bank, old_bank->inflation ); - - /* Block Height */ - - fd_bank_block_height_set( bank, old_bank->block_height ); - - /* Epoch Account Hash */ - - fd_hash_t * epoch_account_hash = fd_solana_manifest_epoch_account_hash_join( manifest ); - if( !!epoch_account_hash ) { - fd_bank_epoch_account_hash_set( bank, *epoch_account_hash ); - } else { - fd_bank_epoch_account_hash_set( bank, (fd_hash_t){0} ); - } - - /* Prev Slot */ - - fd_bank_prev_slot_set( bank, old_bank->parent_slot ); - - /* Execution Fees */ - - fd_bank_execution_fees_set( bank, old_bank->collector_fees ); - - /* Priority Fees */ - - fd_bank_priority_fees_set( bank, 0UL ); - - /* PoH */ - - if( last_hash ) { - fd_bank_poh_set( bank, *last_hash ); - } - - /* Prev Bank Hash */ - - fd_bank_prev_bank_hash_set( bank, old_bank->parent_hash ); - - /* Epoch Schedule */ - - fd_bank_epoch_schedule_set( bank, old_bank->epoch_schedule ); - - /* Rent */ - - fd_bank_rent_set( bank, old_bank->rent_collector.rent ); - - /* Last Restart Slot */ - - /* Update last restart slot - https://github.com/solana-labs/solana/blob/30531d7a5b74f914dde53bfbb0bc2144f2ac92bb/runtime/src/bank.rs#L2152 - - old_bank->hard_forks is sorted ascending by slot number. - To find the last restart slot, take the highest hard fork slot - number that is less or equal than the current slot number. - (There might be some hard forks in the future, ignore these) */ - do { - fd_sol_sysvar_last_restart_slot_t * last_restart_slot = fd_bank_last_restart_slot_modify( bank ); - last_restart_slot->slot = 0UL; - - if( FD_UNLIKELY( old_bank->hard_forks.hard_forks_len == 0 ) ) { - /* SIMD-0047: The first restart slot should be `0` */ - break; - } - - fd_slot_pair_t const * head = fd_hard_forks_hard_forks_join( &old_bank->hard_forks ); - fd_slot_pair_t const * tail = head + old_bank->hard_forks.hard_forks_len - 1UL; - - for( fd_slot_pair_t const *pair = tail; pair >= head; pair-- ) { - if( pair->slot <= bank->slot ) { - fd_sol_sysvar_last_restart_slot_t * last_restart_slot = fd_bank_last_restart_slot_modify( bank ); - last_restart_slot->slot = pair->slot; - break; - } - } - } while (0); - - /* FIXME: Remove the magic number here. */ - fd_clock_timestamp_votes_global_t * clock_timestamp_votes = fd_bank_clock_timestamp_votes_locking_modify( bank ); - uchar * clock_pool_mem = (uchar *)fd_ulong_align_up( (ulong)clock_timestamp_votes + sizeof(fd_clock_timestamp_votes_global_t), fd_clock_timestamp_vote_t_map_align() ); - fd_clock_timestamp_vote_t_mapnode_t * clock_pool = fd_clock_timestamp_vote_t_map_join( fd_clock_timestamp_vote_t_map_new(clock_pool_mem, 30000UL ) ); - clock_timestamp_votes->votes_pool_offset = (ulong)fd_clock_timestamp_vote_t_map_leave( clock_pool) - (ulong)clock_timestamp_votes; - clock_timestamp_votes->votes_root_offset = 0UL; - fd_bank_clock_timestamp_votes_end_locking_modify( bank ); - - recover_clock( bank, runtime_spad ); - - - /* Move EpochStakes */ - do { - - fd_epoch_schedule_t const * epoch_schedule = fd_bank_epoch_schedule_query( bank ); - ulong epoch = fd_slot_to_epoch( epoch_schedule, bank->slot, NULL ); - - /* We need to save the vote accounts for the current epoch and the next - epoch as it is used to calculate the leader schedule at the epoch - boundary. */ - - fd_vote_accounts_global_t * vote_accounts_curr_stakes = NULL; - fd_vote_accounts_global_t * vote_accounts_next_stakes = NULL; - - fd_epoch_epoch_stakes_pair_global_t * versioned_bank_epoch_stakes = fd_versioned_bank_epoch_stakes_join( &manifest->bank ); - for( ulong i=0UL; ibank.epoch_stakes_len; i++ ) { - if( versioned_bank_epoch_stakes[i].key == epoch ) { - vote_accounts_curr_stakes = &versioned_bank_epoch_stakes[i].value.stakes.vote_accounts; - } - if( versioned_bank_epoch_stakes[i].key == epoch+1UL ) { - vote_accounts_next_stakes = &versioned_bank_epoch_stakes[i].value.stakes.vote_accounts; - } - - /* When loading from a snapshot, Agave's stake caches mean that we have to special-case the epoch stakes - that are used for the second epoch E+2 after the snapshot epoch E. - - If the snapshot contains the epoch stakes for E+2, we should use those. - - If the snapshot does not, we should use the stakes at the end of the E-1 epoch, instead of E-2 as we do for - all other epochs. */ - } - - fd_versioned_epoch_stakes_pair_global_t * versioned_epoch_stakes = fd_solana_manifest_versioned_epoch_stakes_join( manifest ); - for( ulong i=0UL; iversioned_epoch_stakes_len; i++ ) { - - if( versioned_epoch_stakes[i].epoch == epoch ) { - vote_accounts_curr_stakes = &versioned_epoch_stakes[i].val.inner.Current.stakes.vote_accounts; - } - if( versioned_epoch_stakes[i].epoch == epoch+1UL ) { - vote_accounts_next_stakes = &versioned_epoch_stakes[i].val.inner.Current.stakes.vote_accounts; - - /* Save the initial value to be used for the get_epoch_stake - syscall. - - A note on Agave's indexing scheme for their epoch_stakes - structure: - - https://github.com/anza-xyz/agave/blob/v2.2.14/runtime/src/bank.rs#L6175 - - If we are loading a snapshot and replaying in the middle of - epoch 7, the syscall is supposed to return the total stake at - the end of epoch 6. The epoch_stakes structure is indexed in - Agave by the epoch number of the leader schedule that the - stakes are meant to determine. For instance, to get the - stakes at the end of epoch 6, we should query by 8, because - the leader schedule for epoch 8 is determined based on the - stakes at the end of epoch 6. Therefore, we save the total - epoch stake by querying for epoch+1. */ - fd_bank_total_epoch_stake_set( bank, versioned_epoch_stakes[i].val.inner.Current.total_stake ); - } - } - - fd_bank_use_prev_epoch_stake_set( bank, epoch + 2UL ); - - fd_vote_accounts_pair_global_t_mapnode_t * vote_accounts_curr_stakes_pool = fd_vote_accounts_vote_accounts_pool_join( vote_accounts_curr_stakes ); - fd_vote_accounts_pair_global_t_mapnode_t * vote_accounts_curr_stakes_root = fd_vote_accounts_vote_accounts_root_join( vote_accounts_curr_stakes ); - - fd_vote_accounts_pair_global_t_mapnode_t * vote_accounts_next_stakes_pool = fd_vote_accounts_vote_accounts_pool_join( vote_accounts_next_stakes ); - fd_vote_accounts_pair_global_t_mapnode_t * vote_accounts_next_stakes_root = fd_vote_accounts_vote_accounts_root_join( vote_accounts_next_stakes ); - - if( FD_UNLIKELY( (!vote_accounts_curr_stakes_pool) | (!vote_accounts_next_stakes_pool) ) ) { - FD_LOG_WARNING(( "snapshot missing EpochStakes for epochs %lu and/or %lu", epoch, epoch+1UL )); - return 0; - } - - /* Move current EpochStakes */ - - fd_vote_accounts_global_t * epoch_stakes = fd_bank_epoch_stakes_locking_modify( bank ); - uchar * epoch_stakes_pool_mem = (uchar *)fd_ulong_align_up( (ulong)epoch_stakes + sizeof(fd_vote_accounts_global_t), fd_vote_accounts_pair_global_t_map_align() ); - fd_vote_accounts_pair_global_t_mapnode_t * epoch_stakes_pool = fd_vote_accounts_pair_global_t_map_join( fd_vote_accounts_pair_global_t_map_new( epoch_stakes_pool_mem, 50000UL ) ); - fd_vote_accounts_pair_global_t_mapnode_t * epoch_stakes_root = NULL; - - uchar * acc_region_curr = (uchar *)fd_ulong_align_up( (ulong)epoch_stakes_pool + fd_vote_accounts_pair_global_t_map_footprint( 50000UL ), 8UL ); - - for( fd_vote_accounts_pair_global_t_mapnode_t * n = fd_vote_accounts_pair_global_t_map_minimum( - vote_accounts_curr_stakes_pool, - vote_accounts_curr_stakes_root ); - n; - n = fd_vote_accounts_pair_global_t_map_successor( vote_accounts_curr_stakes_pool, n ) ) { - - fd_vote_accounts_pair_global_t_mapnode_t * elem = fd_vote_accounts_pair_global_t_map_acquire( - epoch_stakes_pool ); - FD_TEST( elem ); - - elem->elem.stake = n->elem.stake; - elem->elem.key = n->elem.key; - - elem->elem.value.lamports = n->elem.value.lamports; - elem->elem.value.data_len = 0UL; - elem->elem.value.data_offset = 0UL; - elem->elem.value.owner = n->elem.value.owner; - elem->elem.value.executable = n->elem.value.executable; - elem->elem.value.rent_epoch = n->elem.value.rent_epoch; - - elem->elem.value.data_offset = (ulong)(acc_region_curr - (uchar *)&elem->elem.value); - elem->elem.value.data_len = n->elem.value.data_len; - - uchar * manifest_data = fd_solana_account_data_join( &n->elem.value ); - memcpy( acc_region_curr, manifest_data, n->elem.value.data_len ); - acc_region_curr += n->elem.value.data_len; - - fd_vote_accounts_pair_global_t_map_insert( - epoch_stakes_pool, - &epoch_stakes_root, - elem ); - } - - fd_vote_accounts_vote_accounts_pool_update( epoch_stakes, epoch_stakes_pool ); - fd_vote_accounts_vote_accounts_root_update( epoch_stakes, epoch_stakes_root ); - fd_bank_epoch_stakes_end_locking_modify( bank ); - - /* Move next EpochStakes */ - - fd_vote_accounts_global_t * next_epoch_stakes = fd_bank_next_epoch_stakes_locking_modify( bank ); - uchar * next_epoch_stakes_pool_mem = (uchar *)fd_ulong_align_up( (ulong)next_epoch_stakes + sizeof(fd_vote_accounts_global_t), fd_vote_accounts_pair_global_t_map_align() ); - fd_vote_accounts_pair_global_t_mapnode_t * next_epoch_stakes_pool = fd_vote_accounts_pair_global_t_map_join( fd_vote_accounts_pair_global_t_map_new( next_epoch_stakes_pool_mem, 50000UL ) ); - fd_vote_accounts_pair_global_t_mapnode_t * next_epoch_stakes_root = NULL; - - fd_vote_accounts_pair_global_t_mapnode_t * pool = vote_accounts_next_stakes_pool; - fd_vote_accounts_pair_global_t_mapnode_t * root = vote_accounts_next_stakes_root; - - acc_region_curr = (uchar *)fd_ulong_align_up( (ulong)next_epoch_stakes_pool + fd_vote_accounts_pair_global_t_map_footprint( 50000UL ), 8UL ); - - for( fd_vote_accounts_pair_global_t_mapnode_t * n = fd_vote_accounts_pair_global_t_map_minimum( pool, root ); - n; - n = fd_vote_accounts_pair_global_t_map_successor( pool, n ) ) { - - fd_vote_accounts_pair_global_t_mapnode_t * elem = fd_vote_accounts_pair_global_t_map_acquire( next_epoch_stakes_pool ); - FD_TEST( elem ); - - elem->elem.stake = n->elem.stake; - elem->elem.key = n->elem.key; - - elem->elem.value.lamports = n->elem.value.lamports; - elem->elem.value.data_len = 0UL; - elem->elem.value.data_offset = 0UL; - elem->elem.value.owner = n->elem.value.owner; - elem->elem.value.executable = n->elem.value.executable; - elem->elem.value.rent_epoch = n->elem.value.rent_epoch; - - elem->elem.value.data_offset = (ulong)(acc_region_curr - (uchar *)&elem->elem.value);; - elem->elem.value.data_len = n->elem.value.data_len; - - uchar * manifest_data = fd_solana_account_data_join( &n->elem.value ); - memcpy( acc_region_curr, manifest_data, n->elem.value.data_len ); - acc_region_curr += n->elem.value.data_len; - - fd_vote_accounts_pair_global_t_map_insert( - next_epoch_stakes_pool, - &next_epoch_stakes_root, - elem ); - - } - fd_vote_accounts_vote_accounts_pool_update( next_epoch_stakes, next_epoch_stakes_pool ); - fd_vote_accounts_vote_accounts_root_update( next_epoch_stakes, next_epoch_stakes_root ); - fd_bank_next_epoch_stakes_end_locking_modify( bank ); - - } while(0); - - fd_slot_lthash_t * lthash = fd_bank_lthash_modify( bank ); - - fd_slot_lthash_t * lthash_value = fd_solana_manifest_lthash_join( manifest ); - if( !!lthash_value ) { - *lthash = *lthash_value; - } else { - fd_lthash_zero( (fd_lthash_value_t *)lthash->lthash ); - } - /* Setup next epoch stakes */ - - return 1; -} - -fd_exec_slot_ctx_t * -fd_exec_slot_ctx_recover_status_cache( fd_exec_slot_ctx_t * ctx, - fd_bank_slot_deltas_t * slot_deltas, - fd_spad_t * runtime_spad ) { - - return ctx; - - fd_txncache_t * status_cache = ctx->status_cache; - if( !status_cache ) { - FD_LOG_WARNING(("No status cache in slot ctx")); - return NULL; - } - - FD_SPAD_FRAME_BEGIN( runtime_spad ) { - - ulong num_entries = 0; - for( ulong i = 0; i < slot_deltas->slot_deltas_len; i++ ) { - fd_slot_delta_t * slot_delta = &slot_deltas->slot_deltas[i]; - for( ulong j = 0; j < slot_delta->slot_delta_vec_len; j++ ) { - num_entries += slot_delta->slot_delta_vec[j].value.statuses_len; - } - } - fd_txncache_insert_t * insert_vals = fd_spad_alloc_check( runtime_spad, alignof(fd_txncache_insert_t), num_entries * sizeof(fd_txncache_insert_t) ); - - /* Dumb sort for 300 slot entries to insert in order. */ - fd_slot_delta_t ** deltas = fd_spad_alloc_check( runtime_spad, alignof(fd_slot_delta_t*), slot_deltas->slot_deltas_len * sizeof(fd_slot_delta_t*) ); - - long curr = -1; - for( ulong i = 0UL; i < slot_deltas->slot_deltas_len; i++ ) { - ulong curr_min = ULONG_MAX; - ulong curr_min_idx = ULONG_MAX; - for( ulong j = 0; j < slot_deltas->slot_deltas_len; j++ ) { - fd_slot_delta_t * slot_delta = &slot_deltas->slot_deltas[j]; - if( (long)slot_delta->slot <= curr ) continue; - - if( curr_min > slot_delta->slot ) { - curr_min = slot_delta->slot; - curr_min_idx = j; - } - } - deltas[i] = &slot_deltas->slot_deltas[curr_min_idx]; - curr = (long)slot_deltas->slot_deltas[curr_min_idx].slot; - } - - ulong idx = 0; - for( ulong i = 0; i < slot_deltas->slot_deltas_len; i++ ) { - fd_slot_delta_t * slot_delta = deltas[i]; - ulong slot = slot_delta->slot; - if( slot_delta->is_root ) { - fd_txncache_register_root_slot( ctx->status_cache, slot ); - } - for( ulong j = 0; j < slot_delta->slot_delta_vec_len; j++ ) { - fd_status_pair_t * pair = &slot_delta->slot_delta_vec[j]; - fd_hash_t * blockhash = &pair->hash; - uchar * results = fd_spad_alloc( runtime_spad, FD_SPAD_ALIGN, pair->value.statuses_len ); - for( ulong k = 0; k < pair->value.statuses_len; k++ ) { - fd_cache_status_t * status = &pair->value.statuses[k]; - uchar * result = results + k; - *result = (uchar)status->result.discriminant; - insert_vals[idx++] = (fd_txncache_insert_t){ - .blockhash = blockhash->uc, - .slot = slot, - .txnhash = status->key_slice, - .result = result - }; - } - } - } - fd_txncache_insert_batch( ctx->status_cache, insert_vals, num_entries ); - - for( ulong i = 0; i < slot_deltas->slot_deltas_len; i++ ) { - fd_slot_delta_t * slot_delta = deltas[i]; - ulong slot = slot_delta->slot; - for( ulong j = 0; j < slot_delta->slot_delta_vec_len; j++ ) { - fd_status_pair_t * pair = &slot_delta->slot_delta_vec[j]; - fd_hash_t * blockhash = &pair->hash; - fd_txncache_set_txnhash_offset( ctx->status_cache, slot, blockhash->uc, pair->value.txn_idx ); - } - } - - } FD_SPAD_FRAME_END; - return ctx; -} diff --git a/src/flamenco/runtime/context/fd_exec_slot_ctx.h b/src/flamenco/runtime/context/fd_exec_slot_ctx.h index e67a28b784..9a161cf1a3 100644 --- a/src/flamenco/runtime/context/fd_exec_slot_ctx.h +++ b/src/flamenco/runtime/context/fd_exec_slot_ctx.h @@ -53,32 +53,6 @@ fd_exec_slot_ctx_leave( fd_exec_slot_ctx_t * ctx ); void * fd_exec_slot_ctx_delete( void * mem ); -/* fd_exec_slot_ctx_recover re-initializes the current epoch/slot - context and recovers it from the manifest of a Solana Labs snapshot. - - Copies content of manifest to ctx. The 'manifest' object may be - freed after this function returns. Assumes that slot context and - epoch context use same allocator. Returns ctx on success. - On failure, logs reason for error and returns NULL. */ - -int -fd_exec_slot_ctx_recover( fd_banks_t * banks, - fd_bank_t * * bank_out, - fd_solana_manifest_global_t const * manifest_global, - fd_spad_t * spad ); - -/* fd_exec_slot_ctx_recover re-initializes the current slot - context's status cache from the provided solana slot deltas. - Assumes objects in slot deltas were allocated using slot ctx valloc - (U.B. otherwise). - On return, slot deltas is destroyed. Returns ctx on success. - On failure, logs reason for error and returns NULL. */ - -fd_exec_slot_ctx_t * -fd_exec_slot_ctx_recover_status_cache( fd_exec_slot_ctx_t * ctx, - fd_bank_slot_deltas_t * slot_deltas, - fd_spad_t * runtime_spad ); - FD_PROTOTYPES_END #endif /* HEADER_fd_src_flamenco_runtime_context_fd_exec_slot_ctx_h */ diff --git a/src/flamenco/runtime/fd_runtime.c b/src/flamenco/runtime/fd_runtime.c index ba2e7e009a..e19a8a318d 100644 --- a/src/flamenco/runtime/fd_runtime.c +++ b/src/flamenco/runtime/fd_runtime.c @@ -67,6 +67,546 @@ /* Public Runtime Helpers */ /******************************************************************************/ +/* recover_clock recovers PoH/wallclock synchronization. Walks all vote + accounts in current epoch stakes. */ + +static int +recover_clock( fd_bank_t * bank, fd_spad_t * runtime_spad ) { + + fd_stakes_global_t const * stakes = fd_bank_stakes_locking_query( bank ); + if( FD_UNLIKELY( stakes==NULL ) ) { + FD_LOG_WARNING(( "stakes is NULL" )); + fd_bank_stakes_end_locking_query( bank ); + return 0; + } + + fd_vote_accounts_global_t const * vote_accounts = &stakes->vote_accounts; + fd_vote_accounts_pair_global_t_mapnode_t * vote_accounts_pool = fd_vote_accounts_vote_accounts_pool_join( vote_accounts ); + fd_vote_accounts_pair_global_t_mapnode_t * vote_accounts_root = fd_vote_accounts_vote_accounts_root_join( vote_accounts ); + + if( FD_UNLIKELY( !vote_accounts_pool ) ) { + FD_LOG_CRIT(( "vote_accounts_pool is NULL" )); + } + if( FD_UNLIKELY( !vote_accounts_root ) ) { + FD_LOG_CRIT(( "vote_accounts_root is NULL" )); + } + + for( fd_vote_accounts_pair_global_t_mapnode_t * n = fd_vote_accounts_pair_global_t_map_minimum(vote_accounts_pool, vote_accounts_root); + n; + n = fd_vote_accounts_pair_global_t_map_successor( vote_accounts_pool, n ) ) { + + FD_SPAD_FRAME_BEGIN( runtime_spad ) { + + /* Extract vote timestamp of account */ + int err; + + uchar * data = fd_solana_account_data_join( &n->elem.value ); + ulong data_len = n->elem.value.data_len; + + fd_vote_state_versioned_t * vsv = fd_bincode_decode_spad( + vote_state_versioned, runtime_spad, + data, + data_len, + &err ); + if( FD_UNLIKELY( err ) ) { + FD_LOG_WARNING(( "vote state decode failed" )); + fd_bank_stakes_end_locking_query( bank ); + return 0; + } + + long timestamp = 0; + ulong slot = 0; + switch( vsv->discriminant ) { + case fd_vote_state_versioned_enum_v0_23_5: + timestamp = vsv->inner.v0_23_5.last_timestamp.timestamp; + slot = vsv->inner.v0_23_5.last_timestamp.slot; + break; + case fd_vote_state_versioned_enum_v1_14_11: + timestamp = vsv->inner.v1_14_11.last_timestamp.timestamp; + slot = vsv->inner.v1_14_11.last_timestamp.slot; + break; + case fd_vote_state_versioned_enum_current: + timestamp = vsv->inner.current.last_timestamp.timestamp; + slot = vsv->inner.current.last_timestamp.slot; + break; + default: + __builtin_unreachable(); + } + + /* Record timestamp */ + if( slot != 0 || n->elem.stake != 0 ) { + fd_vote_record_timestamp_vote_with_slot( &n->elem.key, timestamp, slot, bank ); + } + } FD_SPAD_FRAME_END; + } + + fd_bank_stakes_end_locking_query( bank ); + return 1; +} + +fd_bank_t * +fd_runtime_recover_bank( fd_banks_t * banks, + fd_solana_manifest_global_t const * manifest, + fd_spad_t * runtime_spad ) { + + fd_bank_t * bank = fd_banks_clone_from_parent( banks, manifest->bank.slot, 0UL ); + if( FD_UNLIKELY( !bank ) ) { + FD_LOG_CRIT(( "fd_banks_clone_from_parent failed" )); + } + + fd_versioned_bank_global_t const * old_bank = &manifest->bank; + + ulong stakes_sz = fd_stakes_size_global( &manifest->bank.stakes ); + fd_stakes_global_t * stakes = fd_bank_stakes_locking_modify( bank ); + fd_memcpy( stakes, &manifest->bank.stakes, stakes_sz ); + /* Verify stakes */ + + fd_bank_stakes_end_locking_modify( bank ); + + /* Index vote accounts */ + + /* Block Hash Queue */ + + fd_block_hash_queue_global_t * bhq = fd_bank_block_hash_queue_modify( bank ); + uchar * last_hash_mem = (uchar *)fd_ulong_align_up( (ulong)bhq + sizeof(fd_block_hash_queue_global_t), alignof(fd_hash_t) ); + uchar * ages_pool_mem = (uchar *)fd_ulong_align_up( (ulong)last_hash_mem + sizeof(fd_hash_t), fd_hash_hash_age_pair_t_map_align() ); + + fd_hash_hash_age_pair_t_mapnode_t * ages_pool = fd_hash_hash_age_pair_t_map_join( fd_hash_hash_age_pair_t_map_new( ages_pool_mem, 301 ) ); + fd_hash_hash_age_pair_t_mapnode_t * ages_root = NULL; + + bhq->last_hash_index = old_bank->blockhash_queue.last_hash_index; + + fd_hash_t const * last_hash = fd_block_hash_vec_last_hash_join( &old_bank->blockhash_queue ); + + if( last_hash ) { + fd_memcpy( last_hash_mem, last_hash, sizeof(fd_hash_t) ); + } else { + fd_memset( last_hash_mem, 0, sizeof(fd_hash_t) ); + } + bhq->last_hash_offset = (ulong)last_hash_mem - (ulong)bhq; + + fd_hash_hash_age_pair_t const * ages = fd_block_hash_vec_ages_join( &old_bank->blockhash_queue ); + + for( ulong i=0UL; iblockhash_queue.ages_len; i++ ) { + fd_hash_hash_age_pair_t const * elem = &ages[i]; + fd_hash_hash_age_pair_t_mapnode_t * node = fd_hash_hash_age_pair_t_map_acquire( ages_pool ); + node->elem = *elem; + fd_hash_hash_age_pair_t_map_insert( ages_pool, &ages_root, node ); + } + + fd_block_hash_queue_ages_pool_update( bhq, ages_pool ); + fd_block_hash_queue_ages_root_update( bhq, ages_root ); + + bhq->max_age = old_bank->blockhash_queue.max_age; + + /* Bank Hash */ + + fd_bank_bank_hash_set( bank, old_bank->hash ); + + /* Fee Rate Governor */ + + fd_fee_rate_governor_t * fee_rate_governor = fd_bank_fee_rate_governor_modify( bank ); + *fee_rate_governor = old_bank->fee_rate_governor; + + /* Capitalization */ + + fd_bank_capitalization_set( bank, old_bank->capitalization ); + + /* Lamports Per Signature */ + + fd_bank_lamports_per_signature_set( bank, manifest->lamports_per_signature ); + + /* Previous Lamports Per Signature */ + + fd_bank_prev_lamports_per_signature_set( bank, manifest->lamports_per_signature ); + + /* Transaction Count */ + + fd_bank_transaction_count_set( bank, old_bank->transaction_count ); + + /* Parent Signature Count */ + + fd_bank_parent_signature_cnt_set( bank, old_bank->signature_count ); + + /* Tick Height */ + + fd_bank_tick_height_set( bank, old_bank->tick_height ); + + /* Max Tick Height */ + + fd_bank_max_tick_height_set( bank, old_bank->max_tick_height ); + + /* Hashes Per Tick */ + + ulong * hashes_per_tick = fd_versioned_bank_hashes_per_tick_join( old_bank ); + fd_bank_hashes_per_tick_set( bank, !!hashes_per_tick ? *hashes_per_tick : 0UL ); + + /* NS Per Slot */ + + fd_bank_ns_per_slot_set( bank, old_bank->ns_per_slot ); + + /* Ticks Per Slot */ + + fd_bank_ticks_per_slot_set( bank, old_bank->ticks_per_slot ); + + /* Genesis Creation Time */ + + fd_bank_genesis_creation_time_set( bank, old_bank->genesis_creation_time ); + + /* Slots Per Year */ + + fd_bank_slots_per_year_set( bank, old_bank->slots_per_year ); + + /* Inflation */ + + fd_bank_inflation_set( bank, old_bank->inflation ); + + /* Block Height */ + + fd_bank_block_height_set( bank, old_bank->block_height ); + + /* Epoch Account Hash */ + + fd_hash_t * epoch_account_hash = fd_solana_manifest_epoch_account_hash_join( manifest ); + if( !!epoch_account_hash ) { + fd_bank_epoch_account_hash_set( bank, *epoch_account_hash ); + } else { + fd_bank_epoch_account_hash_set( bank, (fd_hash_t){0} ); + } + + /* Prev Slot */ + + fd_bank_prev_slot_set( bank, old_bank->parent_slot ); + + /* Execution Fees */ + + fd_bank_execution_fees_set( bank, old_bank->collector_fees ); + + /* Priority Fees */ + + fd_bank_priority_fees_set( bank, 0UL ); + + /* PoH */ + + if( last_hash ) { + fd_bank_poh_set( bank, *last_hash ); + } + + /* Prev Bank Hash */ + + fd_bank_prev_bank_hash_set( bank, old_bank->parent_hash ); + + /* Epoch Schedule */ + + fd_bank_epoch_schedule_set( bank, old_bank->epoch_schedule ); + + /* Rent */ + + fd_bank_rent_set( bank, old_bank->rent_collector.rent ); + + /* Last Restart Slot */ + + /* Update last restart slot + https://github.com/solana-labs/solana/blob/30531d7a5b74f914dde53bfbb0bc2144f2ac92bb/runtime/src/bank.rs#L2152 + + old_bank->hard_forks is sorted ascending by slot number. + To find the last restart slot, take the highest hard fork slot + number that is less or equal than the current slot number. + (There might be some hard forks in the future, ignore these) */ + do { + fd_sol_sysvar_last_restart_slot_t * last_restart_slot = fd_bank_last_restart_slot_modify( bank ); + last_restart_slot->slot = 0UL; + + if( FD_UNLIKELY( old_bank->hard_forks.hard_forks_len == 0 ) ) { + /* SIMD-0047: The first restart slot should be `0` */ + break; + } + + fd_slot_pair_t const * head = fd_hard_forks_hard_forks_join( &old_bank->hard_forks ); + fd_slot_pair_t const * tail = head + old_bank->hard_forks.hard_forks_len - 1UL; + + for( fd_slot_pair_t const *pair = tail; pair >= head; pair-- ) { + if( pair->slot <= bank->slot ) { + fd_sol_sysvar_last_restart_slot_t * last_restart_slot = fd_bank_last_restart_slot_modify( bank ); + last_restart_slot->slot = pair->slot; + break; + } + } + } while (0); + + /* FIXME: Remove the magic number here. */ + fd_clock_timestamp_votes_global_t * clock_timestamp_votes = fd_bank_clock_timestamp_votes_locking_modify( bank ); + uchar * clock_pool_mem = (uchar *)fd_ulong_align_up( (ulong)clock_timestamp_votes + sizeof(fd_clock_timestamp_votes_global_t), fd_clock_timestamp_vote_t_map_align() ); + fd_clock_timestamp_vote_t_mapnode_t * clock_pool = fd_clock_timestamp_vote_t_map_join( fd_clock_timestamp_vote_t_map_new(clock_pool_mem, 30000UL ) ); + clock_timestamp_votes->votes_pool_offset = (ulong)fd_clock_timestamp_vote_t_map_leave( clock_pool) - (ulong)clock_timestamp_votes; + clock_timestamp_votes->votes_root_offset = 0UL; + fd_bank_clock_timestamp_votes_end_locking_modify( bank ); + + recover_clock( bank, runtime_spad ); + + + /* Move EpochStakes */ + do { + + fd_epoch_schedule_t const * epoch_schedule = fd_bank_epoch_schedule_query( bank ); + ulong epoch = fd_slot_to_epoch( epoch_schedule, bank->slot, NULL ); + + /* We need to save the vote accounts for the current epoch and the next + epoch as it is used to calculate the leader schedule at the epoch + boundary. */ + + fd_vote_accounts_global_t * vote_accounts_curr_stakes = NULL; + fd_vote_accounts_global_t * vote_accounts_next_stakes = NULL; + + fd_epoch_epoch_stakes_pair_global_t * versioned_bank_epoch_stakes = fd_versioned_bank_epoch_stakes_join( &manifest->bank ); + for( ulong i=0UL; ibank.epoch_stakes_len; i++ ) { + if( versioned_bank_epoch_stakes[i].key == epoch ) { + vote_accounts_curr_stakes = &versioned_bank_epoch_stakes[i].value.stakes.vote_accounts; + } + if( versioned_bank_epoch_stakes[i].key == epoch+1UL ) { + vote_accounts_next_stakes = &versioned_bank_epoch_stakes[i].value.stakes.vote_accounts; + } + + /* When loading from a snapshot, Agave's stake caches mean that we have to special-case the epoch stakes + that are used for the second epoch E+2 after the snapshot epoch E. + + If the snapshot contains the epoch stakes for E+2, we should use those. + + If the snapshot does not, we should use the stakes at the end of the E-1 epoch, instead of E-2 as we do for + all other epochs. */ + } + + fd_versioned_epoch_stakes_pair_global_t * versioned_epoch_stakes = fd_solana_manifest_versioned_epoch_stakes_join( manifest ); + for( ulong i=0UL; iversioned_epoch_stakes_len; i++ ) { + + if( versioned_epoch_stakes[i].epoch == epoch ) { + vote_accounts_curr_stakes = &versioned_epoch_stakes[i].val.inner.Current.stakes.vote_accounts; + } + if( versioned_epoch_stakes[i].epoch == epoch+1UL ) { + vote_accounts_next_stakes = &versioned_epoch_stakes[i].val.inner.Current.stakes.vote_accounts; + + /* Save the initial value to be used for the get_epoch_stake + syscall. + + A note on Agave's indexing scheme for their epoch_stakes + structure: + + https://github.com/anza-xyz/agave/blob/v2.2.14/runtime/src/bank.rs#L6175 + + If we are loading a snapshot and replaying in the middle of + epoch 7, the syscall is supposed to return the total stake at + the end of epoch 6. The epoch_stakes structure is indexed in + Agave by the epoch number of the leader schedule that the + stakes are meant to determine. For instance, to get the + stakes at the end of epoch 6, we should query by 8, because + the leader schedule for epoch 8 is determined based on the + stakes at the end of epoch 6. Therefore, we save the total + epoch stake by querying for epoch+1. */ + fd_bank_total_epoch_stake_set( bank, versioned_epoch_stakes[i].val.inner.Current.total_stake ); + } + } + + fd_bank_use_prev_epoch_stake_set( bank, epoch + 2UL ); + + fd_vote_accounts_pair_global_t_mapnode_t * vote_accounts_curr_stakes_pool = fd_vote_accounts_vote_accounts_pool_join( vote_accounts_curr_stakes ); + fd_vote_accounts_pair_global_t_mapnode_t * vote_accounts_curr_stakes_root = fd_vote_accounts_vote_accounts_root_join( vote_accounts_curr_stakes ); + + fd_vote_accounts_pair_global_t_mapnode_t * vote_accounts_next_stakes_pool = fd_vote_accounts_vote_accounts_pool_join( vote_accounts_next_stakes ); + fd_vote_accounts_pair_global_t_mapnode_t * vote_accounts_next_stakes_root = fd_vote_accounts_vote_accounts_root_join( vote_accounts_next_stakes ); + + if( FD_UNLIKELY( (!vote_accounts_curr_stakes_pool) | (!vote_accounts_next_stakes_pool) ) ) { + FD_LOG_WARNING(( "snapshot missing EpochStakes for epochs %lu and/or %lu", epoch, epoch+1UL )); + return 0; + } + + /* Move current EpochStakes */ + + fd_vote_accounts_global_t * epoch_stakes = fd_bank_epoch_stakes_locking_modify( bank ); + uchar * epoch_stakes_pool_mem = (uchar *)fd_ulong_align_up( (ulong)epoch_stakes + sizeof(fd_vote_accounts_global_t), fd_vote_accounts_pair_global_t_map_align() ); + fd_vote_accounts_pair_global_t_mapnode_t * epoch_stakes_pool = fd_vote_accounts_pair_global_t_map_join( fd_vote_accounts_pair_global_t_map_new( epoch_stakes_pool_mem, 50000UL ) ); + fd_vote_accounts_pair_global_t_mapnode_t * epoch_stakes_root = NULL; + + uchar * acc_region_curr = (uchar *)fd_ulong_align_up( (ulong)epoch_stakes_pool + fd_vote_accounts_pair_global_t_map_footprint( 50000UL ), 8UL ); + + for( fd_vote_accounts_pair_global_t_mapnode_t * n = fd_vote_accounts_pair_global_t_map_minimum( + vote_accounts_curr_stakes_pool, + vote_accounts_curr_stakes_root ); + n; + n = fd_vote_accounts_pair_global_t_map_successor( vote_accounts_curr_stakes_pool, n ) ) { + + fd_vote_accounts_pair_global_t_mapnode_t * elem = fd_vote_accounts_pair_global_t_map_acquire( + epoch_stakes_pool ); + FD_TEST( elem ); + + elem->elem.stake = n->elem.stake; + elem->elem.key = n->elem.key; + + elem->elem.value.lamports = n->elem.value.lamports; + elem->elem.value.data_len = 0UL; + elem->elem.value.data_offset = 0UL; + elem->elem.value.owner = n->elem.value.owner; + elem->elem.value.executable = n->elem.value.executable; + elem->elem.value.rent_epoch = n->elem.value.rent_epoch; + + elem->elem.value.data_offset = (ulong)(acc_region_curr - (uchar *)&elem->elem.value); + elem->elem.value.data_len = n->elem.value.data_len; + + uchar * manifest_data = fd_solana_account_data_join( &n->elem.value ); + memcpy( acc_region_curr, manifest_data, n->elem.value.data_len ); + acc_region_curr += n->elem.value.data_len; + + fd_vote_accounts_pair_global_t_map_insert( + epoch_stakes_pool, + &epoch_stakes_root, + elem ); + } + + fd_vote_accounts_vote_accounts_pool_update( epoch_stakes, epoch_stakes_pool ); + fd_vote_accounts_vote_accounts_root_update( epoch_stakes, epoch_stakes_root ); + fd_bank_epoch_stakes_end_locking_modify( bank ); + + /* Move next EpochStakes */ + + fd_vote_accounts_global_t * next_epoch_stakes = fd_bank_next_epoch_stakes_locking_modify( bank ); + uchar * next_epoch_stakes_pool_mem = (uchar *)fd_ulong_align_up( (ulong)next_epoch_stakes + sizeof(fd_vote_accounts_global_t), fd_vote_accounts_pair_global_t_map_align() ); + fd_vote_accounts_pair_global_t_mapnode_t * next_epoch_stakes_pool = fd_vote_accounts_pair_global_t_map_join( fd_vote_accounts_pair_global_t_map_new( next_epoch_stakes_pool_mem, 50000UL ) ); + fd_vote_accounts_pair_global_t_mapnode_t * next_epoch_stakes_root = NULL; + + fd_vote_accounts_pair_global_t_mapnode_t * pool = vote_accounts_next_stakes_pool; + fd_vote_accounts_pair_global_t_mapnode_t * root = vote_accounts_next_stakes_root; + + acc_region_curr = (uchar *)fd_ulong_align_up( (ulong)next_epoch_stakes_pool + fd_vote_accounts_pair_global_t_map_footprint( 50000UL ), 8UL ); + + for( fd_vote_accounts_pair_global_t_mapnode_t * n = fd_vote_accounts_pair_global_t_map_minimum( pool, root ); + n; + n = fd_vote_accounts_pair_global_t_map_successor( pool, n ) ) { + + fd_vote_accounts_pair_global_t_mapnode_t * elem = fd_vote_accounts_pair_global_t_map_acquire( next_epoch_stakes_pool ); + FD_TEST( elem ); + + elem->elem.stake = n->elem.stake; + elem->elem.key = n->elem.key; + + elem->elem.value.lamports = n->elem.value.lamports; + elem->elem.value.data_len = 0UL; + elem->elem.value.data_offset = 0UL; + elem->elem.value.owner = n->elem.value.owner; + elem->elem.value.executable = n->elem.value.executable; + elem->elem.value.rent_epoch = n->elem.value.rent_epoch; + + elem->elem.value.data_offset = (ulong)(acc_region_curr - (uchar *)&elem->elem.value);; + elem->elem.value.data_len = n->elem.value.data_len; + + uchar * manifest_data = fd_solana_account_data_join( &n->elem.value ); + memcpy( acc_region_curr, manifest_data, n->elem.value.data_len ); + acc_region_curr += n->elem.value.data_len; + + fd_vote_accounts_pair_global_t_map_insert( + next_epoch_stakes_pool, + &next_epoch_stakes_root, + elem ); + + } + fd_vote_accounts_vote_accounts_pool_update( next_epoch_stakes, next_epoch_stakes_pool ); + fd_vote_accounts_vote_accounts_root_update( next_epoch_stakes, next_epoch_stakes_root ); + fd_bank_next_epoch_stakes_end_locking_modify( bank ); + + } while(0); + + fd_slot_lthash_t * lthash = fd_bank_lthash_modify( bank ); + + fd_slot_lthash_t * lthash_value = fd_solana_manifest_lthash_join( manifest ); + if( !!lthash_value ) { + *lthash = *lthash_value; + } else { + fd_lthash_zero( (fd_lthash_value_t *)lthash->lthash ); + } + /* Setup next epoch stakes */ + + return bank; +} + +fd_txncache_t * +fd_runtime_recover_status_cache( fd_txncache_t * status_cache, + fd_bank_slot_deltas_t * slot_deltas, + fd_spad_t * runtime_spad ) { + + if( !status_cache ) { + FD_LOG_WARNING(("No status cache in slot ctx")); + return NULL; + } + + FD_SPAD_FRAME_BEGIN( runtime_spad ) { + + ulong num_entries = 0; + for( ulong i = 0; i < slot_deltas->slot_deltas_len; i++ ) { + fd_slot_delta_t * slot_delta = &slot_deltas->slot_deltas[i]; + for( ulong j = 0; j < slot_delta->slot_delta_vec_len; j++ ) { + num_entries += slot_delta->slot_delta_vec[j].value.statuses_len; + } + } + fd_txncache_insert_t * insert_vals = fd_spad_alloc_check( runtime_spad, alignof(fd_txncache_insert_t), num_entries * sizeof(fd_txncache_insert_t) ); + + /* Dumb sort for 300 slot entries to insert in order. */ + fd_slot_delta_t ** deltas = fd_spad_alloc_check( runtime_spad, alignof(fd_slot_delta_t*), slot_deltas->slot_deltas_len * sizeof(fd_slot_delta_t*) ); + + long curr = -1; + for( ulong i = 0UL; i < slot_deltas->slot_deltas_len; i++ ) { + ulong curr_min = ULONG_MAX; + ulong curr_min_idx = ULONG_MAX; + for( ulong j = 0; j < slot_deltas->slot_deltas_len; j++ ) { + fd_slot_delta_t * slot_delta = &slot_deltas->slot_deltas[j]; + if( (long)slot_delta->slot <= curr ) continue; + + if( curr_min > slot_delta->slot ) { + curr_min = slot_delta->slot; + curr_min_idx = j; + } + } + deltas[i] = &slot_deltas->slot_deltas[curr_min_idx]; + curr = (long)slot_deltas->slot_deltas[curr_min_idx].slot; + } + + ulong idx = 0; + for( ulong i = 0; i < slot_deltas->slot_deltas_len; i++ ) { + fd_slot_delta_t * slot_delta = deltas[i]; + ulong slot = slot_delta->slot; + if( slot_delta->is_root ) { + fd_txncache_register_root_slot( status_cache, slot ); + } + for( ulong j = 0; j < slot_delta->slot_delta_vec_len; j++ ) { + fd_status_pair_t * pair = &slot_delta->slot_delta_vec[j]; + fd_hash_t * blockhash = &pair->hash; + uchar * results = fd_spad_alloc( runtime_spad, FD_SPAD_ALIGN, pair->value.statuses_len ); + for( ulong k = 0; k < pair->value.statuses_len; k++ ) { + fd_cache_status_t * status = &pair->value.statuses[k]; + uchar * result = results + k; + *result = (uchar)status->result.discriminant; + insert_vals[idx++] = (fd_txncache_insert_t){ + .blockhash = blockhash->uc, + .slot = slot, + .txnhash = status->key_slice, + .result = result + }; + } + } + } + fd_txncache_insert_batch( status_cache, insert_vals, num_entries ); + + for( ulong i = 0; i < slot_deltas->slot_deltas_len; i++ ) { + fd_slot_delta_t * slot_delta = deltas[i]; + ulong slot = slot_delta->slot; + for( ulong j = 0; j < slot_delta->slot_delta_vec_len; j++ ) { + fd_status_pair_t * pair = &slot_delta->slot_delta_vec[j]; + fd_hash_t * blockhash = &pair->hash; + fd_txncache_set_txnhash_offset( status_cache, slot, blockhash->uc, pair->value.txn_idx ); + } + } + + } FD_SPAD_FRAME_END; + return status_cache; +} + /* https://github.com/anza-xyz/agave/blob/v2.1.1/runtime/src/bank.rs#L1254-L1258 https://github.com/anza-xyz/agave/blob/v2.1.1/runtime/src/bank.rs#L1749 diff --git a/src/flamenco/runtime/fd_runtime.h b/src/flamenco/runtime/fd_runtime.h index 8cbae70e5b..5cabbffc75 100644 --- a/src/flamenco/runtime/fd_runtime.h +++ b/src/flamenco/runtime/fd_runtime.h @@ -302,6 +302,31 @@ FD_PROTOTYPES_BEGIN /* Runtime Helpers ************************************************************/ +/* fd_exec_slot_ctx_recover re-initializes the current epoch/slot + context and recovers it from the manifest of a Solana Labs snapshot. + + Copies content of manifest to ctx. The 'manifest' object may be + freed after this function returns. Assumes that slot context and + epoch context use same allocator. Returns ctx on success. + On failure, logs reason for error and returns NULL. */ + +fd_bank_t * +fd_runtime_recover_bank( fd_banks_t * banks, + fd_solana_manifest_global_t const * manifest_global, + fd_spad_t * spad ); + +/* fd_exec_slot_ctx_recover re-initializes the current slot + context's status cache from the provided solana slot deltas. + Assumes objects in slot deltas were allocated using slot ctx valloc + (U.B. otherwise). + On return, slot deltas is destroyed. Returns ctx on success. + On failure, logs reason for error and returns NULL. */ + +fd_txncache_t * +fd_runtime_recover_status_cache( fd_txncache_t * status_cache, + fd_bank_slot_deltas_t * slot_deltas, + fd_spad_t * runtime_spad ); + /* Returns 0 on success, and non zero otherwise. On failure, the out values will not be modified. diff --git a/src/flamenco/snapshot/fd_snapshot.c b/src/flamenco/snapshot/fd_snapshot.c index 97e69490ed..ae0868a2a0 100644 --- a/src/flamenco/snapshot/fd_snapshot.c +++ b/src/flamenco/snapshot/fd_snapshot.c @@ -60,9 +60,8 @@ restore_manifest( void * ctx, fd_spad_t * spad ) { fd_snapshot_load_ctx_t * load_ctx = (fd_snapshot_load_ctx_t *)ctx; - fd_bank_t * bank = NULL; - int err = (!!fd_exec_slot_ctx_recover( load_ctx->banks, &bank, manifest, spad ) ? 0 : EINVAL); - load_ctx->bank = bank; + load_ctx->bank = fd_runtime_recover_bank( load_ctx->banks, manifest, spad ); + int err = (!!load_ctx->bank ? 0 : EINVAL); return err; } @@ -70,7 +69,8 @@ static int restore_status_cache( void * ctx, fd_bank_slot_deltas_t * slot_deltas, fd_spad_t * spad ) { - return (!!fd_exec_slot_ctx_recover_status_cache( ctx, slot_deltas, spad ) ? 0 : EINVAL); + return 1; + return (!!fd_runtime_recover_status_cache( ctx, slot_deltas, spad ) ? 0 : EINVAL); } ulong From 9e3a504ca4750f9e32bcd07941e0778f948bb451 Mon Sep 17 00:00:00 2001 From: Ishan Bhatt Date: Wed, 9 Jul 2025 19:57:11 +0000 Subject: [PATCH 27/27] starting to remove improts --- src/choreo/forks/fd_forks.c | 7 -- src/choreo/forks/fd_forks.h | 3 - src/flamenco/fd_flamenco_base.h | 3 - .../runtime/context/fd_exec_slot_ctx.c | 82 +------------------ .../runtime/context/fd_exec_slot_ctx.h | 32 -------- 5 files changed, 3 insertions(+), 124 deletions(-) diff --git a/src/choreo/forks/fd_forks.c b/src/choreo/forks/fd_forks.c index 2224f090e5..7e26c3cfa2 100644 --- a/src/choreo/forks/fd_forks.c +++ b/src/choreo/forks/fd_forks.c @@ -1,12 +1,5 @@ #include "fd_forks.h" -#include "../../flamenco/runtime/context/fd_exec_slot_ctx.h" -#include "../../flamenco/runtime/fd_acc_mgr.h" -#include "../../flamenco/runtime/fd_borrowed_account.h" -#include "../../flamenco/runtime/fd_runtime.h" -#include "../../flamenco/runtime/program/fd_program_util.h" -#include "../../flamenco/runtime/program/fd_vote_program.h" - void * fd_forks_new( void * shmem, ulong max, ulong seed ) { diff --git a/src/choreo/forks/fd_forks.h b/src/choreo/forks/fd_forks.h index 2275eb47ae..ecd0a9a710 100644 --- a/src/choreo/forks/fd_forks.h +++ b/src/choreo/forks/fd_forks.h @@ -3,9 +3,6 @@ #include "../../flamenco/runtime/context/fd_exec_slot_ctx.h" #include "../../flamenco/runtime/fd_blockstore.h" -#include "../fd_choreo_base.h" -#include "../ghost/fd_ghost.h" -#include "../voter/fd_voter.h" /* FD_FORKS_USE_HANDHOLDING: Define this to non-zero at compile time to turn on additional runtime checks and logging. */ diff --git a/src/flamenco/fd_flamenco_base.h b/src/flamenco/fd_flamenco_base.h index 09512c652d..6548e6a709 100644 --- a/src/flamenco/fd_flamenco_base.h +++ b/src/flamenco/fd_flamenco_base.h @@ -75,9 +75,6 @@ fd_base58_enc_64_fmt( char * out, /* Forward declarations */ -struct fd_exec_slot_ctx; -typedef struct fd_exec_slot_ctx fd_exec_slot_ctx_t; - struct fd_exec_txn_ctx; typedef struct fd_exec_txn_ctx fd_exec_txn_ctx_t; diff --git a/src/flamenco/runtime/context/fd_exec_slot_ctx.c b/src/flamenco/runtime/context/fd_exec_slot_ctx.c index 7dca96b265..f7bd157162 100644 --- a/src/flamenco/runtime/context/fd_exec_slot_ctx.c +++ b/src/flamenco/runtime/context/fd_exec_slot_ctx.c @@ -6,83 +6,7 @@ #include #include -void * -fd_exec_slot_ctx_new( void * mem ) { - - if( FD_UNLIKELY( !mem ) ) { - FD_LOG_WARNING(( "NULL mem" )); - return NULL; - } - - if( FD_UNLIKELY( !fd_ulong_is_aligned( (ulong)mem, FD_EXEC_SLOT_CTX_ALIGN ) ) ) { - FD_LOG_WARNING(( "misaligned mem" )); - return NULL; - } - - fd_memset( mem, 0, sizeof(fd_exec_slot_ctx_t) ); - - fd_exec_slot_ctx_t * self = (fd_exec_slot_ctx_t *)mem; - - FD_COMPILER_MFENCE(); - self->magic = FD_EXEC_SLOT_CTX_MAGIC; - FD_COMPILER_MFENCE(); - - return mem; -} - -fd_exec_slot_ctx_t * -fd_exec_slot_ctx_join( void * mem ) { - if( FD_UNLIKELY( !mem ) ) { - FD_LOG_WARNING(( "NULL block" )); - return NULL; - } - - fd_exec_slot_ctx_t * ctx = (fd_exec_slot_ctx_t *) mem; - - if( FD_UNLIKELY( ctx->magic!=FD_EXEC_SLOT_CTX_MAGIC ) ) { - FD_LOG_WARNING(( "bad magic" )); - return NULL; - } - - return ctx; -} - -void * -fd_exec_slot_ctx_leave( fd_exec_slot_ctx_t * ctx ) { - if( FD_UNLIKELY( !ctx ) ) { - FD_LOG_WARNING(( "NULL block" )); - return NULL; - } - - if( FD_UNLIKELY( ctx->magic!=FD_EXEC_SLOT_CTX_MAGIC ) ) { - FD_LOG_WARNING(( "bad magic" )); - return NULL; - } - - return (void *) ctx; -} - -void * -fd_exec_slot_ctx_delete( void * mem ) { - if( FD_UNLIKELY( !mem ) ) { - FD_LOG_WARNING(( "NULL mem" )); - return NULL; - } - - if( FD_UNLIKELY( !fd_ulong_is_aligned( (ulong)mem, FD_EXEC_SLOT_CTX_ALIGN) ) ) { - FD_LOG_WARNING(( "misaligned mem" )); - return NULL; - } - - fd_exec_slot_ctx_t * hdr = (fd_exec_slot_ctx_t *)mem; - if( FD_UNLIKELY( hdr->magic!=FD_EXEC_SLOT_CTX_MAGIC ) ) { - FD_LOG_WARNING(( "bad magic" )); - return NULL; - } - - FD_COMPILER_MFENCE(); - FD_VOLATILE( hdr->magic ) = 0UL; - FD_COMPILER_MFENCE(); - - return mem; +int +stuff( void ) { + return 0; } diff --git a/src/flamenco/runtime/context/fd_exec_slot_ctx.h b/src/flamenco/runtime/context/fd_exec_slot_ctx.h index 9a161cf1a3..a6566cb66d 100644 --- a/src/flamenco/runtime/context/fd_exec_slot_ctx.h +++ b/src/flamenco/runtime/context/fd_exec_slot_ctx.h @@ -19,40 +19,8 @@ funk, funk_txn, status_cache should be passed in seperately.*/ -struct fd_exec_slot_ctx { - ulong magic; /* ==FD_EXEC_SLOT_CTX_MAGIC */ - - ulong slot; - - fd_banks_t * banks; - fd_bank_t * bank; - - /* External joins, pointers to be set by caller */ - - fd_funk_t * funk; - fd_funk_txn_t * funk_txn; - - fd_txncache_t * status_cache; -}; - -#define FD_EXEC_SLOT_CTX_ALIGN (alignof(fd_exec_slot_ctx_t)) -#define FD_EXEC_SLOT_CTX_FOOTPRINT (sizeof (fd_exec_slot_ctx_t)) -#define FD_EXEC_SLOT_CTX_MAGIC (0xC2287BA2A5E6FC3DUL) /* random */ FD_PROTOTYPES_BEGIN - -void * -fd_exec_slot_ctx_new( void * mem ); - -fd_exec_slot_ctx_t * -fd_exec_slot_ctx_join( void * mem ); - -void * -fd_exec_slot_ctx_leave( fd_exec_slot_ctx_t * ctx ); - -void * -fd_exec_slot_ctx_delete( void * mem ); - FD_PROTOTYPES_END #endif /* HEADER_fd_src_flamenco_runtime_context_fd_exec_slot_ctx_h */