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

Generated by: LCOV version 1.14