Line data Source code
1 : #ifndef HEADER_fd_src_flamenco_fd_flamenco_base_h 2 : #define HEADER_fd_src_flamenco_fd_flamenco_base_h 3 : 4 : #include "../ballet/base58/fd_base58.h" 5 : 6 : /* fd_w_u128 is a wrapped "uint128" type providing basic 128-bit 7 : unsigned int functionality even if the compile target does not 8 : natively support uint128. */ 9 : 10 : union __attribute__((packed)) fd_w_u128 { 11 : uchar uc[16]; 12 : ulong ul[2]; 13 : # ifdef __SIZEOF_INT128__ 14 : uint128 ud; 15 : # endif 16 : }; 17 : 18 : typedef union fd_w_u128 fd_w_u128_t; 19 : 20 : /* 32-byte container */ 21 : 22 63726 : #define FD_HASH_FOOTPRINT (32UL) 23 2085 : #define FD_PUBKEY_FOOTPRINT FD_HASH_FOOTPRINT 24 : union __attribute__((packed)) fd_hash { 25 : uchar hash[ FD_HASH_FOOTPRINT ]; 26 : uchar key [ FD_HASH_FOOTPRINT ]; // Making fd_hash and fd_pubkey interchangeable 27 : 28 : // Generic type specific accessors 29 : ulong ul [ FD_HASH_FOOTPRINT / sizeof(ulong) ]; 30 : uint ui [ FD_HASH_FOOTPRINT / sizeof(uint) ]; 31 : ushort us [ FD_HASH_FOOTPRINT / sizeof(ushort) ]; 32 : uchar uc [ FD_HASH_FOOTPRINT ]; 33 : }; 34 : typedef union fd_hash fd_hash_t; 35 : typedef union fd_hash fd_pubkey_t; 36 : 37 : FD_FN_PURE static inline int 38 : fd_hash_eq( fd_hash_t const * a, 39 190134 : fd_hash_t const * b ) { 40 190134 : return 0==memcmp( a, b, sizeof(fd_hash_t) ); 41 190134 : } 42 : 43 : FD_FN_PURE static inline int 44 : fd_hash_eq1( fd_hash_t a, 45 453 : fd_hash_t b ) { 46 453 : return 47 453 : ( a.ul[0]==b.ul[0] ) & ( a.ul[1]==b.ul[1] ) & 48 453 : ( a.ul[2]==b.ul[2] ) & ( a.ul[3]==b.ul[3] ); 49 453 : } 50 : 51 : FD_FN_PURE static inline int 52 30 : fd_hash_check_zero( fd_hash_t const * _x ) { 53 30 : return !( (_x)->ul[0] | (_x)->ul[1] | (_x)->ul[2] | (_x)->ul[3] ); 54 30 : } 55 : 56 0 : #define fd_pubkey_check_zero fd_hash_check_zero 57 9951 : #define fd_pubkey_eq fd_hash_eq 58 : 59 : /* 64-byte container */ 60 : 61 : union fd_signature { 62 : uchar uc[ 64 ]; 63 : ulong ul[ 8 ]; 64 : }; 65 : typedef union fd_signature fd_signature_t; 66 : 67 : FD_FN_PURE static inline int 68 : fd_signature_eq( fd_signature_t const * a, 69 0 : fd_signature_t const * b ) { 70 0 : return 0==memcmp( a, b, sizeof(fd_signature_t) ); 71 0 : } 72 : 73 : /* Forward declarations */ 74 : 75 : struct fd_bank; 76 : typedef struct fd_bank fd_bank_t; 77 : 78 : struct fd_banks; 79 : typedef struct fd_banks fd_banks_t; 80 : 81 : struct fd_exec_instr_ctx; 82 : typedef struct fd_exec_instr_ctx fd_exec_instr_ctx_t; 83 : 84 : struct fd_acc_mgr; 85 : typedef struct fd_acc_mgr fd_acc_mgr_t; 86 : 87 : struct fd_capture_ctx; 88 : typedef struct fd_capture_ctx fd_capture_ctx_t; 89 : 90 : struct fd_dump_proto_ctx; 91 : typedef struct fd_dump_proto_ctx fd_dump_proto_ctx_t; 92 : 93 : struct fd_txn_dump_ctx; 94 : typedef struct fd_txn_dump_ctx fd_txn_dump_ctx_t; 95 : 96 : struct fd_borrowed_account; 97 : typedef struct fd_borrowed_account fd_borrowed_account_t; 98 : 99 : union fd_features; 100 : typedef union fd_features fd_features_t; 101 : 102 : struct fd_epoch_schedule; 103 : typedef struct fd_epoch_schedule fd_epoch_schedule_t; 104 : 105 : struct fd_slot_params; 106 : typedef struct fd_slot_params fd_slot_params_t; 107 : 108 : struct fd_progcache; 109 : typedef struct fd_progcache fd_progcache_t; 110 : 111 : struct fd_runtime_stack; 112 : typedef struct fd_runtime_stack fd_runtime_stack_t; 113 : 114 : struct fd_runtime; 115 : typedef struct fd_runtime fd_runtime_t; 116 : 117 : struct fd_txn_in; 118 : typedef struct fd_txn_in fd_txn_in_t; 119 : 120 : struct fd_txn_out; 121 : typedef struct fd_txn_out fd_txn_out_t; 122 : 123 : struct fd_log_collector; 124 : typedef struct fd_log_collector fd_log_collector_t; 125 : 126 : struct fd_genesis; 127 : typedef struct fd_genesis fd_genesis_t; 128 : 129 : struct fd_stake_rewards; 130 : typedef struct fd_stake_rewards fd_stake_rewards_t; 131 : 132 : struct fd_top_votes; 133 : typedef struct fd_top_votes fd_top_votes_t; 134 : 135 : /* Misc types */ 136 : 137 3 : #define FD_EPOCH_CREDITS_MAX (64UL) 138 : struct fd_epoch_credits { 139 : uchar pubkey[32]; 140 : ulong base_credits; 141 : ushort epoch [ FD_EPOCH_CREDITS_MAX ]; 142 : uint credits_delta [ FD_EPOCH_CREDITS_MAX ]; 143 : uint prev_credits_delta[ FD_EPOCH_CREDITS_MAX ]; 144 : ushort commission; 145 : uchar cnt; 146 : uchar fast_path_ok; /* True if the entries satisfy the boundary fast path prerequisites: 147 : (1) initial[n]<=final[n], (2) initial[n]==final[n-1], and (3) 148 : epoch[n]>=epoch[n-1]. Always true for production accounts written 149 : by vote programs. Points calculation takes the fast paths only 150 : when true and the slow reference implementation otherwise. So 151 : synthetic fuzzer inputs fall back gracefully. */ 152 : }; 153 : typedef struct fd_epoch_credits fd_epoch_credits_t; 154 : 155 : FD_STATIC_ASSERT( (ulong)UCHAR_MAX>=FD_EPOCH_CREDITS_MAX, cnt_width ); 156 : FD_STATIC_ASSERT( sizeof(fd_epoch_credits_t)==688UL, fd_epoch_credits ); 157 : 158 : static inline uchar 159 327 : fd_epoch_credits_fast_path_ok( fd_epoch_credits_t const * epoch_credits ) { 160 423 : for( ulong i=0UL; i<epoch_credits->cnt; i++ ) { 161 96 : if( FD_UNLIKELY( epoch_credits->base_credits>ULONG_MAX-(ulong)epoch_credits->credits_delta[ i ] ) ) return 0; /* no overflow/wrapping on any credits */ 162 96 : if( FD_UNLIKELY( epoch_credits->prev_credits_delta[ i ]>epoch_credits->credits_delta[ i ] ) ) return 0; /* (1) */ 163 96 : if( FD_UNLIKELY( i && epoch_credits->prev_credits_delta[ i ]!=epoch_credits->credits_delta[ i-1UL ] ) ) return 0; /* (2) */ 164 96 : if( FD_UNLIKELY( i && epoch_credits->epoch[ i ]<epoch_credits->epoch[ i-1UL ] ) ) return 0; /* (3) */ 165 96 : } 166 327 : return 1; 167 327 : } 168 : 169 : struct fd_stashed_commission { 170 : uchar pubkey[32]; 171 : ushort commission; 172 : }; 173 : typedef struct fd_stashed_commission fd_stashed_commission_t; 174 : 175 : struct fd_hard_fork { 176 : ulong slot; 177 : ulong cnt; /* number of hard forks in that slot */ 178 : }; 179 : typedef struct fd_hard_fork fd_hard_fork_t; 180 : 181 : FD_PROTOTYPES_BEGIN 182 : 183 : struct fd_fee_rate_governor { 184 : ulong target_lamports_per_signature; 185 : ulong target_signatures_per_slot; 186 : ulong min_lamports_per_signature; 187 : ulong max_lamports_per_signature; 188 : uchar burn_percent; 189 : }; 190 : typedef struct fd_fee_rate_governor fd_fee_rate_governor_t; 191 : 192 : struct fd_inflation { 193 : double initial; 194 : double terminal; 195 : double taper; 196 : double foundation; 197 : double foundation_term; 198 : double unused; 199 : }; 200 : typedef struct fd_inflation fd_inflation_t; 201 : 202 : #endif /* HEADER_fd_src_flamenco_fd_flamenco_base_h */