Skip to content

Commit 49cd9ca

Browse files
wip
1 parent b670714 commit 49cd9ca

File tree

7 files changed

+68
-115
lines changed

7 files changed

+68
-115
lines changed

src/flamenco/runtime/context/fd_exec_txn_ctx.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -144,11 +144,6 @@ fd_exec_txn_ctx_get_key_of_account_at_index( fd_exec_txn_ctx_t * ctx,
144144
return FD_EXECUTOR_INSTR_SUCCESS;
145145
}
146146

147-
void
148-
fd_exec_txn_ctx_teardown( fd_exec_txn_ctx_t * ctx ) {
149-
(void)ctx;
150-
}
151-
152147
void
153148
fd_exec_txn_ctx_reset_return_data( fd_exec_txn_ctx_t * txn_ctx ) {
154149
txn_ctx->details.return_data.len = 0;

src/flamenco/runtime/context/fd_exec_txn_ctx.h

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@ typedef struct fd_exec_instr_trace_entry fd_exec_instr_trace_entry_t;
4040
#define FD_MAX_INSTRUCTION_STACK_DEPTH (5UL)
4141

4242
struct fd_exec_txn_ctx {
43-
/* EXECUTION INPUT **********************************************/
44-
4543
/* Input fields: memory, bank, acc db, funk, prog cache, and txn */
4644
fd_bank_t * bank;
4745
fd_txncache_t * status_cache;
@@ -83,17 +81,6 @@ struct fd_exec_txn_ctx {
8381

8482
} accounts;
8583

86-
struct {
87-
/* When a program is deployed or upgraded, we must queue it to be
88-
updated in the program cache (if it exists already) so that
89-
the cache entry's ELF / sBPF information can be updated for future
90-
executions. We keep an array of pubkeys for the transaction to
91-
track which programs need to be reverified. The actual queueing
92-
for reverification is done in the transaction finalization step. */
93-
uchar programs_to_reverify_cnt;
94-
fd_pubkey_t programs_to_reverify[ MAX_TX_ACCOUNT_LOCKS ];
95-
} prog_cache;
96-
9784
struct {
9885
uchar stack_sz; /* Current depth of the instruction execution stack. */
9986
fd_exec_instr_ctx_t stack[FD_MAX_INSTRUCTION_STACK_DEPTH]; /* Instruction execution stack. */
@@ -145,6 +132,15 @@ struct fd_exec_txn_ctx {
145132
fd_hash_t blake_txn_msg_hash; /* Hash of raw transaction message used by the status cache */
146133
ulong execution_fee; /* Execution fee paid by the fee payer in the transaction */
147134
ulong priority_fee; /* Priority fee paid by the fee payer in the transaction */
135+
/* When a program is deployed or upgraded, we must queue it to be
136+
updated in the program cache (if it exists already) so that
137+
the cache entry's ELF / sBPF information can be updated for
138+
future executions. We keep an array of pubkeys for the
139+
transaction to track which programs need to be reverified. The
140+
actual queueing for reverification is done in the transaction
141+
finalization step. */
142+
uchar programs_to_reverify_cnt;
143+
fd_pubkey_t programs_to_reverify[ MAX_TX_ACCOUNT_LOCKS ];
148144
} details;
149145

150146
struct {
@@ -208,9 +204,6 @@ fd_exec_txn_ctx_leave( fd_exec_txn_ctx_t * ctx );
208204
void *
209205
fd_exec_txn_ctx_delete( void * mem );
210206

211-
void
212-
fd_exec_txn_ctx_teardown( fd_exec_txn_ctx_t * txn_ctx );
213-
214207
/* Mirrors Agave function solana_sdk::transaction_context::find_index_of_account
215208
216209
Backward scan over transaction accounts.

src/flamenco/runtime/fd_executor.c

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1353,38 +1353,6 @@ fd_executor_reclaim_account( fd_exec_txn_ctx_t * txn_ctx,
13531353
}
13541354
}
13551355

1356-
void
1357-
fd_exec_txn_ctx_setup( fd_bank_t * bank,
1358-
void * accdb_shfunk,
1359-
void * progcache_shfunk,
1360-
fd_funk_txn_xid_t const * xid,
1361-
fd_txncache_t * status_cache,
1362-
fd_exec_txn_ctx_t * ctx,
1363-
fd_bank_hash_cmp_t * bank_hash_cmp,
1364-
void * progcache_scratch,
1365-
ulong progcache_scratch_sz ) {
1366-
if( FD_UNLIKELY( !fd_funk_join( ctx->funk, accdb_shfunk ) ) ) {
1367-
FD_LOG_CRIT(( "fd_funk_join(accdb) failed" ));
1368-
}
1369-
1370-
if( progcache_shfunk ) {
1371-
ctx->progcache = fd_progcache_join( ctx->_progcache, progcache_shfunk, progcache_scratch, progcache_scratch_sz );
1372-
if( FD_UNLIKELY( !ctx->progcache ) ) {
1373-
FD_LOG_CRIT(( "fd_progcache_join() failed" ));
1374-
}
1375-
}
1376-
1377-
ctx->xid[0] = *xid;
1378-
1379-
ctx->status_cache = status_cache;
1380-
1381-
ctx->bank_hash_cmp = bank_hash_cmp;
1382-
1383-
ctx->log.enable_exec_recording = !!( bank->flags & FD_BANK_FLAGS_EXEC_RECORDING );
1384-
1385-
ctx->bank = bank;
1386-
}
1387-
13881356
fd_txn_account_t *
13891357
fd_executor_setup_txn_account( fd_exec_txn_ctx_t * txn_ctx,
13901358
ushort idx ) {

src/flamenco/runtime/fd_executor.h

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -133,17 +133,6 @@ int
133133
fd_instr_stack_pop( fd_exec_txn_ctx_t * txn_ctx,
134134
fd_instr_info_t const * instr );
135135

136-
void
137-
fd_exec_txn_ctx_setup( fd_bank_t * bank,
138-
void * accdb_shfunk,
139-
void * progcache_shfunk,
140-
fd_funk_txn_xid_t const * xid,
141-
fd_txncache_t * status_cache,
142-
fd_exec_txn_ctx_t * ctx,
143-
fd_bank_hash_cmp_t * bank_hash_cmp,
144-
void * progcache_scratch,
145-
ulong progcache_scratch_sz );
146-
147136
FD_PROTOTYPES_END
148137

149138
#endif /* HEADER_fd_src_flamenco_runtime_fd_executor_h */

src/flamenco/runtime/fd_runtime.c

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,12 @@ fd_runtime_update_bank_hash( fd_bank_t * bank,
577577
int
578578
fd_runtime_pre_execute_check( fd_exec_txn_ctx_t * txn_ctx ) {
579579

580+
/* Set up the core account keys. These are the account keys directly
581+
passed in via the serialized transaction, represented as an array.
582+
Note that this does not include additional keys referenced in
583+
address lookup tables. */
584+
fd_executor_setup_txn_account_keys( txn_ctx );
585+
580586
int err;
581587

582588
/* https://github.com/anza-xyz/agave/blob/16de8b75ebcd57022409b422de557dd37b1de8db/sdk/src/transaction/sanitized.rs#L263-L275
@@ -977,8 +983,8 @@ fd_runtime_finalize_txn( fd_funk_t * funk,
977983
cache since their programdata may have changed. ELF / sBPF
978984
metadata will need to be updated. */
979985
ulong current_slot = fd_bank_slot_get( bank );
980-
for( uchar i=0; i<txn_ctx->prog_cache.programs_to_reverify_cnt; i++ ) {
981-
fd_pubkey_t const * program_key = &txn_ctx->prog_cache.programs_to_reverify[i];
986+
for( uchar i=0; i<txn_ctx->details.programs_to_reverify_cnt; i++ ) {
987+
fd_pubkey_t const * program_key = &txn_ctx->details.programs_to_reverify[i];
982988
fd_progcache_invalidate( progcache, xid, program_key, current_slot );
983989
}
984990
}
@@ -1044,8 +1050,7 @@ fd_runtime_prepare_and_execute_txn( fd_bank_t * bank,
10441050
txn_ctx->accounts.accounts_cnt = 0UL;
10451051
txn_ctx->accounts.executable_cnt = 0UL;
10461052

1047-
txn_ctx->prog_cache.programs_to_reverify_cnt = 0UL;
1048-
1053+
txn_ctx->details.programs_to_reverify_cnt = 0UL;
10491054
txn_ctx->details.loaded_accounts_data_size = 0UL;
10501055
txn_ctx->details.loaded_accounts_data_size_cost = 0UL;
10511056
txn_ctx->details.accounts_resize_delta = 0UL;
@@ -1074,21 +1079,12 @@ fd_runtime_prepare_and_execute_txn( fd_bank_t * bank,
10741079
txn_ctx->err.exec_err_idx = INT_MAX;
10751080
txn_ctx->err.custom_err = 0;
10761081

1077-
/* Set up the core account keys. These are the account keys directly
1078-
passed in via the serialized transaction, represented as an array.
1079-
Note that this does not include additional keys referenced in
1080-
address lookup tables. */
1081-
fd_executor_setup_txn_account_keys( txn_ctx );
1082-
1083-
/* Pre-execution checks */
1082+
/* Transaction sanitization. If a transaction can't be commited or is
1083+
fees-only, we return early. */
10841084
txn_ctx->err.txn_err = fd_runtime_pre_execute_check( txn_ctx );
1085-
if( FD_UNLIKELY( !txn_ctx->err.is_committable ) ) {
1086-
return txn_ctx->err.txn_err;
1087-
}
10881085

1089-
/* Execute the transaction. Note that fees-only transactions are still
1090-
marked as "executed". */
1091-
if( FD_LIKELY( !txn_ctx->err.is_fees_only ) ) {
1086+
/* Execute the transaction. */
1087+
if( FD_LIKELY( txn_ctx->err.is_committable && !txn_ctx->err.is_fees_only ) ) {
10921088
txn_ctx->err.txn_err = fd_execute_txn( txn_ctx );
10931089
}
10941090

src/flamenco/runtime/program/fd_bpf_loader_program.c

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ fd_deploy_program( fd_exec_instr_ctx_t * instr_ctx,
216216
}
217217

218218
/* Queue the program for reverification */
219-
instr_ctx->txn_ctx->prog_cache.programs_to_reverify[instr_ctx->txn_ctx->prog_cache.programs_to_reverify_cnt++] = *program_key;
219+
instr_ctx->txn_ctx->details.programs_to_reverify[instr_ctx->txn_ctx->details.programs_to_reverify_cnt++] = *program_key;
220220

221221
return FD_EXECUTOR_INSTR_SUCCESS;
222222
}
@@ -2612,28 +2612,27 @@ fd_directly_invoke_loader_v3_deploy( fd_bank_t * bank,
26122612
fd_pubkey_t const * program_key,
26132613
uchar const * elf,
26142614
ulong elf_sz ) {
2615-
/* FIXME: Breaking this until exec spad is replaced. */
26162615
FD_LOG_ERR(( "fd_directly_invoke_loader_v3_deploy is not implemented" ));
2617-
return 0;
26182616

2619-
/* Set up a dummy instr and txn context */
2617+
/* Set up a dummy instr and txn context.
2618+
FIXME: Memory for a txn context needs to be allocated */
26202619
fd_exec_txn_ctx_t * txn_ctx = fd_exec_txn_ctx_join( fd_exec_txn_ctx_new( NULL ) );
26212620

2622-
fd_exec_txn_ctx_setup( bank,
2623-
accdb_shfunk,
2624-
NULL,
2625-
xid,
2626-
NULL,
2627-
txn_ctx,
2628-
NULL,
2629-
NULL,
2630-
0UL );
2621+
if( FD_UNLIKELY( !fd_funk_join( txn_ctx->funk, accdb_shfunk ) ) ) {
2622+
FD_LOG_CRIT(( "fd_funk_join(accdb) failed" ));
2623+
}
2624+
txn_ctx->xid[0] = *xid;
2625+
txn_ctx->progcache = NULL;
2626+
txn_ctx->status_cache = NULL;
2627+
txn_ctx->bank_hash_cmp = NULL;
2628+
txn_ctx->log.enable_exec_recording = !!(bank->flags & FD_BANK_FLAGS_EXEC_RECORDING);
2629+
txn_ctx->bank = bank;
26312630

26322631
fd_compute_budget_details_new( &txn_ctx->details.compute_budget );
26332632
txn_ctx->accounts.accounts_cnt = 0UL;
26342633
txn_ctx->accounts.executable_cnt = 0UL;
2635-
txn_ctx->prog_cache.programs_to_reverify_cnt = 0UL;
26362634

2635+
txn_ctx->details.programs_to_reverify_cnt = 0UL;
26372636
txn_ctx->details.loaded_accounts_data_size = 0UL;
26382637
txn_ctx->details.loaded_accounts_data_size_cost = 0UL;
26392638
txn_ctx->details.accounts_resize_delta = 0UL;

src/flamenco/runtime/tests/fd_instr_harness.c

Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -81,22 +81,29 @@ fd_solfuzz_pb_instr_ctx_create( fd_solfuzz_runner_t * runner,
8181

8282
uchar * progcache_scratch = fd_spad_alloc_check( runner->spad, FD_PROGCACHE_SCRATCH_ALIGN, FD_PROGCACHE_SCRATCH_FOOTPRINT );
8383

84-
fd_exec_txn_ctx_setup( runner->bank,
85-
runner->accdb->funk->shmem,
86-
runner->progcache->funk->shmem,
87-
xid,
88-
NULL,
89-
txn_ctx,
90-
NULL,
91-
progcache_scratch,
92-
FD_PROGCACHE_SCRATCH_FOOTPRINT );
84+
if( FD_UNLIKELY( !fd_funk_join( txn_ctx->funk, runner->accdb->funk->shmem ) ) ) {
85+
FD_LOG_CRIT(( "fd_funk_join(accdb) failed" ));
86+
}
87+
88+
if( runner->progcache->funk->shmem ) {
89+
txn_ctx->progcache = fd_progcache_join( txn_ctx->_progcache, runner->progcache->funk->shmem, progcache_scratch, FD_PROGCACHE_SCRATCH_FOOTPRINT );
90+
if( FD_UNLIKELY( !txn_ctx->progcache ) ) {
91+
FD_LOG_CRIT(( "fd_progcache_join() failed" ));
92+
}
93+
}
94+
95+
txn_ctx->xid[0] = *xid;
96+
txn_ctx->status_cache = NULL;
97+
txn_ctx->bank_hash_cmp = NULL;
98+
txn_ctx->log.enable_exec_recording = !!( runner->bank->flags & FD_BANK_FLAGS_EXEC_RECORDING );
99+
txn_ctx->bank = runner->bank;
93100

94101
fd_compute_budget_details_new( &txn_ctx->details.compute_budget );
95102
txn_ctx->instr.stack_sz = 0;
96103
txn_ctx->accounts.accounts_cnt = 0UL;
97104
txn_ctx->accounts.executable_cnt = 0UL;
98-
txn_ctx->prog_cache.programs_to_reverify_cnt = 0UL;
99105

106+
txn_ctx->details.programs_to_reverify_cnt = 0UL;
100107
txn_ctx->details.loaded_accounts_data_size = 0UL;
101108
txn_ctx->details.loaded_accounts_data_size_cost = 0UL;
102109
txn_ctx->details.accounts_resize_delta = 0UL;
@@ -334,16 +341,22 @@ fd_solfuzz_pb_instr_ctx_create( fd_solfuzz_runner_t * runner,
334341

335342
ctx->instr = info;
336343

337-
/* Refresh the setup from the updated slot and epoch ctx. */
338-
fd_exec_txn_ctx_setup( runner->bank,
339-
runner->accdb->funk->shmem,
340-
runner->progcache->funk->shmem,
341-
xid,
342-
NULL,
343-
txn_ctx,
344-
NULL,
345-
progcache_scratch,
346-
FD_PROGCACHE_SCRATCH_FOOTPRINT );
344+
if( FD_UNLIKELY( !fd_funk_join( txn_ctx->funk, runner->accdb->funk->shmem ) ) ) {
345+
FD_LOG_CRIT(( "fd_funk_join(accdb) failed" ));
346+
}
347+
348+
if( runner->progcache->funk->shmem ) {
349+
txn_ctx->progcache = fd_progcache_join( txn_ctx->_progcache, runner->progcache->funk->shmem, progcache_scratch, FD_PROGCACHE_SCRATCH_FOOTPRINT );
350+
if( FD_UNLIKELY( !txn_ctx->progcache ) ) {
351+
FD_LOG_CRIT(( "fd_progcache_join() failed" ));
352+
}
353+
}
354+
355+
txn_ctx->xid[0] = *xid;
356+
txn_ctx->status_cache = NULL;
357+
txn_ctx->bank_hash_cmp = NULL;
358+
txn_ctx->log.enable_exec_recording = !!( runner->bank->flags & FD_BANK_FLAGS_EXEC_RECORDING );
359+
txn_ctx->bank = runner->bank;
347360

348361
fd_log_collector_init( &ctx->txn_ctx->log.log_collector, 1 );
349362
fd_base58_encode_32( txn_ctx->accounts.account_keys[ ctx->instr->program_id ].uc, NULL, ctx->program_id_base58 );

0 commit comments

Comments
 (0)