Skip to content

Commit f957e6d

Browse files
committed
compiles
1 parent 3e9091a commit f957e6d

File tree

12 files changed

+74
-86
lines changed

12 files changed

+74
-86
lines changed

src/flamenco/runtime/fd_executor.c

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -405,22 +405,6 @@ fd_executor_verify_transaction( fd_bank_t * bank,
405405
return FD_RUNTIME_EXECUTE_SUCCESS;
406406
}
407407

408-
static void
409-
fd_executor_setup_instr_infos_from_txn_instrs( fd_runtime_t * runtime,
410-
fd_bank_t * bank,
411-
fd_txn_in_t const * txn_in,
412-
fd_txn_out_t * txn_out ) {
413-
ushort instr_cnt = TXN( txn_in->txn )->instr_cnt;
414-
415-
/* Set up the instr infos for the transaction */
416-
for( ushort i=0; i<instr_cnt; i++ ) {
417-
fd_txn_instr_t const * instr = &TXN( txn_in->txn )->instr[i];
418-
fd_instr_info_init_from_txn_instr( &runtime->instr.infos[i], bank, txn_in, txn_out, instr );
419-
}
420-
421-
runtime->instr.info_cnt = instr_cnt;
422-
}
423-
424408
/* https://github.com/anza-xyz/agave/blob/v2.0.9/svm/src/account_loader.rs#L410-427 */
425409
static int
426410
accumulate_and_check_loaded_account_data_size( ulong acc_size,
@@ -1173,11 +1157,13 @@ fd_txn_ctx_push( fd_runtime_t * runtime,
11731157
}
11741158
}
11751159

