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 "info/fd_instr_info.h" 5 : #include "sysvar/fd_sysvar_cache.h" 6 : #include "../fd_flamenco_base.h" 7 : #include "../../ballet/txn/fd_txn.h" 8 : #include "../../disco/fd_txn_p.h" 9 : 10 : /* https://github.com/anza-xyz/agave/blob/v2.3.1/svm/src/account_loader.rs#L40-L47 */ 11 0 : #define FD_TRANSACTION_ACCOUNT_BASE_SIZE (64UL) 12 0 : #define FD_ADDRESS_LOOKUP_TABLE_BASE_SIZE (8248UL) 13 : 14 0 : #define FD_FEE_PAYER_TXN_IDX (0UL) 15 : 16 : /* FD_EXEC_CU_UPDATE consumes CUs from the current instr ctx 17 : and fails in case of error. */ 18 27 : #define FD_EXEC_CU_UPDATE( ctx, cost ) do { \ 19 27 : fd_exec_instr_ctx_t * _ctx = (ctx); \ 20 27 : int err = fd_executor_consume_cus( _ctx->txn_out, (cost) ); \ 21 27 : if( FD_UNLIKELY( err ) ) return err; \ 22 27 : } while(0) 23 : 24 : // https://github.com/anza-xyz/agave/blob/2e6ca8c1f62db62c1db7f19c9962d4db43d0d550/sdk/src/fee.rs#L82 25 0 : #define FD_ACCOUNT_DATA_COST_PAGE_SIZE ( 32UL * 1024UL ) 26 : 27 : FD_PROTOTYPES_BEGIN 28 : 29 : /* fd_exec_instr_fn_t processes an instruction. Returns an error code 30 : in FD_EXECUTOR_INSTR_{ERR_{...},SUCCESS}. */ 31 : 32 : typedef int (* fd_exec_instr_fn_t)( fd_exec_instr_ctx_t * ctx ); 33 : 34 : fd_exec_instr_fn_t 35 : fd_executor_lookup_native_precompile_program( fd_pubkey_t const * pubkey ); 36 : 37 : /* Returns 1 if the given pubkey matches one of the BPF loader v1/v2/v3/v4 38 : program IDs, and 0 otherwise. */ 39 : uchar 40 : fd_executor_pubkey_is_bpf_loader( fd_pubkey_t const * pubkey ); 41 : 42 : int 43 : fd_executor_verify_transaction( fd_bank_t const * bank, 44 : fd_txn_in_t const * txn_in, 45 : fd_txn_out_t * txn_out ); 46 : 47 : int 48 : fd_executor_check_transactions( fd_runtime_t * runtime, 49 : fd_bank_t * bank, 50 : fd_txn_in_t const * txn_in, 51 : fd_txn_out_t * txn_out ); 52 : 53 : /* fd_execute_instr creates a new fd_exec_instr_ctx_t and performs 54 : instruction processing. Does fd_spad_t allocations. Returns an 55 : error code in FD_EXECUTOR_INSTR_{ERR_{...},SUCCESS}. 56 : 57 : IMPORTANT: instr_info must have the same lifetime as txn_ctx. This can 58 : be achieved by using fd_executor_acquire_instr_info_elem( txn_ctx ) to 59 : acquire an fd_instr_info_t element with the same lifetime as the txn_ctx */ 60 : int 61 : fd_executor_txn_verify( fd_txn_p_t * txn_p, 62 : fd_sha512_t * shas[ FD_TXN_ACTUAL_SIG_MAX ] ); 63 : 64 : int 65 : fd_execute_instr( fd_runtime_t * runtime, 66 : fd_bank_t * bank, 67 : fd_txn_in_t const * txn_in, 68 : fd_txn_out_t * txn_out, 69 : fd_instr_info_t * instr_info ); 70 : 71 : /* 72 : Execute the given transaction. 73 : 74 : Makes changes to the Funk accounts DB. */ 75 : int 76 : fd_execute_txn( fd_runtime_t * runtime, 77 : fd_bank_t * bank, 78 : fd_txn_in_t const * txn_in, 79 : fd_txn_out_t * txn_out ); 80 : 81 : int 82 : fd_executor_validate_transaction_fee_payer( fd_runtime_t * runtime, 83 : fd_bank_t * bank, 84 : fd_txn_in_t const * txn_in, 85 : fd_txn_out_t * txn_out ); 86 : 87 : void 88 : fd_executor_setup_accounts_for_txn( fd_runtime_t * runtime, 89 : fd_bank_t * bank, 90 : fd_txn_in_t const * txn_in, 91 : fd_txn_out_t * txn_out ); 92 : 93 : void 94 : fd_executor_setup_txn_account_keys( fd_txn_in_t const * txn_in, 95 : fd_txn_out_t * txn_out ); 96 : 97 : int 98 : fd_executor_setup_txn_alut_account_keys( fd_runtime_t * runtime, 99 : fd_bank_t * bank, 100 : fd_txn_in_t const * txn_in, 101 : fd_txn_out_t * txn_out ); 102 : 103 : void 104 : fd_executor_reclaim_account( fd_account_meta_t * meta, 105 : ulong slot ); 106 : 107 : /* fd_io_strerror converts an FD_EXECUTOR_INSTR_ERR_{...} code into a 108 : human readable cstr. The lifetime of the returned pointer is 109 : infinite and the call itself is thread safe. The returned pointer is 110 : always to a non-NULL cstr. */ 111 : 112 : FD_FN_CONST char const * 113 : fd_executor_instr_strerror( int err ); 114 : 115 : int 116 : fd_executor_load_transaction_accounts( fd_runtime_t * runtime, 117 : fd_bank_t * bank, 118 : fd_txn_in_t const * txn_in, 119 : fd_txn_out_t * txn_out ); 120 : 121 : int 122 : fd_executor_validate_account_locks( fd_bank_t * bank, 123 : fd_txn_out_t const * txn_out ); 124 : 125 : int 126 : fd_executor_consume_cus( fd_txn_out_t * txn_out, 127 : ulong cus ); 128 : 129 : /* We expose these only for the fuzzing harness. 130 : Normally you shouldn't be invoking these manually. */ 131 : int 132 : fd_instr_stack_push( fd_runtime_t * runtime, 133 : fd_txn_in_t const * txn_in, 134 : fd_txn_out_t * txn_out, 135 : fd_instr_info_t * instr ); 136 : 137 : int 138 : fd_instr_stack_pop( fd_runtime_t * runtime, 139 : fd_txn_out_t * txn_out, 140 : fd_instr_info_t const * instr ); 141 : 142 : FD_PROTOTYPES_END 143 : 144 : #endif /* HEADER_fd_src_flamenco_runtime_fd_executor_h */