Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
yufeng-jump committed Dec 18, 2024
1 parent 775af83 commit db82bbb
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 22 deletions.
5 changes: 3 additions & 2 deletions src/flamenco/runtime/context/fd_exec_instr_ctx.h
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down
2 changes: 1 addition & 1 deletion src/flamenco/runtime/fd_executor.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
24 changes: 12 additions & 12 deletions src/flamenco/runtime/program/fd_address_lookup_table_program.c
Original file line number Diff line number Diff line change
Expand Up @@ -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] );

Expand All @@ -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
Expand Down Expand Up @@ -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 ) {
Expand Down Expand Up @@ -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] );

Expand All @@ -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;
Expand Down Expand Up @@ -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
};
Expand All @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/flamenco/runtime/program/fd_bpf_loader_program.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 4 additions & 2 deletions src/flamenco/runtime/program/fd_config_program.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 };

Expand Down Expand Up @@ -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,
};
Expand Down Expand Up @@ -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;
}
2 changes: 1 addition & 1 deletion src/flamenco/runtime/tests/fd_exec_instr_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
4 changes: 2 additions & 2 deletions src/flamenco/vm/test_vm_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/util/spad/fd_spad.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,4 +134,4 @@ const fd_valloc_vtable_t
fd_spad_vtable = {
.malloc = fd_spad_valloc_malloc,
.free = fd_spad_valloc_free
};
};

0 comments on commit db82bbb

Please sign in to comment.