LCOV - code coverage report
Current view: top level - flamenco/genesis - fd_genesis_parse.h (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 0 10 0.0 %
Date: 2026-10-22 18:10:43 Functions: 0 8 0.0 %

          Line data    Source code
       1             : #ifndef HEADER_fd_src_flamenco_genesis_fd_genesis_parse_h
       2             : #define HEADER_fd_src_flamenco_genesis_fd_genesis_parse_h
       3             : 
       4             : #include "../fd_flamenco_base.h"
       5             : 
       6             : /* Hardcoded genesis array limits */
       7             : #define FD_GENESIS_BUILTIN_MAX_COUNT (16UL)
       8             : 
       9             : /* FD_GENESIS_ACCOUNT_MIN_SZ is the smallest bincode encoding of one
      10             :    genesis account (32 pubkey + 8 lamports + 8 data_len + 0 data +
      11             :    32 owner + 1 executable + 8 rent_epoch).  A blob of N bytes can
      12             :    therefore hold at most N/FD_GENESIS_ACCOUNT_MIN_SZ accounts, which is
      13             :    how callers size the account offset table (see fd_genesis_account_max). */
      14           0 : #define FD_GENESIS_ACCOUNT_MIN_SZ (89UL)
      15             : 
      16           0 : #define FD_GENESIS_ACCOUNT_MAX( blob_sz_max ) ((blob_sz_max)/FD_GENESIS_ACCOUNT_MIN_SZ)
      17             : 
      18           0 : #define FD_GENESIS_ALIGN (8UL)
      19           0 : #define FD_GENESIS_FOOTPRINT( account_max ) (sizeof(fd_genesis_t) + (account_max)*sizeof(fd_genesis_account_off_t))
      20             : 
      21           0 : #define FD_GENESIS_TYPE_TESTNET     (0)
      22           0 : #define FD_GENESIS_TYPE_MAINNET     (1)
      23           0 : #define FD_GENESIS_TYPE_DEVNET      (2)
      24             : #define FD_GENESIS_TYPE_DEVELOPMENT (3)
      25             : 
      26             : struct fd_genesis_account_off {
      27             :   ulong pubkey_off;
      28             :   ulong owner_off;
      29             : };
      30             : typedef struct fd_genesis_account_off fd_genesis_account_off_t;
      31             : 
      32             : struct fd_genesis_builtin_off {
      33             :   ulong data_len_off;
      34             :   ulong pubkey_off;
      35             : };
      36             : typedef struct fd_genesis_builtin_off fd_genesis_builtin_off_t;
      37             : 
      38             : /* fd_genesis_t helps interpret a genesis blob.  Contains deserialized
      39             :    values and offsets to binary account data.  The account offset table
      40             :    is a trailing flexible array sized by the caller (fd_genesis_new with
      41             :    fd_genesis_footprint), so instances must be allocated with the
      42             :    footprint for the desired capacity and not declared directly. */
      43             : 
      44             : struct fd_genesis {
      45             :   ulong creation_time;
      46             :   uint  cluster_type;
      47             : 
      48             :   struct {
      49             :     ulong ticks_per_slot;
      50             :     ulong tick_duration_secs;
      51             :     ulong tick_duration_ns;
      52             :     ulong target_tick_count;
      53             :     ulong hashes_per_tick;
      54             :   } poh;
      55             : 
      56             :   struct {
      57             :     ulong target_lamports_per_signature;
      58             :     ulong target_signatures_per_slot;
      59             :     ulong min_lamports_per_signature;
      60             :     ulong max_lamports_per_signature;
      61             :     uchar burn_percent;
      62             :   } fee_rate_governor;
      63             : 
      64             :   struct {
      65             :     ulong  lamports_per_uint8_year;
      66             :     double exemption_threshold;
      67             :     uchar  burn_percent;
      68             :   } rent;
      69             : 
      70             :   struct {
      71             :     double initial;
      72             :     double terminal;
      73             :     double taper;
      74             :     double foundation;
      75             :     double foundation_term;
      76             :   } inflation;
      77             : 
      78             :   struct {
      79             :     ulong slots_per_epoch;
      80             :     ulong leader_schedule_slot_offset;
      81             :     uchar warmup;
      82             :     ulong first_normal_epoch;
      83             :     ulong first_normal_slot;
      84             :   } epoch_schedule;
      85             : 
      86             :   ulong builtin_cnt;
      87             :   ulong account_cnt;
      88             : 
      89             :   fd_genesis_builtin_off_t builtin[ FD_GENESIS_BUILTIN_MAX_COUNT ];
      90             : 
      91             :   ulong account_max; /* capacity of account[], set by fd_genesis_new */
      92             :   fd_genesis_account_off_t account[];
      93             : };
      94             : 
      95             : typedef struct fd_genesis fd_genesis_t;
      96             : 
      97             : struct fd_genesis_account {
      98             :   fd_pubkey_t   pubkey;
      99             :   int           executable;
     100             :   ulong         lamports;
     101             :   fd_pubkey_t   owner;
     102             :   ulong         data_len;
     103             :   uchar const * data;
     104             : };
     105             : 
     106             : typedef struct fd_genesis_account fd_genesis_account_t;
     107             : 
     108             : struct fd_genesis_builtin {
     109             :   fd_pubkey_t   pubkey;
     110             :   ulong         data_len;
     111             :   uchar const * data;
     112             : };
     113             : 
     114             : typedef struct fd_genesis_builtin fd_genesis_builtin_t;
     115             : 
     116             : FD_PROTOTYPES_BEGIN
     117             : 
     118             : /* fd_genesis_account_max returns the largest account count a genesis
     119             :    blob of at most blob_sz_max bytes can encode.  Use it to size the
     120             :    account offset table of an fd_genesis_t that will parse blobs bounded
     121             :    by blob_sz_max (e.g. development.genesis.max_file_size_mib). */
     122             : 
     123             : FD_FN_CONST static inline ulong
     124           0 : fd_genesis_account_max( ulong blob_sz_max ) {
     125           0 :   return FD_GENESIS_ACCOUNT_MAX( blob_sz_max );
     126           0 : }
     127             : 
     128             : /* fd_genesis_{align,footprint} describe the memory region backing an
     129             :    fd_genesis_t able to hold account_max account offsets (account_max
     130             :    may be 0; the caller bounds it, e.g. via fd_genesis_account_max).
     131             : 
     132             :    fd_genesis_new formats such a region and returns the fd_genesis_t to
     133             :    pass to fd_genesis_parse.  Returns NULL and logs a warning if mem is
     134             :    NULL or misaligned.  There is deliberately no join/leave/delete: the
     135             :    object is private to the caller and never shared across processes. */
     136             : 
     137             : FD_FN_CONST ulong
     138             : fd_genesis_align( void );
     139             : 
     140             : FD_FN_CONST ulong
     141             : fd_genesis_footprint( ulong account_max );
     142             : 
     143             : fd_genesis_t *
     144             : fd_genesis_new( void * mem,
     145             :                 ulong  account_max );
     146             : 
     147             : /* fd_genesis_parse decodes a bincode-encoded 'GenesisConfig'.
     148             :    The genesis blob is found in the genesis archive, e.g.
     149             :    GET http://<rpc>/genesis.tar.bz2
     150             : 
     151             :    Agave type definition:
     152             :    https://github.com/anza-xyz/solana-sdk/blob/genesis-config%40v3.0.0/genesis-config/src/lib.rs#L59
     153             : 
     154             :    Decodes the message at bin of size bin_sz.  On success, populates
     155             :    and returns the fd_genesis_t object.  On failure, logs warning and
     156             :    returns NULL.  Reasons for failure include:
     157             :    - Deserialize failed (invalid bincode?)
     158             :    - Hardcoded limit exceeded (builtin count, slots per epoch)
     159             :    - Account count exceeds the capacity genesis was created with (only
     160             :      possible for a malformed blob when the capacity was derived from
     161             :      the blob size bound with fd_genesis_account_max)
     162             :    - Garbage trailing data */
     163             : 
     164             : fd_genesis_t *
     165             : fd_genesis_parse( fd_genesis_t * genesis,
     166             :                   uchar const *  bin,
     167             :                   ulong          bin_sz );
     168             : 
     169             : /* Account/builtin getter */
     170             : 
     171             : fd_genesis_account_t *
     172             : fd_genesis_account( fd_genesis_t const *   genesis,
     173             :                     uchar const *          bin,
     174             :                     fd_genesis_account_t * out,
     175             :                     ulong                  idx );
     176             : 
     177             : fd_genesis_builtin_t *
     178             : fd_genesis_builtin( fd_genesis_t const *   genesis,
     179             :                     uchar const *          bin,
     180             :                     fd_genesis_builtin_t * out,
     181             :                     ulong                  idx );
     182             : 
     183             : FD_PROTOTYPES_END
     184             : 
     185             : #endif /* HEADER_fd_src_flamenco_genesis_fd_genesis_parse_h */

Generated by: LCOV version 1.14