LCOV - code coverage report
Current view: top level - discof/restore/utils - fd_ssmsg.h (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 3 18 16.7 %
Date: 2026-09-17 04:28:31 Functions: 1 180 0.6 %

          Line data    Source code
       1             : #ifndef HEADER_fd_src_discof_restore_utils_fd_ssmsg_h
       2             : #define HEADER_fd_src_discof_restore_utils_fd_ssmsg_h
       3             : 
       4             : #include "../../../flamenco/runtime/fd_runtime_const.h"
       5             : #include "../../../flamenco/runtime/fd_blockhashes.h"
       6             : 
       7           0 : #define FD_SSMSG_MANIFEST_FULL        (0) /* A snapshot manifest message from the full snapshot */
       8           0 : #define FD_SSMSG_MANIFEST_INCREMENTAL (1) /* A snapshot manifest message from the incremental snapshot */
       9           0 : #define FD_SSMSG_DONE                 (2) /* Indicates the snapshot is fully loaded and tiles are shutting down */
      10           0 : #define FD_SSMSG_EXPECTED_SLOT        (3) /* Expected rooted slot from incremental snapshot */
      11             : 
      12             : FD_FN_CONST static inline ulong
      13           0 : fd_ssmsg_sig( ulong message ) {
      14           0 :   return (message & 0x3UL);
      15           0 : }
      16             : 
      17           0 : FD_FN_CONST static inline ulong fd_ssmsg_sig_message( ulong sig ) { return (sig & 0x3UL); }
      18             : struct epoch_credits {
      19             :   ulong epoch;
      20             :   ulong credits;
      21             :   ulong prev_credits;
      22             : };
      23             : 
      24             : typedef struct epoch_credits epoch_credits_t;
      25             : 
      26             : /* fd_epoch_credits_is_alpenglow_marker returns 1 if ec is the
      27             :    tower->Alpenglow migration sentinel, 0 otherwise. */
      28             : 
      29             : FD_FN_PURE static inline int
      30         102 : fd_epoch_credits_is_alpenglow_marker( epoch_credits_t const * ec ) {
      31         102 :   return ec->epoch==ULONG_MAX && ec->credits==ULONG_MAX && ec->prev_credits==ULONG_MAX;
      32         102 : }
      33             : 
      34             : /* The FD_SSMSG_EXPECTED_SLOT uses the tsorig and tspub fields
      35             :    of the fd_frag_meta_t struct to store the low and high 32 bits of
      36             :    the slot number. */
      37             : static inline void
      38             : fd_ssmsg_slot_to_frag( ulong slot,
      39             :                        uint* low,
      40           0 :                        uint* high ) {
      41           0 :    *low = (uint)(slot & 0xFFFFFFFFUL);
      42           0 :    *high = (uint)((slot >> 32UL) & 0xFFFFFFFFUL);
      43           0 : }
      44             : 
      45             : static inline void
      46             : fd_ssmsg_frag_to_slot( ulong low,
      47             :                        ulong high,
      48           0 :                        ulong* slot ) {
      49           0 :    *slot = (high << 32UL) | low;
      50           0 : }
      51             : 
      52             : struct fd_snapshot_manifest_vote_account {
      53             :   /* The pubkey of the vote account */
      54             :   uchar vote_account_pubkey[ 32UL ];
      55             : 
      56             :   /* The pubkey of the node account */
      57             :   uchar node_account_pubkey[ 32UL ];
      58             : 
      59             :   ulong stake;
      60             : };
      61             : 
      62             : typedef struct fd_snapshot_manifest_vote_account fd_snapshot_manifest_vote_account_t;
      63             : 
      64             : /* TODO: Consider combining this struct with
      65             :    fd_snapshot_manifest_vote_account. */
      66             : 
      67             : struct fd_snapshot_manifest_vote_stakes {
      68             :   /* The vote pubkey */
      69             :   uchar vote[ 32UL ];
      70             : 
      71             :   /* The validator identity pubkey, aka node pubkey */
      72             :   uchar identity[ 32UL ];
      73             : 
      74             :   /* The commission account for inflation rewards (vote, before SIMD-0232) */
      75             :   uchar commission_inflation[ 32UL ];
      76             : 
      77             :   /* The commission account for block revenue (identity, before SIMD-0232) */
      78             :   uchar commission_block[ 32UL ];
      79             : 
      80             :   /* Whether this vote account has a BLS pubkey set */
      81             :   uchar has_identity_bls;
      82             : 
      83             :   /* The validator BLS pubkey (used after SIMD-0326: Alpenglow) */
      84             :   uchar identity_bls[ 48UL ];
      85             : 
      86             :   /* The total amount of active stake for the vote account */
      87             :   ulong stake;
      88             : 
      89             :   /* The latest slot and timestamp that the vote account voted on in
      90             :      the given epoch. */
      91             :   ulong slot;
      92             :   long  timestamp;
      93             : 
      94             :   /* The validator's commission rate as of the given epoch. */
      95             :   ushort commission;
      96             : 
      97             :   /* The epoch credits array tracks the history of how many credits the
      98             :      provided vote account earned in each recorded epoch.  Entries are
      99             :      ordered by strictly increasing epoch: epoch_credits[0] is the
     100             :      oldest and epoch_credits[epoch_credits_history_len-1] is the
     101             :      newest.  Epochs with no recorded credits can be absent.  When
     102             :      booting a new chain from genesis, or for new vote accounts, the
     103             :      epoch credits history may be short.  The maximum number of entries
     104             :      in the epoch credits history is 64.
     105             : 
     106             :      Note one entry may be the Alpenglow migration marker (all three
     107             :      fields ULONG_MAX, see fd_epoch_credits_is_alpenglow_marker). */
     108             :   ulong           epoch_credits_history_len;
     109             :   epoch_credits_t epoch_credits[ FD_EPOCH_CREDITS_MAX ];
     110             : };
     111             : 
     112             : typedef struct fd_snapshot_manifest_vote_stakes fd_snapshot_manifest_vote_stakes_t;
     113             : 
     114             : struct fd_snapshot_manifest_epoch_stakes {
     115             :    /* The epoch for which these vote accounts and stakes are valid for */
     116             :   ulong                              epoch;
     117             :   /* The total amount of active stake at the end of the given epoch.*/
     118             :   ulong                              total_stake;
     119             : 
     120             :   /* The vote accounts and their stakes for a given epoch.
     121             :      FIXME: Snapshot manifest has to support a much larger bound. */
     122             :   ulong                              vote_stakes_len;
     123             :   fd_snapshot_manifest_vote_stakes_t vote_stakes[ FD_RUNTIME_MAX_VAT_VOTE_ACCOUNTS ];
     124             : };
     125             : 
     126             : typedef struct fd_snapshot_manifest_epoch_stakes fd_snapshot_manifest_epoch_stakes_t;
     127             : 
     128             : struct fd_snapshot_manifest_inflation_params {
     129             :   /* The initial inflation percentage starting at genesis.  This value is
     130             :      set at genesis to 8%, and is only changed at the boundary when
     131             :      double_disinflation_rate activates. */
     132             :   double initial;
     133             : 
     134             :   /* The terminal inflation percentage is the long-term steady state
     135             :      inflation rate after a period of disinflation.  This value is set
     136             :      at genesis to 1.5% and is not expected to change. */
     137             :   double terminal;
     138             : 
     139             :   /* The rate per year at which inflation is lowered until it reaches
     140             :      the terminal inflation rate.  This value is set to 15% at genesis
     141             :      and only changes at the boundary when double_disinflation_rate
     142             :      activates. */
     143             :   double taper;
     144             : 
     145             :   /* The percentage of total inflation allocated to the foundation.
     146             :      This value is set at genesis to 5% and is not expected to change. */
     147             :   double foundation;
     148             : 
     149             :   /* The number of years in which a portion of the total inflation is
     150             :      allocated to the foundation (see foundation field).  This value is
     151             :      set to 7 years at genesis and is not expected to change. */
     152             :   double foundation_term;
     153             : };
     154             : 
     155             : typedef struct fd_snapshot_manifest_inflation_params fd_snapshot_manifest_inflation_params_t;
     156             : 
     157             : struct fd_snapshot_manifest_epoch_schedule_params {
     158             :   /* The maximum number of slots in each epoch. */
     159             :   ulong slots_per_epoch;
     160             : 
     161             :   /* A number of slots before beginning of an epoch to calculate a
     162             :      leader schedule for that epoch.  This value is set to
     163             :      slots_per_epoch (basically one epoch) and is unlikely to change. */
     164             :   ulong leader_schedule_slot_offset;
     165             : 
     166             :   /* Whether there is a warmup period where epochs are short and grow by
     167             :      powers of two until they reach the default epoch length of
     168             :      slots_per_epoch.  This value is set by default to true at genesis,
     169             :      though it may be configured differently in development
     170             :      environments. */
     171             :   uchar warmup;
     172             : 
     173             :   /* TODO: Probably remove this? Redundant and can be calculated from
     174             :      the above. */
     175             :   ulong first_normal_epoch;
     176             :   ulong first_normal_slot;
     177             : };
     178             : 
     179             : typedef struct fd_snapshot_manifest_epoch_schedule_params fd_snapshot_manifest_epoch_schedule_params_t;
     180             : 
     181             : struct fd_snapshot_manifest_fee_rate_governor {
     182             :   /* Transaction fees are calculated by charging a cost for each
     183             :      signature.  There is a mechanism to dynamically adjust the cost per
     184             :      signature based on the cluster's transaction processing capacity.
     185             :      In this mechanism, the cost per signature can vary between 50% to
     186             :      1000% of the target_lamports_per_signature value, which is the cost
     187             :      per signature when the cluster is operating at the desired
     188             :      transaction processing capacity defined by
     189             :      target_signatures_per_slot.
     190             : 
     191             :      This value is fixed at 10,000 from genesis onwards but may be
     192             :      changed in the future with feature flags. */
     193             :   ulong target_lamports_per_signature;
     194             : 
     195             :   /* The cluster transaction processing capacity is measured by
     196             :      signatures per slot.  Solana defines the desired transaction
     197             :      processing capacity using the value target_signatures_per_slot.
     198             : 
     199             :      This value is fixed at 20,000 from genesis onwards but may be
     200             :      changed in the future with feature flags. */
     201             :   ulong target_signatures_per_slot;
     202             : 
     203             :   /* The minimum cost per signature is 50% of the
     204             :      target_lamports_per_signature value.  Under the current default for
     205             :      target_lamports_per_signature, this value is at 5,000 lamports per
     206             :      signature. */
     207             :   ulong min_lamports_per_signature;
     208             : 
     209             :   /* The maximum cost per signature is 1000% of the
     210             :      target_lamports_per_signature value.  Under the current default for
     211             :      target_lamports_per_signature, this value is at 100,000 lamports
     212             :      per signature.*/
     213             :   ulong max_lamports_per_signature;
     214             : 
     215             :   /* The percent of collected fees that are burned.  This value is
     216             :      currently set to a fixed value of 50% from genesis onwards, but
     217             :      may be changed in the future with feature flags. */
     218             :   uchar burn_percent;
     219             : };
     220             : 
     221             : typedef struct fd_snapshot_manifest_fee_rate_governor fd_snapshot_manifest_fee_rate_governor_t;
     222             : 
     223             : struct fd_snapshot_manifest_rent {
     224             :   ulong lamports_per_uint8_year;
     225             :   double exemption_threshold;
     226             :   uchar burn_percent;
     227             : };
     228             : 
     229             : typedef struct fd_snapshot_manifest_rent fd_snapshot_manifest_rent_t;
     230             : 
     231             : struct fd_snapshot_manifest_blockhash {
     232             :    uchar hash[ 32UL ];
     233             :    ulong lamports_per_signature;
     234             :    ulong hash_index;
     235             :    ulong timestamp;
     236             : };
     237             : 
     238             : typedef struct fd_snapshot_manifest_blockhash fd_snapshot_manifest_blockhash_t;
     239             : 
     240             : struct fd_snapshot_manifest {
     241             :   /* The UNIX timestamp when the genesis block was for this chain
     242             :      was created, in seconds.
     243             :      https://github.com/anza-xyz/agave/blob/v4.0.0-beta.1/runtime/src/bank.rs#L2108-L2114 */
     244             :   ulong creation_time_seconds;
     245             : 
     246             :   /* At genesis, certain parameters can be set which control the
     247             :      inflation rewards going forward.  This includes what the initial
     248             :      inflation is and how the inflation curve changes over time.
     249             : 
     250             :      These parameters may change with feature gate activations, for
     251             :      example double_disinflation_rate. */
     252             :   fd_snapshot_manifest_inflation_params_t inflation_params;
     253             : 
     254             :   /* At genesis, certain parameters can be set which control the
     255             :      epoch schedule going forward.  This includes how many slots
     256             :      there are per epoch, and certain development settings like if
     257             :      epochs start short and grow longer as the chain progresses.
     258             : 
     259             :      Currently, these parameters can never change and are fixed from
     260             :      genesis onwards, although in future they may change with new
     261             :      feature flags. */
     262             :   fd_snapshot_manifest_epoch_schedule_params_t epoch_schedule_params;
     263             : 
     264             :   /* At genesis, certain parameters can be set which control
     265             :      how transaction fees are dynamically adjusted going forward.
     266             : 
     267             :      Currently, these parameters can never change and are fixed from
     268             :      genesis onwards, although in future they may change with new
     269             :      feature flags. */
     270             :   fd_snapshot_manifest_fee_rate_governor_t fee_rate_governor;
     271             : 
     272             :   fd_snapshot_manifest_rent_t rent_params;
     273             : 
     274             :   /* The slot number for this snapshot */
     275             :   ulong slot;
     276             : 
     277             :   /* The number of blocks that have been built since genesis.  This is
     278             :      kind of like the slot number, in that it increments by 1 for every
     279             :      landed block, but it does not increment for skipped slots, so the
     280             :      block_height will always be less than or equal to the slot. */
     281             :   ulong block_height;
     282             : 
     283             :   /* TODO: Document */
     284             :   ulong collector_fees;
     285             : 
     286             :   /* The parent slot is the slot that this block builds on top of.  It
     287             :      is typically slot-1, but can be an arbitrary amount of slots
     288             :      earlier in case of forks, when the block skips over preceding
     289             :      slots. */
     290             :   ulong parent_slot;
     291             : 
     292             :   /* The bank hash of the slot represented by this snapshot.  The bank
     293             :      hash is used by the validator to detect mismatches.  All validators
     294             :      must agree on a bank hash for each slot or they will fork off.
     295             : 
     296             :      The bank hash is created for every slot by hashing together the
     297             :      parent bank hash with the accounts delta hash, the most recent
     298             :      Proof of History blockhash, and the number of signatures in the
     299             :      slot.
     300             : 
     301             :      The bank hash includes the epoch accounts hash when the epoch
     302             :      accounts hash is ready at slot 324000 in the current epoch. See the
     303             :      epoch_accounts_hash for more details regarding the epcoh accounts
     304             :      hash calculation . */
     305             :   uchar bank_hash[ 32UL ];
     306             : 
     307             :   /* The bank hash of the parent slot. */
     308             :   uchar parent_bank_hash[ 32UL ];
     309             : 
     310             :   /* The merkle-based hash of all account state on chain at the slot the
     311             :      snapshot is created.  The accounts hash is calculated when producing
     312             :      a snapshot. */
     313             :   uchar accounts_hash[ 32UL ];
     314             : 
     315             :   /* The merkle-based hash of modified accounts for the slot the
     316             :      snapshot is created.  The accounts_delta_hash is computed at
     317             :      the end of every slot and included into each bank hash.  It is
     318             :      computed by hashing all modified account state together. */
     319             :   uchar accounts_delta_hash[ 32UL ];
     320             : 
     321             :   /* The lattice hash of all account state on chain. */
     322             :   int   has_accounts_lthash;
     323             :   uchar accounts_lthash[ 2048UL ];
     324             : 
     325             :   /* The hash of all accounts at this snapshot's epoch.
     326             :      The epoch account hash is very expensive to calculate, so it is
     327             :      only calculated once per epoch during the epoch account hash
     328             :      calculation window, which is a range of slots in an epoch starting
     329             :      at slot 108000 and ending at slot 324000, where each epoch has
     330             :      432000 slots.
     331             : 
     332             :      The epoch_account_hash may be empty if the snapshot was produced
     333             :      before the epoch account hash calculation window. */
     334             :   int   has_epoch_account_hash;
     335             :   uchar epoch_account_hash[ 32UL ];
     336             : 
     337             :   /* The merkle root of the snapshot slot's block.
     338             :      Only present in snapshots generated by Agave >=4.1. */
     339             :   int   has_block_id;
     340             :   uchar block_id[ 32UL ];
     341             : 
     342             :   ulong blockhashes_len;
     343             :   fd_snapshot_manifest_blockhash_t blockhashes[ FD_BLOCKHASHES_MAX ];
     344             : 
     345             :   ushort accdb_fork_id; /* The fork_id in the account database for the root slot. */
     346             :   ushort txncache_fork_id; /* The fork_id in the status cache for the root slot. */
     347             : 
     348             :   /* A list of ancestor slots has been deprecated.  Agave's bank now
     349             :      creates an ancestor set with a single entry (the current slot):
     350             :      https://github.com/anza-xyz/agave/blob/v4.0.0-beta.1/runtime/src/bank.rs#L1846 */
     351             : 
     352             :   /* A hard fork is a deliberate deviation from the canonical blockchain
     353             :      progression.  This contains the list of slots which have
     354             :      historically undergone a hard fork.  The typical case for these is
     355             :      a feature is deactivated and the cluster is restarted. */
     356             :   ulong          hard_fork_cnt;
     357             :   fd_hard_fork_t hard_forks[ FD_HARD_FORKS_MAX ];
     358             : 
     359             :   /* The proof of history component "proves" the passage of time (see
     360             :      extended discussion in PoH tile for what that actually means) by
     361             :      continually doing sha256 hashes.  A certain number of hashes are
     362             :      required to be in each slot, to prove the leader spent some amount
     363             :      of time on the slot and didn't end it too early.
     364             : 
     365             :      In all clusters and environments that matter, this value is fixed
     366             :      at 64 and is unlikely to change, however it might be configured
     367             :      differently in development environments. */
     368             :   ulong ticks_per_slot;
     369             : 
     370             :   /* TODO: Document */
     371             :   ulong ns_per_slot;
     372             : 
     373             :   /* TODO: Document */
     374             :   double slots_per_year;
     375             : 
     376             :   /* The proof of history component typically requires every block to
     377             :      have 64 "ticks" in it (although this is configurable during
     378             :      development), but each tick is some flexible number of recursive
     379             :      sha256 hashes defined at genesis.
     380             : 
     381             :      The number of hashes for mainnet genesis is 12,500, meaning there
     382             :      will be 800,000 hashes per slot.
     383             : 
     384             :      There are various features, named like update_hashes_per_tick*
     385             :      which if enabled update the hashes_per_tick of the chain as-of the
     386             :      epoch where they are enabled.  This value incorporates any changes
     387             :      due to such features.
     388             : 
     389             :      In development environments, sometimes hashes_per_tick will not be
     390             :      specified (has_hashes_per_tick will be 0).  Agave refers to this as
     391             :      a "low power" mode, where ticks have just one hash in them.  It is
     392             :      distinct from just setting hahes_per_tick to 1, because it also
     393             :      reduces the slot duration from 400ms down to 0ms (or however long
     394             :      it takes to produce the hash).  See comments in the PoH tile for
     395             :      more extended discussion. */
     396             :   int   has_hashes_per_tick;
     397             :   ulong hashes_per_tick;
     398             : 
     399             :   /* The sum of all account balances in lamports as of this snapshots
     400             :      slot.  Total capitalization is used when computing inflation
     401             :      rewards and validating snapshots. */
     402             :   ulong capitalization;
     403             : 
     404             :   /* TODO: Why is this needed? */
     405             :   ulong tick_height;
     406             :   ulong max_tick_height;
     407             : 
     408             :   /* TODO: What is this? */
     409             :   ulong lamports_per_signature;
     410             : 
     411             :   /* TODO: Why is this needed? */
     412             :   ulong transaction_count;
     413             : 
     414             :   /* TODO: Why is this needed? */
     415             :   ulong signature_count;
     416             : 
     417             :   /* Every staked vote account and its stake, taken from the stakes
     418             :      cache rather than a single epoch's admitted set.  This field is only
     419             :      used for wait for supermajority cluster restarts, which measures
     420             :      what fraction of activated stake is visible in gossip. */
     421             :   ulong                               vote_accounts_len;
     422             :   fd_snapshot_manifest_vote_account_t vote_accounts[ FD_RUNTIME_MAX_SNAPSHOT_VOTE_ACCOUNTS ];
     423             : 
     424             :   /* Epoch stakes represent the exact amount staked to each vote
     425             :      account at the beginning of a previous epoch.  They are primarily
     426             :      used to derive the leader schedule.
     427             : 
     428             :      Let's say the manifest is at epoch E.
     429             : 
     430             :      The field versioned_epoch_stakes in the manifest is a map
     431             : 
     432             :        <epoch> -> <VersionedEpochStakes>
     433             : 
     434             :      where <epoch> assumes these values:
     435             : 
     436             :        E-1 - represents the stakes at the beginning of epoch E-2,
     437             :              used to compute the leader schedule at E-1.  Also used
     438             :              by delay_commission_updates (SIMD-0249) to determine
     439             :              the commission rate for partitioned epoch rewards
     440             :              recalculation at boot.
     441             : 
     442             :        E   - represents the stakes at the beginning of epoch E-1,
     443             :              used to compute the leader schedule at E.
     444             : 
     445             :        E+1 - represents the stakes at the beginning of epoch E,
     446             :              used to compute the leader schedule at E+1.
     447             : 
     448             :      The epoch stakes are stored in an array:
     449             :        epoch_stakes[0] = epoch E-1
     450             :        epoch_stakes[1] = epoch E
     451             :        epoch_stakes[2] = epoch E+1 */
     452             :   fd_snapshot_manifest_epoch_stakes_t epoch_stakes[ FD_RUNTIME_MANIFEST_EPOCH_STAKES_LEN ];
     453             : };
     454             : 
     455             : typedef struct fd_snapshot_manifest fd_snapshot_manifest_t;
     456             : 
     457             : #endif /* HEADER_fd_src_discof_restore_utils_fd_ssmsg_h */

Generated by: LCOV version 1.14