Line data Source code
1 : #ifndef HEADER_fd_src_flamenco_runtime_fd_executor_h 2 : #define HEADER_fd_src_flamenco_runtime_fd_executor_h 3 : 4 : #include "fd_executor_err.h" 5 : #include "context/fd_exec_txn_ctx.h" 6 : #include "context/fd_exec_instr_ctx.h" 7 : #include "../../ballet/block/fd_microblock.h" 8 : #include "../../ballet/pack/fd_microblock.h" 9 : #include "../../ballet/txn/fd_txn.h" 10 : #include "../../ballet/poh/fd_poh.h" 11 : #include "../types/fd_types_yaml.h" 12 : #include "../log_collector/fd_log_collector.h" 13 : #include "tests/generated/invoke.pb.h" 14 : #include "tests/generated/txn.pb.h" 15 : #include "../features/fd_features.h" 16 : #include "fd_runtime.h" 17 : 18 : /* FD_EXEC_CU_UPDATE consumes CUs from the current instr ctx 19 : and fails in case of error. */ 20 90918 : #define FD_EXEC_CU_UPDATE( ctx, cost ) do { \ 21 90918 : fd_exec_instr_ctx_t * _ctx = (ctx); \ 22 90918 : int err = fd_exec_consume_cus( _ctx->txn_ctx, (cost) ); \ 23 90918 : if( FD_UNLIKELY( err ) ) return err; \ 24 90918 : } while(0) 25 : 26 : FD_PROTOTYPES_BEGIN 27 : 28 : /* https://github.com/anza-xyz/agave/blob/v2.0.9/runtime/src/bank.rs#L3239-L3251 */ 29 : static inline ulong 30 7641 : get_transaction_account_lock_limit( fd_exec_slot_ctx_t const * slot_ctx ) { 31 7641 : return fd_ulong_if( FD_FEATURE_ACTIVE( slot_ctx, increase_tx_account_lock_limit ), MAX_TX_ACCOUNT_LOCKS, 64UL ); 32 7641 : } 33 : 34 : /* Create an InstrContext protobuf struct from a given 35 : transaction context and instr info. 36 : 37 : NOTE: Calling this function requires the caller to have a scratch 38 : frame ready and pushed (see dump_instr_to_protobuf) */ 39 : void 40 : fd_create_instr_context_protobuf_from_instructions( fd_exec_test_instr_context_t * instr_context, 41 : fd_exec_txn_ctx_t const * txn_ctx, 42 : fd_instr_info_t const * instr ); 43 : 44 : /* fd_exec_instr_fn_t processes an instruction. Returns an error code 45 : in FD_EXECUTOR_INSTR_{ERR_{...},SUCCESS}. */ 46 : 47 : typedef int (* fd_exec_instr_fn_t)( fd_exec_instr_ctx_t * ctx ); 48 : 49 : /* fd_executor_lookup_native_program returns the appropriate instruction 50 : processor for the given native program ID. Returns NULL if given ID 51 : is not a recognized native program. */ 52 : 53 : fd_exec_instr_fn_t 54 : fd_executor_lookup_native_program( fd_borrowed_account_t const * account ); 55 : 56 : /* TODO:FIXME: add documentation here */ 57 : 58 : int 59 : fd_validate_fee_payer( fd_borrowed_account_t * account, fd_rent_t const * rent, ulong fee ); 60 : 61 : int 62 : fd_executor_check_transactions( fd_exec_txn_ctx_t * txn_ctx ); 63 : 64 : int 65 : fd_executor_verify_precompiles( fd_exec_txn_ctx_t * txn_ctx ); 66 : 67 : /* fd_execute_instr creates a new fd_exec_instr_ctx_t and performs 68 : instruction processing. Does fd_scratch allocations. Returns an 69 : error code in FD_EXECUTOR_INSTR_{ERR_{...},SUCCESS}. 70 : 71 : IMPORTANT: instr_info must have the same lifetime as txn_ctx. This can 72 : be achieved by using fd_executor_acquire_instr_info_elem( txn_ctx ) to 73 : acquire an fd_instr_info_t element with the same lifetime as the txn_ctx */ 74 : int 75 : fd_executor_txn_verify( fd_exec_txn_ctx_t * txn_ctx ); 76 : 77 : int 78 : fd_execute_instr( fd_exec_txn_ctx_t * txn_ctx, 79 : fd_instr_info_t * instr_info ); 80 : 81 : int 82 : fd_execute_txn_prepare_start( fd_exec_slot_ctx_t * slot_ctx, 83 : fd_exec_txn_ctx_t * txn_ctx, 84 : fd_txn_t const * txn_descriptor, 85 : fd_rawtxn_b_t const * txn_raw ); 86 : 87 : int 88 : fd_execute_txn_prepare_phase3( fd_exec_slot_ctx_t * slot_ctx, 89 : fd_exec_txn_ctx_t * txn_ctx, 90 : fd_txn_p_t * txn ); 91 : 92 : int 93 : fd_execute_txn_finalize( fd_exec_txn_ctx_t * txn_ctx, 94 : int exec_txn_err ); 95 : 96 : /* 97 : Execute the given transaction. 98 : 99 : Makes changes to the Funk accounts DB. */ 100 : int 101 : fd_execute_txn( fd_exec_txn_ctx_t * txn_ctx ); 102 : 103 : uint 104 : fd_executor_txn_uses_sysvar_instructions( fd_exec_txn_ctx_t const * txn_ctx ); 105 : 106 : int 107 : fd_executor_validate_transaction_fee_payer( fd_exec_txn_ctx_t * txn_ctx ); 108 : 109 : int 110 : fd_executor_setup_accessed_accounts_for_txn( fd_exec_txn_ctx_t * txn_ctx ); 111 : 112 : void 113 : fd_executor_setup_borrowed_accounts_for_txn( fd_exec_txn_ctx_t * txn_ctx ); 114 : 115 : int 116 : fd_executor_is_system_nonce_account( fd_borrowed_account_t * account ); 117 : 118 : /* 119 : Validate the txn after execution for violations of various lamport balance and size rules 120 : */ 121 : 122 : int 123 : fd_executor_txn_check( fd_exec_slot_ctx_t const * slot_ctx, 124 : fd_exec_txn_ctx_t * txn ); 125 : 126 : void 127 : fd_txn_reclaim_accounts( fd_exec_txn_ctx_t * txn_ctx ); 128 : 129 : int 130 : fd_executor_is_blockhash_valid_for_age( fd_block_hash_queue_t const * block_hash_queue, 131 : fd_hash_t const * blockhash, 132 : ulong max_age ); 133 : 134 : /* fd_io_strerror converts an FD_EXECUTOR_INSTR_ERR_{...} code into a 135 : human readable cstr. The lifetime of the returned pointer is 136 : infinite and the call itself is thread safe. The returned pointer is 137 : always to a non-NULL cstr. */ 138 : 139 : FD_FN_CONST char const * 140 : fd_executor_instr_strerror( int err ); 141 : 142 : int 143 : fd_executor_load_transaction_accounts( fd_exec_txn_ctx_t * txn_ctx ); 144 : 145 : int 146 : fd_executor_validate_account_locks( fd_exec_txn_ctx_t const * txn_ctx ); 147 : 148 : static inline int 149 : fd_exec_consume_cus( fd_exec_txn_ctx_t * txn_ctx, 150 90918 : ulong cus ) { 151 90918 : ulong new_cus = txn_ctx->compute_meter - cus; 152 90918 : int underflow = (txn_ctx->compute_meter < cus); 153 90918 : if( FD_UNLIKELY( underflow ) ) { 154 16740 : txn_ctx->compute_meter = 0UL; 155 16740 : return FD_EXECUTOR_INSTR_ERR_COMPUTE_BUDGET_EXCEEDED; 156 16740 : } 157 74178 : txn_ctx->compute_meter = new_cus; 158 74178 : return FD_EXECUTOR_INSTR_SUCCESS; 159 90918 : } 160 : 161 : void 162 : dump_txn_to_protobuf( fd_exec_txn_ctx_t *txn_ctx, fd_spad_t * spad ); 163 : 164 : /* We expose these only for the fuzzing harness. 165 : Normally you shouldn't be invoking these manually. */ 166 : int 167 : fd_instr_stack_push( fd_exec_txn_ctx_t * txn_ctx, 168 : fd_instr_info_t * instr ); 169 : 170 : int 171 : fd_instr_stack_pop( fd_exec_txn_ctx_t * txn_ctx, 172 : fd_instr_info_t const * instr ); 173 : 174 : FD_PROTOTYPES_END 175 : 176 : #endif /* HEADER_fd_src_flamenco_runtime_fd_executor_h */