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/harness/generated/invoke.pb.h" 14 : #include "tests/harness/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_BANK( txn_ctx->bank, 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_exec_instr_fn_t 45 : fd_executor_lookup_native_precompile_program( fd_txn_account_t const * prog_acc ); 46 : 47 : /* Returns 1 if the given pubkey matches one of the BPF loader v1/v2/v3/v4 48 : program IDs, and 0 otherwise. */ 49 : uchar 50 : fd_executor_pubkey_is_bpf_loader( fd_pubkey_t const * pubkey ); 51 : 52 : int 53 : fd_executor_check_transactions( fd_exec_txn_ctx_t * txn_ctx ); 54 : 55 : int 56 : fd_executor_verify_precompiles( fd_exec_txn_ctx_t * txn_ctx ); 57 : 58 : /* fd_execute_instr creates a new fd_exec_instr_ctx_t and performs 59 : instruction processing. Does fd_spad_t allocations. Returns an 60 : error code in FD_EXECUTOR_INSTR_{ERR_{...},SUCCESS}. 61 : 62 : IMPORTANT: instr_info must have the same lifetime as txn_ctx. This can 63 : be achieved by using fd_executor_acquire_instr_info_elem( txn_ctx ) to 64 : acquire an fd_instr_info_t element with the same lifetime as the txn_ctx */ 65 : int 66 : fd_executor_txn_verify( fd_exec_txn_ctx_t * txn_ctx ); 67 : 68 : int 69 : fd_execute_instr( fd_exec_txn_ctx_t * txn_ctx, 70 : fd_instr_info_t * instr_info ); 71 : 72 : int 73 : fd_execute_txn_prepare_start( fd_exec_slot_ctx_t const * slot_ctx, 74 : fd_exec_txn_ctx_t * txn_ctx, 75 : fd_txn_t const * txn_descriptor, 76 : fd_rawtxn_b_t const * txn_raw ); 77 : 78 : /* 79 : Execute the given transaction. 80 : 81 : Makes changes to the Funk accounts DB. */ 82 : int 83 : fd_execute_txn( fd_execute_txn_task_info_t * task_info ); 84 : 85 : int 86 : fd_executor_validate_transaction_fee_payer( fd_exec_txn_ctx_t * txn_ctx ); 87 : 88 : void 89 : fd_executor_setup_accounts_for_txn( fd_exec_txn_ctx_t * txn_ctx ); 90 : 91 : int 92 : fd_executor_setup_accessed_accounts_for_txn( fd_exec_txn_ctx_t * txn_ctx ); 93 : 94 : /* 95 : Validate the txn after execution for violations of various lamport balance and size rules 96 : */ 97 : 98 : int 99 : fd_executor_txn_check( fd_exec_txn_ctx_t * txn_ctx ); 100 : 101 : void 102 : fd_txn_reclaim_accounts( fd_exec_txn_ctx_t * txn_ctx ); 103 : 104 : int 105 : fd_executor_is_blockhash_valid_for_age( fd_block_hash_queue_global_t const * block_hash_queue, 106 : fd_hash_t const * blockhash, 107 : ulong max_age ); 108 : 109 : /* fd_io_strerror converts an FD_EXECUTOR_INSTR_ERR_{...} code into a 110 : human readable cstr. The lifetime of the returned pointer is 111 : infinite and the call itself is thread safe. The returned pointer is 112 : always to a non-NULL cstr. */ 113 : 114 : FD_FN_CONST char const * 115 : fd_executor_instr_strerror( int err ); 116 : 117 : int 118 : fd_executor_load_transaction_accounts( fd_exec_txn_ctx_t * txn_ctx ); 119 : 120 : int 121 : fd_executor_validate_account_locks( fd_exec_txn_ctx_t const * txn_ctx ); 122 : 123 : static inline int 124 : fd_exec_consume_cus( fd_exec_txn_ctx_t * txn_ctx, 125 0 : ulong cus ) { 126 0 : ulong new_cus = txn_ctx->compute_meter - cus; 127 0 : int underflow = (txn_ctx->compute_meter < cus); 128 0 : if( FD_UNLIKELY( underflow ) ) { 129 0 : txn_ctx->compute_meter = 0UL; 130 0 : return FD_EXECUTOR_INSTR_ERR_COMPUTE_BUDGET_EXCEEDED; 131 0 : } 132 0 : txn_ctx->compute_meter = new_cus; 133 0 : return FD_EXECUTOR_INSTR_SUCCESS; 134 0 : } 135 : 136 : /* We expose these only for the fuzzing harness. 137 : Normally you shouldn't be invoking these manually. */ 138 : int 139 : fd_instr_stack_push( fd_exec_txn_ctx_t * txn_ctx, 140 : fd_instr_info_t * instr ); 141 : 142 : int 143 : fd_instr_stack_pop( fd_exec_txn_ctx_t * txn_ctx, 144 : fd_instr_info_t const * instr ); 145 : 146 : void 147 : fd_exec_txn_ctx_from_exec_slot_ctx( fd_exec_slot_ctx_t const * slot_ctx, 148 : fd_exec_txn_ctx_t * ctx, 149 : fd_wksp_t const * funk_wksp, 150 : fd_wksp_t const * runtime_pub_wksp, 151 : ulong funk_txn_gaddr, 152 : ulong funk_gaddr, 153 : fd_bank_hash_cmp_t * bank_hash_cmp ); 154 : 155 : FD_PROTOTYPES_END 156 : 157 : #endif /* HEADER_fd_src_flamenco_runtime_fd_executor_h */