Line data Source code
1 : #ifndef HEADER_fd_src_discof_replay_fd_sched_h
2 : #define HEADER_fd_src_discof_replay_fd_sched_h
3 :
4 : #include "fd_rdisp.h"
5 : #include "../../flamenco/alpenglow/fd_block_marker.h"
6 : #include "../../disco/fd_txn_p.h"
7 : #include "../../disco/store/fd_store.h" /* for fd_store_fec_t */
8 : #include "../../flamenco/accdb/fd_accdb.h"
9 : #include "../../disco/fd_clock_tile.h"
10 : #include "../../ballet/lthash/fd_lthash.h"
11 : #include "../../ballet/ed25519/fd_ed25519_verifier.h"
12 :
13 : /* fd_sched schedules replay work across a fork tree. It uses fd_rdisp
14 : to order conflicting transactions and adds fork-aware lane
15 : management, out-of-band signature verification, out-of-band LtHash,
16 : and various block validity checks as well as block boundary work.
17 :
18 : Conceptually, transactions in a block form a DAG. We would like to
19 : make our way through a block with a sufficient degree of parallelism,
20 : such that the execution time of the critical path of the DAG is the
21 : limiting factor. The dispatcher does a good job of emerging the
22 : critical path of the DAG on the fly. Blocks are tracked by the
23 : dispatcher either as a block staged on a lane, or as an unstaged
24 : block. When a block is staged, it will enjoy the most intelligent
25 : online scheduling that the dispatcher has to offer. Lanes have to
26 : consist of linear chains of blocks down a fork. So to map a fork
27 : tree to lanes, we will need multiple lanes. Ideally, every branch in
28 : the fork tree sits on some lane. However, memory footprint limits us
29 : to a few number of lanes.
30 :
31 : This module implements a state machine for ensuring that blocks enter
32 : into and exit out of lanes in an orderly fashion. The public APIs of
33 : this module are invoked to drive state transitions on a small number
34 : of events, such as new transactions arriving, or transactions
35 : completing, or a block being aborted/abandoned. We also implement
36 : policies for deciding which blocks get staged onto lanes, or evicted
37 : from lanes, as well as which lanes to prioritize for execution.
38 :
39 : To further enhance performance, the scheduler has a policy of placing
40 : one block per lane. So rather than treating lanes as lanes, we treat
41 : them as parking spots. Callers are encouraged to check for lane
42 : availability before inserting new blocks. A new block inserted when
43 : every lane is taken gets the lane of an idle block if there is one,
44 : and is unstaged otherwise. See fd_sched_fec_waits_for_lane().
45 :
46 : Callers ingest FEC sets, poll fd_sched_task_next_ready(), and return
47 : each result through fd_sched_task_done(). BLOCK_START and BLOCK_END
48 : tasks bracket the caller's block processing. */
49 :
50 : struct fd_sched;
51 : typedef struct fd_sched fd_sched_t;
52 :
53 : /* Max microblocks (including ticks) that fit in a block's shreds;
54 : scaled with max_shreds_per_block at runtime. */
55 1007 : #define FD_SCHED_MAX_MBLK_PER_SLOT (FD_SHRED_DATA_PAYLOAD_MAX_PER_SLOT/sizeof(fd_microblock_hdr_t))
56 :
57 23167 : #define FD_SCHED_MAX_STAGING_LANES_LOG (2)
58 23167 : #define FD_SCHED_MAX_STAGING_LANES (1UL<<FD_SCHED_MAX_STAGING_LANES_LOG)
59 :
60 0 : #define FD_SCHED_MIN_DEPTH 478
61 : #define FD_SCHED_MAX_DEPTH FD_RDISP_MAX_DEPTH
62 :
63 5036 : #define FD_SCHED_MAX_EXEC_TILE_CNT (64UL)
64 :
65 : /* Out-of-band LtHash batch size, at most FD_EXECRP_LTHASH_BATCH_MAX.
66 : This seems to be a sweet spot in scheduling overhead vs task
67 : granularity. */
68 0 : #define FD_SCHED_LTHASH_BATCH_MAX (32UL)
69 :
70 : /* While a transaction of the block is in flight, a batch carries at
71 : most this many accounts, so that the tile it takes is free again
72 : soon. Otherwise, a batch is allowed to carry up to
73 : FD_SCHED_LTHASH_BATCH_MAX accounts. */
74 0 : #define FD_SCHED_LTHASH_BATCH_BUSY_MAX (8UL)
75 :
76 : /* A staged fec_eos block turns its owed additions into pseudo
77 : transactions this many at a time. */
78 0 : #define FD_SCHED_LTHASH_DRAIN_CHUNK (64UL)
79 :
80 : /* Bounds on the writable accounts a block declares in its transactions
81 : and writes in start-of-block processing. The 8k for inflation
82 : rewards is twice the per-block target of 4096. A partition's size is
83 : binomial with a mean of at most the target, and exceeding 8k is a
84 : super high deviation event. Only a warmup epoch, which pays every
85 : stake account in a single partition, could potentially escape that
86 : bound.
87 :
88 : FIXME These should scale with CU and block time. */
89 1007 : #define FD_SCHED_LTHASH_TXN_WRITERS_MAX (200802UL)
90 0 : #define FD_SCHED_LTHASH_START_WRITES_MAX (FD_RDISP_MAX_WRITERS_PER_BLOCK-FD_SCHED_LTHASH_TXN_WRITERS_MAX)
91 :
92 : struct fd_sched_alut_ctx {
93 : fd_accdb_t * accdb;
94 : fd_accdb_fork_id_t fork_id;
95 : ulong els; /* Effective lookup slot. */
96 : };
97 : typedef struct fd_sched_alut_ctx fd_sched_alut_ctx_t;
98 :
99 : struct fd_sched_fec {
100 : ulong bank_idx; /* Index of the block. Assumed to be in [0, block_cnt_max). Caller
101 : is responsible for ensuring that bank idx is in bounds and unique
102 : across equivocated blocks. */
103 : ulong parent_bank_idx; /* Index of the parent block. Assumed to be in [0, block_cnt_max).
104 : Caller is responsible for ensuring that parent bank idx is in
105 : bounds and unique across equivocated blocks. */
106 : ulong slot; /* Slot number of the block. */
107 : ulong parent_slot; /* Slot number of the parent block. */
108 : fd_store_fec_t * fec; /* FEC set metadata. */
109 : uchar * data; /* Resolved laddr of the FEC set data buffer. */
110 : uint shred_cnt; /* Number of shreds in the FEC set. */
111 : uint is_last_in_batch:1; /* Set if this is the last FEC set in the batch; relevant because the
112 : parser should ignore trailing bytes at the end of a batch. */
113 : uint is_last_in_block:1; /* Set if this is the last FEC set in the block. */
114 : uint is_first_in_block:1; /* Set if this is the first FEC set in the block. Bank should increment refcnt for sched if such a FEC set has been ingested by sched. */
115 : uint starts_at_update_parent:1; /* Set with is_first_in_block if replay starts the block at its UpdateParent FEC set, skipping the abandoned prefix. The block must then open with an UpdateParent naming parent_slot. */
116 : long completed_ns; /* Network arrival (wallclock ns) of the shred that completed this FEC set; 0 if unavailable. */
117 :
118 : fd_sched_alut_ctx_t alut_ctx[ 1 ];
119 : };
120 : typedef struct fd_sched_fec fd_sched_fec_t;
121 :
122 : /* The state of a transaction. Non mutually exclusive. */
123 0 : #define FD_SCHED_TXN_EXEC_DONE (0x0001UL)
124 0 : #define FD_SCHED_TXN_SIGVERIFY_DONE (0x0002UL)
125 0 : #define FD_SCHED_TXN_IS_COMMITTABLE (0x0004UL)
126 0 : #define FD_SCHED_TXN_IS_FEES_ONLY (0x0008UL)
127 0 : #define FD_SCHED_TXN_IS_NOOP (0x0010UL)
128 1542 : #define FD_SCHED_TXN_ALT_UNRESOLVED (0x0020UL)
129 : #define FD_SCHED_TXN_REPLAY_DONE (FD_SCHED_TXN_EXEC_DONE|FD_SCHED_TXN_SIGVERIFY_DONE)
130 :
131 : struct fd_sched_txn_info {
132 : ulong flags;
133 : int txn_err;
134 : uint next_idx;
135 : long received_ns;
136 :
137 : /* LONG_MAX if stage was not reached */
138 : long tick_parsed;
139 : long tick_sigverify_disp;
140 : long tick_sigverify_done;
141 : long tick_exec_disp;
142 : long tick_exec_done;
143 : long tick_load_start;
144 : long tick_check_start;
145 : long tick_exec_start;
146 : long tick_commit_start;
147 : long tick_commit_end;
148 :
149 : ulong slot;
150 : ulong bank_seq;
151 : ulong index_in_slot; /* 0-indexed position of this transaction within its block. */
152 : ulong exec_tile_idx;
153 : ulong sigverify_exec_tile_idx;
154 : uint compute_units_consumed; /* possibly zero if is_committable is zero */
155 : ulong max_compute_units;
156 : ulong transaction_fee;
157 : ulong priority_fee;
158 : ulong tips;
159 : };
160 : typedef struct fd_sched_txn_info fd_sched_txn_info_t;
161 :
162 : /* The scheduler may return one of the following types of tasks for the
163 : replay tile.
164 :
165 : e - passed down to exec tiles.
166 : i - replay completes the task immediately.
167 : q - replay may either do it immediately or queue the task up. */
168 0 : #define FD_SCHED_TT_NULL (0UL)
169 0 : #define FD_SCHED_TT_BLOCK_START (1UL) /* (i) Start-of-block processing. */
170 0 : #define FD_SCHED_TT_BLOCK_END (2UL) /* (q) End-of-block processing. */
171 0 : #define FD_SCHED_TT_TXN_EXEC (3UL) /* (e) Transaction execution. */
172 0 : #define FD_SCHED_TT_TXN_SIGVERIFY (4UL) /* (e) Transaction sigverify. */
173 0 : #define FD_SCHED_TT_LTHASH_SUB (5UL) /* (e) Hash an account from the parent fork and subtract. */
174 0 : #define FD_SCHED_TT_POH_HASH (6UL) /* (e) PoH hashing. */
175 0 : #define FD_SCHED_TT_MARK_DEAD (7UL) /* (i) Mark the block dead. */
176 0 : #define FD_SCHED_TT_CERT_VERIFY (8UL) /* (e) Footer cert verify. */
177 0 : #define FD_SCHED_TT_LTHASH_ADD (9UL) /* (e) Hash an account from this fork and add. */
178 0 : #define FD_SCHED_TT_REWARDS (10UL) /* (e) Footer vote rewards slice. */
179 :
180 : /* Slot-level replay states. States are tracked for one block at a
181 : time, the one the scheduler is working on. A block's interval opens
182 : at its first dispatch (BLOCK_START). It closes when another block's
183 : interval opens, or when end of block processing completes or the
184 : block dies. A block deactivated while waiting on the network stays
185 : tracked until another block takes over.
186 :
187 : BLOCKED_TILES no exec tile is free
188 : BLOCKED_CONFLICTS txns queued, but waiting on in-flight conflicting txns
189 : BLOCKED_NETWORK no txns queued, waiting for more to arrive
190 : FINISH end of the slot received, txns or PoH still in flight
191 :
192 : States are only reevaluated on FEC ingest, task_next_ready and
193 : task_done. A new state is committed only once it has held for at
194 : least FD_SCHED_SLOT_STATE_DEBOUNCE_NS. */
195 :
196 0 : #define FD_SCHED_SLOT_STATE_NONE (0)
197 0 : #define FD_SCHED_SLOT_STATE_BLOCKED_TILES (1)
198 0 : #define FD_SCHED_SLOT_STATE_BLOCKED_CONFLICTS (2)
199 0 : #define FD_SCHED_SLOT_STATE_BLOCKED_NETWORK (3)
200 0 : #define FD_SCHED_SLOT_STATE_FINISH (4)
201 :
202 1007 : #define FD_SCHED_SLOT_STATE_DEBOUNCE_NS (10000L)
203 :
204 : /* Max state transitions between after_credit drains. The real bound
205 : is ~3, but a tight bound needs an exhaustive proof tightly coupled
206 : to the sched state machine. Filled buffer is handled gracefully. */
207 : #define FD_SCHED_SLOT_STATE_MAX (32UL)
208 :
209 : struct fd_sched_slot_state {
210 : ulong slot;
211 : long start_tick;
212 : long end_tick;
213 : ulong state; /* FD_SCHED_SLOT_STATE_* */
214 : };
215 : typedef struct fd_sched_slot_state fd_sched_slot_state_t;
216 :
217 : struct fd_sched_block_start {
218 : ulong bank_idx; /* Same as in fd_sched_fec_t. */
219 : ulong parent_bank_idx; /* Same as in fd_sched_fec_t. */
220 : ulong slot; /* Slot number of the block. */
221 : int lthash_inband; /* 1 if the block hashes in band, 0 if out of band. An in-band block
222 : reports no start-of-block writes and has no delta to fold from
223 : sched at its end. */
224 : };
225 : typedef struct fd_sched_block_start fd_sched_block_start_t;
226 :
227 : struct fd_sched_block_end {
228 : ulong bank_idx;
229 : };
230 : typedef struct fd_sched_block_end fd_sched_block_end_t;
231 :
232 : struct fd_sched_txn_exec {
233 : ulong bank_idx;
234 : ulong slot;
235 : ulong txn_idx;
236 : ulong exec_idx;
237 : };
238 : typedef struct fd_sched_txn_exec fd_sched_txn_exec_t;
239 :
240 : /* A sigverify task takes up to FD_SCHED_SIGVERIFY_SIG_PARA consecutive
241 : transactions of one block, whose signatures fill the group the exec
242 : tile verifies together; a transaction with more signatures than a
243 : group goes alone. Every transaction carries a signature, so a group
244 : holds at most FD_ED25519_VERIFIER_GROUP transactions. */
245 : #define FD_SCHED_SIGVERIFY_SIG_PARA FD_ED25519_VERIFIER_GROUP
246 : struct fd_sched_txn_sigverify {
247 : ulong bank_idx;
248 : ulong exec_idx;
249 : ulong cnt;
250 : ulong txn_idx[ FD_SCHED_SIGVERIFY_SIG_PARA ];
251 : };
252 : typedef struct fd_sched_txn_sigverify fd_sched_txn_sigverify_t;
253 :
254 0 : #define FD_SCHED_POH_PARA 16
255 : struct fd_sched_poh_hash {
256 : ulong bank_idx;
257 : ulong exec_idx;
258 : ulong cnt; /* In [1,FD_SCHED_POH_PARA] */
259 : ulong hashcnt; /* 0 or 1, same for every element of the batch */
260 : ulong mblk_idx[ FD_SCHED_POH_PARA ];
261 : fd_hash_t hash [ FD_SCHED_POH_PARA ];
262 : };
263 : typedef struct fd_sched_poh_hash fd_sched_poh_hash_t;
264 :
265 : struct fd_sched_mark_dead {
266 : ulong bank_idx;
267 : };
268 : typedef struct fd_sched_mark_dead fd_sched_mark_dead_t;
269 :
270 : struct fd_sched_lthash_task {
271 : ulong bank_idx;
272 : ulong exec_idx;
273 : ulong cnt; /* In [1,FD_SCHED_LTHASH_BATCH_MAX] */
274 : fd_acct_addr_t const * accts; /* Points into sched memory that stays as it is until the task completes. */
275 : };
276 : typedef struct fd_sched_lthash_task fd_sched_lthash_task_t;
277 :
278 : /* A footer cert verify task. Between the footer's parse and BLOCK_END,
279 : fd_sched_task_next_ready may return one when no transaction is ready,
280 : one cert per task. */
281 : struct fd_sched_cert_task {
282 : ulong bank_idx;
283 : ulong cert_idx; /* The cert's index in fd_alpenglow_footer_certs order. */
284 : ulong exec_idx; /* Target tile. */
285 : };
286 : typedef struct fd_sched_cert_task fd_sched_cert_task_t;
287 :
288 : /* The writable lookup table accounts of a completed TXN_EXEC task that
289 : was flagged FD_SCHED_TXN_ALT_UNRESOLVED. */
290 : struct fd_sched_txn_alts {
291 : ulong cnt;
292 : fd_acct_addr_t const * addrs;
293 : };
294 : typedef struct fd_sched_txn_alts fd_sched_txn_alts_t;
295 :
296 : struct fd_sched_task {
297 : ulong task_type; /* Set to one of the task types defined above. */
298 : union {
299 : fd_sched_block_start_t block_start[ 1 ];
300 : fd_sched_block_end_t block_end[ 1 ];
301 : fd_sched_txn_exec_t txn_exec[ 1 ];
302 : fd_sched_txn_sigverify_t txn_sigverify[ 1 ];
303 : fd_sched_poh_hash_t poh_hash[ 1 ];
304 : fd_sched_mark_dead_t mark_dead[ 1 ];
305 : fd_sched_lthash_task_t lthash[ 1 ];
306 : fd_sched_cert_task_t cert_verify[ 1 ];
307 : };
308 : };
309 : typedef struct fd_sched_task fd_sched_task_t;
310 :
311 :
312 16724 : #define FD_SCHED_DEAD_REASON_NONE (0) /* Block was not ruled invalid by the scheduler. The replay tile may still rule it invalid, unbeknownst to the scheduler. */
313 0 : #define FD_SCHED_DEAD_REASON_UNPARSEABLE_CONTENT (1) /* Bytes at the head of the stream failed to parse out as any structure (transaction, microblock header, or count) within the largest size a valid block allows: malformed content. */
314 2 : #define FD_SCHED_DEAD_REASON_SHORT_BLOCK (2) /* Block bytes ended short of the microblocks and transactions declared. */
315 0 : #define FD_SCHED_DEAD_REASON_TOO_MANY_TXNS (3) /* More transactions than a valid block can hold. */
316 0 : #define FD_SCHED_DEAD_REASON_TOO_MANY_MICROBLOCKS (4) /* More microblocks than a valid block can hold. */
317 0 : #define FD_SCHED_DEAD_REASON_DUPLICATE_ACCOUNT (5) /* Transaction referenced the same account more than once. */
318 0 : #define FD_SCHED_DEAD_REASON_TRAILING_ENTRY (6) /* Block did not end on a tick. */
319 1486 : #define FD_SCHED_DEAD_REASON_TOO_MANY_TICKS (7) /* More ticks than required. */
320 0 : #define FD_SCHED_DEAD_REASON_TOO_FEW_TICKS (8) /* Fewer ticks than required. */
321 0 : #define FD_SCHED_DEAD_REASON_TICK_HASH_MISMATCH (16) /* PoH hash of a tick did not verify. */
322 0 : #define FD_SCHED_DEAD_REASON_ENTRY_HASH_MISMATCH (17) /* PoH hash of a transaction entry did not verify, detected when the entry's PoH hashing task completed. */
323 0 : #define FD_SCHED_DEAD_REASON_ENTRY_HASH_MISMATCH_INGEST (18) /* PoH hash of a transaction entry did not verify, detected at FEC ingest when a later FEC set completed the entry's transactions. */
324 0 : #define FD_SCHED_DEAD_REASON_DEAD_ANCESTOR (19) /* The block went down with its lineage. Whether the lineage was discarded or ruled invalid is distinguished by fd_sched_block_is_discarded. */
325 0 : #define FD_SCHED_DEAD_REASON_BAD_BLOCK_MARKER (20) /* An Alpenglow block marker (header, footer, genesis certificate or update parent) failed to parse or had an unknown kind. */
326 0 : #define FD_SCHED_DEAD_REASON_ALPENGLOW_HASH_CNT (21) /* An Alpenglow block had an entry whose hash count was not exactly one, detected at FEC ingest. */
327 : /* Alpenglow block structure, mirroring agave's BlockComponentProcessor:
328 : header | [genesis cert] | entries* | footer | alpentick */
329 0 : #define FD_SCHED_DEAD_REASON_MISSING_PARENT_MARKER (22) /* An Alpenglow block carried an entry batch or footer before any block header. */
330 0 : #define FD_SCHED_DEAD_REASON_MULTIPLE_BLOCK_HEADERS (23) /* An Alpenglow block carried more than one block header. */
331 0 : #define FD_SCHED_DEAD_REASON_GENESIS_CERT_OUT_OF_ORDER (24) /* An Alpenglow genesis certificate marker did not immediately follow the block header. */
332 0 : #define FD_SCHED_DEAD_REASON_MULTIPLE_BLOCK_FOOTERS (25) /* An Alpenglow block carried more than one block footer. */
333 0 : #define FD_SCHED_DEAD_REASON_ENTRY_AFTER_BLOCK_FOOTER (26) /* An Alpenglow block carried an entry batch other than the alpentick after its footer. */
334 0 : #define FD_SCHED_DEAD_REASON_INVALID_ALPENTICK_POSITION (27) /* An Alpenglow block ended without the alpentick directly after its footer. */
335 0 : #define FD_SCHED_DEAD_REASON_MISSING_BLOCK_FOOTER (28) /* An Alpenglow block ended without a block footer. */
336 0 : #define FD_SCHED_DEAD_REASON_SPURIOUS_UPDATE_PARENT (29) /* An Alpenglow block carried an UpdateParent marker after its header or footer. Agave replays one after the header (before the footer) as a valid block, so that case means replay was handed the abandoned prefix rather than a bad block. */
337 0 : #define FD_SCHED_DEAD_REASON_TOO_MANY_WRITABLE_ACCOUNTS (30) /* The block's transactions declare more writable accounts than a valid block can afford. */
338 0 : #define FD_SCHED_DEAD_REASON_MULTIPLE_UPDATE_PARENTS (31) /* An Alpenglow block carried more than one UpdateParent marker. */
339 0 : #define FD_SCHED_DEAD_REASON_UPDATE_PARENT_MISMATCH (33) /* An Alpenglow block's initial UpdateParent named a parent other than the one replay built it on. */
340 : /* Cause to pass to fd_sched_block_abandon(). A block is considered
341 : invalid when it violates the protocol, so validity is a function of
342 : the block's content. A block may be discarded (temporarily) because
343 : the validator is under resource pressure. A block may be discarded
344 : (permanently) if consensus converged on an alternative fork, which is
345 : done implicitly in fd_sched_root_notify() for the minority forks it
346 : abandons. */
347 0 : #define FD_SCHED_ABANDON_DISCARDED (0)
348 0 : #define FD_SCHED_ABANDON_INVALID (1)
349 :
350 : struct __attribute__((packed)) fd_microblock_hdr {
351 : /* Number of PoH hashes between this and last microblock */
352 : /* 0x00 */ ulong hash_cnt;
353 :
354 : /* PoH state after evaluating this microblock (including all
355 : appends and mixin). The input to the poh calculation of the first
356 : microblock is the last hash of the parent block, otherwise it is the
357 : hash of the previous microblock. */
358 : /* 0x08 */ uchar hash[32];
359 :
360 : /* Number of transactions in this microblock */
361 : /* 0x28 */ ulong txn_cnt;
362 : };
363 : typedef struct fd_microblock_hdr fd_microblock_hdr_t;
364 :
365 : FD_PROTOTYPES_BEGIN
366 :
367 : /* fd_sched_{align,footprint} return the required alignment and
368 : footprint in bytes for a region of memory to be used as a scheduler.
369 : footprint silently returns 0 if params are invalid (thus convenient
370 : to validate params).
371 :
372 : depth controls the reorder buffer transaction count (~1 million
373 : recommended for live replay, ~10k recommended for async replay).
374 : block_cnt_max is the maximum number of blocks that will be tracked by
375 : the scheduler. max_shreds_per_block bounds the data shreds a block
376 : may hold (the shred tile enforces the same limit upstream, sched
377 : asserts it); a block declaring more than max_txn_per_slot
378 : transactions is ruled invalid. FD_SHRED_BLK_MAX and
379 : FD_MAX_TXN_PER_SLOT in production. */
380 :
381 : ulong
382 : fd_sched_align( void );
383 :
384 : ulong
385 : fd_sched_footprint( ulong depth, /* in [FD_SCHED_MIN_DEPTH,FD_SCHED_MAX_DEPTH] */
386 : ulong block_cnt_max, /* >= 1 */
387 : ulong max_shreds_per_block, /* in [1,UINT_MAX] */
388 : ulong max_txn_per_slot ); /* in [1,UINT_MAX] */
389 :
390 : /* fd_sched_new creates a sched object backed by the given memory region
391 : (conforming to align() and footprint()). Returns NULL if any
392 : parameter is invalid. */
393 :
394 : void *
395 : fd_sched_new( void * mem,
396 : fd_rng_t * rng,
397 : ulong depth,
398 : ulong block_cnt_max,
399 : ulong max_shreds_per_block,
400 : ulong max_txn_per_slot,
401 : ulong exec_cnt );
402 :
403 : fd_sched_t *
404 : fd_sched_join( void * mem );
405 :
406 : /* Add the data in the FEC set to the scheduler. If is_last_fec is 1,
407 : then this is the last FEC set in the block. Transactions may span
408 : FEC set boundaries. The scheduler is responsible for incrementally
409 : parsing transactions from concatenated FEC set data. Assumes that
410 : FEC sets are delivered in replay order. That is, forks form a
411 : partial ordering over FEC sets: in-order per fork, but arbitrary
412 : ordering across forks. The fork tree is implied by the stream of
413 : parent-child relationships delivered in FEC sets. Also assumes that
414 : there is enough space in the scheduler to ingest the FEC set. The
415 : caller should generally call fd_sched_fec_can_ingest() first.
416 :
417 : Returns 1 on success, 0 if the block is bad and should be marked
418 : dead. */
419 : FD_WARN_UNUSED int
420 : fd_sched_fec_ingest( fd_sched_t * sched, fd_sched_fec_t * fec );
421 :
422 : /* Check if there is enough space in the scheduler to ingest the data in
423 : the FEC set. Returns 1 if there is, 0 otherwise. This is a cheap
424 : and conservative check. Staging lanes are a separate matter. See
425 : fd_sched_fec_waits_for_lane(). */
426 : int
427 : fd_sched_fec_can_ingest( fd_sched_t * sched, fd_sched_fec_t * fec );
428 :
429 : /* Returns the number of worst-case FEC sets sched can ingest. This is a
430 : cheap and conservative check. */
431 : ulong
432 : fd_sched_can_ingest_cnt( fd_sched_t * sched );
433 :
434 : /* Returns 1 if the caller is advised to delay the ingestion of the FEC
435 : set due to hopefully transient lane shortage, 0 otherwise. A
436 : parent_bank_idx of ULONG_MAX stands for a parent the caller has not
437 : resolved yet, in which case it will be assumed that a lane is needed.
438 : Any other parent_bank_idx must be a block tracked by the scheduler.
439 : A caller that ingests a FEC set anyway against the advice will get
440 : the block unstaged. */
441 : int
442 : fd_sched_fec_waits_for_lane( fd_sched_t * sched, ulong parent_bank_idx, int is_first_in_block );
443 :
444 : /* Returns 1 if sched has no queued or in-flight work, 0 otherwise. A
445 : non-drained scheduler may still return no task while it waits for
446 : in-flight work or advances an LtHash drain. */
447 : int
448 : fd_sched_is_drained( fd_sched_t * sched );
449 :
450 : /* Claims up to cnt idle exec tiles for footer tasks of the active
451 : block, whose BLOCK_END is signaled and not done yet. The tasks
452 : include the cert verifies the scheduler has not sent out as tasks of
453 : its own and the vote reward slices. Returns the claimed tiles, bit i
454 : for tile i. Each completes with
455 :
456 : fd_sched_task_done( FD_SCHED_TT_CERT_VERIFY or FD_SCHED_TT_REWARDS, ULONG_MAX, i, NULL )
457 :
458 : and the block is not done until all tasks have completed. */
459 :
460 : ulong
461 : fd_sched_footer_dispatch( fd_sched_t * sched,
462 : ulong bank_idx,
463 : ulong cnt );
464 :
465 : /* Writes one dispatchable task to out and returns 1, or returns 0 if no
466 : task can be dispatched now. Transaction tasks respect prior
467 : read-write and write-write conflicts. Tasks from different forks may
468 : interleave, but a child does not start until its parent completes.
469 :
470 : LtHash tasks carry up to FD_SCHED_LTHASH_BATCH_MAX accounts. A
471 : subtraction reads the parent fork and an addition reads the block's
472 : fork. The caller returns the account hash sum through
473 : fd_sched_task_done(). */
474 : ulong
475 : fd_sched_task_next_ready( fd_sched_t * sched, fd_sched_task_t * out );
476 :
477 : /* Marks a task complete. Transaction effects must be visible to every
478 : core that could execute a dependent transaction before this call.
479 : data carries late writable lookup table accounts for a transaction,
480 : hash results for PoH and LtHash tasks, and is NULL for the other task
481 : types.
482 :
483 : Returns FD_SCHED_DEAD_REASON_NONE on success or the reason the result
484 : ruled the block invalid.
485 :
486 : If a block has been abandoned or marked dead for any reason, it'll be
487 : pruned the moment in-flight task count hits 0 due to the last task
488 : completing. Then, in the immediate ensuing stem run loop,
489 : fd_sched_pruned_block_next() will return the index for the corresponding bank
490 : so the refcnt can be decremented for sched.
491 :
492 : A sigverify task retires every transaction dispatched to exec_idx;
493 : txn_idx and data are ignored for it.
494 :
495 : The transaction at the given index may be freed upon return from this
496 : function. Nonetheless, as long as there is no intervening FEC
497 : ingestion, it would still be safe to query the transaction using
498 : get_txn(). */
499 : int
500 : fd_sched_task_done( fd_sched_t * sched, ulong task_type, ulong txn_idx, ulong exec_idx, void * data );
501 :
502 : /* Returns the block's LtHash delta accumulated so far. The delta is
503 : final once the block's BLOCK_END task has been handed out. The block
504 : must be tracked by the scheduler and its BLOCK_END must not have
505 : completed. It must hash out of band, which its BLOCK_START task
506 : reports in lthash_inband. A block hashing in band has no delta from
507 : sched. */
508 : fd_lthash_value_t const *
509 : fd_sched_lthash_delta( fd_sched_t * sched, ulong bank_idx );
510 :
511 : /* Inform the scheduler which accounts start-of-block processing wrote
512 : (e.g. sysvars, rewards), so their LtHash can be done out of band.
513 : Call between the block's BLOCK_START task being handed out and its
514 : completion, and only for a block whose BLOCK_START said it hashes out
515 : of band. cnt must not exceed FD_SCHED_LTHASH_START_WRITES_MAX,
516 : duplicates included. */
517 : void
518 : fd_sched_block_start_writes( fd_sched_t * sched, ulong bank_idx, fd_acct_addr_t const * addrs, ulong cnt );
519 :
520 : /* Abandon a block. This means that we are no longer interested in
521 : executing the block. This also implies that any block which chains
522 : off of the provided block shall be abandoned. This is mainly used
523 : when a block is aborted because we decided that it would be a
524 : dead/invalid block, and so there's no point in spending resources
525 : executing it. The scheduler will no longer return transactions from
526 : abandoned blocks for execution. May be called on completed blocks
527 : still tracked by the scheduler. Repeated calls retain the original
528 : abandonment cause.
529 :
530 : For the purposes of bank lifetime management, sched is a subsidiary
531 : of banks. So while sched sets things in motion for a bad block to be
532 : eagerly pruned, banks/replay is the sole initiator of actual pruning.
533 : The way this works is that an abandoned block will have its refcnt
534 : queued for release by sched as soon as, and only if, the block has no
535 : more in-flight tasks associated with it. No sooner, no later. In
536 : the immediate ensuing stem run loop, fd_sched_pruned_block_next() will return
537 : the index for the corresponding bank so the refcnt can be decremented
538 : for sched. After that point, banks will eventually instruct sched to
539 : prune the block, when all other components release their refcnts on
540 : said bank. Then the bank_idx may be recycled for another block.
541 :
542 : Pass FD_SCHED_ABANDON_INVALID if the block is ruled invalid for any
543 : reason, or FD_SCHED_ABANDON_DISCARDED if we are merely giving up on
544 : it without fault, e.g. eviction under resource pressure. Descendants
545 : inherit the flavor: they record DEAD_ANCESTOR, and are marked
546 : discarded iff the lineage was discarded, provided they have no dead
547 : reason of their own. A block that is already going down keeps the
548 : flavor it went down with, so a later abandon cannot re-label it. */
549 : void
550 : fd_sched_block_abandon( fd_sched_t * sched, ulong bank_idx, int cause );
551 :
552 : /* fd_sched_get_dead_reason returns the scheduler's reason (one of
553 : FD_SCHED_DEAD_REASON_*) for why the block at bank_idx went down.
554 : Returns FD_SCHED_DEAD_REASON_NONE if the block itself was merely
555 : discarded (root advance, eviction) or if no block is currently
556 : tracked at bank_idx. Descendants of a discarded lineage carry
557 : DEAD_ANCESTOR like any other lineage death;
558 : fd_sched_block_is_discarded disambiguates discarded from
559 : ruled-invalid. The recorded reason is the first one; later failures
560 : on an already-dead block (e.g. an in-flight PoH task draining after
561 : the block was abandoned) do not overwrite it. */
562 : int
563 : fd_sched_get_dead_reason( fd_sched_t * sched, ulong bank_idx );
564 :
565 : /* fd_sched_block_is_discarded returns 1 if the block went down with a
566 : discarded (not invalid) lineage, 0 otherwise (including when no
567 : block is tracked at bank_idx). Never set on a block that has a dead
568 : reason of its own, so it does not mask the scheduler's own verdict. */
569 : int
570 : fd_sched_block_is_discarded( fd_sched_t * sched, ulong bank_idx );
571 :
572 : /* Prune the given block including descendants of it. */
573 : void
574 : fd_sched_cancel( fd_sched_t * sched, ulong bank_idx );
575 :
576 : /* Add a block as immediately done to the scheduler. This is useful for
577 : installing the snapshot slot, or for informing the scheduler of a
578 : packed leader block. Parent block should be ULONG_MAX for the
579 : snapshot slot, and otherwise a block that hasn't been pruned. */
580 : void
581 : fd_sched_block_add_done( fd_sched_t * sched, ulong bank_idx, ulong parent_bank_idx, ulong slot );
582 :
583 : /* Advance the root, pruning all blocks across forks that do not descend
584 : from the new root. Assumes the new root is in the fork tree and
585 : connected to the current root. Also assumes that there are no more
586 : in-flight transactions from the soon-to-be-pruned blocks. This
587 : should be called after root_notify() and the caller is responsible
588 : for figuring out the new root to safely prune to. */
589 : void
590 : fd_sched_advance_root( fd_sched_t * sched, ulong root_idx );
591 :
592 : /* Notify the scheduler of a new root. This has the effect of calling
593 : abandon() on all minority forks that do not descend from the new
594 : root. Shortly after a call to this function, in-flight transactions
595 : from these abandoned blocks should retire from the execution
596 : pipeline, and the new root will be safe for pruning. */
597 : void
598 : fd_sched_root_notify( fd_sched_t * sched, ulong root_idx );
599 :
600 : /* Returns the index of a bank whose refcnt should be decremented for
601 : sched. This function should be called in a loop to drain all
602 : outstanding refcnt decrements before any other sched API is called in
603 : a stem run loop. Returns ULONG_MAX when there are no more
604 : outstanding references from sched and the loop should break. */
605 : ulong
606 : fd_sched_pruned_block_next( fd_sched_t * sched );
607 :
608 : /* fd_sched_slot_states_drain copies the slot state intervals closed
609 : since the last drain into out (room for FD_SCHED_SLOT_STATE_MAX) and
610 : returns how many were copied. Intervals are in tickcount units. */
611 : ulong
612 : fd_sched_slot_states_drain( fd_sched_t * sched, fd_sched_slot_state_t * out );
613 :
614 : void
615 : fd_sched_set_poh_params( fd_sched_t * sched, ulong bank_idx, ulong tick_height, ulong max_tick_height, fd_hash_t const * start_poh );
616 :
617 : /* fd_sched_set_flh_active records whether alpenglow_fast_leader_handover
618 : is active on the block's bank. Called during BLOCK_START, once the
619 : bank is cloned. A block started at its UpdateParent without the
620 : feature dies as SPURIOUS_UPDATE_PARENT when BLOCK_START is done. */
621 : void
622 : fd_sched_set_flh_active( fd_sched_t * sched, ulong bank_idx, int flh_active );
623 :
624 : /* fd_sched_block_verify_ticks sets the tick window and verifies
625 : ticks on bank_idx (shred fuzz harness, no exec). Returns
626 : FD_SCHED_DEAD_REASON_NONE (0) if valid, else the
627 : FD_SCHED_DEAD_REASON_* the ticks are invalid for. Does not rule the
628 : block invalid; the caller decides what to do with the verdict. */
629 : int
630 : fd_sched_block_verify_ticks( fd_sched_t * sched,
631 : ulong bank_idx,
632 : ulong tick_height,
633 : ulong max_tick_height );
634 :
635 : /* fd_sched_set_bypass_poh_verify configures whether the per-microblock
636 : PoH end_hash comparison in maybe_mixin is bypassed. This is intended
637 : for test and fuzz harnesses: the expected end_hash is carried in the
638 : shred payload, so comparing it would reject any mutated input before
639 : the deeper parse/tick logic is exercised. Production call sites
640 : should leave this disabled. */
641 : void
642 : fd_sched_set_bypass_poh_verify( fd_sched_t * sched, int bypass_poh_verify );
643 :
644 : /* fd_sched_set_bypass_alut_resolution bypasses ALUT resolution during
645 : parsing (test/fuzz: no accounts DB). ALUT txns become serializing.
646 : Production call sites should leave this disabled. */
647 : void
648 : fd_sched_set_bypass_alut_resolution( fd_sched_t * sched, int bypass_alut_resolution );
649 :
650 : /* fd_sched_set_sigverify_group sets the signature count a sigverify
651 : task collects before it goes out, in [1,FD_SCHED_SIGVERIFY_SIG_PARA],
652 : FD_ED25519_VERIFIER_GROUP by default. This is intended for
653 : tests that want a specific grouping. Production call sites should
654 : leave the default. */
655 : void
656 : fd_sched_set_sigverify_group( fd_sched_t * sched, ulong sigverify_group );
657 :
658 : /* fd_sched_set_lthash_txn_writers_max lowers the bound on writable
659 : accounts declared by a block's transactions from
660 : FD_SCHED_LTHASH_TXN_WRITERS_MAX. This is intended for use by tests
661 : to reach the bound with a few transactions. Production code should
662 : not use this. */
663 : void
664 : fd_sched_set_lthash_txn_writers_max( fd_sched_t * sched, ulong lthash_txn_writers_max );
665 :
666 : /* fd_sched_set_lthash_oob_block_max lowers the bound on blocks hashing
667 : out of band at once from the number of demoted blocks' writable sets
668 : the dispatcher has room to park. This is intended for use by tests
669 : to reach the in-band fallback with a few blocks. Production code
670 : should not use this. */
671 : void
672 : fd_sched_set_lthash_oob_block_max( fd_sched_t * sched, ulong lthash_oob_block_max );
673 :
674 : fd_txn_p_t *
675 : fd_sched_get_txn( fd_sched_t * sched, ulong txn_idx );
676 :
677 : fd_sched_txn_info_t *
678 : fd_sched_get_txn_info( fd_sched_t * sched, ulong txn_idx );
679 :
680 : fd_hash_t *
681 : fd_sched_get_poh( fd_sched_t * sched, ulong bank_idx );
682 :
683 : uint
684 : fd_sched_get_shred_cnt( fd_sched_t * sched, ulong bank_idx );
685 :
686 : /* fd_sched_get_footer returns the block footer, or NULL if no footer
687 : marker has been parsed for the block. The shapes were validated at
688 : parse time; the signatures are not verified. The footer stays valid
689 : until the block is pruned. */
690 : fd_block_footer_t const *
691 : fd_sched_get_footer( fd_sched_t * sched, ulong bank_idx );
692 :
693 : void
694 : fd_sched_metrics_write( fd_sched_t * sched,
695 : fd_clock_tile_t const * clock );
696 :
697 : /* Serialize the current state as a cstr to the returned buffer. Caller
698 : may read from the buffer until the next invocation of any fd_sched
699 : function. */
700 : char *
701 : fd_sched_get_state_cstr( fd_sched_t * sched );
702 :
703 : void *
704 : fd_sched_leave( fd_sched_t * sched );
705 :
706 : void *
707 : fd_sched_delete( void * mem );
708 :
709 : FD_PROTOTYPES_END
710 :
711 : #endif /* HEADER_fd_src_discof_replay_fd_sched_h */
|