LCOV - code coverage report
Current view: top level - discof/replay - fd_sched.h (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 27 46 58.7 %
Date: 2026-09-17 04:28:31 Functions: 0 0 -

          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 "../../discof/poh/fd_poh.h" /* for MAX_SKIPPED_TICKS */
      10             : 
      11             : /* Microblocks per slot at the production shred limit; scaled with
      12             :    max_shreds_per_block at runtime. */
      13         114 : #define FD_SCHED_MAX_MBLK_PER_SLOT (MAX_SKIPPED_TICKS)
      14             : 
      15             : /* fd_sched wraps all the smarts and mechanical chores around scheduling
      16             :    transactions for replay execution.  It is built on top of the
      17             :    dispatcher fd_rdisp.  The dispatcher is responsible for high
      18             :    performance lane-based scheduling of transactions.  On top of that,
      19             :    we add fork-aware management of lanes, and policies regarding which
      20             :    lanes to prioritize for execution.
      21             : 
      22             :    Conceptually, transactions in a block form a DAG.  We would like to
      23             :    make our way through a block with a sufficient degree of parallelism,
      24             :    such that the execution time of the critical path of the DAG is the
      25             :    limiting factor.  The dispatcher does a good job of emerging the
      26             :    critical path of the DAG on the fly.  Blocks are tracked by the
      27             :    dispatcher either as a block staged on a lane, or as an unstaged
      28             :    block.  When a block is staged, it will enjoy the most intelligent
      29             :    online scheduling that the dispatcher has to offer.  Lanes have to
      30             :    consist of linear chains of blocks down a fork.  So to map a fork
      31             :    tree to lanes, we will need multiple lanes.  Ideally, every branch in
      32             :    the fork tree sits on some lane.  However, memory footprint limits us
      33             :    to a few number of lanes.
      34             : 
      35             :    This module implements a state machine for ensuring that blocks enter
      36             :    into and exit out of lanes in an orderly fashion.  The public APIs of
      37             :    this module are invoked to drive state transitions on a small number
      38             :    of events, such as new transactions arriving, or transactions
      39             :    completing, or a block being aborted/abandoned.  We also implement
      40             :    policies for deciding which blocks get staged onto lanes, or evicted
      41             :    from lanes, as well as which lanes to prioritize for execution.
      42             : 
      43             : 
      44             :    The general order in which calls happen under the normal case is:
      45             : 
      46             :    fd_sched_fec_ingest()* ... fd_sched_txn_next_ready()* ... fd_sched_txn_done()* ...
      47             :    more ingest, more ready, more done ...
      48             :    ...
      49             :    fd_sched_txn_next_ready() indicates that the last transaction in the block is being scheduled
      50             :    fd_sched_txn_done()*
      51             :    fd_sched_block_is_done()
      52             :    end-of-block processing in caller
      53             :    fd_sched_txn_next_ready() starts returning transactions from the next block
      54             :    more ingest, more ready, more done ...
      55             :    ... */
      56             : 
      57          87 : #define FD_SCHED_MIN_DEPTH 478
      58             : #define FD_SCHED_MAX_DEPTH FD_RDISP_MAX_DEPTH
      59             : 
      60             : struct fd_sched;
      61             : typedef struct fd_sched fd_sched_t;
      62             : 
      63             : struct fd_sched_alut_ctx {
      64             :   fd_accdb_t *       accdb;
      65             :   fd_accdb_fork_id_t fork_id;
      66             :   ulong              els; /* Effective lookup slot. */
      67             : };
      68             : typedef struct fd_sched_alut_ctx fd_sched_alut_ctx_t;
      69             : 
      70             : struct fd_sched_fec {
      71             :   ulong            bank_idx;            /* Index of the block.  Assumed to be in [0, block_cnt_max).  Caller
      72             :                                            is responsible for ensuring that bank idx is in bounds and unique
      73             :                                            across equivocated blocks. */
      74             :   ulong            parent_bank_idx;     /* Index of the parent block.  Assumed to be in [0, block_cnt_max).
      75             :                                            Caller is responsible for ensuring that parent bank idx is in
      76             :                                            bounds and unique across equivocated blocks. */
      77             :   ulong            slot;                /* Slot number of the block. */
      78             :   ulong            parent_slot;         /* Slot number of the parent block. */
      79             :   fd_store_fec_t * fec;                 /* FEC set metadata. */
      80             :   uchar          * data;                /* Resolved laddr of the FEC set data buffer. */
      81             :   uint             shred_cnt;           /* Number of shreds in the FEC set. */
      82             :   uint             is_last_in_batch:1;  /* Set if this is the last FEC set in the batch; relevant because the
      83             :                                            parser should ignore trailing bytes at the end of a batch. */
      84             :   uint             is_last_in_block:1;  /* Set if this is the last FEC set in the block. */
      85             :   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. */
      86             :   long             completed_ns;        /* Network arrival (wallclock ns) of the shred that completed this FEC set; 0 if unavailable. */
      87             : 
      88             :   fd_sched_alut_ctx_t alut_ctx[ 1 ];
      89             : };
      90             : typedef struct fd_sched_fec fd_sched_fec_t;
      91             : 
      92             : /* The state of a transaction.  Non mutually exclusive. */
      93          12 : #define FD_SCHED_TXN_EXEC_DONE      (0x0001UL)
      94           9 : #define FD_SCHED_TXN_SIGVERIFY_DONE (0x0002UL)
      95           0 : #define FD_SCHED_TXN_IS_COMMITTABLE (0x0004UL)
      96           0 : #define FD_SCHED_TXN_IS_FEES_ONLY   (0x0008UL)
      97           0 : #define FD_SCHED_TXN_IS_NOOP        (0x0010UL)
      98             : #define FD_SCHED_TXN_REPLAY_DONE    (FD_SCHED_TXN_EXEC_DONE|FD_SCHED_TXN_SIGVERIFY_DONE)
      99             : 
     100             : struct fd_sched_txn_info {
     101             :    ulong flags;
     102             :    int   txn_err;
     103             :    uint  next_idx;
     104             :    long  received_ns;
     105             :    int   is_simple_vote;
     106             : 
     107             :    /* LONG_MAX if stage was not reached */
     108             :    long  tick_parsed;
     109             :    long  tick_sigverify_disp;
     110             :    long  tick_sigverify_done;
     111             :    long  tick_exec_disp;
     112             :    long  tick_exec_done;
     113             :    long  tick_load_start;
     114             :    long  tick_check_start;
     115             :    long  tick_exec_start;
     116             :    long  tick_commit_start;
     117             :    long  tick_commit_end;
     118             : 
     119             :    ulong slot;
     120             :    ulong bank_seq;
     121             :    ulong index_in_slot; /* 0-indexed position of this transaction within its block. */
     122             :    ulong exec_tile_idx;
     123             :    ulong sigverify_exec_tile_idx;
     124             :    uint  compute_units_consumed; /* possibly zero if is_committable is zero */
     125             :    ulong max_compute_units;
     126             :    ulong transaction_fee;
     127             :    ulong priority_fee;
     128             :    ulong tips;
     129             : };
     130             : typedef struct fd_sched_txn_info fd_sched_txn_info_t;
     131             : 
     132             : /* The scheduler may return one of the following types of tasks for the
     133             :    replay tile.
     134             : 
     135             :    e - passed down to exec tiles.
     136             :    i - replay completes the task immediately.
     137             :    q - replay may either do it immediately or queue the task up. */
     138         354 : #define FD_SCHED_TT_NULL          (0UL)
     139         165 : #define FD_SCHED_TT_BLOCK_START   (1UL) /* (i) Start-of-block processing. */
     140         345 : #define FD_SCHED_TT_BLOCK_END     (2UL) /* (q) End-of-block processing. */
     141          45 : #define FD_SCHED_TT_TXN_EXEC      (3UL) /* (e) Transaction execution. */
     142          48 : #define FD_SCHED_TT_TXN_SIGVERIFY (4UL) /* (e) Transaction sigverify. */
     143             : #define FD_SCHED_TT_LTHASH        (5UL) /* (e) Account lthash. */
     144         723 : #define FD_SCHED_TT_POH_HASH      (6UL) /* (e) PoH hashing. */
     145           6 : #define FD_SCHED_TT_MARK_DEAD     (7UL) /* (i) Mark the block dead. */
     146             : 
     147             : struct fd_sched_block_start {
     148             :   ulong bank_idx;        /* Same as in fd_sched_fec_t. */
     149             :   ulong parent_bank_idx; /* Same as in fd_sched_fec_t. */
     150             :   ulong slot;            /* Slot number of the block. */
     151             : };
     152             : typedef struct fd_sched_block_start fd_sched_block_start_t;
     153             : 
     154             : struct fd_sched_block_end {
     155             :   ulong bank_idx;
     156             : };
     157             : typedef struct fd_sched_block_end fd_sched_block_end_t;
     158             : 
     159             : struct fd_sched_txn_exec {
     160             :   ulong bank_idx;
     161             :   ulong slot;
     162             :   ulong txn_idx;
     163             :   ulong exec_idx;
     164             : };
     165             : typedef struct fd_sched_txn_exec fd_sched_txn_exec_t;
     166             : 
     167             : struct fd_sched_txn_sigverify {
     168             :   ulong bank_idx;
     169             :   ulong txn_idx;
     170             :   ulong exec_idx;
     171             : };
     172             : typedef struct fd_sched_txn_sigverify fd_sched_txn_sigverify_t;
     173             : 
     174             : #define FD_SCHED_POH_PARA 16
     175             : struct fd_sched_poh_hash {
     176             :   ulong     bank_idx;
     177             :   ulong     exec_idx;
     178             :   ulong     cnt;     /* In [1,FD_SCHED_POH_PARA] */
     179             :   ulong     hashcnt; /* Same for every element of the batch */
     180             :   ulong     mblk_idx[ FD_SCHED_POH_PARA ];
     181             :   fd_hash_t hash    [ FD_SCHED_POH_PARA ];
     182             : };
     183             : typedef struct fd_sched_poh_hash fd_sched_poh_hash_t;
     184             : 
     185             : struct fd_sched_mark_dead {
     186             :   ulong     bank_idx;
     187             : };
     188             : typedef struct fd_sched_mark_dead fd_sched_mark_dead_t;
     189             : 
     190             : struct fd_sched_task {
     191             :   ulong task_type; /* Set to one of the task types defined above. */
     192             :   union {
     193             :     fd_sched_block_start_t   block_start[ 1 ];
     194             :     fd_sched_block_end_t     block_end[ 1 ];
     195             :     fd_sched_txn_exec_t      txn_exec[ 1 ];
     196             :     fd_sched_txn_sigverify_t txn_sigverify[ 1 ];
     197             :     fd_sched_poh_hash_t      poh_hash[ 1 ];
     198             :     fd_sched_mark_dead_t     mark_dead[ 1 ];
     199             :   };
     200             : };
     201             : typedef struct fd_sched_task fd_sched_task_t;
     202             : 
     203             : 
     204        1014 : #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. */
     205           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. */
     206           0 : #define FD_SCHED_DEAD_REASON_SHORT_BLOCK                 (2)  /* Block bytes ended short of the microblocks and transactions declared. */
     207           3 : #define FD_SCHED_DEAD_REASON_TOO_MANY_TXNS               (3)  /* More transactions than a valid block can hold. */
     208           3 : #define FD_SCHED_DEAD_REASON_TOO_MANY_MICROBLOCKS        (4)  /* More microblocks than a valid block can hold. */
     209           0 : #define FD_SCHED_DEAD_REASON_DUPLICATE_ACCOUNT           (5)  /* Transaction referenced the same account more than once. */
     210           0 : #define FD_SCHED_DEAD_REASON_TRAILING_ENTRY              (6)  /* Block did not end on a tick. */
     211           6 : #define FD_SCHED_DEAD_REASON_TOO_MANY_TICKS              (7)  /* More ticks than required. */
     212           6 : #define FD_SCHED_DEAD_REASON_TOO_FEW_TICKS               (8)  /* Fewer ticks than required. */
     213           0 : #define FD_SCHED_DEAD_REASON_ZERO_MICROBLOCKS            (9)  /* A batch header declared zero microblocks. */
     214           6 : #define FD_SCHED_DEAD_REASON_WRONG_HASHES_PER_TICK       (10) /* Tick hash count did not advance the expected hashes per tick. */
     215           0 : #define FD_SCHED_DEAD_REASON_INCONSISTENT_TICK_HASHES    (11) /* Tick hash count differs from the block's preceding ticks, detected at FEC ingest. */
     216           0 : #define FD_SCHED_DEAD_REASON_TICK_HASHES_OVERFLOW        (12) /* More hashes since the last tick than hashes per tick allows. */
     217           0 : #define FD_SCHED_DEAD_REASON_TICK_HASHES_OVERFLOW_INGEST (13) /* Tick header declared more hashes than can fit before the next tick, detected at FEC ingest. */
     218           0 : #define FD_SCHED_DEAD_REASON_ZERO_HASH_TICK              (14) /* Tick advanced zero hashes; PoH params were unknown when the tick parsed. */
     219           0 : #define FD_SCHED_DEAD_REASON_ZERO_HASH_TICK_INGEST       (15) /* Tick advanced zero hashes, detected at FEC ingest. */
     220           0 : #define FD_SCHED_DEAD_REASON_TICK_HASH_MISMATCH          (16) /* PoH hash of a tick did not verify. */
     221           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. */
     222           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. */
     223          15 : #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. */
     224           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. */
     225          12 : #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. */
     226             : /* Alpenglow block structure, mirroring agave's BlockComponentProcessor:
     227             :    header | [genesis cert] | entries* | footer | alpentick */
     228          12 : #define FD_SCHED_DEAD_REASON_MISSING_PARENT_MARKER       (22) /* An Alpenglow block carried an entry batch or footer before any block header. */
     229           6 : #define FD_SCHED_DEAD_REASON_MULTIPLE_BLOCK_HEADERS      (23) /* An Alpenglow block carried more than one block header. */
     230           0 : #define FD_SCHED_DEAD_REASON_GENESIS_CERT_OUT_OF_ORDER   (24) /* An Alpenglow genesis certificate marker did not immediately follow the block header. */
     231           6 : #define FD_SCHED_DEAD_REASON_MULTIPLE_BLOCK_FOOTERS      (25) /* An Alpenglow block carried more than one block footer. */
     232           6 : #define FD_SCHED_DEAD_REASON_ENTRY_AFTER_BLOCK_FOOTER    (26) /* An Alpenglow block carried an entry batch other than the alpentick after its footer. */
     233           0 : #define FD_SCHED_DEAD_REASON_INVALID_ALPENTICK_POSITION  (27) /* An Alpenglow block ended without the alpentick directly after its footer. */
     234           6 : #define FD_SCHED_DEAD_REASON_MISSING_BLOCK_FOOTER        (28) /* An Alpenglow block ended without a block footer. */
     235          12 : #define FD_SCHED_DEAD_REASON_SPURIOUS_UPDATE_PARENT      (29) /* An Alpenglow block carried an UpdateParent marker where none is valid: before the header or after the footer. */
     236             : /* Cause to pass to fd_sched_block_abandon().  A block is considered
     237             :    invalid when it violates the protocol, so validity is a function of
     238             :    the block's content.  A block may be discarded (temporarily) because
     239             :    the validator is under resource pressure.  A block may be discarded
     240             :    (permanently) if consensus converged on an alternative fork, which is
     241             :    done implicitly in fd_sched_root_notify() for the minority forks it
     242             :    abandons. */
     243           6 : #define FD_SCHED_ABANDON_DISCARDED (0)
     244           9 : #define FD_SCHED_ABANDON_INVALID   (1)
     245             : 
     246             : struct __attribute__((packed)) fd_microblock_hdr {
     247             :   /* Number of PoH hashes between this and last microblock */
     248             :   /* 0x00 */ ulong hash_cnt;
     249             : 
     250             :   /* PoH state after evaluating this microblock (including all
     251             :      appends and mixin). The input to the poh calculation of the first
     252             :      microblock is the last hash of the parent block, otherwise it is the
     253             :      hash of the previous microblock. */
     254             :   /* 0x08 */ uchar hash[32];
     255             : 
     256             :   /* Number of transactions in this microblock */
     257             :   /* 0x28 */ ulong txn_cnt;
     258             : };
     259             : typedef struct fd_microblock_hdr fd_microblock_hdr_t;
     260             : 
     261             : FD_PROTOTYPES_BEGIN
     262             : 
     263             : /* fd_sched_{align,footprint} return the required alignment and
     264             :    footprint in bytes for a region of memory to be used as a scheduler.
     265             :    footprint silently returns 0 if params are invalid (thus convenient
     266             :    to validate params).
     267             : 
     268             :    depth controls the reorder buffer transaction count (~1 million
     269             :    recommended for live replay, ~10k recommended for async replay).
     270             :    block_cnt_max is the maximum number of blocks that will be tracked by
     271             :    the scheduler.  max_shreds_per_block bounds the data shreds a block
     272             :    may hold (the shred tile enforces the same limit upstream, sched
     273             :    asserts it); a block declaring more than max_txn_per_slot
     274             :    transactions is ruled invalid.  FD_SHRED_BLK_MAX and
     275             :    FD_MAX_TXN_PER_SLOT in production. */
     276             : 
     277             : ulong
     278             : fd_sched_align( void );
     279             : 
     280             : ulong
     281             : fd_sched_footprint( ulong depth,                /* in [FD_SCHED_MIN_DEPTH,FD_SCHED_MAX_DEPTH] */
     282             :                     ulong block_cnt_max,        /* >= 1 */
     283             :                     ulong max_shreds_per_block, /* in [1,UINT_MAX] */
     284             :                     ulong max_txn_per_slot );   /* in [1,UINT_MAX] */
     285             : 
     286             : /* fd_sched_new creates a sched object backed by the given memory region
     287             :    (conforming to align() and footprint()).  Returns NULL if any
     288             :    parameter is invalid. */
     289             : 
     290             : void *
     291             : fd_sched_new( void *     mem,
     292             :               fd_rng_t * rng,
     293             :               ulong      depth,
     294             :               ulong      block_cnt_max,
     295             :               ulong      max_shreds_per_block,
     296             :               ulong      max_txn_per_slot,
     297             :               ulong      exec_cnt,
     298             :               int        is_alpenglow );
     299             : 
     300             : fd_sched_t *
     301             : fd_sched_join( void * mem );
     302             : 
     303             : /* Add the data in the FEC set to the scheduler.  If is_last_fec is 1,
     304             :    then this is the last FEC set in the block.  Transactions may span
     305             :    FEC set boundaries.  The scheduler is responsible for incrementally
     306             :    parsing transactions from concatenated FEC set data.  Assumes that
     307             :    FEC sets are delivered in replay order.  That is, forks form a
     308             :    partial ordering over FEC sets: in-order per fork, but arbitrary
     309             :    ordering across forks.  The fork tree is implied by the stream of
     310             :    parent-child relationships delivered in FEC sets.  Also assumes that
     311             :    there is enough space in the scheduler to ingest the FEC set.  The
     312             :    caller should generally call fd_sched_fec_can_ingest() first.
     313             : 
     314             :    Returns 1 on success, 0 if the block is bad and should be marked
     315             :    dead. */
     316             : FD_WARN_UNUSED int
     317             : fd_sched_fec_ingest( fd_sched_t * sched, fd_sched_fec_t * fec );
     318             : 
     319             : /* Check if there is enough space in the scheduler to ingest the data in
     320             :    the FEC set.  Returns 1 if there is, 0 otherwise.  This is a cheap
     321             :    and conservative check. */
     322             : int
     323             : fd_sched_fec_can_ingest( fd_sched_t * sched, fd_sched_fec_t * fec );
     324             : 
     325             : /* Returns the number of worst-case FEC sets sched can ingest. This is a
     326             :    cheap and conservative check. */
     327             : ulong
     328             : fd_sched_can_ingest_cnt( fd_sched_t * sched );
     329             : 
     330             : /* Returns 1 if sched is drained, 0 otherwise.  A drained scheduler will
     331             :    not return more work.  Otherwise, next_ready will return more work,
     332             :    so long as there are exec tiles available. */
     333             : int
     334             : fd_sched_is_drained( fd_sched_t * sched );
     335             : 
     336             : /* Obtain a transaction eligible for execution.  This implies that all
     337             :    prior transactions with w-r or w-w conflicts have completed.
     338             :    Information regarding the scheduled transaction is written to the out
     339             :    pointer.  Returns 1 on success, 0 on failure.  Failures are generally
     340             :    transient and non-fatal, and are simply an indication that no
     341             :    transaction is ready for execution yet.  When in-flight transactions
     342             :    retire or when more FEC sets are ingested, more transactions may
     343             :    become ready for execution.
     344             : 
     345             :    Transactions on the same fork will be returned in a way that
     346             :    maintains the serial fiction.  That is, reordering can happen, but
     347             :    only within the constraint that transactions appear to be ready in
     348             :    the order in which they occur in the block.  Transactions from
     349             :    different forks may interleave, and the caller should be prepared to
     350             :    switch execution context in response to interleavings.  The scheduler
     351             :    will barrier on block boundaries, in the sense that transactions from
     352             :    a subsequent block will not be returned for execution until all
     353             :    transactions from the previous block have completed.  This gives the
     354             :    caller a chance to perform end-of-block processing before
     355             :    transactions from a subsequent block start executing.  In general,
     356             :    the caller should check if the last transaction in the current block
     357             :    is done, and if so, do end-of-block processing before calling this
     358             :    function to start the next block.
     359             : 
     360             :    In addition to returning transactions for execution, this function
     361             :    may also return a sigverify task.  Sigverify can be completed
     362             :    asynchronously outside the critical path of transaction execution, as
     363             :    long as every transaction in a block passes sigverify before we
     364             :    commit the block.  The scheduler prioritizes actual execution of
     365             :    transactions over sigverify, and in general sigverify tasks are only
     366             :    returned when no real transaction can be dispatched.  In other words,
     367             :    the scheduler tries to exploit idle cycles in the exec tiles during
     368             :    times of low parallelism critical path progression.
     369             : 
     370             :    This function may also return a PoH hashing task.  These tasks are
     371             :    lower priority than transaction execution, but higher priority than
     372             :    sigverify.  This is because sigverify tasks are generally bite-sized,
     373             :    whereas PoH hashing can be longer, so we would like to get started on
     374             :    hashing sooner rather than later. */
     375             : ulong
     376             : fd_sched_task_next_ready( fd_sched_t * sched, fd_sched_task_t * out );
     377             : 
     378             : /* Mark a task as complete.  For transaction execution, this means that
     379             :    the effects of the execution are now visible on any core that could
     380             :    execute a subsequent transaction.  Returns FD_SCHED_DEAD_REASON_NONE
     381             :    (0) on success.  If, given the result of the task, the block turns
     382             :    out to be bad, returns the nonzero FD_SCHED_DEAD_REASON_* it was
     383             :    ruled bad for.  Only PoH tasks can rule a block bad, and not only
     384             :    for a PoH hash mismatch: eager tick verification also runs on this
     385             :    path.
     386             : 
     387             :    If a block has been abandoned or marked dead for any reason, it'll be
     388             :    pruned the moment in-flight task count hits 0 due to the last task
     389             :    completing.  Then, in the immediate ensuing stem run loop,
     390             :    sched_pruned_next() will return the index for the corresponding bank
     391             :    so the refcnt can be decremented for sched.
     392             : 
     393             :    The transaction at the given index may be freed upon return from this
     394             :    function.  Nonetheless, as long as there is no intervening FEC
     395             :    ingestion, it would still be safe to query the transaction using
     396             :    get_txn(). */
     397             : int
     398             : fd_sched_task_done( fd_sched_t * sched, ulong task_type, ulong txn_idx, ulong exec_idx, void * data );
     399             : 
     400             : /* Abandon a block.  This means that we are no longer interested in
     401             :    executing the block.  This also implies that any block which chains
     402             :    off of the provided block shall be abandoned.  This is mainly used
     403             :    when a block is aborted because we decided that it would be a
     404             :    dead/invalid block, and so there's no point in spending resources
     405             :    executing it.  The scheduler will no longer return transactions from
     406             :    abandoned blocks for execution.  This should only be invoked on an
     407             :    actively replayed block, and should only be invoked once on it.
     408             : 
     409             :    For the purposes of bank lifetime management, sched is a subsidiary
     410             :    of banks.  So while sched sets things in motion for a bad block to be
     411             :    eagerly pruned, banks/replay is the sole initiator of actual pruning.
     412             :    The way this works is that an abandoned block will have its refcnt
     413             :    queued for release by sched as soon as, and only if, the block has no
     414             :    more in-flight tasks associated with it.  No sooner, no later.  In
     415             :    the immediate ensuing stem run loop, sched_pruned_next() will return
     416             :    the index for the corresponding bank so the refcnt can be decremented
     417             :    for sched.  After that point, banks will eventually instruct sched to
     418             :    prune the block, when all other components release their refcnts on
     419             :    said bank.  Then the bank_idx may be recycled for another block.
     420             : 
     421             :    Pass FD_SCHED_ABANDON_INVALID if the block is ruled invalid for any
     422             :    reason, or FD_SCHED_ABANDON_DISCARDED if we are merely giving up on
     423             :    it without fault, e.g. eviction under resource pressure.  Descendants
     424             :    inherit the flavor: they record DEAD_ANCESTOR, and are marked
     425             :    discarded iff the lineage was discarded, provided they have no dead
     426             :    reason of their own.  A block that is already going down keeps the
     427             :    flavor it went down with, so a later abandon cannot re-label it. */
     428             : void
     429             : fd_sched_block_abandon( fd_sched_t * sched, ulong bank_idx, int cause );
     430             : 
     431             : /* fd_sched_get_dead_reason returns the scheduler's reason (one of
     432             :    FD_SCHED_DEAD_REASON_*) for why the block at bank_idx went down.
     433             :    Returns FD_SCHED_DEAD_REASON_NONE if the block itself was merely
     434             :    discarded (root advance, eviction) or if no block is currently
     435             :    tracked at bank_idx.  Descendants of a discarded lineage carry
     436             :    DEAD_ANCESTOR like any other lineage death;
     437             :    fd_sched_block_is_discarded disambiguates discarded from
     438             :    ruled-invalid.  The recorded reason is the first one; later failures
     439             :    on an already-dead block (e.g. an in-flight PoH task draining after
     440             :    the block was abandoned) do not overwrite it. */
     441             : int
     442             : fd_sched_get_dead_reason( fd_sched_t * sched, ulong bank_idx );
     443             : 
     444             : /* fd_sched_block_is_discarded returns 1 if the block went down with a
     445             :    discarded (not invalid) lineage, 0 otherwise (including when no
     446             :    block is tracked at bank_idx).  Never set on a block that has a dead
     447             :    reason of its own, so it does not mask the scheduler's own verdict. */
     448             : int
     449             : fd_sched_block_is_discarded( fd_sched_t * sched, ulong bank_idx );
     450             : 
     451             : /* Prune the given block including descendants of it. */
     452             : void
     453             : fd_sched_cancel( fd_sched_t * sched, ulong bank_idx );
     454             : 
     455             : /* Add a block as immediately done to the scheduler.  This is useful for
     456             :    installing the snapshot slot, or for informing the scheduler of a
     457             :    packed leader block.  Parent block should be ULONG_MAX for the
     458             :    snapshot slot, and otherwise a block that hasn't been pruned. */
     459             : void
     460             : fd_sched_block_add_done( fd_sched_t * sched, ulong bank_idx, ulong parent_bank_idx, ulong slot );
     461             : 
     462             : /* Advance the root, pruning all blocks across forks that do not descend
     463             :    from the new root.  Assumes the new root is in the fork tree and
     464             :    connected to the current root.  Also assumes that there are no more
     465             :    in-flight transactions from the soon-to-be-pruned blocks.  This
     466             :    should be called after root_notify() and the caller is responsible
     467             :    for figuring out the new root to safely prune to. */
     468             : void
     469             : fd_sched_advance_root( fd_sched_t * sched, ulong root_idx );
     470             : 
     471             : /* Notify the scheduler of a new root.  This has the effect of calling
     472             :    abandon() on all minority forks that do not descend from the new
     473             :    root.  Shortly after a call to this function, in-flight transactions
     474             :    from these abandoned blocks should retire from the execution
     475             :    pipeline, and the new root will be safe for pruning. */
     476             : void
     477             : fd_sched_root_notify( fd_sched_t * sched, ulong root_idx );
     478             : 
     479             : /* Returns the index of a bank whose refcnt should be decremented for
     480             :    sched.  This function should be called in a loop to drain all
     481             :    outstanding refcnt decrements before any other sched API is called in
     482             :    a stem run loop.  Returns ULONG_MAX when there are no more
     483             :    outstanding references from sched and the loop should break. */
     484             : ulong
     485             : fd_sched_pruned_block_next( fd_sched_t * sched );
     486             : 
     487             : void
     488             : fd_sched_set_poh_params( fd_sched_t * sched, ulong bank_idx, ulong tick_height, ulong max_tick_height, ulong hashes_per_tick, fd_hash_t const * start_poh );
     489             : 
     490             : /* fd_sched_block_verify_ticks sets the tick window and verifies
     491             :    ticks on bank_idx (shred fuzz harness, no exec).  Returns
     492             :    FD_SCHED_DEAD_REASON_NONE (0) if valid, else the
     493             :    FD_SCHED_DEAD_REASON_* the ticks are invalid for.  Does not rule the
     494             :    block invalid; the caller decides what to do with the verdict. */
     495             : int
     496             : fd_sched_block_verify_ticks( fd_sched_t * sched,
     497             :                              ulong        bank_idx,
     498             :                              ulong        tick_height,
     499             :                              ulong        max_tick_height,
     500             :                              ulong        hashes_per_tick );
     501             : 
     502             : /* fd_sched_set_bypass_poh_verify configures whether the per-microblock
     503             :    PoH end_hash comparison in maybe_mixin is bypassed.  This is intended
     504             :    for test and fuzz harnesses: the expected end_hash is carried in the
     505             :    shred payload, so comparing it would reject any mutated input before
     506             :    the deeper parse/tick logic is exercised.  Production call sites
     507             :    should leave this disabled. */
     508             : void
     509             : fd_sched_set_bypass_poh_verify( fd_sched_t * sched, int bypass_poh_verify );
     510             : 
     511             : /* fd_sched_set_bypass_alut_resolution bypasses ALUT resolution during
     512             :    parsing (test/fuzz: no accounts DB).  ALUT txns become serializing.
     513             :    Production call sites should leave this disabled. */
     514             : void
     515             : fd_sched_set_bypass_alut_resolution( fd_sched_t * sched, int bypass_alut_resolution );
     516             : 
     517             : fd_txn_p_t *
     518             : fd_sched_get_txn( fd_sched_t * sched, ulong txn_idx );
     519             : 
     520             : fd_sched_txn_info_t *
     521             : fd_sched_get_txn_info( fd_sched_t * sched, ulong txn_idx );
     522             : 
     523             : fd_hash_t *
     524             : fd_sched_get_poh( fd_sched_t * sched, ulong bank_idx );
     525             : 
     526             : uint
     527             : fd_sched_get_shred_cnt( fd_sched_t * sched, ulong bank_idx );
     528             : 
     529             : /* fd_sched_get_footer returns the block footer, or NULL if no footer
     530             :    marker has been parsed for the block.  The shapes were validated at
     531             :    parse time; the signatures are not verified.  The footer stays valid
     532             :    until the block is pruned. */
     533             : fd_block_footer_t const *
     534             : fd_sched_get_footer( fd_sched_t * sched, ulong bank_idx );
     535             : 
     536             : void
     537             : fd_sched_metrics_write( fd_sched_t * sched );
     538             : 
     539             : /* Serialize the current state as a cstr to the returned buffer.  Caller
     540             :    may read from the buffer until the next invocation of any fd_sched
     541             :    function. */
     542             : char *
     543             : fd_sched_get_state_cstr( fd_sched_t * sched );
     544             : 
     545             : void *
     546             : fd_sched_leave( fd_sched_t * sched );
     547             : 
     548             : void *
     549             : fd_sched_delete( void * mem );
     550             : 
     551             : FD_PROTOTYPES_END
     552             : 
     553             : #endif /* HEADER_fd_src_discof_replay_fd_sched_h */

Generated by: LCOV version 1.14