LCOV - code coverage report
Current view: top level - discof/restore/utils - fd_ssmsg.h (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 0 15 0.0 %
Date: 2026-08-14 04:54:57 Functions: 0 124 0.0 %

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

Generated by: LCOV version 1.14