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