Line data Source code
1 : #ifndef HEADER_fd_src_flamenco_runtime_fd_types_custom 2 : #define HEADER_fd_src_flamenco_runtime_fd_types_custom 3 : 4 : #include "fd_types_meta.h" 5 : #include "fd_bincode.h" 6 : #include "../../ballet/ed25519/fd_ed25519.h" 7 : #include "../../ballet/txn/fd_txn.h" 8 : #include "../../util/net/fd_ip4.h" 9 : 10 15 : #define FD_HASH_FOOTPRINT (32UL) 11 15 : #define FD_HASH_ALIGN (8UL) 12 0 : #define FD_PUBKEY_FOOTPRINT FD_HASH_FOOTPRINT 13 0 : #define FD_PUBKEY_ALIGN FD_HASH_ALIGN 14 : 15 : /* TODO this should not have packed alignment, but it's misused everywhere */ 16 : 17 : union __attribute__((packed)) fd_hash { 18 : uchar hash[ FD_HASH_FOOTPRINT ]; 19 : uchar key [ FD_HASH_FOOTPRINT ]; // Making fd_hash and fd_pubkey interchangeable 20 : 21 : // Generic type specific accessors 22 : ulong ul [ FD_HASH_FOOTPRINT / sizeof(ulong) ]; 23 : uint ui [ FD_HASH_FOOTPRINT / sizeof(uint) ]; 24 : uchar uc [ FD_HASH_FOOTPRINT ]; 25 : }; 26 : 27 : typedef union fd_hash fd_hash_t; 28 : typedef union fd_hash fd_pubkey_t; 29 : 30 : static const fd_pubkey_t pubkey_null = { 0 }; 31 : static const fd_hash_t hash_null = { 0 }; 32 : 33 : union fd_signature { 34 : uchar uc[ 64 ]; 35 : ulong ul[ 8 ]; 36 : }; 37 : 38 : typedef union fd_signature fd_signature_t; 39 : typedef union fd_signature fd_signature_global_t; 40 : 41 : FD_PROTOTYPES_BEGIN 42 : 43 : #define fd_hash_check_zero(_x) (!((_x)->ul[0] | (_x)->ul[1] | (_x)->ul[2] | (_x)->ul[3])) 44 : #define fd_hash_set_zero(_x) {((_x)->ul[0] = 0); ((_x)->ul[1] = 0); ((_x)->ul[2] = 0); ((_x)->ul[3] = 0);} 45 : 46 136092 : #define fd_pubkey_new fd_hash_new 47 91590 : #define fd_pubkey_encode fd_hash_encode 48 0 : #define fd_pubkey_destroy fd_hash_destroy 49 6 : #define fd_pubkey_size fd_hash_size 50 : #define fd_pubkey_check_zero fd_hash_check_zero 51 : #define fd_pubkey_set_zero fd_hash_set_zero 52 45462 : #define fd_pubkey_walk fd_hash_walk 53 136284 : #define fd_pubkey_decode_inner fd_hash_decode_inner 54 : #define fd_pubkey_decode_footprint fd_hash_decode_footprint 55 90882 : #define fd_pubkey_decode_footprint_inner fd_hash_decode_footprint_inner 56 : #define fd_pubkey_decode fd_hash_decode 57 : #define fd_pubkey_decode_global fd_hash_decode_global 58 12 : #define fd_pubkey_decode_inner_global fd_hash_decode_inner_global 59 204 : #define fd_pubkey_convert_global_to_local fd_hash_convert_global_to_local 60 : 61 : struct __attribute__((aligned(8UL))) fd_option_slot { 62 : uchar is_some; 63 : ulong slot; 64 : }; 65 : typedef struct fd_option_slot fd_option_slot_t; 66 : 67 : /* Index structure needed for transaction status (metadata) blocks */ 68 : struct fd_txnstatusidx { 69 : fd_ed25519_sig_t sig; 70 : ulong offset; 71 : ulong status_sz; 72 : }; 73 : typedef struct fd_txnstatusidx fd_txnstatusidx_t; 74 : 75 : /* IPv4 ***************************************************************/ 76 : 77 : typedef uint fd_gossip_ip4_addr_t; 78 : typedef uint fd_gossip_ip4_addr_t; 79 : 80 : typedef uint fd_gossip_ip4_addr_global_t; 81 : typedef uint fd_gossip_ip4_addr_global_t; 82 : 83 : /* IPv6 ***************************************************************/ 84 : 85 : union fd_gossip_ip6_addr { 86 : uchar uc[ 16 ]; 87 : ushort us[ 8 ]; 88 : uint ul[ 4 ]; 89 : }; 90 : 91 : typedef union fd_gossip_ip6_addr fd_gossip_ip6_addr_t; 92 : 93 : union fd_gossip_ip6_addr_global { 94 : uchar uc[ 16 ]; 95 : ushort us[ 8 ]; 96 : uint ul[ 4 ]; 97 : }; 98 : 99 : typedef union fd_gossip_ip6_addr_global fd_gossip_ip6_addr_global_t; 100 : 101 : int 102 : fd_solana_vote_account_decode_footprint( fd_bincode_decode_ctx_t * ctx, ulong * total_sz ); 103 : 104 : int 105 : fd_solana_vote_account_decode_footprint_inner( fd_bincode_decode_ctx_t * ctx, ulong * total_sz ); 106 : 107 : void * 108 : fd_solana_vote_account_decode( void * mem, fd_bincode_decode_ctx_t * ctx ); 109 : 110 : void 111 : fd_solana_vote_account_decode_inner( void * struct_mem, void * * alloc_mem, fd_bincode_decode_ctx_t * ctx ); 112 : 113 : /* Transaction wrapper ************************************************/ 114 : 115 : /* fd_flamenco_txn_t is yet another fd_txn_t wrapper. 116 : This should die as soon as we have a better stubs generator. */ 117 : 118 : struct fd_flamenco_txn { 119 : union { 120 : uchar txn_buf[ FD_TXN_MAX_SZ ]; 121 : __extension__ fd_txn_t txn[0]; 122 : }; 123 : uchar raw[ FD_TXN_MTU ]; 124 : ulong raw_sz; 125 : }; 126 : 127 : typedef struct fd_flamenco_txn fd_flamenco_txn_t; 128 : typedef struct fd_flamenco_txn fd_flamenco_txn_global_t; 129 : 130 : 131 : static inline void 132 3 : fd_flamenco_txn_new( fd_flamenco_txn_t * self FD_FN_UNUSED ) {} 133 : 134 : static inline void 135 0 : fd_flamenco_txn_destroy( fd_flamenco_txn_t const * self FD_FN_UNUSED ) {} 136 : 137 : FD_FN_CONST static inline ulong 138 0 : fd_flamenco_txn_size( fd_flamenco_txn_t const * self ) { 139 0 : return self->raw_sz; 140 0 : } 141 : 142 : static inline int 143 : fd_flamenco_txn_encode( fd_flamenco_txn_t const * self, 144 0 : fd_bincode_encode_ctx_t * ctx ) { 145 0 : return fd_bincode_bytes_encode( self->raw, self->raw_sz, ctx ); 146 0 : } 147 : 148 : static inline void 149 : fd_flamenco_txn_walk( void * w, 150 : fd_flamenco_txn_t const * self, 151 : fd_types_walk_fn_t fun, 152 : char const * name, 153 9 : uint level ) { 154 : 155 9 : static uchar const zero[ 64 ]={0}; 156 9 : fd_txn_t const * txn = self->txn; 157 9 : uchar const * sig0 = zero; 158 : 159 9 : if( FD_LIKELY( txn->signature_cnt > 0 ) ) 160 9 : sig0 = fd_txn_get_signatures( txn, self->raw )[0]; 161 : 162 : /* For now, just print the transaction's signature */ 163 9 : fun( w, sig0, name, FD_FLAMENCO_TYPE_SIG512, "txn", level ); 164 9 : } 165 : 166 : static inline ulong 167 3 : fd_flamenco_txn_align( void ) { 168 3 : return alignof(fd_flamenco_txn_t); 169 3 : } 170 : 171 : static inline ulong 172 0 : fd_flamenco_txn_footprint( void ) { 173 0 : return sizeof(fd_flamenco_txn_t); 174 0 : } 175 : 176 : int 177 : fd_flamenco_txn_decode_footprint( fd_bincode_decode_ctx_t * ctx, ulong * total_sz ); 178 : 179 : int 180 : fd_flamenco_txn_decode_footprint_inner( fd_bincode_decode_ctx_t * ctx, ulong * total_sz ); 181 : 182 : void * 183 : fd_flamenco_txn_decode( void * mem, fd_bincode_decode_ctx_t * ctx ); 184 : 185 : void 186 : fd_flamenco_txn_decode_inner( void * struct_mem, void * * alloc_mem, fd_bincode_decode_ctx_t * ctx ); 187 : 188 : void 189 : fd_flamenco_txn_decode_inner_global( void * struct_mem, void * * alloc_mem, fd_bincode_decode_ctx_t * ctx ); 190 : 191 : void * 192 : fd_flamenco_txn_decode_global( void * mem, fd_bincode_decode_ctx_t * ctx ); 193 : 194 : int 195 : fd_flamenco_txn_convert_global_to_local( void const * global_self, fd_flamenco_txn_t * self, fd_bincode_decode_ctx_t * ctx ); 196 : 197 : /* Represents the lamport balance associated with an account. */ 198 : typedef ulong fd_acc_lamports_t; 199 : 200 : #if FD_HAS_INT128 201 : /********************* Rewards types **************************************************/ 202 : /* TODO: move these into fd_types, but first we need to add dlist support to fd_types */ 203 : struct __attribute__((aligned(8UL))) fd_stake_reward { 204 : /* dlist */ 205 : ulong prev; 206 : ulong next; 207 : /* pool */ 208 : ulong parent; 209 : /* data */ 210 : fd_pubkey_t stake_pubkey; 211 : ulong credits_observed; 212 : ulong lamports; 213 : uchar valid; 214 : }; 215 : typedef struct fd_stake_reward fd_stake_reward_t; 216 : #define FD_STAKE_REWARD_FOOTPRINT sizeof(fd_stake_reward_t) 217 : #define FD_STAKE_REWARD_ALIGN (8UL) 218 : 219 : /* Encoded Size: Fixed (42 bytes) */ 220 : struct __attribute__((aligned(8UL))) fd_vote_reward { 221 : fd_pubkey_t pubkey; 222 : ulong vote_rewards; 223 : uchar commission; 224 : uchar needs_store; 225 : }; 226 : typedef struct fd_vote_reward fd_vote_reward_t; 227 : #define FD_VOTE_REWARD_FOOTPRINT sizeof(fd_vote_reward_t) 228 : #define FD_VOTE_REWARD_ALIGN (8UL) 229 : 230 : #define DLIST_NAME fd_stake_reward_dlist 231 : #define DLIST_ELE_T fd_stake_reward_t 232 : #include "../../util/tmpl/fd_dlist.c" 233 : #undef DLIST_NAME 234 : #undef DLIST_ELE_T 235 : 236 : #define POOL_NAME fd_stake_reward_pool 237 0 : #define POOL_T fd_stake_reward_t 238 0 : #define POOL_NEXT parent 239 : #include "../../util/tmpl/fd_pool.c" 240 : #undef POOL_NAME 241 : #undef POOL_T 242 : #undef POOL_NEXT 243 : 244 : typedef struct fd_vote_reward_t_mapnode fd_vote_reward_t_mapnode_t; 245 : #define REDBLK_T fd_vote_reward_t_mapnode_t 246 : #define REDBLK_NAME fd_vote_reward_t_map 247 : #define REDBLK_IMPL_STYLE 1 248 : #include "../../util/tmpl/fd_redblack.c" 249 : struct fd_vote_reward_t_mapnode { 250 : fd_vote_reward_t elem; 251 : ulong redblack_parent; 252 : ulong redblack_left; 253 : ulong redblack_right; 254 : int redblack_color; 255 : }; 256 : 257 : /* https://github.com/anza-xyz/agave/blob/cbc8320d35358da14d79ebcada4dfb6756ffac79/programs/stake/src/points.rs#L21 */ 258 : /* Encoded Size: Fixed (24 bytes) */ 259 : struct __attribute__((aligned(8UL))) fd_point_value { 260 : ulong rewards; 261 : uint128 points; 262 : }; 263 : typedef struct fd_point_value fd_point_value_t; 264 0 : #define FD_POINT_VALUE_FOOTPRINT sizeof(fd_point_value_t) 265 : #define FD_POINT_VALUE_ALIGN (8UL) 266 : 267 : /* https://github.com/anza-xyz/agave/blob/7117ed9653ce19e8b2dea108eff1f3eb6a3378a7/runtime/src/bank/partitioned_epoch_rewards/mod.rs#L56 */ 268 : /* Encoded Size: Dynamic */ 269 : struct __attribute__((aligned(8UL))) fd_partitioned_stake_rewards { 270 : ulong partitions_len; 271 : fd_stake_reward_dlist_t * partitions; 272 : fd_stake_reward_t * pool; 273 : }; 274 : typedef struct fd_partitioned_stake_rewards fd_partitioned_stake_rewards_t; 275 0 : #define FD_PARTITIONED_STAKE_REWARDS_FOOTPRINT sizeof(fd_partitioned_stake_rewards_t) 276 : #define FD_PARTITIONED_STAKE_REWARDS_ALIGN (8UL) 277 : 278 : /* https://github.com/anza-xyz/agave/blob/7117ed9653ce19e8b2dea108eff1f3eb6a3378a7/runtime/src/bank/partitioned_epoch_rewards/mod.rs#L131 */ 279 : /* Encoded Size: Dynamic */ 280 : struct __attribute__((aligned(8UL))) fd_stake_reward_calculation_partitioned { 281 : fd_partitioned_stake_rewards_t partitioned_stake_rewards; 282 : ulong total_stake_rewards_lamports; 283 : }; 284 : typedef struct fd_stake_reward_calculation_partitioned fd_stake_reward_calculation_partitioned_t; 285 0 : #define FD_STAKE_REWARD_CALCULATION_PARTITIONED_FOOTPRINT sizeof(fd_stake_reward_calculation_partitioned_t) 286 : #define FD_STAKE_REWARD_CALCULATION_PARTITIONED_ALIGN (8UL) 287 : 288 : /* https://github.com/anza-xyz/agave/blob/7117ed9653ce19e8b2dea108eff1f3eb6a3378a7/runtime/src/bank/partitioned_epoch_rewards/mod.rs#L94 */ 289 : /* Encoded Size: Dynamic */ 290 : struct __attribute__((aligned(8UL))) fd_stake_reward_calculation { 291 : fd_stake_reward_dlist_t stake_rewards; 292 : ulong stake_rewards_len; 293 : fd_stake_reward_t * pool; 294 : ulong total_stake_rewards_lamports; 295 : }; 296 : typedef struct fd_stake_reward_calculation fd_stake_reward_calculation_t; 297 : #define FD_STAKE_REWARD_CALCULATION_FOOTPRINT sizeof(fd_stake_reward_calculation_t) 298 : #define FD_STAKE_REWARD_CALCULATION_ALIGN (8UL) 299 : 300 : /* Encoded Size: Dynamic */ 301 : struct __attribute__((aligned(8UL))) fd_calculate_stake_vote_rewards_result { 302 : fd_stake_reward_calculation_t stake_reward_calculation; 303 : fd_vote_reward_t_mapnode_t * vote_reward_map_pool; 304 : fd_vote_reward_t_mapnode_t * vote_reward_map_root; 305 : }; 306 : typedef struct fd_calculate_stake_vote_rewards_result fd_calculate_stake_vote_rewards_result_t; 307 : #define FD_CALCULATE_STAKE_VOTE_REWARDS_RESULT_FOOTPRINT sizeof(fd_calculate_stake_vote_rewards_result_t) 308 : #define FD_CALCULATE_STAKE_VOTE_REWARDS_RESULT_ALIGN (8UL) 309 : 310 : /* https://github.com/anza-xyz/agave/blob/7117ed9653ce19e8b2dea108eff1f3eb6a3378a7/runtime/src/bank/partitioned_epoch_rewards/mod.rs#L102 */ 311 : /* Encoded Size: Dynamic */ 312 : struct __attribute__((aligned(8UL))) fd_calculate_validator_rewards_result { 313 : fd_calculate_stake_vote_rewards_result_t calculate_stake_vote_rewards_result; 314 : fd_point_value_t point_value; 315 : }; 316 : typedef struct fd_calculate_validator_rewards_result fd_calculate_validator_rewards_result_t; 317 : #define FD_CALCULATE_VALIDATOR_REWARDS_RESULT_FOOTPRINT sizeof(fd_calculate_validator_rewards_result_t) 318 : #define FD_CALCULATE_VALIDATOR_REWARDS_RESULT_ALIGN (8UL) 319 : 320 : /* https://github.com/anza-xyz/agave/blob/7117ed9653ce19e8b2dea108eff1f3eb6a3378a7/runtime/src/bank/partitioned_epoch_rewards/mod.rs#L138 */ 321 : /* Encoded Size: Dynamic */ 322 : struct __attribute__((aligned(8UL))) fd_calculate_rewards_and_distribute_vote_rewards_result { 323 : ulong total_rewards; 324 : ulong distributed_rewards; 325 : fd_point_value_t point_value; 326 : fd_stake_reward_calculation_partitioned_t stake_rewards_by_partition; 327 : }; 328 : typedef struct fd_calculate_rewards_and_distribute_vote_rewards_result fd_calculate_rewards_and_distribute_vote_rewards_result_t; 329 : #define FD_CALCULATE_REWARDS_AND_DISTRIBUTE_VOTE_REWARDS_RESULT_FOOTPRINT sizeof(fd_calculate_rewards_and_distribute_vote_rewards_result_t) 330 : #define FD_CALCULATE_REWARDS_AND_DISTRIBUTE_VOTE_REWARDS_RESULT_ALIGN (8UL) 331 : 332 : /* https://github.com/anza-xyz/agave/blob/7117ed9653ce19e8b2dea108eff1f3eb6a3378a7/runtime/src/bank/partitioned_epoch_rewards/mod.rs#L118 */ 333 : /* Encoded Size: Dynamic */ 334 : struct __attribute__((aligned(8UL))) fd_partitioned_rewards_calculation { 335 : fd_vote_reward_t_mapnode_t * vote_reward_map_pool; 336 : fd_vote_reward_t_mapnode_t * vote_reward_map_root; 337 : fd_stake_reward_calculation_partitioned_t stake_rewards_by_partition; 338 : ulong old_vote_balance_and_staked; 339 : ulong validator_rewards; 340 : double validator_rate; 341 : double foundation_rate; 342 : double prev_epoch_duration_in_years; 343 : ulong capitalization; 344 : fd_point_value_t point_value; 345 : }; 346 : typedef struct fd_partitioned_rewards_calculation fd_partitioned_rewards_calculation_t; 347 : #define FD_PARTITIONED_REWARDS_CALCULATION_FOOTPRINT sizeof(fd_partitioned_rewards_calculation_t) 348 : #define FD_PARTITIONED_REWARDS_CALCULATION_ALIGN (8UL) 349 : 350 : /* https://github.com/anza-xyz/agave/blob/7117ed9653ce19e8b2dea108eff1f3eb6a3378a7/runtime/src/bank/partitioned_epoch_rewards/mod.rs#L60 */ 351 : /* Encoded Size: Dynamic */ 352 : struct __attribute__((aligned(8UL))) fd_start_block_height_and_rewards { 353 : ulong distribution_starting_block_height; 354 : fd_partitioned_stake_rewards_t partitioned_stake_rewards; 355 : }; 356 : typedef struct fd_start_block_height_and_rewards fd_start_block_height_and_rewards_t; 357 : #define FD_START_BLOCK_HEIGHT_AND_REWARDS_FOOTPRINT sizeof(fd_start_block_height_and_rewards_t) 358 : #define FD_START_BLOCK_HEIGHT_AND_REWARDS_ALIGN (8UL) 359 : 360 : union fd_epoch_reward_status_inner { 361 : fd_start_block_height_and_rewards_t Active; 362 : }; 363 : typedef union fd_epoch_reward_status_inner fd_epoch_reward_status_inner_t; 364 : 365 : /* https://github.com/anza-xyz/agave/blob/7117ed9653ce19e8b2dea108eff1f3eb6a3378a7/runtime/src/bank/partitioned_epoch_rewards/mod.rs#L70 */ 366 : struct fd_epoch_reward_status { 367 : uint discriminant; 368 : fd_epoch_reward_status_inner_t inner; 369 : }; 370 : typedef struct fd_epoch_reward_status fd_epoch_reward_status_t; 371 : #define FD_EPOCH_REWARD_STATUS_FOOTPRINT sizeof(fd_epoch_reward_status_t) 372 : #define FD_EPOCH_REWARD_STATUS_ALIGN (8UL) 373 : 374 : enum { 375 : fd_epoch_reward_status_enum_Active = 0, 376 : fd_epoch_reward_status_enum_Inactive = 1, 377 : }; 378 : 379 : /*******************************************************************************************/ 380 : #endif 381 : 382 : FD_PROTOTYPES_END 383 : 384 : #endif /* HEADER_fd_src_flamenco_runtime_fd_types_custom */