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