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