Line data Source code
1 : #include "fd_runtime_err.h"
2 : #include "fd_rocksdb.h"
3 : #include "fd_acc_mgr.h"
4 : #include "fd_hashes.h"
5 : #include "fd_txncache.h"
6 : #include "fd_compute_budget_details.h"
7 : #include "fd_cost_tracker.h"
8 : #include "context/fd_exec_instr_ctx.h"
9 : #include "info/fd_instr_info.h"
10 : #include "../features/fd_features.h"
11 : #include "../capture/fd_capture_ctx.h"
12 : #include "../../disco/pack/fd_pack.h"
13 : #include "../../ballet/sbpf/fd_sbpf_loader.h"
14 :
15 : #ifndef HEADER_fd_src_flamenco_runtime_fd_runtime_helpers_h
16 : #define HEADER_fd_src_flamenco_runtime_fd_runtime_helpers_h
17 :
18 : /* Return data for syscalls */
19 :
20 : struct fd_txn_return_data {
21 : fd_pubkey_t program_id;
22 : ulong len;
23 : uchar data[1024];
24 : };
25 : typedef struct fd_txn_return_data fd_txn_return_data_t;
26 :
27 : /* fd_exec_txn_ctx_t is the context needed to execute a transaction. */
28 :
29 : FD_PROTOTYPES_BEGIN
30 :
31 : /* Returns 0 on success, and non zero otherwise. On failure, the out
32 : values will not be modified. */
33 : int
34 : fd_runtime_compute_max_tick_height( ulong ticks_per_slot,
35 : ulong slot,
36 : ulong * out_max_tick_height /* out */ );
37 :
38 : void
39 : fd_runtime_update_leaders( fd_bank_t * bank,
40 : fd_runtime_stack_t * runtime_stack );
41 :
42 : /* Load the accounts in the address lookup tables of txn into out_accts_alt */
43 : int
44 : fd_runtime_load_txn_address_lookup_tables( fd_txn_t const * txn,
45 : uchar const * payload,
46 : fd_accdb_user_t * accdb,
47 : fd_funk_txn_xid_t const * xid,
48 : ulong slot,
49 : fd_slot_hash_t const * hashes, /* deque */
50 : fd_acct_addr_t * out_accts_alt );
51 :
52 : /* fd_runtime_new_fee_rate_governor_derived updates the bank's
53 : FeeRateGovernor to a new derived value based on the parent bank's
54 : FeeRateGovernor and the latest_signatures_per_slot.
55 : https://github.com/anza-xyz/solana-sdk/blob/badc2c40071e6e7f7a8e8452b792b66613c5164c/fee-calculator/src/lib.rs#L97-L157
56 :
57 : latest_signatures_per_slot is typically obtained from the parent
58 : slot's signature count for the bank being processed.
59 :
60 : The fee rate governor is deprecated in favor of FeeStructure in
61 : transaction fee calculations but we still need to maintain the old
62 : logic for recent blockhashes sysvar (and nonce logic that relies on
63 : it). Thus, a separate bank field, `rbh_lamports_per_sig`, tracks the
64 : updates to the fee rate governor derived lamports-per-second value.
65 :
66 : Relevant links:
67 : - Deprecation issue tracker:
68 : https://github.com/anza-xyz/agave/issues/3303
69 : - PR that deals with disambiguation between FeeStructure and
70 : FeeRateGovernor in SVM: https://github.com/anza-xyz/agave/pull/3216
71 : */
72 : void
73 : fd_runtime_new_fee_rate_governor_derived( fd_bank_t * bank,
74 : ulong latest_signatures_per_slot );
75 :
76 : void
77 : fd_runtime_read_genesis( fd_banks_t * banks,
78 : fd_bank_t * bank,
79 : fd_accdb_user_t * accdb,
80 : fd_funk_txn_xid_t const * xid,
81 : fd_capture_ctx_t * capture_ctx,
82 : fd_hash_t const * genesis_hash,
83 : fd_lthash_value_t const * genesis_lthash,
84 : fd_genesis_t const * genesis_block,
85 : fd_runtime_stack_t * runtime_stack );
86 :
87 : /* Error logging handholding assertions */
88 :
89 : #ifdef FD_RUNTIME_ERR_HANDHOLDING
90 :
91 : /* Asserts that the error and error kind are not populated (zero) */
92 : #define FD_TXN_TEST_ERR_OVERWRITE( txn_out ) \
93 : FD_TEST( !txn_out->err.exec_err ); \
94 : FD_TEST( !txn_out->err.exec_err_kind )
95 :
96 : /* Used prior to a FD_TXN_ERR_FOR_LOG_INSTR call to deliberately
97 : bypass overwrite handholding checks.
98 : Only use this if you know what you're doing. */
99 : #define FD_TXN_PREPARE_ERR_OVERWRITE( txn_out ) \
100 : txn_out->err.exec_err = 0; \
101 : txn_out->err.exec_err_kind = 0
102 :
103 : #else
104 :
105 0 : #define FD_TXN_TEST_ERR_OVERWRITE( txn_out ) ( ( void )0 )
106 0 : #define FD_TXN_PREPARE_ERR_OVERWRITE( txn_out ) ( ( void )0 )
107 :
108 : #endif
109 :
110 0 : #define FD_TXN_ERR_FOR_LOG_INSTR( txn_out, err_, idx ) (__extension__({ \
111 0 : FD_TXN_TEST_ERR_OVERWRITE( txn_out ); \
112 0 : txn_out->err.exec_err = err_; \
113 0 : txn_out->err.exec_err_kind = FD_EXECUTOR_ERR_KIND_INSTR; \
114 0 : txn_out->err.exec_err_idx = idx; \
115 0 : }))
116 :
117 : int
118 : fd_runtime_find_index_of_account( fd_txn_out_t const * txn_out,
119 : fd_pubkey_t const * pubkey );
120 :
121 : typedef int fd_txn_account_condition_fn_t ( fd_txn_in_t const * txn_in,
122 : fd_txn_out_t * txn_out,
123 : ushort idx );
124 :
125 : /* Mirrors Agave function solana_sdk::transaction_context::get_account_at_index
126 :
127 : Takes a function pointer to a condition function to check pre-conditions on the
128 : obtained account. If the condition function is NULL, the account is returned without
129 : any pre-condition checks.
130 :
131 : https://github.com/anza-xyz/agave/blob/v2.1.14/sdk/src/transaction_context.rs#L223-L230 */
132 :
133 : int
134 : fd_runtime_get_account_at_index( fd_txn_in_t const * txn_in,
135 : fd_txn_out_t * txn_out,
136 : ushort idx,
137 : fd_txn_account_condition_fn_t * condition );
138 :
139 : /* A wrapper around fd_exec_txn_ctx_get_account_at_index that obtains an
140 : account from the transaction context by its pubkey. */
141 :
142 : int
143 : fd_runtime_get_account_with_key( fd_txn_in_t const * txn_in,
144 : fd_txn_out_t * txn_out,
145 : fd_pubkey_t const * pubkey,
146 : int * index_out,
147 : fd_txn_account_condition_fn_t * condition );
148 :
149 : /* Gets an executable (program data) account via its pubkey. */
150 :
151 : int
152 : fd_runtime_get_executable_account( fd_runtime_t * runtime,
153 : fd_txn_in_t const * txn_in,
154 : fd_txn_out_t * txn_out,
155 : fd_pubkey_t const * pubkey,
156 : fd_account_meta_t const * * meta );
157 :
158 : /* Mirrors Agave function solana_sdk::transaction_context::get_key_of_account_at_index
159 :
160 : https://github.com/anza-xyz/agave/blob/v2.1.14/sdk/src/transaction_context.rs#L212 */
161 :
162 : int
163 : fd_runtime_get_key_of_account_at_index( fd_txn_out_t * txn_out,
164 : ushort idx,
165 : fd_pubkey_t const * * key );
166 :
167 : /* In agave, the writable accounts cache is populated by this below function.
168 : This cache is then referenced to determine if a transaction account is
169 : writable or not.
170 :
171 : The overall logic is as follows: an account can be passed
172 : in as writable based on the signature and readonly signature as they are
173 : passed in by the transaction message. However, the account's writable
174 : status will be demoted if either of the two conditions are met:
175 : 1. If the account is in the set of reserved pubkeys
176 : 2. If the account is the program id AND the upgradeable loader account is in
177 : the set of transaction accounts. */
178 : /* https://github.com/anza-xyz/agave/blob/v2.1.1/sdk/program/src/message/versions/v0/loaded.rs#L137-L150 */
179 :
180 : int
181 : fd_runtime_account_is_writable_idx( fd_txn_in_t const * txn_in,
182 : fd_txn_out_t const * txn_out,
183 : fd_bank_t * bank,
184 : ushort idx );
185 :
186 : /* Account pre-condition filtering functions
187 :
188 : Used to filter accounts based on pre-conditions such as existence, is_writable, etc.
189 : when obtaining accounts from the transaction context. Passed as a function pointer. */
190 :
191 : int
192 : fd_runtime_account_check_exists( fd_txn_in_t const * txn_in,
193 : fd_txn_out_t * txn_out,
194 : ushort idx );
195 :
196 : /* The fee payer is a valid modifiable account if it is passed in as writable
197 : in the message via a valid signature. We ignore if the account has been
198 : demoted or not (see fd_exec_txn_ctx_account_is_writable_idx) for more details.
199 : Agave and Firedancer will reject the fee payer if the transaction message
200 : doesn't have a writable signature. */
201 :
202 : int
203 : fd_runtime_account_check_fee_payer_writable( fd_txn_in_t const * txn_in,
204 : fd_txn_out_t * txn_out,
205 : ushort idx );
206 :
207 : int
208 : fd_account_meta_checked_sub_lamports( fd_account_meta_t * meta,
209 : ulong lamports );
210 :
211 : FD_FN_UNUSED static void
212 : fd_account_meta_resize( fd_account_meta_t * meta,
213 0 : ulong dlen ) {
214 0 : ulong old_sz = meta->dlen;
215 0 : ulong new_sz = dlen;
216 0 : ulong memset_sz = fd_ulong_sat_sub( new_sz, old_sz );
217 0 : fd_memset( fd_account_data( meta ) + old_sz, 0, memset_sz );
218 0 : meta->dlen = (uint)dlen;
219 0 : }
220 :
221 : FD_PROTOTYPES_END
222 :
223 : #endif /* HEADER_fd_src_flamenco_runtime_fd_runtime_helpers_h */
|