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