LCOV - code coverage report
Current view: top level - flamenco/runtime - fd_genesis_parse.h (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 0 4 0.0 %
Date: 2026-03-19 18:19:27 Functions: 0 0 -

          Line data    Source code
       1             : #ifndef HEADER_fd_src_flamenco_runtime_fd_genesis_parse_h
       2             : #define HEADER_fd_src_flamenco_runtime_fd_genesis_parse_h
       3             : 
       4             : #include "../../util/fd_util_base.h"
       5             : #include "../fd_flamenco_base.h"
       6             : #include "../types/fd_types_custom.h"
       7             : 
       8             : /* Hardcoded max serialized genesis blob size */
       9           0 : #define FD_GENESIS_MAX_MESSAGE_SIZE (1UL<<28) /* 256 MiB */
      10             : 
      11             : /* Hardcoded genesis array limits */
      12             : #define FD_GENESIS_ACCOUNT_MAX_COUNT (65536UL)
      13             : #define FD_GENESIS_BUILTIN_MAX_COUNT (16UL)
      14             : 
      15           0 : #define FD_GENESIS_TYPE_TESTNET     (0)
      16           0 : #define FD_GENESIS_TYPE_MAINNET     (1)
      17           0 : #define FD_GENESIS_TYPE_DEVNET      (2)
      18             : #define FD_GENESIS_TYPE_DEVELOPMENT (3)
      19             : 
      20             : struct fd_genesis_account_off {
      21             :   ulong pubkey_off;
      22             :   ulong owner_off;
      23             : };
      24             : typedef struct fd_genesis_account_off fd_genesis_account_off_t;
      25             : 
      26             : struct fd_genesis_builtin_off {
      27             :   ulong data_len_off;
      28             :   ulong pubkey_off;
      29             : };
      30             : typedef struct fd_genesis_builtin_off fd_genesis_builtin_off_t;
      31             : 
      32             : /* fd_genesis_t helps interpret a genesis blob.  Contains deserialized
      33             :    values and offsets to binary account data.  This is a very large
      34             :    struct (~1 MiB) so it should not be stack allocated. */
      35             : 
      36             : struct fd_genesis {
      37             :   ulong creation_time;
      38             :   uint  cluster_type;
      39             : 
      40             :   struct {
      41             :     ulong ticks_per_slot;
      42             :     ulong tick_duration_secs;
      43             :     ulong tick_duration_ns;
      44             :     ulong target_tick_count;
      45             :     ulong hashes_per_tick;
      46             :   } poh;
      47             : 
      48             :   struct {
      49             :     ulong target_lamports_per_signature;
      50             :     ulong target_signatures_per_slot;
      51             :     ulong min_lamports_per_signature;
      52             :     ulong max_lamports_per_signature;
      53             :     uchar burn_percent;
      54             :   } fee_rate_governor;
      55             : 
      56             :   struct {
      57             :     ulong  lamports_per_uint8_year;
      58             :     double exemption_threshold;
      59             :     uchar  burn_percent;
      60             :   } rent;
      61             : 
      62             :   struct {
      63             :     double initial;
      64             :     double terminal;
      65             :     double taper;
      66             :     double foundation;
      67             :     double foundation_term;
      68             :   } inflation;
      69             : 
      70             :   struct {
      71             :     ulong slots_per_epoch;
      72             :     ulong leader_schedule_slot_offset;
      73             :     uchar warmup;
      74             :     ulong first_normal_epoch;
      75             :     ulong first_normal_slot;
      76             :   } epoch_schedule;
      77             : 
      78             :   ulong builtin_cnt;
      79             :   ulong account_cnt;
      80             : 
      81             :   fd_genesis_builtin_off_t builtin[ FD_GENESIS_BUILTIN_MAX_COUNT ];
      82             :   fd_genesis_account_off_t account[ FD_GENESIS_ACCOUNT_MAX_COUNT ];
      83             : };
      84             : 
      85             : typedef struct fd_genesis fd_genesis_t;
      86             : 
      87             : struct fd_genesis_account {
      88             :   fd_pubkey_t       pubkey;
      89             :   fd_account_meta_t meta; /* do not use fd_account_data() */
      90             :   uchar const *     data;
      91             : };
      92             : 
      93             : typedef struct fd_genesis_account fd_genesis_account_t;
      94             : 
      95             : struct fd_genesis_builtin {
      96             :   fd_pubkey_t   pubkey;
      97             :   ulong         dlen;
      98             :   uchar const * data;
      99             : };
     100             : 
     101             : typedef struct fd_genesis_builtin fd_genesis_builtin_t;
     102             : 
     103             : FD_PROTOTYPES_BEGIN
     104             : 
     105             : /* fd_genesis_parse decodes a bincode-encoded 'GenesisConfig'.
     106             :    The genesis blob is found in the genesis archive, e.g.
     107             :    GET http://<rpc>/genesis.tar.bz2
     108             : 
     109             :    Agave type definition:
     110             :    https://github.com/anza-xyz/solana-sdk/blob/genesis-config%40v3.0.0/genesis-config/src/lib.rs#L59
     111             : 
     112             :    Decodes the message at bin of size bin_sz.  On success, populates
     113             :    and returns the fd_genesis_t object.  On failure, logs warning and
     114             :    returns NULL.  Reasons for failure include:
     115             :    - Deserialize failed (invalid bincode?)
     116             :    - Hardcoded limit exceeded (builtin/account count)
     117             :    - Garbage trailing data */
     118             : 
     119             : fd_genesis_t *
     120             : fd_genesis_parse( fd_genesis_t * genesis,
     121             :                   uchar const *  bin,
     122             :                   ulong          bin_sz );
     123             : 
     124             : /* Account/builtin getter */
     125             : 
     126             : fd_genesis_account_t *
     127             : fd_genesis_account( fd_genesis_t const *   genesis,
     128             :                     uchar const *          bin,
     129             :                     fd_genesis_account_t * out,
     130             :                     ulong                  idx );
     131             : 
     132             : fd_genesis_builtin_t *
     133             : fd_genesis_builtin( fd_genesis_t const *   genesis,
     134             :                     uchar const *          bin,
     135             :                     fd_genesis_builtin_t * out,
     136             :                     ulong                  idx );
     137             : 
     138             : FD_PROTOTYPES_END
     139             : 
     140             : #endif /* HEADER_fd_src_flamenco_runtime_fd_genesis_parse_h */

Generated by: LCOV version 1.14