@@ -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 */
425409static int
426410accumulate_and_check_loaded_account_data_size ( ulong acc_size ,
@@ -456,8 +440,7 @@ accumulate_and_check_loaded_account_data_size( ulong acc_size,
456440
457441 https://github.com/anza-xyz/agave/blob/v2.3.1/svm/src/account_loader.rs#L199-L228 */
458442static ulong
459- load_transaction_account ( fd_runtime_t * runtime ,
460- fd_bank_t * bank ,
443+ load_transaction_account ( fd_bank_t * bank ,
461444 fd_txn_in_t const * txn_in ,
462445 fd_txn_out_t * txn_out ,
463446 fd_txn_account_t * acct ,
@@ -472,7 +455,7 @@ load_transaction_account( fd_runtime_t * runtime,
472455 constructed by the SVM and modified within each transaction's
473456 instruction execution only, so it incurs a loaded size cost
474457 of 0. */
475- fd_sysvar_instructions_serialize_account ( txn_in , txn_out , ( fd_instr_info_t const * ) runtime -> instr . infos , TXN ( txn_in -> txn ) -> instr_cnt , txn_idx );
458+ fd_sysvar_instructions_serialize_account ( bank , txn_in , txn_out , txn_idx );
476459 return 0UL ;
477460 }
478461
@@ -549,7 +532,7 @@ fd_executor_load_transaction_accounts_old( fd_runtime_t * runtime,
549532 }
550533
551534 /* https://github.com/anza-xyz/agave/blob/v2.3.1/svm/src/account_loader.rs#L733-L740 */
552- ulong loaded_acc_size = load_transaction_account ( runtime , bank , txn_in , txn_out , acct , is_writable , unknown_acc , i );
535+ ulong loaded_acc_size = load_transaction_account ( bank , txn_in , txn_out , acct , is_writable , unknown_acc , i );
553536 int err = accumulate_and_check_loaded_account_data_size ( loaded_acc_size ,
554537 requested_loaded_accounts_data_size ,
555538 & txn_out -> details .loaded_accounts_data_size );
@@ -816,7 +799,7 @@ fd_executor_load_transaction_accounts_simd_186( fd_runtime_t * runtime,
816799
817800 /* Load and collect any remaining accounts
818801 https://github.com/anza-xyz/agave/blob/v2.3.1/svm/src/account_loader.rs#L652-L659 */
819- ulong loaded_acc_size = load_transaction_account ( runtime , bank , txn_in , txn_out , acct , is_writable , unknown_acc , i );
802+ ulong loaded_acc_size = load_transaction_account ( bank , txn_in , txn_out , acct , is_writable , unknown_acc , i );
820803 int err = fd_collect_loaded_account (
821804 runtime ,
822805 txn_out ,
@@ -1112,14 +1095,14 @@ fd_executor_setup_txn_alut_account_keys( fd_runtime_t * runtime,
11121095 return FD_RUNTIME_EXECUTE_SUCCESS ;
11131096}
11141097
1115- /* https://github.com/anza-xyz/agave/blob/c4b42ab045860d7b13b3912eafb30e6d2f4e593f /sdk/src/transaction_context.rs#L319-L357 */
1098+ /* https://github.com/anza-xyz/agave/blob/v2.0.0 /sdk/src/transaction_context.rs#L319-L357 */
11161099static inline int
11171100fd_txn_ctx_push ( fd_runtime_t * runtime ,
11181101 fd_txn_in_t const * txn_in ,
11191102 fd_txn_out_t * txn_out ,
11201103 fd_instr_info_t * instr ) {
11211104 /* Earlier checks in the permalink are redundant since Agave maintains instr stack and trace accounts separately
1122- https://github.com/anza-xyz/agave/blob/c4b42ab045860d7b13b3912eafb30e6d2f4e593f /sdk/src/transaction_context.rs#L327-L328 */
1105+ https://github.com/anza-xyz/agave/blob/v2.0.0 /sdk/src/transaction_context.rs#L327-L328 */
11231106 ulong starting_lamports_h = 0UL ;
11241107 ulong starting_lamports_l = 0UL ;
11251108 int err = fd_instr_info_sum_account_lamports ( instr ,
@@ -1133,16 +1116,16 @@ fd_txn_ctx_push( fd_runtime_t * runtime,
11331116 instr -> starting_lamports_l = starting_lamports_l ;
11341117
11351118 /* Check that the caller's lamport sum has not changed.
1136- https://github.com/anza-xyz/agave/blob/c4b42ab045860d7b13b3912eafb30e6d2f4e593f /sdk/src/transaction_context.rs#L329-L340 */
1119+ https://github.com/anza-xyz/agave/blob/v2.0.0 /sdk/src/transaction_context.rs#L329-L340 */
11371120 if ( runtime -> instr .stack_sz > 0 ) {
1138- /* https://github.com/anza-xyz/agave/blob/c4b42ab045860d7b13b3912eafb30e6d2f4e593f /sdk/src/transaction_context.rs#L330 */
1121+ /* https://github.com/anza-xyz/agave/blob/v2.0.0 /sdk/src/transaction_context.rs#L330 */
11391122 fd_exec_instr_ctx_t const * caller_instruction_context = & runtime -> instr .stack [ runtime -> instr .stack_sz - 1 ];
11401123
1141- /* https://github.com/anza-xyz/agave/blob/c4b42ab045860d7b13b3912eafb30e6d2f4e593f /sdk/src/transaction_context.rs#L331-L332 */
1124+ /* https://github.com/anza-xyz/agave/blob/v2.0.0 /sdk/src/transaction_context.rs#L331-L332 */
11421125 ulong original_caller_lamport_sum_h = caller_instruction_context -> instr -> starting_lamports_h ;
11431126 ulong original_caller_lamport_sum_l = caller_instruction_context -> instr -> starting_lamports_l ;
11441127
1145- /* https://github.com/anza-xyz/agave/blob/c4b42ab045860d7b13b3912eafb30e6d2f4e593f /sdk/src/transaction_context.rs#L333-L334 */
1128+ /* https://github.com/anza-xyz/agave/blob/v2.0.0 /sdk/src/transaction_context.rs#L333-L334 */
11461129 ulong current_caller_lamport_sum_h = 0UL ;
11471130 ulong current_caller_lamport_sum_l = 0UL ;
11481131 int err = fd_instr_info_sum_account_lamports ( caller_instruction_context -> instr ,
@@ -1153,20 +1136,22 @@ fd_txn_ctx_push( fd_runtime_t * runtime,
11531136 return err ;
11541137 }
11551138
1156- /* https://github.com/anza-xyz/agave/blob/c4b42ab045860d7b13b3912eafb30e6d2f4e593f /sdk/src/transaction_context.rs#L335-L339 */
1139+ /* https://github.com/anza-xyz/agave/blob/v2.0.0 /sdk/src/transaction_context.rs#L335-L339 */
11571140 if ( FD_UNLIKELY ( current_caller_lamport_sum_h != original_caller_lamport_sum_h ||
11581141 current_caller_lamport_sum_l != original_caller_lamport_sum_l ) ) {
11591142 return FD_EXECUTOR_INSTR_ERR_UNBALANCED_INSTR ;
11601143 }
11611144 }
11621145
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 ) ) {
1146+ /* Note that we don't update the trace length here - since the caller
1147+ allocates out of the trace array, they are also responsible for
1148+ incrementing the trace length variable.
1149+ https://github.com/anza-xyz/agave/blob/v2.0.0/sdk/src/transaction_context.rs#L347-L351 */
1150+ if ( FD_UNLIKELY ( runtime -> instr .trace_length > FD_MAX_INSTRUCTION_TRACE_LENGTH ) ) {
11651151 return FD_EXECUTOR_INSTR_ERR_MAX_INSN_TRACE_LENS_EXCEEDED ;
11661152 }
1167- runtime -> instr .trace_length ++ ;
11681153
1169- /* https://github.com/anza-xyz/agave/blob/c4b42ab045860d7b13b3912eafb30e6d2f4e593f /sdk/src/transaction_context.rs#L352-L356 */
1154+ /* https://github.com/anza-xyz/agave/blob/v2.0.0 /sdk/src/transaction_context.rs#L352-L356 */
11701155 if ( FD_UNLIKELY ( runtime -> instr .stack_sz >=FD_MAX_INSTRUCTION_STACK_DEPTH ) ) {
11711156 return FD_EXECUTOR_INSTR_ERR_CALL_DEPTH ;
11721157 }
@@ -1200,7 +1185,7 @@ fd_txn_ctx_push( fd_runtime_t * runtime,
12001185 and checks for reentrancy violations. If successful, simply increments the instruction stack and trace size and returns. It is
12011186 the responsibility of the caller to populate the newly pushed instruction fields, which are undefined otherwise.
12021187
1203- https://github.com/anza-xyz/agave/blob/c4b42ab045860d7b13b3912eafb30e6d2f4e593f /program-runtime/src/invoke_context.rs#L246-L290 */
1188+ https://github.com/anza-xyz/agave/blob/v2.0.0 /program-runtime/src/invoke_context.rs#L246-L290 */
12041189int
12051190fd_instr_stack_push ( fd_runtime_t * runtime ,
12061191 fd_txn_in_t const * txn_in ,
@@ -1224,9 +1209,9 @@ fd_instr_stack_push( fd_runtime_t * runtime,
12241209 return FD_EXECUTOR_INSTR_ERR_UNSUPPORTED_PROGRAM_ID ;
12251210 }
12261211
1227- /* https://github.com/anza-xyz/agave/blob/c4b42ab045860d7b13b3912eafb30e6d2f4e593f /program-runtime/src/invoke_context.rs#L256-L286 */
1212+ /* https://github.com/anza-xyz/agave/blob/v2.0.0 /program-runtime/src/invoke_context.rs#L256-L286 */
12281213 if ( runtime -> instr .stack_sz ) {
1229- /* https://github.com/anza-xyz/agave/blob/c4b42ab045860d7b13b3912eafb30e6d2f4e593f /program-runtime/src/invoke_context.rs#L261-L285 */
1214+ /* https://github.com/anza-xyz/agave/blob/v2.0.0 /program-runtime/src/invoke_context.rs#L261-L285 */
12301215 uchar contains = 0 ;
12311216 uchar is_last = 0 ;
12321217
@@ -1242,26 +1227,26 @@ fd_instr_stack_push( fd_runtime_t * runtime,
12421227 contains = 1 ;
12431228 }
12441229 }
1245- /* https://github.com/anza-xyz/agave/blob/c4b42ab045860d7b13b3912eafb30e6d2f4e593f /program-runtime/src/invoke_context.rs#L282-L285 */
1230+ /* https://github.com/anza-xyz/agave/blob/v2.0.0 /program-runtime/src/invoke_context.rs#L282-L285 */
12461231 if ( FD_UNLIKELY ( contains && !is_last ) ) {
12471232 return FD_EXECUTOR_INSTR_ERR_REENTRANCY_NOT_ALLOWED ;
12481233 }
12491234 }
12501235 /* "Push" a new instruction onto the stack by simply incrementing the stack and trace size counters
1251- https://github.com/anza-xyz/agave/blob/c4b42ab045860d7b13b3912eafb30e6d2f4e593f /program-runtime/src/invoke_context.rs#L289 */
1236+ https://github.com/anza-xyz/agave/blob/v2.0.0 /program-runtime/src/invoke_context.rs#L289 */
12521237 return fd_txn_ctx_push ( runtime , txn_in , txn_out , instr );
12531238}
12541239
12551240/* Pops an instruction from the instruction stack. Agave's implementation performs instruction balancing checks every time pop is called,
12561241 but error codes returned from `pop` are only used if the program's execution was successful. Therefore, we can optimize our code by only
12571242 checking for unbalanced instructions if the program execution was successful within fd_execute_instr.
12581243
1259- https://github.com/anza-xyz/agave/blob/c4b42ab045860d7b13b3912eafb30e6d2f4e593f /program-runtime/src/invoke_context.rs#L293-L298 */
1244+ https://github.com/anza-xyz/agave/blob/v2.0.0 /program-runtime/src/invoke_context.rs#L293-L298 */
12601245int
12611246fd_instr_stack_pop ( fd_runtime_t * runtime ,
12621247 fd_txn_out_t * txn_out ,
12631248 fd_instr_info_t const * instr ) {
1264- /* https://github.com/anza-xyz/agave/blob/c4b42ab045860d7b13b3912eafb30e6d2f4e593f /sdk/src/transaction_context.rs#L362-L364 */
1249+ /* https://github.com/anza-xyz/agave/blob/v2.0.0 /sdk/src/transaction_context.rs#L362-L364 */
12651250 if ( FD_UNLIKELY ( runtime -> instr .stack_sz == 0 ) ) {
12661251 return FD_EXECUTOR_INSTR_ERR_CALL_DEPTH ;
12671252 }
@@ -1279,7 +1264,7 @@ fd_instr_stack_pop( fd_runtime_t * runtime,
12791264 }
12801265
12811266 /* Verify lamports are balanced before and after instruction
1282- https://github.com/anza-xyz/agave/blob/c4b42ab045860d7b13b3912eafb30e6d2f4e593f /sdk/src/transaction_context.rs#L366-L380 */
1267+ https://github.com/anza-xyz/agave/blob/v2.0.0 /sdk/src/transaction_context.rs#L366-L380 */
12831268 ulong ending_lamports_h = 0UL ;
12841269 ulong ending_lamports_l = 0UL ;
12851270 int err = fd_instr_info_sum_account_lamports ( instr ,
@@ -1342,11 +1327,6 @@ fd_execute_instr( fd_runtime_t * runtime,
13421327 };
13431328 fd_base58_encode_32 ( txn_out -> accounts .accounts [ instr -> program_id ].pubkey -> uc , NULL , ctx -> program_id_base58 );
13441329
1345- runtime -> instr .trace [ runtime -> instr .trace_length - 1 ] = (fd_exec_instr_trace_entry_t ) {
1346- .instr_info = instr ,
1347- .stack_height = runtime -> instr .stack_sz ,
1348- };
1349-
13501330 /* Look up the native program. We check for precompiles within the lookup function as well.
13511331 https://github.com/anza-xyz/agave/blob/v2.1.6/svm/src/message_processor.rs#L88 */
13521332 fd_exec_instr_fn_t native_prog_fn ;
@@ -1588,9 +1568,6 @@ fd_executor_setup_accounts_for_txn( fd_runtime_t * runtime,
15881568
15891569 txn_out -> accounts .nonce_idx_in_txn = ULONG_MAX ;
15901570 runtime -> executable .cnt = executable_idx ;
1591-
1592- /* Set up instr infos from the txn descriptor. No Agave equivalent to this function. */
1593- fd_executor_setup_instr_infos_from_txn_instrs ( runtime , bank , txn_in , txn_out );
15941571}
15951572
15961573int
@@ -1620,19 +1597,34 @@ fd_execute_txn( fd_runtime_t * runtime,
16201597 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 ;
16211598 (void )dump_insn ;
16221599
1600+ fd_txn_t const * txn = TXN ( txn_in -> txn );
1601+
16231602 /* Initialize log collection. */
16241603 fd_log_collector_init ( runtime -> log .log_collector , runtime -> log .enable_log_collector );
16251604
16261605 for ( ushort i = 0 ; i < TXN ( txn_in -> txn )-> instr_cnt ; i ++ ) {
1627- runtime -> instr .current_idx = i ;
1606+ /* Set up the instr info for the current instruction */
1607+ fd_instr_info_t * instr_info = & runtime -> instr .trace [runtime -> instr .trace_length ++ ];
1608+ fd_instr_info_init_from_txn_instr (
1609+ instr_info ,
1610+ bank ,
1611+ txn_in ,
1612+ txn_out ,
1613+ & txn -> instr [i ]
1614+ );
1615+
16281616# if FD_HAS_FLATCC
16291617 if ( FD_UNLIKELY ( dump_insn ) ) {
16301618 // Capture the input and convert it into a Protobuf message
1631- fd_dump_instr_to_protobuf ( runtime , bank , txn_in , txn_out , & runtime -> instr . infos [ i ] , i );
1619+ fd_dump_instr_to_protobuf ( runtime , bank , txn_in , txn_out , instr_info , i );
16321620 }
16331621# endif
16341622
1635- int instr_exec_result = fd_execute_instr ( runtime , bank , txn_in , txn_out , & runtime -> instr .infos [i ] );
1623+ /* Update the current executing instruction index */
1624+ runtime -> instr .current_idx = i ;
1625+
1626+ /* Execute the current instruction */
1627+ int instr_exec_result = fd_execute_instr ( runtime , bank , txn_in , txn_out , instr_info );
16361628 if ( FD_UNLIKELY ( instr_exec_result != FD_EXECUTOR_INSTR_SUCCESS ) ) {
16371629 if ( txn_out -> err .exec_err_idx == INT_MAX ) {
16381630 txn_out -> err .exec_err_idx = i ;
0 commit comments