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 "../../disco/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 0 : #define FD_FEE_PAYER_TXN_IDX (0UL) 19 : 20 : /* FD_EXEC_CU_UPDATE consumes CUs from the current instr ctx 21 : and fails in case of error. */ 22 0 : #define FD_EXEC_CU_UPDATE( ctx, cost ) do { \ 23 0 : fd_exec_instr_ctx_t * _ctx = (ctx); \ 24 0 : int err = fd_exec_consume_cus( _ctx->txn_ctx, (cost) ); \ 25 0 : if( FD_UNLIKELY( err ) ) return err; \ 26 0 : } while(0) 27 : 28 : // https://github.com/anza-xyz/agave/blob/2e6ca8c1f62db62c1db7f19c9962d4db43d0d550/sdk/src/fee.rs#L82 29 0 : #define FD_ACCOUNT_DATA_COST_PAGE_SIZE ( 32UL * 1024UL ) 30 : 31 : FD_PROTOTYPES_BEGIN 32 : 33 : /* https://github.com/anza-xyz/agave/blob/v2.0.9/runtime/src/bank.rs#L3239-L3251 */ 34 : static inline ulong 35 0 : get_transaction_account_lock_limit( fd_exec_txn_ctx_t const * txn_ctx ) { 36 0 : return fd_ulong_if( FD_FEATURE_ACTIVE( txn_ctx->slot, txn_ctx->features, increase_tx_account_lock_limit ), MAX_TX_ACCOUNT_LOCKS, 64UL ); 37 0 : } 38 : 39 : /* fd_exec_instr_fn_t processes an instruction. Returns an error code 40 : in FD_EXECUTOR_INSTR_{ERR_{...},SUCCESS}. */ 41 : 42 : typedef int (* fd_exec_instr_fn_t)( fd_exec_instr_ctx_t * ctx ); 43 : 44 : /* fd_executor_lookup_native_program returns the appropriate instruction 45 : processor for the given native program ID. Returns NULL if given ID 46 : is not a recognized native program. */ 47 : 48 : fd_exec_instr_fn_t 49 : fd_executor_lookup_native_program( fd_txn_account_t const * account ); 50 : 51 : fd_exec_instr_fn_t 52 : fd_executor_lookup_native_precompile_program( fd_txn_account_t const * prog_acc ); 53 : 54 : int 55 : fd_executor_check_transactions( fd_exec_txn_ctx_t * txn_ctx ); 56 : 57 : int 58 : fd_executor_verify_precompiles( fd_exec_txn_ctx_t * txn_ctx ); 59 : 60 : /* fd_execute_instr creates a new fd_exec_instr_ctx_t and performs 61 : instruction processing. Does fd_spad_t allocations. Returns an 62 : error code in FD_EXECUTOR_INSTR_{ERR_{...},SUCCESS}. 63 : 64 : IMPORTANT: instr_info must have the same lifetime as txn_ctx. This can 65 : be achieved by using fd_executor_acquire_instr_info_elem( txn_ctx ) to 66 : acquire an fd_instr_info_t element with the same lifetime as the txn_ctx */ 67 : int 68 : fd_executor_txn_verify( fd_exec_txn_ctx_t * txn_ctx ); 69 : 70 : int 71 : fd_execute_instr( fd_exec_txn_ctx_t * txn_ctx, 72 : fd_instr_info_t * instr_info ); 73 : 74 : int 75 : fd_execute_txn_prepare_start( fd_exec_slot_ctx_t const * slot_ctx, 76 : fd_exec_txn_ctx_t * txn_ctx, 77 : fd_txn_t const * txn_descriptor, 78 : fd_rawtxn_b_t const * txn_raw, 79 : fd_spad_t * spad ); 80 : 81 : /* 82 : Execute the given transaction. 83 : 84 : Makes changes to the Funk accounts DB. */ 85 : int 86 : fd_execute_txn( fd_execute_txn_task_info_t * task_info ); 87 : 88 : uint 89 : fd_executor_txn_uses_sysvar_instructions( fd_exec_txn_ctx_t const * txn_ctx ); 90 : 91 : int 92 : fd_executor_validate_transaction_fee_payer( fd_exec_txn_ctx_t * txn_ctx ); 93 : 94 : void 95 : fd_executor_setup_borrowed_accounts_for_txn( fd_exec_txn_ctx_t * txn_ctx ); 96 : 97 : /* 98 : Validate the txn after execution for violations of various lamport balance and size rules 99 : */ 100 : 101 : int 102 : fd_executor_txn_check( fd_exec_txn_ctx_t * txn_ctx ); 103 : 104 : void 105 : fd_txn_reclaim_accounts( fd_exec_txn_ctx_t * txn_ctx ); 106 : 107 : int 108 : fd_executor_is_blockhash_valid_for_age( fd_block_hash_queue_t const * block_hash_queue, 109 : fd_hash_t const * blockhash, 110 : ulong max_age ); 111 : 112 : /* fd_io_strerror converts an FD_EXECUTOR_INSTR_ERR_{...} code into a 113 : human readable cstr. The lifetime of the returned pointer is 114 : infinite and the call itself is thread safe. The returned pointer is 115 : always to a non-NULL cstr. */ 116 : 117 : FD_FN_CONST char const * 118 : fd_executor_instr_strerror( int err ); 119 : 120 : int 121 : fd_executor_load_transaction_accounts( fd_exec_txn_ctx_t * txn_ctx ); 122 : 123 : int 124 : fd_executor_validate_account_locks( fd_exec_txn_ctx_t const * txn_ctx ); 125 : 126 : static inline int 127 : fd_exec_consume_cus( fd_exec_txn_ctx_t * txn_ctx, 128 0 : ulong cus ) { 129 0 : ulong new_cus = txn_ctx->compute_meter - cus; 130 0 : int underflow = (txn_ctx->compute_meter < cus); 131 0 : if( FD_UNLIKELY( underflow ) ) { 132 0 : txn_ctx->compute_meter = 0UL; 133 0 : return FD_EXECUTOR_INSTR_ERR_COMPUTE_BUDGET_EXCEEDED; 134 0 : } 135 0 : txn_ctx->compute_meter = new_cus; 136 0 : return FD_EXECUTOR_INSTR_SUCCESS; 137 0 : } 138 : 139 : /* We expose these only for the fuzzing harness. 140 : Normally you shouldn't be invoking these manually. */ 141 : int 142 : fd_instr_stack_push( fd_exec_txn_ctx_t * txn_ctx, 143 : fd_instr_info_t * instr ); 144 : 145 : int 146 : fd_instr_stack_pop( fd_exec_txn_ctx_t * txn_ctx, 147 : fd_instr_info_t const * instr ); 148 : 149 : FD_PROTOTYPES_END 150 : 151 : #endif /* HEADER_fd_src_flamenco_runtime_fd_executor_h */