From db82bbb7d499faef19f1397951cc0ef04e6d2564 Mon Sep 17 00:00:00 2001 From: Yufeng Zhou Date: Wed, 18 Dec 2024 22:45:51 +0000 Subject: [PATCH] . --- .../runtime/context/fd_exec_instr_ctx.h | 5 ++-- src/flamenco/runtime/fd_executor.c | 2 +- .../program/fd_address_lookup_table_program.c | 24 +++++++++---------- .../runtime/program/fd_bpf_loader_program.c | 2 +- .../runtime/program/fd_config_program.c | 6 +++-- .../runtime/tests/fd_exec_instr_test.c | 2 +- src/flamenco/vm/test_vm_util.c | 4 ++-- src/util/spad/fd_spad.c | 2 +- 8 files changed, 25 insertions(+), 22 deletions(-) diff --git a/src/flamenco/runtime/context/fd_exec_instr_ctx.h b/src/flamenco/runtime/context/fd_exec_instr_ctx.h index b599c05d01..c03d61794a 100644 --- a/src/flamenco/runtime/context/fd_exec_instr_ctx.h +++ b/src/flamenco/runtime/context/fd_exec_instr_ctx.h @@ -25,10 +25,11 @@ struct __attribute__((aligned(8UL))) fd_exec_instr_ctx { fd_funk_txn_t * funk_txn; fd_acc_mgr_t * acc_mgr; - /* This is for instruction-level test harnesses. + /* This is for instruction-level test harnesses, and really just + test_vm_util.c at the moment. Offline and live instruction execution should use the spad in txn_ctx. */ - fd_valloc_t valloc; + fd_valloc_t test_only_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/fd_executor.c b/src/flamenco/runtime/fd_executor.c index da140977b1..1bce8db2db 100644 --- a/src/flamenco/runtime/fd_executor.c +++ b/src/flamenco/runtime/fd_executor.c @@ -1182,7 +1182,7 @@ fd_execute_instr( fd_exec_txn_ctx_t * txn_ctx, .txn_ctx = txn_ctx, .epoch_ctx = txn_ctx->epoch_ctx, .slot_ctx = txn_ctx->slot_ctx, - .valloc = fd_scratch_virtual(), + .test_only_valloc = (fd_valloc_t){NULL, NULL}, .acc_mgr = txn_ctx->acc_mgr, .funk_txn = txn_ctx->funk_txn, .parent = parent, diff --git a/src/flamenco/runtime/program/fd_address_lookup_table_program.c b/src/flamenco/runtime/program/fd_address_lookup_table_program.c index 22dfc4e868..012c457f60 100644 --- a/src/flamenco/runtime/program/fd_address_lookup_table_program.c +++ b/src/flamenco/runtime/program/fd_address_lookup_table_program.c @@ -292,9 +292,9 @@ create_lookup_table( fd_exec_instr_ctx_t * ctx, /* https://github.com/solana-labs/solana/blob/v1.17.4/programs/address-lookup-table/src/processor.rs#L144-L149 */ if( required_lamports>0UL ) { // Create account metas - FD_SCRATCH_SCOPE_BEGIN { + FD_SPAD_FRAME_BEGIN( ctx->txn_ctx->spad ) { fd_vm_rust_account_meta_t * acct_metas = (fd_vm_rust_account_meta_t *) - fd_scratch_alloc( FD_VM_RUST_ACCOUNT_META_ALIGN, 2 * sizeof(fd_vm_rust_account_meta_t) ); + fd_spad_alloc( ctx->txn_ctx->spad, FD_VM_RUST_ACCOUNT_META_ALIGN, 2 * sizeof(fd_vm_rust_account_meta_t) ); fd_native_cpi_create_account_meta( payer_key, 1, 1, &acct_metas[0] ); fd_native_cpi_create_account_meta( lut_key, 0, 1, &acct_metas[1] ); @@ -319,12 +319,12 @@ create_lookup_table( fd_exec_instr_ctx_t * ctx, if( FD_UNLIKELY( err ) ) { return err; } - } FD_SCRATCH_SCOPE_END; + } FD_SPAD_FRAME_END; } - FD_SCRATCH_SCOPE_BEGIN { + FD_SPAD_FRAME_BEGIN( ctx->txn_ctx->spad ) { fd_vm_rust_account_meta_t * acct_metas = ( fd_vm_rust_account_meta_t * ) - fd_scratch_alloc( FD_VM_RUST_ACCOUNT_META_ALIGN, sizeof(fd_vm_rust_account_meta_t) ); + fd_spad_alloc( ctx->txn_ctx->spad, FD_VM_RUST_ACCOUNT_META_ALIGN, sizeof(fd_vm_rust_account_meta_t) ); fd_native_cpi_create_account_meta( lut_key, 1, 1, &acct_metas[0] ); // Create signers list @@ -365,7 +365,7 @@ create_lookup_table( fd_exec_instr_ctx_t * ctx, if( FD_UNLIKELY( err ) ) { return err; } - } FD_SCRATCH_SCOPE_END; + } FD_SPAD_FRAME_END; FD_BORROWED_ACCOUNT_TRY_BORROW_IDX( ctx, ACC_IDX_LUT, lut_acct ) { @@ -662,10 +662,10 @@ extend_lookup_table( fd_exec_instr_ctx_t * ctx, } FD_BORROWED_ACCOUNT_DROP( payer_acct ); - FD_SCRATCH_SCOPE_BEGIN { + FD_SPAD_FRAME_BEGIN( ctx->txn_ctx->spad ) { // Create account metas fd_vm_rust_account_meta_t * acct_metas = (fd_vm_rust_account_meta_t *) - fd_scratch_alloc( FD_VM_RUST_ACCOUNT_META_ALIGN, 2 * sizeof(fd_vm_rust_account_meta_t) ); + fd_spad_alloc( ctx->txn_ctx->spad, FD_VM_RUST_ACCOUNT_META_ALIGN, 2 * sizeof(fd_vm_rust_account_meta_t) ); fd_native_cpi_create_account_meta( payer_key, 1, 1, &acct_metas[0] ); fd_native_cpi_create_account_meta( lut_key, 0, 1, &acct_metas[1] ); @@ -688,7 +688,7 @@ extend_lookup_table( fd_exec_instr_ctx_t * ctx, if( FD_UNLIKELY( err ) ) { return err; } - } FD_SCRATCH_SCOPE_END; + } FD_SPAD_FRAME_END; } return FD_EXECUTOR_INSTR_SUCCESS; @@ -955,10 +955,10 @@ fd_address_lookup_table_program_execute( fd_exec_instr_ctx_t * ctx ) { return FD_EXECUTOR_INSTR_ERR_INVALID_INSTR_DATA; } - FD_SCRATCH_SCOPE_BEGIN { + FD_SPAD_FRAME_BEGIN( ctx->txn_ctx->spad ) { fd_bincode_decode_ctx_t decode = { - .valloc = fd_scratch_virtual(), + .valloc = fd_spad_virtual( ctx->txn_ctx->spad ), .data = instr_data, .dataend = instr_data + instr_data_sz }; @@ -983,7 +983,7 @@ fd_address_lookup_table_program_execute( fd_exec_instr_ctx_t * ctx ) { default: break; } - } FD_SCRATCH_SCOPE_END; + } FD_SPAD_FRAME_END; return FD_EXECUTOR_INSTR_SUCCESS; } diff --git a/src/flamenco/runtime/program/fd_bpf_loader_program.c b/src/flamenco/runtime/program/fd_bpf_loader_program.c index 4963c137c1..d1063bc818 100644 --- a/src/flamenco/runtime/program/fd_bpf_loader_program.c +++ b/src/flamenco/runtime/program/fd_bpf_loader_program.c @@ -1990,7 +1990,7 @@ fd_directly_invoke_loader_v3_deploy( fd_exec_slot_ctx_t * slot_ctx, .txn_ctx = txn_ctx, .epoch_ctx = txn_ctx->epoch_ctx, .slot_ctx = txn_ctx->slot_ctx, - .valloc = (fd_valloc_t){ .self = NULL, .vt = NULL }, + .test_only_valloc = (fd_valloc_t){ .self = NULL, .vt = NULL }, .acc_mgr = txn_ctx->acc_mgr, .funk_txn = txn_ctx->funk_txn, .parent = NULL, diff --git a/src/flamenco/runtime/program/fd_config_program.c b/src/flamenco/runtime/program/fd_config_program.c index f967ed5abe..39919d3c76 100644 --- a/src/flamenco/runtime/program/fd_config_program.c +++ b/src/flamenco/runtime/program/fd_config_program.c @@ -28,7 +28,7 @@ _process_config_instr( fd_exec_instr_ctx_t * ctx ) { } fd_bincode_decode_ctx_t decode = - { .valloc = ctx->valloc, + { .valloc = fd_spad_virtual( ctx->txn_ctx->spad ), .data = ctx->instr->data, .dataend = ctx->instr->data + ctx->instr->data_sz }; @@ -63,7 +63,7 @@ _process_config_instr( fd_exec_instr_ctx_t * ctx ) { /* https://github.com/solana-labs/solana/blob/v1.17.17/programs/config/src/config_processor.rs#L33-L40 */ fd_bincode_decode_ctx_t config_acc_state_decode_context = { - .valloc = ctx->valloc, + .valloc = fd_spad_virtual( ctx->txn_ctx->spad ), .data = config_acc_rec->const_data, .dataend = config_acc_rec->const_data + config_acc_rec->const_meta->dlen, }; @@ -253,10 +253,12 @@ fd_config_program_execute( fd_exec_instr_ctx_t * ctx ) { See DEFAULT_COMPUTE_UNITS */ FD_EXEC_CU_UPDATE( ctx, DEFAULT_COMPUTE_UNITS ); + FD_SPAD_FRAME_BEGIN( ctx->txn_ctx->spad ) { FD_SCRATCH_SCOPE_BEGIN { int ret = _process_config_instr( ctx ); return ret; } FD_SCRATCH_SCOPE_END; + } FD_SPAD_FRAME_END; } diff --git a/src/flamenco/runtime/tests/fd_exec_instr_test.c b/src/flamenco/runtime/tests/fd_exec_instr_test.c index 567224aace..8a02870357 100644 --- a/src/flamenco/runtime/tests/fd_exec_instr_test.c +++ b/src/flamenco/runtime/tests/fd_exec_instr_test.c @@ -531,7 +531,7 @@ fd_exec_test_instr_context_create( fd_exec_instr_test_runner_t * runner, ctx->epoch_ctx = epoch_ctx; ctx->funk_txn = funk_txn; ctx->acc_mgr = acc_mgr; - ctx->valloc = fd_scratch_virtual(); + ctx->test_only_valloc = (fd_valloc_t){NULL, NULL}; ctx->instr = info; fd_log_collector_init( &ctx->txn_ctx->log_collector, 1 ); diff --git a/src/flamenco/vm/test_vm_util.c b/src/flamenco/vm/test_vm_util.c index 64c1400ba1..5afe554a62 100644 --- a/src/flamenco/vm/test_vm_util.c +++ b/src/flamenco/vm/test_vm_util.c @@ -17,7 +17,7 @@ test_vm_minimal_exec_instr_ctx( return NULL; } - ctx->valloc = valloc; + ctx->test_only_valloc = valloc; /* Keep slot_ctx and epoch_ctx initialization simple. We only want features ATM. Feel free to change this to use actual init semantics (*_new and *_join), @@ -48,7 +48,7 @@ void test_vm_exec_instr_ctx_delete( fd_exec_instr_ctx_t * ctx ) { - fd_valloc_t valloc = ctx->valloc; + fd_valloc_t valloc = ctx->test_only_valloc; fd_exec_slot_ctx_t * slot_ctx = (fd_exec_slot_ctx_t *)ctx->slot_ctx; fd_exec_epoch_ctx_t * epoch_ctx = slot_ctx->epoch_ctx; fd_exec_txn_ctx_t * txn_ctx = ctx->txn_ctx; diff --git a/src/util/spad/fd_spad.c b/src/util/spad/fd_spad.c index 665c801a51..e338c710be 100644 --- a/src/util/spad/fd_spad.c +++ b/src/util/spad/fd_spad.c @@ -134,4 +134,4 @@ const fd_valloc_vtable_t fd_spad_vtable = { .malloc = fd_spad_valloc_malloc, .free = fd_spad_valloc_free -}; \ No newline at end of file +};