Line data Source code
1 : #ifndef HEADER_fd_src_flamenco_runtime_fd_runtime_h
2 : #define HEADER_fd_src_flamenco_runtime_fd_runtime_h
3 :
4 : #include "../fd_flamenco_base.h"
5 : #include "fd_runtime_err.h"
6 : #include "fd_runtime_init.h"
7 : #include "fd_rocksdb.h"
8 : #include "fd_acc_mgr.h"
9 : #include "../features/fd_features.h"
10 : #include "fd_rent_lists.h"
11 : #include "../../ballet/poh/fd_poh.h"
12 : #include "../leaders/fd_leaders.h"
13 : #include "context/fd_exec_epoch_ctx.h"
14 : #include "context/fd_exec_slot_ctx.h"
15 : #include "context/fd_capture_ctx.h"
16 : #include "info/fd_block_info.h"
17 : #include "info/fd_instr_info.h"
18 : #include "../gossip/fd_gossip.h"
19 : #include "../repair/fd_repair.h"
20 : #include "../../ballet/pack/fd_microblock.h"
21 :
22 : #define DEFAULT_HASHES_PER_TICK 12500
23 0 : #define UPDATED_HASHES_PER_TICK2 17500
24 0 : #define UPDATED_HASHES_PER_TICK3 27500
25 0 : #define UPDATED_HASHES_PER_TICK4 47500
26 0 : #define UPDATED_HASHES_PER_TICK5 57500
27 0 : #define UPDATED_HASHES_PER_TICK6 62500
28 :
29 : #define FD_RUNTIME_TRACE_NONE (0)
30 : #define FD_RUNTIME_TRACE_SAVE (1)
31 : #define FD_RUNTIME_TRACE_REPLAY (2)
32 :
33 0 : #define FD_RUNTIME_NUM_ROOT_BLOCKS (32UL)
34 :
35 379425 : #define FD_FEATURE_ACTIVE(_slot_ctx, _feature_name) (_slot_ctx->slot_bank.slot >= _slot_ctx->epoch_ctx->features. _feature_name)
36 :
37 11370 : #define FD_BLOCKHASH_QUEUE_MAX_ENTRIES (300UL)
38 2496360 : #define FD_RECENT_BLOCKHASHES_MAX_ENTRIES (150UL)
39 :
40 411 : #define FD_RENT_EXEMPT_RENT_EPOCH (ULONG_MAX)
41 :
42 11370 : #define SECONDS_PER_YEAR ((double)(365.242199 * 24.0 * 60.0 * 60.0))
43 :
44 : /* TODO: increase this to default once we have enough memory to support a 95G status cache. */
45 0 : #define MAX_CACHE_TXNS_PER_SLOT (FD_TXNCACHE_DEFAULT_MAX_TRANSACTIONS_PER_SLOT / 8)
46 :
47 : struct fd_execute_txn_task_info {
48 : fd_spad_t * * spads;
49 : fd_exec_txn_ctx_t * txn_ctx;
50 : fd_txn_p_t * txn;
51 : int exec_res;
52 : };
53 : typedef struct fd_execute_txn_task_info fd_execute_txn_task_info_t;
54 :
55 : typedef ulong fd_microblock_txn_iter_t;
56 :
57 : struct fd_microblock_batch_txn_iter {
58 : ulong curr_microblock;
59 : fd_microblock_txn_iter_t microblock_iter;
60 : };
61 :
62 : typedef struct fd_microblock_batch_txn_iter fd_microblock_batch_txn_iter_t;
63 :
64 : struct fd_block_txn_iter {
65 : ulong curr_batch;
66 : fd_microblock_batch_txn_iter_t microblock_batch_iter;
67 : };
68 :
69 : typedef struct fd_block_txn_iter fd_block_txn_iter_t;
70 :
71 : struct fd_raw_block_txn_iter {
72 : ulong remaining_microblocks;
73 : ulong remaining_txns;
74 : ulong curr_offset;
75 : ulong data_sz;
76 :
77 : ulong curr_txn_sz;
78 : };
79 :
80 : typedef struct fd_raw_block_txn_iter fd_raw_block_txn_iter_t;
81 :
82 : /* The prevailing layout we have in the runtime is the meta followed by
83 : the account's data. This struct encodes that layout and asserts that
84 : the alignment requirements of the constituents are satisfied. */
85 : // TODO: Use this struct at allocation sites so it's clear we use this layout
86 : struct __attribute__((packed)) fd_account_rec {
87 : fd_account_meta_t meta;
88 : uchar data[];
89 : };
90 : typedef struct fd_account_rec fd_account_rec_t;
91 1192767 : #define FD_ACCOUNT_REC_ALIGN (8UL)
92 : #define FD_ACCOUNT_REC_DATA_ALIGN (8UL)
93 : FD_STATIC_ASSERT( FD_ACCOUNT_REC_ALIGN>=FD_ACCOUNT_META_ALIGN, account_rec_meta_align );
94 : FD_STATIC_ASSERT( FD_ACCOUNT_REC_ALIGN>=FD_ACCOUNT_REC_DATA_ALIGN, account_rec_data_align );
95 : FD_STATIC_ASSERT( (offsetof(fd_account_rec_t, meta)%FD_ACCOUNT_META_ALIGN)==0, account_rec_meta_offset );
96 : FD_STATIC_ASSERT( (offsetof(fd_account_rec_t, data)%FD_ACCOUNT_REC_DATA_ALIGN)==0, account_rec_data_offset );
97 :
98 : FD_PROTOTYPES_BEGIN
99 :
100 : ulong
101 : fd_runtime_lamports_per_signature( fd_slot_bank_t const * slot_bank );
102 :
103 : ulong
104 : fd_runtime_txn_lamports_per_signature( fd_exec_txn_ctx_t * txn_ctx,
105 : fd_txn_t const * txn_descriptor,
106 : fd_rawtxn_b_t const * txn_raw );
107 :
108 : void
109 : fd_runtime_init_bank_from_genesis( fd_exec_slot_ctx_t * slot_ctx,
110 : fd_genesis_solana_t * genesis_block,
111 : fd_hash_t const * genesis_hash );
112 :
113 : void
114 : fd_runtime_init_program( fd_exec_slot_ctx_t * slot_ctx );
115 :
116 : int
117 : fd_runtime_block_execute_prepare( fd_exec_slot_ctx_t *slot_ctx );
118 :
119 : int
120 : fd_runtime_block_execute( fd_exec_slot_ctx_t * slot_ctx,
121 : fd_capture_ctx_t * capture_ctx,
122 : fd_block_info_t const * block_info );
123 :
124 : int
125 : fd_runtime_microblock_verify( fd_microblock_info_t const * microblock_info,
126 : fd_hash_t const * in_poh_hash,
127 : fd_hash_t * out_poh_hash );
128 :
129 : int
130 : fd_runtime_block_verify( fd_block_info_t const * block_info,
131 : fd_hash_t const * in_poh_hash,
132 : fd_hash_t * out_poh_hash );
133 :
134 : int
135 : fd_runtime_block_verify_tpool( fd_block_info_t const * block_info,
136 : fd_hash_t const * in_poh_hash,
137 : fd_hash_t * out_poh_hash,
138 : fd_valloc_t valloc,
139 : fd_tpool_t * tpool );
140 :
141 : int
142 : fd_runtime_block_prepare( void const * buf,
143 : ulong buf_sz,
144 : fd_valloc_t valloc,
145 : fd_block_info_t * out_block_info );
146 :
147 : ulong
148 : fd_runtime_block_collect_txns( fd_block_info_t const * block_info,
149 : fd_txn_p_t * out_txns );
150 :
151 : int
152 : fd_runtime_block_eval_tpool( fd_exec_slot_ctx_t * slot_ctx,
153 : fd_capture_ctx_t * capture_ctx,
154 : const void * block,
155 : ulong blocklen,
156 : fd_tpool_t * tpool,
157 : ulong scheduler,
158 : ulong * txn_cnt,
159 : fd_spad_t * * spads,
160 : ulong spads_cnt );
161 :
162 : int
163 : fd_runtime_execute_pack_txns( fd_exec_slot_ctx_t * slot_ctx,
164 : fd_spad_t * spad,
165 : fd_capture_ctx_t * capture_ctx,
166 : fd_txn_p_t * txns,
167 : ulong txn_cnt );
168 :
169 : int
170 : fd_runtime_execute_txns_in_waves_tpool( fd_exec_slot_ctx_t * slot_ctx,
171 : fd_capture_ctx_t * capture_ctx,
172 : fd_txn_p_t * txns,
173 : ulong txn_cnt,
174 : fd_tpool_t * tpool,
175 : fd_spad_t * * spads,
176 : ulong spads_cnt );
177 :
178 : void
179 : fd_runtime_calculate_fee ( fd_exec_txn_ctx_t * txn_ctx,
180 : fd_txn_t const * txn_descriptor,
181 : fd_rawtxn_b_t const * txn_raw,
182 : ulong *execution_fee,
183 : ulong *priority_fee );
184 : void
185 : fd_runtime_freeze( fd_exec_slot_ctx_t * slot_ctx );
186 :
187 : ulong
188 : fd_runtime_lamports_per_signature_for_blockhash( fd_exec_slot_ctx_t const * slot_ctx,
189 : fd_hash_t const * blockhash );
190 :
191 : // int
192 : // fd_global_import_solana_manifest( fd_exec_slot_ctx_t * slot_ctx,
193 : // fd_solana_manifest_t * manifest);
194 :
195 :
196 : void
197 : fd_process_new_epoch( fd_exec_slot_ctx_t * slot_ctx,
198 : ulong parent_epoch );
199 :
200 : void
201 : fd_runtime_update_leaders( fd_exec_slot_ctx_t * slot_ctx, ulong slot );
202 :
203 : /* rollback runtime to the state where the given slot just FINISHED executing */
204 : int
205 : fd_runtime_rollback_to( fd_exec_slot_ctx_t * slot_ctx, ulong slot );
206 :
207 : int
208 : fd_runtime_sysvar_cache_load( fd_exec_slot_ctx_t * slot_ctx );
209 :
210 : void
211 : fd_runtime_cleanup_incinerator( fd_exec_slot_ctx_t * slot_ctx );
212 :
213 : int
214 : fd_runtime_prep_and_exec_txns_tpool( fd_exec_slot_ctx_t * slot_ctx,
215 : fd_execute_txn_task_info_t * task_info,
216 : ulong txn_cnt,
217 : fd_tpool_t * tpool );
218 :
219 : int
220 : fd_runtime_prepare_txns( fd_exec_slot_ctx_t * slot_ctx,
221 : fd_execute_txn_task_info_t * task_info,
222 : fd_txn_p_t * txns,
223 : ulong txn_cnt );
224 :
225 : int
226 : fd_runtime_prepare_txns_start( fd_exec_slot_ctx_t * slot_ctx,
227 : fd_execute_txn_task_info_t * task_info,
228 : fd_txn_p_t * txns,
229 : ulong txn_cnt );
230 :
231 : int
232 : fd_runtime_prepare_txns_phase3( fd_exec_slot_ctx_t * slot_ctx,
233 : fd_execute_txn_task_info_t * task_info,
234 : ulong txn_cnt );
235 :
236 : int
237 : fd_runtime_prepare_execute_finalize_txn( fd_exec_slot_ctx_t * slot_ctx,
238 : fd_spad_t * spad,
239 : fd_capture_ctx_t * capture_ctx,
240 : fd_txn_p_t * txn,
241 : fd_execute_txn_task_info_t * task_info );
242 :
243 : int
244 : fd_runtime_block_execute_finalize_tpool( fd_exec_slot_ctx_t * slot_ctx,
245 : fd_capture_ctx_t * capture_ctx,
246 : fd_block_info_t const * block_info,
247 : fd_tpool_t * tpool );
248 :
249 : ulong
250 : fd_runtime_collect_rent_from_account( fd_exec_slot_ctx_t const * slot_ctx,
251 : fd_account_meta_t * acc,
252 : fd_pubkey_t const * key,
253 : ulong epoch );
254 :
255 : void
256 : fd_runtime_execute_txn( fd_execute_txn_task_info_t * task_info );
257 :
258 : void
259 : fd_runtime_pre_execute_check( fd_execute_txn_task_info_t * task_info );
260 :
261 : int
262 : fd_runtime_finalize_txns_tpool( fd_exec_slot_ctx_t * slot_ctx,
263 : fd_capture_ctx_t * capture_ctx,
264 : fd_execute_txn_task_info_t * task_info,
265 : ulong txn_cnt,
266 : fd_tpool_t * tpool );
267 :
268 : int
269 : fd_runtime_finalize_txn( fd_exec_slot_ctx_t * slot_ctx,
270 : fd_capture_ctx_t * capture_ctx,
271 : fd_execute_txn_task_info_t * task_info );
272 :
273 : void
274 : fd_runtime_collect_rent_accounts_prune( ulong slot,
275 : fd_exec_slot_ctx_t * slot_ctx,
276 : fd_capture_ctx_t * capture_ctx );
277 :
278 : void
279 : fd_runtime_read_genesis( fd_exec_slot_ctx_t * slot_ctx,
280 : char const * genesis_filepath,
281 : uchar is_snapshot,
282 : fd_capture_ctx_t * capture_ctx );
283 :
284 : void
285 : fd_runtime_checkpt( fd_capture_ctx_t * capture_ctx,
286 : fd_exec_slot_ctx_t * slot_ctx,
287 : ulong slot );
288 :
289 : fd_microblock_txn_iter_t
290 : fd_microblock_txn_iter_init( fd_microblock_info_t const * microblock_info );
291 :
292 : ulong
293 : fd_microblock_txn_iter_done( fd_microblock_info_t const * microblock_info, fd_microblock_txn_iter_t iter );
294 :
295 : fd_microblock_txn_iter_t
296 : fd_microblock_txn_iter_next( fd_microblock_info_t const * microblock_info FD_PARAM_UNUSED, fd_microblock_txn_iter_t iter );
297 :
298 : fd_txn_p_t *
299 : fd_microblock_txn_iter_ele( fd_microblock_info_t const * microblock_info, fd_microblock_txn_iter_t iter );
300 :
301 : fd_microblock_batch_txn_iter_t
302 : fd_microblock_batch_txn_iter_init( fd_microblock_batch_info_t const * microblock_batch_info );
303 :
304 : ulong
305 : fd_microblock_batch_txn_iter_done( fd_microblock_batch_info_t const * microblock_batch_info, fd_microblock_batch_txn_iter_t iter );
306 :
307 : fd_microblock_batch_txn_iter_t
308 : fd_microblock_batch_txn_iter_next( fd_microblock_batch_info_t const * microblock_batch_info, fd_microblock_batch_txn_iter_t iter );
309 :
310 : fd_txn_p_t *
311 : fd_microblock_batch_txn_iter_ele( fd_microblock_batch_info_t const * microblock_batch_info, fd_microblock_batch_txn_iter_t iter );
312 :
313 : fd_block_txn_iter_t
314 : fd_block_txn_iter_init( fd_block_info_t const * block_info );
315 :
316 : ulong
317 : fd_block_txn_iter_done( fd_block_info_t const * block_info, fd_block_txn_iter_t iter );
318 :
319 : fd_block_txn_iter_t
320 : fd_block_txn_iter_next( fd_block_info_t const * block_info, fd_block_txn_iter_t iter );
321 :
322 : fd_txn_p_t *
323 : fd_block_txn_iter_ele( fd_block_info_t const * block_info, fd_block_txn_iter_t iter );
324 :
325 : fd_raw_block_txn_iter_t
326 : fd_raw_block_txn_iter_init( uchar const * data, ulong data_sz );
327 :
328 : ulong
329 : fd_raw_block_txn_iter_done( fd_raw_block_txn_iter_t iter );
330 :
331 : fd_raw_block_txn_iter_t
332 : fd_raw_block_txn_iter_next( uchar const * data, fd_raw_block_txn_iter_t iter );
333 :
334 : void
335 : fd_raw_block_txn_iter_ele( uchar const * data, fd_raw_block_txn_iter_t iter, fd_txn_p_t * out_txn );
336 :
337 : FD_PROTOTYPES_END
338 :
339 : #endif /* HEADER_fd_src_flamenco_runtime_fd_runtime_h */
|