LCOV - code coverage report
Current view: top level - discof/restore/utils - fd_ssmsg.h (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 0 8 0.0 %
Date: 2025-08-05 05:04:49 Functions: 0 39 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             : 
       6           0 : #define FD_SSMSG_MANIFEST_FULL        (0) /* A snapshot manifest message from the full snapshot */
       7           0 : #define FD_SSMSG_MANIFEST_INCREMENTAL (1) /* A snapshot manifest message from the incremental snapshot */
       8           0 : #define FD_SSMSG_DONE                 (2) /* Indicates the snapshot is fully loaded and tiles are shutting down */
       9             : 
      10             : /* This number is exhagerately high, but is consisent with Frankendancer.
      11             :    We need this to be about the number of validators, so roughly
      12             :    1-2k for mainnet and 3k for testnet. With Alpenglow this will be 2k.
      13             :    Also, the snapshot currently contains vote account with 0 stakes,
      14             :    so the length (from snapshot) might be actually higher that the
      15             :    number of entries we actually need/consume. */
      16             : #define MAX_VOTE_STAKES (40200)
      17             : 
      18             : FD_FN_CONST static inline ulong
      19             : fd_ssmsg_sig( ulong message,
      20           0 :               ulong manifest_size ) {
      21           0 :   return (manifest_size << 2) | (message & 0x3UL);
      22           0 : }
      23             : 
      24           0 : FD_FN_CONST static inline ulong fd_ssmsg_sig_manifest_size( ulong sig ) { return (sig >> 2); }
      25           0 : FD_FN_CONST static inline ulong fd_ssmsg_sig_message( ulong sig ) { return (sig & 0x3UL); }
      26             : 
      27             : struct fd_snapshot_manifest_vote_account {
      28             :   /* The pubkey of the vote account */
      29             :   uchar vote_account_pubkey[ 32UL ];
      30             : 
      31             :   ulong stake;
      32             :   ulong last_slot;
      33             :   long  last_timestamp;
      34             : 
      35             :   /* The percent of inflation rewards earned by the validator and
      36             :      deposited into the validator's vote account, from 0 to 100%.
      37             :      The remaning percentage of inflation rewards is distributed to
      38             :      all delegated stake accounts by stake weight. */
      39             :   uchar commission;
      40             : 
      41             :   /* The epoch credits array tracks the history of how many credits the
      42             :      provided vote account earned in each of the past epochs.  The
      43             :      entry at epoch_credits[0] is for the current epoch,
      44             :      epoch_credits[1] is for the previous epoch, and so on.  In cases of
      45             :      booting a new chain from genesis, or for new vote accounts the
      46             :      epoch credits history may be short.  The maximum number of entries
      47             :      in the epoch credits history is 64. */
      48             :   ulong epoch_credits_history_len;
      49             :   ulong epoch_credits[ 64UL ];
      50             : };
      51             : 
      52             : typedef struct fd_snapshot_manifest_vote_account fd_snapshot_manifest_vote_account_t;
      53             : 
      54             : struct fd_snapshot_manifest_vote_stakes {
      55             :   /* The vote pubkey */
      56             :   uchar vote[ 32UL ];
      57             : 
      58             :   /* The validator identity pubkey, aka node pubkey */
      59             :   uchar identity[ 32UL ];
      60             : 
      61             :   /* The commission account for inflation rewards (vote, before SIMD-0232) */
      62             :   uchar commission_inflation[ 32UL ];
      63             : 
      64             :   /* The commission account for block revenue (identity, before SIMD-0232) */
      65             :   uchar commission_block[ 32UL ];
      66             : 
      67             :   /* The validator BLS pubkey (used after SIMD-0326: Alpenglow) */
      68             :   uchar identity_bls[ 48UL ];
      69             : 
      70             :   /* The total amount of active stake for the vote account */
      71             :   ulong stake;
      72             : };
      73             : 
      74             : typedef struct fd_snapshot_manifest_vote_stakes fd_snapshot_manifest_vote_stakes_t;
      75             : 
      76             : struct fd_snapshot_manifest_epoch_stakes {
      77             :   ulong                              vote_stakes_len;
      78             :   fd_snapshot_manifest_vote_stakes_t vote_stakes[ MAX_VOTE_STAKES ];
      79             : };
      80             : 
      81             : typedef struct fd_snapshot_manifest_epoch_stakes fd_snapshot_manifest_epoch_stakes_t;
      82             : 
      83             : struct fd_snapshot_manifest_inflation_params {
      84             :   /* The initial inflation percentage starting at genesis.
      85             :      This value is set at genesis to 8% and is not expected to change. */
      86             :   double initial;
      87             : 
      88             :   /* The terminal inflation percentage is the long-term steady state
      89             :      inflation rate after a period of disinflation.  This value is set
      90             :      at genesis to 1.5% and is not expected to change. */
      91             :   double terminal;
      92             : 
      93             :   /* The rate per year at which inflation is lowered until it reaches
      94             :      the terminal inflation rate.  This value is set to 15% at genesis
      95             :      and is not expected to change. */
      96             :   double taper;
      97             : 
      98             :   /* The percentage of total inflation allocated to the foundation.
      99             :      This value is set at genesis to 5% and is not expected to change. */
     100             :   double foundation;
     101             : 
     102             :   /* The number of years in which a portion of the total inflation is
     103             :      allocated to the foundation (see foundation field).  This value is
     104             :      set to 7 years at genesis and is not expected to change. */
     105             :   double foundation_term;
     106             : };
     107             : 
     108             : typedef struct fd_snapshot_manifest_inflation_params fd_snapshot_manifest_inflation_params_t;
     109             : 
     110             : struct fd_snapshot_manifest_epoch_schedule_params {
     111             :   /* The maximum number of slots in each epoch. */
     112             :   ulong slots_per_epoch;
     113             : 
     114             :   /* A number of slots before beginning of an epoch to calculate a
     115             :      leader schedule for that epoch.  This value is set to
     116             :      slots_per_epoch (basically one epoch) and is unlikely to change. */
     117             :   ulong leader_schedule_slot_offset;
     118             : 
     119             :   /* Whether there is a warmup period where epochs are short and grow by
     120             :      powers of two until they reach the default epoch length of
     121             :      slots_per_epoch.  This value is set by default to true at genesis,
     122             :      though it may be configured differently in development
     123             :      environments. */
     124             :   uchar warmup;
     125             : 
     126             :   /* TODO: Probably remove this? Redundant and can be calculated from
     127             :      the above. */
     128             :   ulong first_normal_epoch;
     129             :   ulong first_normal_slot;
     130             : };
     131             : 
     132             : typedef struct fd_snapshot_manifest_epoch_schedule_params fd_snapshot_manifest_epoch_schedule_params_t;
     133             : 
     134             : struct fd_snapshot_manifest_fee_rate_governor {
     135             :   /* Transaction fees are calculated by charging a cost for each
     136             :      signature.  There is a mechanism to dynamically adjust the cost per
     137             :      signature based on the cluster's transaction processing capacity.
     138             :      In this mechanism, the cost per signature can vary between 50% to
     139             :      1000% of the target_lamports_per_signature value, which is the cost
     140             :      per signature when the cluster is operating at the desired
     141             :      transaction processing capacity defined by
     142             :      target_signatures_per_slot.
     143             : 
     144             :      This value is fixed at 10,000 from genesis onwards but may be
     145             :      changed in the future with feature flags. */
     146             :   ulong target_lamports_per_signature;
     147             : 
     148             :   /* The cluster transaction processing capacity is measured by
     149             :      signatures per slot.  Solana defines the desired transaction
     150             :      processing capacity using the value target_signatures_per_slot.
     151             : 
     152             :      This value is fixed at 20,000 from genesis onwards but may be
     153             :      changed in the future with feature flags. */
     154             :   ulong target_signatures_per_slot;
     155             : 
     156             :   /* The minimum cost per signature is 50% of the
     157             :      target_lamports_per_signature value.  Under the current default for
     158             :      target_lamports_per_signature, this value is at 5,000 lamports per
     159             :      signature. */
     160             :   ulong min_lamports_per_signature;
     161             : 
     162             :   /* The maximum cost per signature is 1000% of the
     163             :      target_lamports_per_signature value.  Under the current default for
     164             :      target_lamports_per_signature, this value is at 100,000 lamports
     165             :      per signature.*/
     166             :   ulong max_lamports_per_signature;
     167             : 
     168             :   /* The percent of collected fees that are burned.  This value is
     169             :      currently set to a fixed value of 50% from genesis onwards, but
     170             :      may be changed in the future with feature flags. */
     171             :   uchar burn_percent;
     172             : };
     173             : 
     174             : typedef struct fd_snapshot_manifest_fee_rate_governor fd_snapshot_manifest_fee_rate_governor_t;
     175             : 
     176             : struct fd_snapshot_manifest_rent {
     177             :   ulong lamports_per_uint8_year;
     178             :   double exemption_threshold;
     179             :   uchar burn_percent;
     180             : };
     181             : 
     182             : typedef struct fd_snapshot_manifest_rent fd_snapshot_manifest_rent_t;
     183             : 
     184             : struct fd_snapshot_manifest_blockhash {
     185             :    uchar hash[ 32UL ];
     186             :    ulong lamports_per_signature;
     187             :    ulong hash_index;
     188             :    ulong timestamp;
     189             : };
     190             : 
     191             : typedef struct fd_snapshot_manifest_blockhash fd_snapshot_manifest_blockhash_t;
     192             : 
     193             : struct fd_snapshot_manifest {
     194             :   /* The UNIX timestamp when the genesis block was for this chain
     195             :      was created, in nanoseconds.  */
     196             :   ulong creation_time_millis;
     197             : 
     198             :   /* At genesis, certain parameters can be set which control the
     199             :      inflation rewards going forward.  This includes what the initial
     200             :      inflation is and how the inflation curve changes over time.
     201             : 
     202             :      Currently, these parameters can never change and are fixed from
     203             :      genesis onwards, although in future they may change with new
     204             :      feature flags. */
     205             :   fd_snapshot_manifest_inflation_params_t inflation_params;
     206             : 
     207             :   /* At genesis, certain parameters can be set which control the
     208             :      epoch schedule going forward.  This includes how many slots
     209             :      there are per epoch, and certain development settings like if
     210             :      epochs start short and grow longer as the chain progreses.
     211             : 
     212             :      Currently, these parameters can never change and are fixed from
     213             :      genesis onwards, although in future they may change with new
     214             :      feature flags. */
     215             :   fd_snapshot_manifest_epoch_schedule_params_t epoch_schedule_params;
     216             : 
     217             :   /* At genesis, certain parameters can be set which control
     218             :      how transaction fees are dynamically adjusted going forward.
     219             : 
     220             :      Currently, these parameters can never change and are fixed from
     221             :      genesis onwards, although in future they may change with new
     222             :      feature flags. */
     223             :   fd_snapshot_manifest_fee_rate_governor_t fee_rate_governor;
     224             : 
     225             :   fd_snapshot_manifest_rent_t rent_params;
     226             : 
     227             :   /* The slot number for this snapshot */
     228             :   ulong slot;
     229             : 
     230             :   /* The number of blocks that have been built since genesis.  This is
     231             :      kind of like the slot number, in that it increments by 1 for every
     232             :      landed block, but it does not increment for skipped slots, so the
     233             :      block_height will always be less than or equal to the slot. */
     234             :   ulong block_height;
     235             : 
     236             :   /* TODO: Document */
     237             :   ulong collector_fees;
     238             : 
     239             :   /* The parent slot is the slot that this block builds on top of.  It
     240             :      is typically slot-1, but can be an arbitrary amount of slots
     241             :      earlier in case of forks, when the block skips over preceding
     242             :      slots. */
     243             :   ulong parent_slot;
     244             : 
     245             :   /* The bank hash of the slot represented by this snapshot.  The bank
     246             :      hash is used by the validator to detect mismatches.  All validators
     247             :      must agree on a bank hash for each slot or they will fork off.
     248             : 
     249             :      The bank hash is created for every slot by hashing together the
     250             :      parent bank hash with the accounts delta hash, the most recent
     251             :      Proof of History blockhash, and the number of signatures in the
     252             :      slot.
     253             : 
     254             :      The bank hash includes the epoch accounts hash when the epoch
     255             :      accounts hash is ready at slot 324000 in the current epoch. See the
     256             :      epoch_accounts_hash for more details regarding the epcoh accounts
     257             :      hash calculation . */
     258             :   uchar bank_hash[ 32UL ];
     259             : 
     260             :   /* The bank hash of the parent slot. */
     261             :   uchar parent_bank_hash[ 32UL ];
     262             : 
     263             :   /* The merkle-based hash of all account state on chain at the slot the
     264             :      snapshot is created.  The accounts hash is calculated when producing
     265             :      a snapshot. */
     266             :   uchar accounts_hash[ 32UL ];
     267             : 
     268             :   /* The merkle-based hash of modified accounts for the slot the
     269             :      snapshot is created.  The accounts_delta_hash is computed at
     270             :      the end of every slot and included into each bank hash.  It is
     271             :      computed by hashing all modified account state together. */
     272             :   uchar accounts_delta_hash[ 32UL ];
     273             : 
     274             :   /* The lattice hash of all account state on chain.  It is not yet used
     275             :      but in future will replace the accounts hash and the accounts delta
     276             :      hash.  Those hashes are expensive to compute because they require
     277             :      sorting the accounts, while the lattice hash uses newer cryptography
     278             :      to avoid this. */
     279             :   int   has_accounts_lthash;
     280             :   uchar accounts_lthash[ 2048UL ];
     281             : 
     282             :   /* The hash of all accounts at this snapshot's epoch.
     283             :      The epoch account hash is very expensive to calculate, so it is
     284             :      only calculated once per epoch during the epoch account hash
     285             :      calculation window, which is a range of slots in an epoch starting
     286             :      at slot 108000 and ending at slot 324000, where each epoch has
     287             :      432000 slots.
     288             : 
     289             :      The epoch_account_hash may be empty if the snapshot was produced
     290             :      before the epoch account hash calculation window. */
     291             :   int   has_epoch_account_hash;
     292             :   uchar epoch_account_hash[ 32UL ];
     293             : 
     294             :   ulong blockhashes_len;
     295             :   fd_snapshot_manifest_blockhash_t blockhashes[ 301UL ];
     296             : 
     297             :   ulong hard_forks_len;
     298             :   ulong hard_forks[ 64UL ];
     299             : 
     300             :   /* The proof of history component "proves" the passage of time (see
     301             :      extended discussion in PoH tile for what that acutally means) by
     302             :      continually doing sha256 hashes.  A certain number of hashes are
     303             :      required to be in each slot, to prove the leader spent some amount
     304             :      of time on the slot and didn't end it too early.
     305             : 
     306             :      In all clusters and environments that matter, this value is fixed
     307             :      at 64 and is unlikely to change, however it might be configured
     308             :      differently in development environments. */
     309             :   ulong ticks_per_slot;
     310             : 
     311             :   /* TODO: Document */
     312             :   ulong ns_per_slot;
     313             : 
     314             :   /* TODO: Document */
     315             :   double slots_per_year;
     316             : 
     317             :   /* The proof of history component typically requires every block to
     318             :      have 64 "ticks" in it (although this is configurable during
     319             :      development), but each tick is some flexible number of recursive
     320             :      sha256 hashes defined at genesis.
     321             : 
     322             :      The number of hashes for mainnet genesis is 12,500, meaning there
     323             :      will be 800,000 hashes per slot.
     324             : 
     325             :      There are various features, named like update_hashes_per_tick*
     326             :      which if enabled update the hashes_per_tick of the chain as-of the
     327             :      epoch where they are enabled.  This value incorporates any changes
     328             :      due to such features.
     329             : 
     330             :      In development environments, sometimes hashes_per_tick will not be
     331             :      specified (has_hashes_per_tick will be 0).  Agave refers to this as
     332             :      a "low power" mode, where ticks have just one hash in them.  It is
     333             :      distinct from just setting hahes_per_tick to 1, because it also
     334             :      reduces the slot duration from 400ms down to 0ms (or however long
     335             :      it takes to produce the hash).  See comments in the PoH tile for
     336             :      more extended discussion. */
     337             :   int   has_hashes_per_tick;
     338             :   ulong hashes_per_tick;
     339             : 
     340             :   /* The sum of all account balances in lamports as of this snapshots
     341             :      slot.  Total capitalization is used when computing inflation
     342             :      rewards and validating snapshots. */
     343             :   ulong capitalization;
     344             : 
     345             :   /* TODO: Why is this needed? */
     346             :   ulong tick_height;
     347             :   ulong max_tick_height;
     348             : 
     349             :   /* TODO: What is this? */
     350             :   ulong lamports_per_signature;
     351             : 
     352             :   /* TODO: Why is this needed? */
     353             :   ulong transaction_count;
     354             : 
     355             :   /* TODO: Why is this needed? */
     356             :   ulong signature_count;
     357             : 
     358             :   /* A list of this epoch's vote accounts and their state relating to
     359             :      rewards distribution, which includes the vote account's commission
     360             :      and vote credits.
     361             : 
     362             :      The validator distributes vote and stake rewards for the previous
     363             :      epoch in the slots immediately after the epoch boundary.  These
     364             :      vote and stake rewards are calculated as a stake-weighted
     365             :      percentage of the inflation rewards for the epoch and validator
     366             :      uptime, which is measured by vote account vote credits. */
     367             :   ulong                               vote_accounts_len;
     368             :   fd_snapshot_manifest_vote_account_t vote_accounts[ 16384UL ]; /* TODO: Bound correctly */
     369             : 
     370             :   /* Epoch stakes represent the exact amount staked to each vote
     371             :      account at the beginning of the previous epoch. They are
     372             :      primarily used to derive the leader schedule.
     373             : 
     374             :      Let's say the manifest is at epoch E.
     375             : 
     376             :      The field versioned_epoch_stakes in the manifest is a map
     377             : 
     378             :        <epoch> -> <VersionedEpochStakes>
     379             : 
     380             :      where <epoch> assumes these values:
     381             : 
     382             :        E   - represents the stakes at the beginning of epoch E-1,
     383             :              used to compute the leader schedule at E.
     384             : 
     385             :        E+1 - represents the stakes at the beginning of epoch E,
     386             :              used to compute the leader schedule at E+1.
     387             : 
     388             :      The epoch stakes are stored in an array, where epoch_stakes[0]
     389             :      contains the data to generate the current leader schedule (i.e. E)
     390             :      and epoch_stakes[1] contains the data to generate the next leader
     391             :      schedule (i.e. E+1). */
     392             :   fd_snapshot_manifest_epoch_stakes_t epoch_stakes[ 2UL ];
     393             : };
     394             : 
     395             : typedef struct fd_snapshot_manifest fd_snapshot_manifest_t;
     396             : 
     397             : /* Forward Declarations */
     398             : 
     399             : typedef struct fd_solana_manifest fd_solana_manifest_t;
     400             : 
     401             : FD_PROTOTYPES_BEGIN
     402             : 
     403             : fd_snapshot_manifest_t *
     404             : fd_snapshot_manifest_init_from_solana_manifest( void *                        mem,
     405             :                                                 fd_solana_manifest_global_t * solana_manifest );
     406             : 
     407             : FD_PROTOTYPES_END
     408             : 
     409             : #endif /* HEADER_fd_src_discof_restore_utils_fd_ssmsg_h */

Generated by: LCOV version 1.14