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 3 : #define FD_EXEC_CU_UPDATE( ctx, cost ) do { \
19 3 : fd_exec_instr_ctx_t * _ctx = (ctx); \
20 3 : int err = fd_executor_consume_cus( _ctx->txn_out, (cost) ); \
21 3 : if( FD_UNLIKELY( err ) ) return err; \
22 3 : } 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_txn_account_t const * prog_acc );
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 * 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 : /*
104 : Validate the txn after execution for violations of various lamport balance and size rules
105 : */
106 :
107 : int
108 : fd_executor_txn_check( fd_bank_t * bank,
109 : fd_txn_out_t * txn_out );
110 :
111 : void
112 : fd_executor_reclaim_account( fd_txn_account_t * account,
113 : ulong slot );
114 :
115 : /* fd_io_strerror converts an FD_EXECUTOR_INSTR_ERR_{...} code into a
116 : human readable cstr. The lifetime of the returned pointer is
117 : infinite and the call itself is thread safe. The returned pointer is
118 : always to a non-NULL cstr. */
119 :
120 : FD_FN_CONST char const *
121 : fd_executor_instr_strerror( int err );
122 :
123 : int
124 : fd_executor_load_transaction_accounts( fd_runtime_t * runtime,
125 : fd_bank_t * bank,
126 : fd_txn_in_t const * txn_in,
127 : fd_txn_out_t * txn_out );
128 :
129 : int
130 : fd_executor_validate_account_locks( fd_bank_t * bank,
131 : fd_txn_out_t const * txn_out );
132 :
133 : int
134 : fd_executor_consume_cus( fd_txn_out_t * txn_out,
135 : ulong cus );
136 :
137 : /* We expose these only for the fuzzing harness.
138 : Normally you shouldn't be invoking these manually. */
139 : int
140 : fd_instr_stack_push( fd_runtime_t * runtime,
141 : fd_txn_in_t const * txn_in,
142 : fd_txn_out_t * txn_out,
143 : fd_instr_info_t * instr );
144 :
145 : int
146 : fd_instr_stack_pop( fd_runtime_t * runtime,
147 : fd_txn_out_t * txn_out,
148 : fd_instr_info_t const * instr );
149 :
150 : FD_PROTOTYPES_END
151 :
152 : #endif /* HEADER_fd_src_flamenco_runtime_fd_executor_h */
|