1176-
/* https://github.com/anza-xyz/agave/blob/c4b42ab045860d7b13b3912eafb30e6d2f4e593f/sdk/src/transaction_context.rs#L347-L351 */
1177-
if( FD_UNLIKELY( runtime->instr.trace_length>=FD_MAX_INSTRUCTION_TRACE_LENGTH ) ) {
1160+
/* Note that we don't update the trace length here - since the caller
1161+
allocates out of the trace array, they are also responsible for
1162+
incrementing the trace length variable.
1163+
https://github.com/anza-xyz/agave/blob/c4b42ab045860d7b13b3912eafb30e6d2f4e593f/sdk/src/transaction_context.rs#L347-L351 */
1164+
if( FD_UNLIKELY( runtime->instr.trace_length>FD_MAX_INSTRUCTION_TRACE_LENGTH ) ) {
11781165
return FD_EXECUTOR_INSTR_ERR_MAX_INSN_TRACE_LENS_EXCEEDED;
11791166
}
1180-
runtime->instr.trace_length++;
11811167

11821168
/* https://github.com/anza-xyz/agave/blob/c4b42ab045860d7b13b3912eafb30e6d2f4e593f/sdk/src/transaction_context.rs#L352-L356 */
11831169
if( FD_UNLIKELY( runtime->instr.stack_sz>=FD_MAX_INSTRUCTION_STACK_DEPTH ) ) {
@@ -1355,11 +1341,6 @@ fd_execute_instr( fd_runtime_t * runtime,
13551341
};
13561342
fd_base58_encode_32( txn_out->accounts.accounts[ instr->program_id ].pubkey->uc, NULL, ctx->program_id_base58 );
13571343

1358-
runtime->instr.trace[ runtime->instr.trace_length - 1 ] = (fd_exec_instr_trace_entry_t) {
1359-
.instr_info = instr,
1360-
.stack_height = runtime->instr.stack_sz,
1361-
};
1362-
13631344
/* Look up the native program. We check for precompiles within the lookup function as well.
13641345
https://github.com/anza-xyz/agave/blob/v2.1.6/svm/src/message_processor.rs#L88 */
13651346
fd_exec_instr_fn_t native_prog_fn;
@@ -1601,9 +1582,6 @@ fd_executor_setup_accounts_for_txn( fd_runtime_t * runtime,
16011582

16021583
txn_out->accounts.nonce_idx_in_txn = ULONG_MAX;
16031584
runtime->executable.cnt = executable_idx;
1604-
1605-
/* Set up instr infos from the txn descriptor. No Agave equivalent to this function. */
1606-
fd_executor_setup_instr_infos_from_txn_instrs( runtime, bank, txn_in, txn_out );
16071585
}
16081586

16091587
int
@@ -1633,19 +1611,41 @@ fd_execute_txn( fd_runtime_t * runtime,
16331611
bool dump_insn = runtime->log.capture_ctx && fd_bank_slot_get( bank ) >= runtime->log.capture_ctx->dump_proto_start_slot && runtime->log.capture_ctx->dump_instr_to_pb;
16341612
(void)dump_insn;
16351613

1614+
fd_txn_t const * txn = TXN( txn_in->txn );
1615+
16361616
/* Initialize log collection. */
16371617
fd_log_collector_init( runtime->log.log_collector, runtime->log.enable_log_collector );
16381618

16391619
for( ushort i=0; i<TXN( txn_in->txn )->instr_cnt; i++ ) {
1640-
runtime->instr.current_idx = i;
1620+
/* Set up the instr info for the current instruction */
1621+
fd_instr_info_init_from_txn_instr(
1622+
&runtime->instr.trace[runtime->instr.trace_length],
1623+
bank,
1624+
txn_in,
1625+
txn_out,
1626+
&txn->instr[i]
1627+
);
1628+
16411629
# if FD_HAS_FLATCC
16421630
if( FD_UNLIKELY( dump_insn ) ) {
16431631
// Capture the input and convert it into a Protobuf message
1644-
fd_dump_instr_to_protobuf( runtime, bank, txn_in, txn_out, &runtime->instr.infos[i], i );
1632+
fd_dump_instr_to_protobuf(
1633+
runtime,
1634+
bank,
1635+
txn_in,
1636+
txn_out,
1637+
&runtime->instr.trace[runtime->instr.trace_length],
1638+
i
1639+
);
16451640
}
16461641
# endif
16471642

1648-
int instr_exec_result = fd_execute_instr( runtime, bank, txn_in, txn_out, &runtime->instr.infos[i] );
1643+
/* Update the current executing instruction index and trace length */
1644+
runtime->instr.current_idx = i;
1645+
runtime->instr.trace_length++;
1646+
1647+
/* Execute the current instruction */
1648+
int instr_exec_result = fd_execute_instr( runtime, bank, txn_in, txn_out, &runtime->instr.trace[i] );
16491649
if( FD_UNLIKELY( instr_exec_result!=FD_EXECUTOR_INSTR_SUCCESS ) ) {
16501650
if( txn_out->err.exec_err_idx==INT_MAX ) {
16511651
txn_out->err.exec_err_idx = i;

src/flamenco/runtime/fd_runtime.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1341,7 +1341,6 @@ fd_runtime_prepare_and_execute_txn( fd_runtime_t * runtime,
13411341

13421342
runtime->executable.cnt = 0UL;
13431343
runtime->log.enable_log_collector = 0;
1344-
runtime->instr.info_cnt = 0UL;
13451344
runtime->instr.trace_length = 0UL;
13461345
runtime->instr.current_idx = 0;
13471346
runtime->instr.stack_sz = 0;

src/flamenco/runtime/fd_runtime.h

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,19 @@ struct fd_runtime {
1313
uchar stack_sz; /* Current depth of the instruction execution stack. */
1414
fd_exec_instr_ctx_t stack[ FD_MAX_INSTRUCTION_STACK_DEPTH ]; /* Instruction execution stack. */
1515
/* The memory for all of the instructions in the transaction
16-
(including CPI instructions) are preallocated. However, the order
17-
in which the instructions are executed does not match the order in
18-
which they are allocated. The instr_trace will instead be used to
19-
track the order in which the instructions are executed. We leave
20-
space for an extra instruction to account for the case where the
21-
transaction has too many instructions leading to
22-
FD_EXECUTOR_INSTR_ERR_MAX_INSN_TRACE_LENS_EXCEEDED.
23-
TODO: In reality, we should just be allocating instr_infos per
24-
instruction and not up front. The dependency on using instr_info
25-
for the sysvar instruction setup is not needed and should be
26-
removed. At this point, instr_info and instr_trace should be
27-
combined. */
28-
fd_instr_info_t infos[ FD_MAX_INSTRUCTION_TRACE_LENGTH * 2UL ];
29-
ulong info_cnt;
30-
fd_exec_instr_trace_entry_t trace[ FD_MAX_INSTRUCTION_TRACE_LENGTH ]; /* Instruction trace */
31-
ulong trace_length; /* Number of instructions in the trace */
16+
(including CPI instructions) are preallocated. However, the
17+
order in which the instructions are executed does not match the
18+
order in which they are allocated. The instr_trace will instead
19+
be used to track the order in which the instructions are
20+
executed. We add a +1 to allow any instructions past the max
21+
instr trace limit to be safely allocated, so that we can fail
22+
out like Agave does later at the stack push step within
23+
fd_execute_instr.
24+
25+
The caller is responsible for updating the trace_length for the
26+
callee. */
27+
fd_instr_info_t trace[ FD_MAX_INSTRUCTION_TRACE_LENGTH+1UL ];
28+
ulong trace_length;
3229
/* The current instruction index being executed */
3330
int current_idx;
3431
} instr;

src/flamenco/runtime/fd_runtime_helpers.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,6 @@ typedef struct fd_txn_return_data fd_txn_return_data_t;
3232

3333
/* fd_exec_txn_ctx_t is the context needed to execute a transaction. */
3434

35-
/* An entry in the instruction trace */
36-
struct fd_exec_instr_trace_entry {
37-
/* Metadata about the instruction */
38-
fd_instr_info_t * instr_info;
39-
/* Stack height when this instruction was pushed onto the stack (including itself)
40-
https://github.com/anza-xyz/agave/blob/d87e23d8d91c32d5f2be2bb3557c730bee1e9434/sdk/src/transaction_context.rs#L475-L480 */
41-
ulong stack_height;
42-
};
43-
typedef struct fd_exec_instr_trace_entry fd_exec_instr_trace_entry_t;
44-
4535
FD_PROTOTYPES_BEGIN
4636

4737
/* Returns 0 on success, and non zero otherwise. On failure, the out

src/flamenco/runtime/info/fd_instr_info.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ struct fd_instr_info {
4444
fd_instruction_account_t accounts[ FD_INSTR_ACCT_MAX ];
4545
uchar is_duplicate[ FD_INSTR_ACCT_MAX ];
4646

47+
/* Stack height when this instruction was pushed onto the stack (including itself) */
48+
ulong stack_height;
49+
4750
/* TODO: convert to fd_uwide_t representation of uint_128 */
4851
ulong starting_lamports_h;
4952
ulong starting_lamports_l;

src/flamenco/runtime/program/fd_native_cpi.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ fd_native_cpi_native_invoke( fd_exec_instr_ctx_t * ctx,
1414
fd_pubkey_t const * signers,
1515
ulong signers_cnt ) {
1616
/* Set up the instr info */
17-
fd_instr_info_t instr_info[ 1 ];
17+
fd_instr_info_t * instr_info = &ctx->runtime->instr.trace[ ctx->runtime->instr.trace_length++ ];
1818
fd_instruction_account_t instruction_accounts[ FD_INSTR_ACCT_MAX ];
19-
ulong instruction_accounts_cnt;
19+
ulong instruction_accounts_cnt;
2020

2121
/* fd_vm_prepare_instruction will handle missing/invalid account case */
2222
instr_info->program_id = UCHAR_MAX;

src/flamenco/runtime/program/fd_precompiles.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,11 @@ fd_precompile_get_instr_data( fd_exec_instr_ctx_t * ctx,
100100
if( FD_UNLIKELY( index>=TXN( ctx->txn_in->txn )->instr_cnt ) )
101101
return FD_EXECUTOR_PRECOMPILE_ERR_DATA_OFFSET;
102102

103-
fd_instr_info_t const * instr = &ctx->runtime->instr.infos[ index ];
104-
data = instr->dogtor;
103+
fd_txn_t const * txn = TXN( ctx->txn_in->txn );
104+
uchar const * payload = ctx->txn_in->txn->payload;
105+
fd_txn_instr_t const * instr = &txn->instr[ index ];
106+
107+
data = fd_txn_get_instr_data( instr, payload );
105108
data_sz = instr->data_sz;
106109

107110
}

src/flamenco/runtime/tests/fd_instr_harness.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,7 @@ fd_solfuzz_pb_instr_ctx_create( fd_solfuzz_runner_t * runner,
104104

105105
runtime->log.capture_ctx = NULL;
106106

107-
runtime->instr.info_cnt = 0UL;
108-
runtime->instr.trace_length = 0UL;
107+
runtime->instr.trace_length = 1UL;
109108

110109
txn_out->err.exec_err = 0;
111110
txn_out->err.exec_err_kind = FD_EXECUTOR_ERR_KIND_NONE;
@@ -114,15 +113,14 @@ fd_solfuzz_pb_instr_ctx_create( fd_solfuzz_runner_t * runner,
114113
txn_in->txn = txn;
115114
txn_out->details.compute_budget.compute_unit_limit = test_ctx->cu_avail;
116115
txn_out->details.compute_budget.compute_meter = test_ctx->cu_avail;
117-
runtime->instr.info_cnt = 1UL;
118116
runtime->log.enable_vm_tracing = runner->enable_vm_tracing;
119117
runtime->log.tracing_mem = runner->enable_vm_tracing ?
120118
fd_spad_alloc_check( runner->spad, FD_RUNTIME_VM_TRACE_STATIC_ALIGN, FD_RUNTIME_VM_TRACE_STATIC_FOOTPRINT * FD_MAX_INSTRUCTION_STACK_DEPTH ) :
121119
NULL;
122120

123121
/* Set up instruction context */
124122

125-
fd_instr_info_t * info = fd_spad_alloc( runner->spad, 8UL, sizeof(fd_instr_info_t) );
123+
fd_instr_info_t * info = &runtime->instr.trace[ 0UL ];
126124
assert( info );
127125
memset( info, 0, sizeof(fd_instr_info_t) );
128126

@@ -131,8 +129,6 @@ fd_solfuzz_pb_instr_ctx_create( fd_solfuzz_runner_t * runner,
131129
memcpy( info->dogtor, test_ctx->data->bytes, info->data_sz );
132130
}
133131

134-
runtime->instr.infos[ 0UL ] = *info;
135-
136132
/* Prepare borrowed account table (correctly handles aliasing) */
137133

138134
if( FD_UNLIKELY( test_ctx->accounts_count > MAX_TX_ACCOUNT_LOCKS ) ) {

src/flamenco/runtime/tests/fd_txn_harness.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -444,8 +444,9 @@ fd_solfuzz_pb_txn_run( fd_solfuzz_runner_t * runner,
444444
} else {
445445
/* Capture the instruction error code */
446446
if( exec_res==FD_RUNTIME_TXN_ERR_INSTRUCTION_ERROR ) {
447-
int instr_err_idx = txn_out->err.exec_err_idx;
448-
int program_id_idx = runtime->instr.infos[instr_err_idx].program_id;
447+
fd_txn_t const * txn = TXN( txn_in->txn );
448+
int instr_err_idx = txn_out->err.exec_err_idx;
449+
int program_id_idx = txn->instr[instr_err_idx].program_id;
449450

450451
txn_result->instruction_error = (uint32_t) -txn_out->err.exec_err;
451452
txn_result->instruction_error_index = (uint32_t) instr_err_idx;

src/flamenco/runtime/tests/fd_vm_harness.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,6 @@ fd_solfuzz_pb_syscall_run( fd_solfuzz_runner_t * runner,
403403
if( !fd_solfuzz_pb_instr_ctx_create( runner, ctx, input_instr_ctx, skip_extra_checks ) )
404404
goto error;
405405

406-
ctx->runtime->instr.trace[0].instr_info = (fd_instr_info_t *)ctx->instr;
407406
ctx->runtime->instr.trace[0].stack_height = 1;
408407
ctx->txn_out->err.exec_err = 0;
409408
ctx->txn_out->err.exec_err_kind = FD_EXECUTOR_ERR_KIND_NONE;

0 commit comments

Comments
 (0)