diff --git a/src/flamenco/runtime/Local.mk b/src/flamenco/runtime/Local.mk index c4c317cd35..753b6c08e9 100644 --- a/src/flamenco/runtime/Local.mk +++ b/src/flamenco/runtime/Local.mk @@ -25,9 +25,6 @@ $(call add-objs,fd_pubkey_utils,fd_flamenco) $(call add-hdrs,fd_rent_lists.h) -$(call add-hdrs,fd_runtime_spad.h) -$(call add-objs,fd_runtime_spad,fd_flamenco) - ifdef FD_HAS_ATOMIC $(call add-hdrs,fd_runtime.h fd_runtime_init.h fd_runtime_err.h) $(call add-objs,fd_runtime fd_runtime_init,fd_flamenco) diff --git a/src/flamenco/runtime/context/fd_exec_instr_ctx.h b/src/flamenco/runtime/context/fd_exec_instr_ctx.h index 5ca074d626..b599c05d01 100644 --- a/src/flamenco/runtime/context/fd_exec_instr_ctx.h +++ b/src/flamenco/runtime/context/fd_exec_instr_ctx.h @@ -25,7 +25,10 @@ struct __attribute__((aligned(8UL))) fd_exec_instr_ctx { fd_funk_txn_t * funk_txn; fd_acc_mgr_t * acc_mgr; - fd_valloc_t valloc; /* Scratch-backed valloc TODO: migrate to transaction spad */ + /* This is for instruction-level test harnesses. + Offline and live instruction execution should use the spad in + txn_ctx. */ + fd_valloc_t valloc; /* Most instructions log the base58 program id multiple times, so it's convenient to compute it once and reuse it. */ diff --git a/src/flamenco/runtime/context/fd_exec_txn_ctx.c b/src/flamenco/runtime/context/fd_exec_txn_ctx.c index 7da9f56b83..dd71436cc6 100644 --- a/src/flamenco/runtime/context/fd_exec_txn_ctx.c +++ b/src/flamenco/runtime/context/fd_exec_txn_ctx.c @@ -266,7 +266,6 @@ fd_exec_txn_ctx_from_exec_slot_ctx( fd_exec_slot_ctx_t * slot_ctx, fd_exec_txn_ctx_t * txn_ctx ) { txn_ctx->slot_ctx = slot_ctx; txn_ctx->epoch_ctx = slot_ctx->epoch_ctx; - txn_ctx->valloc = slot_ctx->valloc; txn_ctx->funk_txn = NULL; txn_ctx->acc_mgr = slot_ctx->acc_mgr; } diff --git a/src/flamenco/runtime/context/fd_exec_txn_ctx.h b/src/flamenco/runtime/context/fd_exec_txn_ctx.h index 975bdff80f..dc6a2e3b44 100644 --- a/src/flamenco/runtime/context/fd_exec_txn_ctx.h +++ b/src/flamenco/runtime/context/fd_exec_txn_ctx.h @@ -64,7 +64,6 @@ struct __attribute__((aligned(8UL))) fd_exec_txn_ctx { fd_funk_txn_t * funk_txn; fd_acc_mgr_t * acc_mgr; - fd_valloc_t valloc; /* Workspace-backed valloc TODO: migrate to spad */ fd_spad_t * spad; /* Sized out to handle the worst case footprint of single transaction execution. */ ulong paid_fees; diff --git a/src/flamenco/runtime/fd_executor.c b/src/flamenco/runtime/fd_executor.c index 87932828e6..da140977b1 100644 --- a/src/flamenco/runtime/fd_executor.c +++ b/src/flamenco/runtime/fd_executor.c @@ -1454,45 +1454,6 @@ fd_execute_txn_prepare_phase3( fd_exec_slot_ctx_t * slot_ctx, return 0; } -/* Stuff to be done after multithreading ends */ -int -fd_execute_txn_finalize( fd_exec_txn_ctx_t * txn_ctx, - int exec_txn_err ) { - if( exec_txn_err != 0 ) { - for( ulong i = 0; i < txn_ctx->accounts_cnt; i++ ) { - fd_borrowed_account_t * acc_rec = &txn_ctx->borrowed_accounts[i]; - void * acc_rec_data = fd_borrowed_account_destroy( acc_rec ); - if( acc_rec_data != NULL ) { - fd_valloc_free( txn_ctx->valloc, acc_rec_data ); - } - } - - // fd_funk_txn_cancel( slot_ctx->acc_mgr->funk, txn_ctx->funk_txn, 0 ); - return 0; - } - - for( ulong i = 0; i < txn_ctx->accounts_cnt; i++ ) { - if( !fd_txn_account_is_writable_idx( txn_ctx, (int)i ) ) { - continue; - } - - fd_borrowed_account_t * acc_rec = &txn_ctx->borrowed_accounts[i]; - - int ret = fd_acc_mgr_save_non_tpool( txn_ctx->acc_mgr, txn_ctx->funk_txn, acc_rec ); - if( ret != FD_ACC_MGR_SUCCESS ) { - FD_LOG_ERR(( "failed to save edits to accounts" )); - return -1; - } - - void * borrow_account_data = fd_borrowed_account_destroy( acc_rec ); - if( borrow_account_data != NULL ) { - fd_valloc_free( txn_ctx->valloc, borrow_account_data ); - } - } - - return 0; -} - /* Creates a TxnContext Protobuf message from a provided txn_ctx. - The transaction is assumed to have just finished phase 1 of preparation - Caller of this function should have a scratch frame ready @@ -1828,10 +1789,8 @@ fd_dump_txn_to_protobuf( fd_exec_txn_ctx_t *txn_ctx, fd_spad_t * spad ) { fd_base58_encode_64( signature, &out_size, encoded_signature ); if( txn_ctx->capture_ctx->dump_proto_sig_filter ) { - ulong filter_strlen = (ulong) strlen(txn_ctx->capture_ctx->dump_proto_sig_filter); - // Terminate early if the signature does not match - if( memcmp( txn_ctx->capture_ctx->dump_proto_sig_filter, encoded_signature, filter_strlen < out_size ? filter_strlen : out_size ) ) { + if( strcmp( txn_ctx->capture_ctx->dump_proto_sig_filter, encoded_signature ) ) { return; } } diff --git a/src/flamenco/runtime/fd_executor.h b/src/flamenco/runtime/fd_executor.h index 0e594708a4..6db4c38bf7 100644 --- a/src/flamenco/runtime/fd_executor.h +++ b/src/flamenco/runtime/fd_executor.h @@ -91,10 +91,6 @@ fd_execute_txn_prepare_phase3( fd_exec_slot_ctx_t * slot_ctx, fd_exec_txn_ctx_t * txn_ctx, fd_txn_p_t * txn ); -int -fd_execute_txn_finalize( fd_exec_txn_ctx_t * txn_ctx, - int exec_txn_err ); - /* Execute the given transaction. diff --git a/src/flamenco/runtime/fd_runtime.c b/src/flamenco/runtime/fd_runtime.c index 7309622946..1e64f3baeb 100644 --- a/src/flamenco/runtime/fd_runtime.c +++ b/src/flamenco/runtime/fd_runtime.c @@ -1125,8 +1125,6 @@ fd_runtime_prepare_execute_finalize_txn( fd_exec_slot_ctx_t * slot_ctx, return -1; } - txn_ctx->valloc = fd_scratch_virtual(); - /* NOTE: This intentionally does not have sigverify */ fd_runtime_pre_execute_check( task_info ); @@ -1452,7 +1450,7 @@ fd_runtime_finalize_txn( fd_exec_slot_ctx_t * slot_ctx, fd_bincode_decode_ctx_t decode_vsv = { .data = acc_rec->const_data, .dataend = acc_rec->const_data + acc_rec->const_meta->dlen, - .valloc = fd_runtime_spad_virtual( txn_ctx->spad ) }; + .valloc = fd_spad_virtual( txn_ctx->spad ) }; int err = fd_vote_state_versioned_decode( vsv, &decode_vsv ); if( err ) break; /* out of scratch scope */ @@ -1472,7 +1470,7 @@ fd_runtime_finalize_txn( fd_exec_slot_ctx_t * slot_ctx, __builtin_unreachable(); } - fd_valloc_t valloc = fd_runtime_spad_virtual( txn_ctx->spad ); + fd_valloc_t valloc = fd_spad_virtual( txn_ctx->spad ); fd_vote_record_timestamp_vote_with_slot( slot_ctx, acc_rec->pubkey, ts->timestamp, ts->slot, valloc ); } FD_SPAD_FRAME_END; fd_funk_end_write( slot_ctx->acc_mgr->funk ); @@ -1844,7 +1842,7 @@ fd_runtime_finalize_txns_tpool( fd_exec_slot_ctx_t * slot_ctx, fd_bincode_decode_ctx_t decode_vsv = { .data = acc_rec->const_data, .dataend = acc_rec->const_data + acc_rec->const_meta->dlen, - .valloc = fd_runtime_spad_virtual( txn_ctx->spad ) }; + .valloc = fd_spad_virtual( txn_ctx->spad ) }; int err = fd_vote_state_versioned_decode( vsv, &decode_vsv ); if( err ) break; /* out of scratch scope */ @@ -1864,7 +1862,7 @@ fd_runtime_finalize_txns_tpool( fd_exec_slot_ctx_t * slot_ctx, __builtin_unreachable(); } - fd_valloc_t valloc = fd_runtime_spad_virtual( txn_ctx->spad ); + fd_valloc_t valloc = fd_spad_virtual( txn_ctx->spad ); fd_vote_record_timestamp_vote_with_slot( slot_ctx, acc_rec->pubkey, ts->timestamp, ts->slot, valloc ); } FD_SPAD_FRAME_END; } @@ -2136,7 +2134,6 @@ fd_runtime_execute_txns_in_waves_tpool( fd_exec_slot_ctx_t * slot_ctx, // Dump txns in waves if( dump_txn ) { for( ulong i = 0; i < wave_task_infos_cnt; ++i ) { - // TODO this dumper still relies on scratch, move to spad? /* Manual push/pop on the spad within the callee. */ fd_dump_txn_to_protobuf( wave_task_infos[i].txn_ctx, spads[0] ); } @@ -2977,10 +2974,12 @@ fd_runtime_txn_lamports_per_signature( fd_exec_txn_ctx_t * txn_ctx, // why is asan not detecting access to uninitialized memory here?! fd_nonce_state_versions_t state; int err; - if ((NULL != txn_descriptor) && fd_load_nonce_account(txn_ctx, &state, txn_ctx->valloc, &err)) { + FD_SPAD_FRAME_BEGIN( txn_ctx->spad ) { + if ((NULL != txn_descriptor) && fd_load_nonce_account(txn_ctx, &state, fd_spad_virtual( txn_ctx->spad ), &err)) { if (state.inner.current.discriminant == fd_nonce_state_enum_initialized) return state.inner.current.inner.initialized.fee_calculator.lamports_per_signature; } + } FD_SPAD_FRAME_END; // lamports_per_signature = (transaction has a DurableNonce, use the lamports_per_signature from that nonce instead of looking up the recent_block_hash and using the lamports_per_signature associated with that hash // let TransactionExecutionDetails { diff --git a/src/flamenco/runtime/fd_runtime.h b/src/flamenco/runtime/fd_runtime.h index 47e59ab49d..1156bc5a24 100644 --- a/src/flamenco/runtime/fd_runtime.h +++ b/src/flamenco/runtime/fd_runtime.h @@ -4,7 +4,6 @@ #include "../fd_flamenco_base.h" #include "fd_runtime_err.h" #include "fd_runtime_init.h" -#include "fd_runtime_spad.h" #include "fd_rocksdb.h" #include "fd_acc_mgr.h" #include "../features/fd_features.h" @@ -246,7 +245,7 @@ fd_runtime_spad_private_frame_end( fd_runtime_spad_verify_handle_private_t * _sp then we invoke verify to check things. */ /* -1UL because spad pop is called after instr stack pop. */ if( FD_UNLIKELY( _spad_handle->txn_ctx->instr_stack_sz>=FD_MAX_INSTRUCTION_STACK_DEPTH-1UL && fd_spad_verify( _spad_handle->txn_ctx->spad ) ) ) { - uchar * txn_signature = (uchar*)_spad_handle->txn_ctx->_txn_raw->raw + _spad_handle->txn_ctx->txn_descriptor->signature_off; + uchar const * txn_signature = (uchar const *)fd_txn_get_signatures( _spad_handle->txn_ctx->txn_descriptor, _spad_handle->txn_ctx->_txn_raw->raw ); FD_BASE58_ENCODE_64_BYTES( txn_signature, sig ); FD_LOG_ERR(( "spad corrupted or overflown on transaction %s", sig )); } diff --git a/src/flamenco/runtime/fd_runtime_spad.c b/src/flamenco/runtime/fd_runtime_spad.c deleted file mode 100644 index 1c8cdef419..0000000000 --- a/src/flamenco/runtime/fd_runtime_spad.c +++ /dev/null @@ -1,26 +0,0 @@ -#include "fd_runtime_spad.h" - -/* fd_valloc virtual function table for the runtime spad */ -void * -fd_runtime_spad_valloc_malloc( void * _self, - ulong align, - ulong sz ) { - fd_spad_t * spad = _self; - void * rv = fd_spad_alloc( spad, align, sz ); - if( FD_UNLIKELY( fd_spad_mem_used( spad )>fd_spad_mem_max( spad ) ) ) { - FD_LOG_ERR(( "spad overflow mem_used=%lu mem_max=%lu", fd_spad_mem_used( spad ), fd_spad_mem_max( spad ) )); - } - return rv; -} - -void -fd_runtime_spad_valloc_free( void * _self, - void * _addr ) { - (void)_self; (void)_addr; -} - -const fd_valloc_vtable_t -fd_runtime_spad_vtable = { - .malloc = fd_runtime_spad_valloc_malloc, - .free = fd_runtime_spad_valloc_free -}; diff --git a/src/flamenco/runtime/fd_runtime_spad.h b/src/flamenco/runtime/fd_runtime_spad.h deleted file mode 100644 index 6fea6854ed..0000000000 --- a/src/flamenco/runtime/fd_runtime_spad.h +++ /dev/null @@ -1,24 +0,0 @@ -#ifndef HEADER_fd_src_flamenco_runtime_fd_runtime_spad_h -#define HEADER_fd_src_flamenco_runtime_fd_runtime_spad_h - -#include "../../util/log/fd_log.h" -#include "../../util/spad/fd_spad.h" -#include "../../util/valloc/fd_valloc.h" - -FD_PROTOTYPES_BEGIN - -/* fd_valloc virtual function table for the runtime spad */ -extern const fd_valloc_vtable_t fd_runtime_spad_vtable; - -/* Returns an fd_valloc handle to the fd_spad join. - Valid for lifetime of the current spad frame. Handle invalid if spad - frame changes or spad detaches. */ -FD_FN_PURE static inline fd_valloc_t -fd_runtime_spad_virtual( fd_spad_t * spad ) { - fd_valloc_t valloc = { spad, &fd_runtime_spad_vtable }; - return valloc; -} - -FD_PROTOTYPES_END - -#endif /* HEADER_fd_src_flamenco_runtime_fd_runtime_spad_h */ diff --git a/src/flamenco/runtime/program/fd_bpf_loader_program.c b/src/flamenco/runtime/program/fd_bpf_loader_program.c index 6c4869a7f7..4963c137c1 100644 --- a/src/flamenco/runtime/program/fd_bpf_loader_program.c +++ b/src/flamenco/runtime/program/fd_bpf_loader_program.c @@ -148,7 +148,7 @@ fd_bpf_loader_v3_is_executable( fd_exec_slot_ctx_t * slot_ctx, fd_bincode_decode_ctx_t ctx = { .data = (uchar *)meta + meta->hlen, .dataend = (char *) ctx.data + meta->dlen, - .valloc = fd_runtime_spad_virtual( instr_ctx->txn_ctx->spad ), + .valloc = fd_spad_virtual( instr_ctx->txn_ctx->spad ), }; fd_bpf_upgradeable_loader_state_t loader_state = {0}; @@ -187,7 +187,7 @@ read_bpf_upgradeable_loader_state_for_program( fd_exec_txn_ctx_t * fd_bincode_decode_ctx_t ctx = { .data = rec->const_data, .dataend = rec->const_data + rec->const_meta->dlen, - .valloc = fd_runtime_spad_virtual( txn_ctx->spad ), + .valloc = fd_spad_virtual( txn_ctx->spad ), }; if( FD_UNLIKELY( fd_bpf_upgradeable_loader_state_decode( result, &ctx ) ) ) { @@ -370,7 +370,7 @@ fd_bpf_loader_v3_program_get_state( fd_exec_instr_ctx_t const * instr_ct fd_bincode_decode_ctx_t ctx = { .data = borrowed_acc->const_data, .dataend = borrowed_acc->const_data + borrowed_acc->const_meta->dlen, - .valloc = fd_runtime_spad_virtual( instr_ctx->txn_ctx->spad ), + .valloc = fd_spad_virtual( instr_ctx->txn_ctx->spad ), }; int err = fd_bpf_upgradeable_loader_state_decode( state, &ctx ); @@ -535,7 +535,7 @@ fd_bpf_execute( fd_exec_instr_ctx_t * instr_ctx, fd_sbpf_validated_program_t * p return FD_EXECUTOR_INSTR_ERR_PROGRAM_ENVIRONMENT_SETUP_FAILURE; } - fd_valloc_t valloc = fd_runtime_spad_virtual( instr_ctx->txn_ctx->spad ); + fd_valloc_t valloc = fd_spad_virtual( instr_ctx->txn_ctx->spad ); #ifdef FD_DEBUG_SBPF_TRACES uchar * signature = (uchar*)vm->instr_ctx->txn_ctx->_txn_raw->raw + vm->instr_ctx->txn_ctx->txn_descriptor->signature_off; @@ -658,7 +658,7 @@ fd_bpf_execute( fd_exec_instr_ctx_t * instr_ctx, fd_sbpf_validated_program_t * p static int process_loader_upgradeable_instruction( fd_exec_instr_ctx_t * instr_ctx ) { uchar const * data = instr_ctx->instr->data; - fd_valloc_t valloc = fd_runtime_spad_virtual( instr_ctx->txn_ctx->spad ); + fd_valloc_t valloc = fd_spad_virtual( instr_ctx->txn_ctx->spad ); fd_bpf_upgradeable_loader_program_instruction_t instruction = {0}; fd_bincode_decode_ctx_t decode_ctx = {0}; @@ -962,7 +962,7 @@ process_loader_upgradeable_instruction( fd_exec_instr_ctx_t * instr_ctx ) { const uchar * buffer_data = buffer->const_data + buffer_data_offset; - err = fd_deploy_program( instr_ctx, buffer_data, buffer_data_len, fd_runtime_spad_virtual( instr_ctx->txn_ctx->spad ) ); + err = fd_deploy_program( instr_ctx, buffer_data, buffer_data_len, fd_spad_virtual( instr_ctx->txn_ctx->spad ) ); if( FD_UNLIKELY( err ) ) { FD_LOG_WARNING(( "Failed to deploy program" )); // custom log return err; @@ -1218,7 +1218,7 @@ process_loader_upgradeable_instruction( fd_exec_instr_ctx_t * instr_ctx ) { } const uchar * buffer_data = buffer->const_data + buffer_data_offset; - err = fd_deploy_program( instr_ctx, buffer_data, buffer_data_len, fd_runtime_spad_virtual( instr_ctx->txn_ctx->spad ) ); + err = fd_deploy_program( instr_ctx, buffer_data, buffer_data_len, fd_spad_virtual( instr_ctx->txn_ctx->spad ) ); if( FD_UNLIKELY( err ) ) { FD_LOG_WARNING(( "Failed to deploy program" )); return err; @@ -1750,7 +1750,7 @@ process_loader_upgradeable_instruction( fd_exec_instr_ctx_t * instr_ctx ) { uchar * programdata_data = programdata_account->data + PROGRAMDATA_METADATA_SIZE; ulong programdata_size = new_len - PROGRAMDATA_METADATA_SIZE; - err = fd_deploy_program( instr_ctx, programdata_data, programdata_size, fd_runtime_spad_virtual( instr_ctx->txn_ctx->spad ) ); + err = fd_deploy_program( instr_ctx, programdata_data, programdata_size, fd_spad_virtual( instr_ctx->txn_ctx->spad ) ); if( FD_UNLIKELY( err ) ) { FD_LOG_WARNING(( "Failed to deploy program" )); return err; diff --git a/src/flamenco/runtime/program/fd_bpf_loader_serialization.c b/src/flamenco/runtime/program/fd_bpf_loader_serialization.c index d050d46365..33b31fc4e7 100644 --- a/src/flamenco/runtime/program/fd_bpf_loader_serialization.c +++ b/src/flamenco/runtime/program/fd_bpf_loader_serialization.c @@ -1,5 +1,6 @@ #include "fd_bpf_loader_serialization.h" #include "../fd_account.h" +#include "../fd_runtime.h" /* As a general note, copy_account_data implies that direct mapping is not being used/is inactive. This file is responsible for serializing and deserializing diff --git a/src/flamenco/runtime/program/fd_bpf_loader_serialization.h b/src/flamenco/runtime/program/fd_bpf_loader_serialization.h index a92c705295..9d16210178 100644 --- a/src/flamenco/runtime/program/fd_bpf_loader_serialization.h +++ b/src/flamenco/runtime/program/fd_bpf_loader_serialization.h @@ -3,7 +3,6 @@ #include "../../fd_flamenco_base.h" #include "../../vm/fd_vm.h" -#include "../fd_runtime.h" #define FD_NON_DUP_MARKER (0xFF ) diff --git a/src/flamenco/runtime/program/fd_compute_budget_program.c b/src/flamenco/runtime/program/fd_compute_budget_program.c index cbdaeb9f49..89879247e5 100644 --- a/src/flamenco/runtime/program/fd_compute_budget_program.c +++ b/src/flamenco/runtime/program/fd_compute_budget_program.c @@ -58,7 +58,7 @@ fd_executor_compute_budget_program_execute_instructions( fd_exec_txn_ctx_t * ctx fd_bincode_decode_ctx_t decode_ctx = { .data = data, .dataend = &data[ instr->data_sz ], - .valloc = fd_runtime_spad_virtual( ctx->spad ), + .valloc = fd_spad_virtual( ctx->spad ), }; int ret = fd_compute_budget_program_instruction_decode( &instruction, &decode_ctx ); diff --git a/src/flamenco/runtime/program/fd_loader_v4_program.c b/src/flamenco/runtime/program/fd_loader_v4_program.c index d9398adff2..c34b2dd3d6 100644 --- a/src/flamenco/runtime/program/fd_loader_v4_program.c +++ b/src/flamenco/runtime/program/fd_loader_v4_program.c @@ -418,7 +418,7 @@ fd_loader_v4_program_instruction_deploy( fd_exec_instr_ctx_t * instr_ctx ) { end of the slot. Since programs cannot be invoked until the next slot anyways, doing this is okay. https://github.com/anza-xyz/agave/blob/09ef71223b24e30e59eaeaf5eb95e85f222c7de1/programs/loader-v4/src/lib.rs#L262-L269 */ - err = fd_deploy_program( instr_ctx, programdata, buffer->const_meta->dlen - LOADER_V4_PROGRAM_DATA_OFFSET, fd_runtime_spad_virtual( instr_ctx->txn_ctx->spad ) ); + err = fd_deploy_program( instr_ctx, programdata, buffer->const_meta->dlen - LOADER_V4_PROGRAM_DATA_OFFSET, fd_spad_virtual( instr_ctx->txn_ctx->spad ) ); if( FD_UNLIKELY( err ) ) { return FD_EXECUTOR_INSTR_ERR_INVALID_ACC_DATA; } @@ -704,7 +704,7 @@ fd_loader_v4_program_execute( fd_exec_instr_ctx_t * instr_ctx ) { fd_bincode_decode_ctx_t decode_ctx = { .data = data, .dataend = &data[ instr_ctx->instr->data_sz > 1232UL ? 1232UL : instr_ctx->instr->data_sz ], - .valloc = fd_runtime_spad_virtual( instr_ctx->txn_ctx->spad ), + .valloc = fd_spad_virtual( instr_ctx->txn_ctx->spad ), }; if( FD_UNLIKELY( fd_loader_v4_program_instruction_decode( &instruction, &decode_ctx ) ) ) { diff --git a/src/flamenco/runtime/program/fd_stake_program.c b/src/flamenco/runtime/program/fd_stake_program.c index d1164ba80e..a336f4480e 100644 --- a/src/flamenco/runtime/program/fd_stake_program.c +++ b/src/flamenco/runtime/program/fd_stake_program.c @@ -1201,7 +1201,7 @@ initialize( fd_exec_instr_ctx_t const * ctx, // https://github.com/anza-xyz/agave/blob/c8685ce0e1bb9b26014f1024de2cd2b8c308cbde/programs/stake/src/stake_state.rs#L224 fd_stake_state_v2_t stake_state = {0}; do { - int rc = get_state( stake_account, fd_runtime_spad_virtual( ctx->txn_ctx->spad ), &stake_state ); + int rc = get_state( stake_account, fd_spad_virtual( ctx->txn_ctx->spad ), &stake_state ); if( FD_UNLIKELY( rc ) ) return rc; } while(0); @@ -1244,7 +1244,7 @@ authorize( fd_exec_instr_ctx_t const * ctx, int rc; fd_stake_state_v2_t stake_state = {0}; // https://github.com/anza-xyz/agave/blob/c8685ce0e1bb9b26014f1024de2cd2b8c308cbde/programs/stake/src/stake_state.rs#L251 - rc = get_state( stake_account, fd_runtime_spad_virtual( ctx->txn_ctx->spad ), &stake_state ); + rc = get_state( stake_account, fd_spad_virtual( ctx->txn_ctx->spad ), &stake_state ); if( FD_UNLIKELY( rc ) ) return rc; switch( stake_state.discriminant ) { /* FIXME check if the compiler can optimize away branching (given the layout of `meta` in both @@ -1343,7 +1343,7 @@ delegate( fd_exec_instr_ctx_t const * ctx, fd_pubkey_t const * signers[static FD_TXN_SIG_MAX] ) { int rc; - fd_valloc_t valloc = fd_runtime_spad_virtual( ctx->txn_ctx->spad ); + fd_valloc_t valloc = fd_spad_virtual( ctx->txn_ctx->spad ); fd_pubkey_t const * vote_pubkey; fd_vote_state_versioned_t vote_state = {0}; @@ -1365,7 +1365,7 @@ delegate( fd_exec_instr_ctx_t const * ctx, // https://github.com/anza-xyz/agave/blob/c8685ce0e1bb9b26014f1024de2cd2b8c308cbde/programs/stake/src/stake_state.rs#L330 FD_BORROWED_ACCOUNT_TRY_BORROW_IDX( ctx, stake_account_index, stake_account ) { - rc = get_state( stake_account, fd_runtime_spad_virtual( ctx->txn_ctx->spad ), &stake_state ); + rc = get_state( stake_account, fd_spad_virtual( ctx->txn_ctx->spad ), &stake_state ); if( FD_UNLIKELY( rc ) ) return rc; // https://github.com/anza-xyz/agave/blob/c8685ce0e1bb9b26014f1024de2cd2b8c308cbde/programs/stake/src/stake_state.rs#L332 @@ -1455,7 +1455,7 @@ deactivate( fd_exec_instr_ctx_t const * ctx, int rc; fd_stake_state_v2_t state = {0}; - rc = get_state( stake_account, fd_runtime_spad_virtual( ctx->txn_ctx->spad ), &state ); + rc = get_state( stake_account, fd_spad_virtual( ctx->txn_ctx->spad ), &state ); if( FD_UNLIKELY( rc ) ) return rc; // https://github.com/anza-xyz/agave/blob/c8685ce0e1bb9b26014f1024de2cd2b8c308cbde/programs/stake/src/stake_state.rs#L370 @@ -1489,7 +1489,7 @@ set_lockup( fd_exec_instr_ctx_t const * ctx, // https://github.com/anza-xyz/agave/blob/c8685ce0e1bb9b26014f1024de2cd2b8c308cbde/programs/stake/src/stake_state.rs#L385 fd_stake_state_v2_t state = {0}; - rc = get_state( stake_account, fd_runtime_spad_virtual( ctx->txn_ctx->spad ), &state ); + rc = get_state( stake_account, fd_spad_virtual( ctx->txn_ctx->spad ), &state ); if( FD_UNLIKELY( rc ) ) return rc; switch( state.discriminant ) { @@ -1536,7 +1536,7 @@ split( fd_exec_instr_ctx_t const * ctx, // https://github.com/anza-xyz/agave/blob/c8685ce0e1bb9b26014f1024de2cd2b8c308cbde/programs/stake/src/stake_state.rs#L415 fd_stake_state_v2_t split_get_state = {0}; - rc = get_state( split, fd_runtime_spad_virtual( ctx->txn_ctx->spad ), &split_get_state ); + rc = get_state( split, fd_spad_virtual( ctx->txn_ctx->spad ), &split_get_state ); if( FD_UNLIKELY( rc ) ) return rc; if( FD_UNLIKELY( split_get_state.discriminant!=fd_stake_state_v2_enum_uninitialized ) ) { return FD_EXECUTOR_INSTR_ERR_INVALID_ACC_DATA; @@ -1554,7 +1554,7 @@ split( fd_exec_instr_ctx_t const * ctx, if( FD_UNLIKELY( lamports>stake_account->const_meta->info.lamports ) ) return FD_EXECUTOR_INSTR_ERR_INSUFFICIENT_FUNDS; - rc = get_state( stake_account, fd_runtime_spad_virtual( ctx->txn_ctx->spad ), &stake_state ); + rc = get_state( stake_account, fd_spad_virtual( ctx->txn_ctx->spad ), &stake_state ); if( FD_UNLIKELY( rc ) ) return rc; } FD_BORROWED_ACCOUNT_DROP( stake_account ); @@ -1774,7 +1774,7 @@ merge( fd_exec_instr_ctx_t * ctx, // not const to log FD_BORROWED_ACCOUNT_TRY_BORROW_IDX( ctx, stake_account_index, stake_account ) { fd_stake_state_v2_t stake_account_state = {0}; - rc = get_state( stake_account, fd_runtime_spad_virtual( ctx->txn_ctx->spad ), &stake_account_state ); + rc = get_state( stake_account, fd_spad_virtual( ctx->txn_ctx->spad ), &stake_account_state ); if( FD_UNLIKELY( rc ) ) return rc; merge_kind_t stake_merge_kind = {0}; @@ -1796,7 +1796,7 @@ merge( fd_exec_instr_ctx_t * ctx, // not const to log return rc; fd_stake_state_v2_t source_account_state = {0}; - rc = get_state( source_account, fd_runtime_spad_virtual( ctx->txn_ctx->spad ), &source_account_state ); + rc = get_state( source_account, fd_spad_virtual( ctx->txn_ctx->spad ), &source_account_state ); if( FD_UNLIKELY( rc ) ) return rc; merge_kind_t source_merge_kind = {0}; @@ -1897,7 +1897,7 @@ move_stake_or_lamports_shared_checks( fd_exec_instr_ctx_t * invoke_context, // // https://github.com/anza-xyz/agave/blob/cdff19c7807b006dd63429114fb1d9573bf74172/programs/stake/src/stake_state.rs#L182 fd_stake_state_v2_t source_account_state = {0}; - rc = get_state( source_account, fd_runtime_spad_virtual( invoke_context->txn_ctx->spad ), &source_account_state ); + rc = get_state( source_account, fd_spad_virtual( invoke_context->txn_ctx->spad ), &source_account_state ); if( FD_UNLIKELY( rc ) ) return rc; rc = get_if_mergeable( invoke_context, @@ -1915,7 +1915,7 @@ move_stake_or_lamports_shared_checks( fd_exec_instr_ctx_t * invoke_context, // // https://github.com/anza-xyz/agave/blob/cdff19c7807b006dd63429114fb1d9573bf74172/programs/stake/src/stake_state.rs#L197 fd_stake_state_v2_t destination_account_state = {0}; - rc = get_state( destination_account, fd_runtime_spad_virtual( invoke_context->txn_ctx->spad ), &destination_account_state ); + rc = get_state( destination_account, fd_spad_virtual( invoke_context->txn_ctx->spad ), &destination_account_state ); if( FD_UNLIKELY( rc ) ) return rc; rc = get_if_mergeable( invoke_context, @@ -2182,7 +2182,7 @@ withdraw( fd_exec_instr_ctx_t const * ctx, // https://github.com/anza-xyz/agave/blob/c8685ce0e1bb9b26014f1024de2cd2b8c308cbde/programs/stake/src/stake_state.rs#L821 fd_stake_state_v2_t stake_state = {0}; - rc = get_state( stake_account, fd_runtime_spad_virtual( ctx->txn_ctx->spad ), &stake_state ); + rc = get_state( stake_account, fd_spad_virtual( ctx->txn_ctx->spad ), &stake_state ); if( FD_UNLIKELY( rc ) ) return rc; fd_stake_lockup_t lockup; @@ -2323,7 +2323,7 @@ deactivate_delinquent( fd_exec_instr_ctx_t * ctx, uint * custom_err ) { int rc; - fd_valloc_t valloc = fd_runtime_spad_virtual( ctx->txn_ctx->spad ); + fd_valloc_t valloc = fd_spad_virtual( ctx->txn_ctx->spad ); // https://github.com/anza-xyz/agave/blob/c8685ce0e1bb9b26014f1024de2cd2b8c308cbde/programs/stake/src/stake_state.rs#L911 fd_pubkey_t const * delinquent_vote_account_pubkey = @@ -2364,7 +2364,7 @@ deactivate_delinquent( fd_exec_instr_ctx_t * ctx, } fd_stake_state_v2_t stake_state = {0}; - rc = get_state( stake_account, fd_runtime_spad_virtual( ctx->txn_ctx->spad ), &stake_state ); + rc = get_state( stake_account, fd_spad_virtual( ctx->txn_ctx->spad ), &stake_state ); if( FD_UNLIKELY( rc ) ) return rc; // https://github.com/anza-xyz/agave/blob/c8685ce0e1bb9b26014f1024de2cd2b8c308cbde/programs/stake/src/stake_state.rs#L937 if( FD_LIKELY( stake_state.discriminant==fd_stake_state_v2_enum_stake ) ) { @@ -2465,7 +2465,7 @@ fd_stake_program_execute( fd_exec_instr_ctx_t * ctx ) { // https://github.com/anza-xyz/agave/blob/c8685ce0e1bb9b26014f1024de2cd2b8c308cbde/programs/stake/src/stake_instruction.rs#L79 fd_spad_t * spad = ctx->txn_ctx->spad; - fd_valloc_t valloc = fd_runtime_spad_virtual( spad ); + fd_valloc_t valloc = fd_spad_virtual( spad ); fd_bincode_decode_ctx_t decode = { .valloc = valloc, .data = ctx->instr->data, diff --git a/src/flamenco/runtime/program/fd_system_program.c b/src/flamenco/runtime/program/fd_system_program.c index 0054c81527..fd7c380747 100644 --- a/src/flamenco/runtime/program/fd_system_program.c +++ b/src/flamenco/runtime/program/fd_system_program.c @@ -616,7 +616,7 @@ fd_system_program_execute( fd_exec_instr_ctx_t * ctx ) { fd_bincode_decode_ctx_t decode = { .data = data, .dataend = data + ctx->instr->data_sz, - .valloc = fd_runtime_spad_virtual( ctx->txn_ctx->spad ) }; + .valloc = fd_spad_virtual( ctx->txn_ctx->spad ) }; /* Fail if the number of bytes consumed by deserialize exceeds 1232 */ if( fd_system_program_instruction_decode( &instruction, &decode ) || (ulong)data + 1232UL < (ulong)decode.data ) @@ -693,7 +693,7 @@ fd_system_program_execute( fd_exec_instr_ctx_t * ctx ) { } } - fd_bincode_destroy_ctx_t destroy = { .valloc = fd_runtime_spad_virtual( ctx->txn_ctx->spad ) }; + fd_bincode_destroy_ctx_t destroy = { .valloc = fd_spad_virtual( ctx->txn_ctx->spad ) }; fd_system_program_instruction_destroy( &instruction, &destroy ); return result; } diff --git a/src/flamenco/runtime/program/fd_vote_program.c b/src/flamenco/runtime/program/fd_vote_program.c index e81ae66bec..f5a496700a 100644 --- a/src/flamenco/runtime/program/fd_vote_program.c +++ b/src/flamenco/runtime/program/fd_vote_program.c @@ -814,7 +814,7 @@ set_vote_account_state( ulong vote_acct_idx, // https://github.com/anza-xyz/agave/blob/v2.0.1/programs/vote/src/vote_state/mod.rs#L184 fd_vote_state_versioned_t v1_14_11; fd_vote_state_versioned_new_disc( &v1_14_11, fd_vote_state_versioned_enum_v1_14_11 ); - from_vote_state_1_14_11( vote_state, &v1_14_11.inner.v1_14_11, fd_runtime_spad_virtual( ctx->txn_ctx->spad ) ); + from_vote_state_1_14_11( vote_state, &v1_14_11.inner.v1_14_11, fd_spad_virtual( ctx->txn_ctx->spad ) ); return set_state( vote_acct_idx, vote_account, &v1_14_11, ctx ); } @@ -828,7 +828,7 @@ set_vote_account_state( ulong vote_acct_idx, fd_vote_state_versioned_t v1_14_11; fd_vote_state_versioned_new_disc( &v1_14_11, fd_vote_state_versioned_enum_v1_14_11 ); - from_vote_state_1_14_11( vote_state, &v1_14_11.inner.v1_14_11, fd_runtime_spad_virtual( ctx->txn_ctx->spad ) ); + from_vote_state_1_14_11( vote_state, &v1_14_11.inner.v1_14_11, fd_spad_virtual( ctx->txn_ctx->spad ) ); return set_state( vote_acct_idx, vote_account, &v1_14_11, ctx ); } } @@ -1458,7 +1458,7 @@ authorize( ulong vote_acct_idx, fd_exec_instr_ctx_t const * ctx /* feature_set */ ) { int rc; - fd_valloc_t valloc = fd_runtime_spad_virtual( ctx->txn_ctx->spad ); + fd_valloc_t valloc = fd_spad_virtual( ctx->txn_ctx->spad ); // https://github.com/anza-xyz/agave/blob/v2.0.1/programs/vote/src/vote_state/mod.rs#L857 fd_vote_state_versioned_t vote_state_versioned; @@ -1514,7 +1514,7 @@ update_validator_identity( ulong vote_acct_idx, fd_exec_instr_ctx_t const * ctx /* feature_set */ ) { int rc; - fd_valloc_t valloc = fd_runtime_spad_virtual( ctx->txn_ctx->spad ); + fd_valloc_t valloc = fd_spad_virtual( ctx->txn_ctx->spad ); // https://github.com/anza-xyz/agave/blob/v2.0.1/programs/vote/src/vote_state/mod.rs#L900 fd_vote_state_versioned_t vote_state_versioned; @@ -1562,7 +1562,7 @@ update_commission( ulong vote_acct_idx, fd_exec_instr_ctx_t const * ctx /* feature_set */ ) { int rc; - fd_valloc_t valloc = fd_runtime_spad_virtual( ctx->txn_ctx->spad ); + fd_valloc_t valloc = fd_spad_virtual( ctx->txn_ctx->spad ); // https://github.com/anza-xyz/agave/blob/v2.0.1/programs/vote/src/vote_state/mod.rs#L925 fd_vote_state_versioned_t vote_state_versioned; fd_vote_state_t * vote_state = NULL; @@ -1622,7 +1622,7 @@ withdraw( ) { int rc; - fd_valloc_t valloc = fd_runtime_spad_virtual( ctx->txn_ctx->spad ); + fd_valloc_t valloc = fd_spad_virtual( ctx->txn_ctx->spad ); // https://github.com/anza-xyz/agave/blob/v2.0.1/programs/vote/src/vote_state/mod.rs#L1010 fd_vote_state_versioned_t vote_state_versioned; @@ -1773,7 +1773,7 @@ initialize_account( ulong vote_acct_idx, fd_exec_instr_ctx_t const * ctx /* feature_set */ ) { int rc; - fd_valloc_t valloc = fd_runtime_spad_virtual( ctx->txn_ctx->spad ); + fd_valloc_t valloc = fd_spad_virtual( ctx->txn_ctx->spad ); // https://github.com/anza-xyz/agave/blob/v2.0.1/programs/vote/src/vote_state/mod.rs#L1067 ulong data_len = vote_account->const_meta->dlen; @@ -1820,7 +1820,7 @@ verify_and_get_vote_state( fd_borrowed_account_t * vote_account, int rc; fd_vote_state_versioned_t versioned; - fd_valloc_t valloc = fd_runtime_spad_virtual( ctx->txn_ctx->spad ); + fd_valloc_t valloc = fd_spad_virtual( ctx->txn_ctx->spad ); // https://github.com/anza-xyz/agave/blob/v2.0.1/programs/vote/src/vote_state/mod.rs#L1091 rc = get_state( vote_account, valloc, &versioned ); @@ -1908,7 +1908,7 @@ do_process_vote_state_update( fd_vote_state_t * vote_state, fd_exec_instr_ctx_t const * ctx /* feature_set */ ) { int rc; - fd_valloc_t valloc = fd_runtime_spad_virtual( ctx->txn_ctx->spad ); + fd_valloc_t valloc = fd_spad_virtual( ctx->txn_ctx->spad ); // https://github.com/anza-xyz/agave/blob/v2.0.1/programs/vote/src/vote_state/mod.rs#L1164 rc = check_and_filter_proposed_vote_state( @@ -2029,7 +2029,7 @@ do_process_tower_sync( fd_vote_state_t * vote_state, // https://github.com/anza-xyz/agave/blob/v2.0.1/programs/vote/src/vote_state/mod.rs#L1221 err = process_new_vote_state( vote_state, - landed_votes_from_lockouts( tower_sync->lockouts, fd_runtime_spad_virtual( ctx->txn_ctx->spad ) ), + landed_votes_from_lockouts( tower_sync->lockouts, fd_spad_virtual( ctx->txn_ctx->spad ) ), tower_sync->has_root, tower_sync->root, tower_sync->has_timestamp, @@ -2110,7 +2110,7 @@ fd_vote_decode_compact_update( fd_compact_vote_state_update_t * compact_update, vote_update->root = ULONG_MAX; } - fd_valloc_t valloc = fd_runtime_spad_virtual( ctx->txn_ctx->spad ); + fd_valloc_t valloc = fd_spad_virtual( ctx->txn_ctx->spad ); ulong lockouts_len = compact_update->lockouts_len; ulong lockouts_max = fd_ulong_max( lockouts_len, MAX_LOCKOUT_HISTORY ); @@ -2187,7 +2187,7 @@ fd_vote_acc_credits( fd_exec_instr_ctx_t const * ctx, ulong * result ) { int rc; - fd_valloc_t valloc = fd_runtime_spad_virtual( ctx->txn_ctx->spad ); + fd_valloc_t valloc = fd_spad_virtual( ctx->txn_ctx->spad ); fd_sol_sysvar_clock_t const * clock = fd_sysvar_cache_clock( ctx->slot_ctx->sysvar_cache ); if( FD_UNLIKELY( !clock ) ) return FD_EXECUTOR_INSTR_ERR_UNSUPPORTED_SYSVAR; @@ -2404,7 +2404,7 @@ fd_vote_program_execute( fd_exec_instr_ctx_t * ctx ) { fd_bincode_decode_ctx_t decode = { .data = ctx->instr->data, .dataend = ctx->instr->data + ctx->instr->data_sz, - .valloc = fd_runtime_spad_virtual( ctx->txn_ctx->spad ) + .valloc = fd_spad_virtual( ctx->txn_ctx->spad ) }; int decode_result = fd_vote_instruction_decode( &instruction, &decode ); if( decode_result != FD_BINCODE_SUCCESS || @@ -2884,10 +2884,10 @@ upsert_vote_account( fd_exec_slot_ctx_t * slot_ctx, fd_bincode_decode_ctx_t decode = { .data = vote_account->const_data, .dataend = vote_account->const_data + vote_account->const_meta->dlen, - .valloc = fd_runtime_spad_virtual( spad ), + .valloc = fd_spad_virtual( spad ), }; fd_bincode_destroy_ctx_t destroy = { - .valloc = fd_runtime_spad_virtual( spad ), + .valloc = fd_spad_virtual( spad ), }; fd_vote_state_versioned_t vote_state[1] = {0}; if( FD_UNLIKELY( 0!=fd_vote_state_versioned_decode( vote_state, &decode ) ) ) { diff --git a/src/flamenco/runtime/tests/fd_exec_sol_compat.c b/src/flamenco/runtime/tests/fd_exec_sol_compat.c index 9f11dae656..db3fa51cf5 100644 --- a/src/flamenco/runtime/tests/fd_exec_sol_compat.c +++ b/src/flamenco/runtime/tests/fd_exec_sol_compat.c @@ -65,11 +65,6 @@ sol_compat_wksp_init( void ) { wksp = fd_wksp_new_anonymous( FD_SHMEM_NORMAL_PAGE_SZ, 65536UL * 8UL, fd_shmem_cpu_idx( fd_shmem_numa_idx( cpu_idx ) ), "wksp", 0UL ); assert( wksp ); - // FD_LOG_WARNING(( "footprint min %lu max %lu default %lu fuzz %lu", - // FD_RUNTIME_TRANSACTION_EXECUTION_FOOTPRINT(64UL,1), - // FD_RUNTIME_TRANSACTION_EXECUTION_FOOTPRINT(MAX_TX_ACCOUNT_LOCKS,0), - // FD_RUNTIME_TRANSACTION_EXECUTION_FOOTPRINT_DEFAULT, - // FD_RUNTIME_TRANSACTION_EXECUTION_FOOTPRINT_FUZZ )); spad_mem = fd_wksp_alloc_laddr( wksp, FD_SPAD_ALIGN, FD_RUNTIME_TRANSACTION_EXECUTION_FOOTPRINT_FUZZ, 3 ); /* 1342191744 B */ assert( spad_mem ); diff --git a/src/util/spad/fd_spad.c b/src/util/spad/fd_spad.c index d681c57041..665c801a51 100644 --- a/src/util/spad/fd_spad.c +++ b/src/util/spad/fd_spad.c @@ -110,3 +110,28 @@ fd_spad_publish_debug( fd_spad_t * spad, tracking that state */ fd_spad_publish( spad, sz ); } + +/* fd_valloc virtual function table for spad */ +void * +fd_spad_valloc_malloc( void * _self, + ulong align, + ulong sz ) { + fd_spad_t * spad = _self; + void * rv = fd_spad_alloc( spad, align, sz ); + if( FD_UNLIKELY( fd_spad_mem_used( spad )>fd_spad_mem_max( spad ) ) ) { + FD_LOG_ERR(( "spad overflow mem_used=%lu mem_max=%lu", fd_spad_mem_used( spad ), fd_spad_mem_max( spad ) )); + } + return rv; +} + +void +fd_spad_valloc_free( void * _self, + void * _addr ) { + (void)_self; (void)_addr; +} + +const fd_valloc_vtable_t +fd_spad_vtable = { + .malloc = fd_spad_valloc_malloc, + .free = fd_spad_valloc_free +}; \ No newline at end of file diff --git a/src/util/spad/fd_spad.h b/src/util/spad/fd_spad.h index 8ae9152764..6c63ee6574 100644 --- a/src/util/spad/fd_spad.h +++ b/src/util/spad/fd_spad.h @@ -29,6 +29,7 @@ sanitization. */ #include "../bits/fd_bits.h" +#include "../valloc/fd_valloc.h" // For valloc wrapper interface /* FD_SPAD_{ALIGN,FOOTPRINT} give the alignment and footprint of a fd_spad_t. ALIGN is an integer power of 2. FOOTPRINT is a multiple @@ -530,6 +531,18 @@ fd_spad_private_frame_end_debug( fd_spad_t ** _spad ) { #define FD_SPAD_FRAME_END_DEBUG while(0); } while(0) +/* fd_valloc virtual function table for spad */ +extern const fd_valloc_vtable_t fd_spad_vtable; + +/* Returns an fd_valloc handle to the fd_spad join. + Valid for lifetime of the current spad frame. Handle invalid if spad + frame changes or spad detaches. */ +FD_FN_PURE static inline fd_valloc_t +fd_spad_virtual( fd_spad_t * spad ) { + fd_valloc_t valloc = { spad, &fd_spad_vtable }; + return valloc; +} + FD_PROTOTYPES_END #endif /* HEADER_fd_src_util_spad_fd_spad_h */