Line data Source code
1 : #ifndef HEADER_fd_src_flamenco_stakes_fd_vote_stakes_private_h 2 : #define HEADER_fd_src_flamenco_stakes_fd_vote_stakes_private_h 3 : 4 : #include "../../util/fd_util_base.h" 5 : #include "../types/fd_types_custom.h" 6 : #include "../fd_rwlock.h" 7 : 8 : struct index_key { 9 : fd_pubkey_t pubkey; 10 : fd_pubkey_t node_account_t_1; 11 : ulong stake_t_1 : 63; 12 : ulong epoch : 1; 13 : }; 14 : typedef struct index_key index_key_t; 15 : 16 : struct index_ele { 17 : union { 18 : struct { 19 : fd_pubkey_t pubkey; 20 : fd_pubkey_t node_account_t_1; 21 : ulong stake_t_1 : 63; 22 : ulong epoch : 1; 23 : }; 24 : index_key_t index_key; 25 : }; 26 : ulong stake_t_2; 27 : fd_pubkey_t node_account_t_2; 28 : uint next; 29 : uint prev_multi; 30 : uint next_multi; 31 : ushort refcnt; 32 : uchar exists_t_1; 33 : }; 34 : typedef struct index_ele index_ele_t; 35 : 36 : #define POOL_NAME index_pool 37 60285 : #define POOL_T index_ele_t 38 1057714 : #define POOL_NEXT next 39 : #define POOL_IDX_T uint 40 : #include "../../util/tmpl/fd_pool.c" 41 : 42 : #define MAP_NAME index_map 43 : #define MAP_KEY_T index_key_t 44 : #define MAP_ELE_T index_ele_t 45 300 : #define MAP_KEY index_key 46 1 : #define MAP_KEY_EQ(k0,k1) (!memcmp( k0, k1, sizeof(index_key_t) )) 47 302 : #define MAP_KEY_HASH(key,seed) (fd_hash( seed, key, sizeof(index_key_t) )) 48 300 : #define MAP_NEXT next 49 30447 : #define MAP_IDX_T uint 50 : #include "../../util/tmpl/fd_map_chain.c" 51 : 52 : #define MAP_NAME index_map_multi 53 : #define MAP_MULTI 1 54 : #define MAP_OPTIMIZE_RANDOM_ACCESS_REMOVAL 1 55 : #define MAP_KEY_T fd_pubkey_t 56 3 : #define MAP_ELE_T index_ele_t 57 302 : #define MAP_KEY pubkey 58 305 : #define MAP_KEY_EQ(k0,k1) (!memcmp( k0, k1, sizeof(fd_pubkey_t) )) 59 623 : #define MAP_KEY_HASH(key,seed) (fd_hash( seed, key, sizeof(fd_pubkey_t) )) 60 305 : #define MAP_PREV prev_multi 61 305 : #define MAP_NEXT next_multi 62 31065 : #define MAP_IDX_T uint 63 : #include "../../util/tmpl/fd_map_chain.c" 64 : 65 : /* Each pool index is just an array of uint indices into the pool. */ 66 : struct stake { 67 : uint idx; 68 : uint next; 69 : }; 70 : typedef struct stake stake_t; 71 : 72 : #define POOL_NAME stakes_pool 73 120564 : #define POOL_T stake_t 74 2130560 : #define POOL_NEXT next 75 : #define POOL_IDX_T uint 76 : #include "../../util/tmpl/fd_pool.c" 77 : 78 : #define MAP_NAME stakes_map 79 : #define MAP_KEY_T uint 80 : #define MAP_ELE_T stake_t 81 302 : #define MAP_KEY idx 82 1204 : #define MAP_NEXT next 83 62384 : #define MAP_IDX_T uint 84 : #include "../../util/tmpl/fd_map_chain.c" 85 : 86 : struct fork { 87 : ushort prev; 88 : ushort next; 89 : }; 90 : typedef struct fork fork_t; 91 : 92 : #define POOL_NAME fork_pool 93 60275 : #define POOL_T fork_t 94 90418 : #define POOL_NEXT next 95 : #define POOL_IDX_T ushort 96 : #include "../../util/tmpl/fd_pool.c" 97 : 98 : #define DLIST_NAME fork_dlist 99 : #define DLIST_ELE_T fork_t 100 : #define DLIST_IDX_T ushort 101 : #include "../../util/tmpl/fd_dlist.c" 102 : 103 30172 : #define FD_VOTE_STAKES_MAGIC (0xF17EDA2CE7601E71UL) /* FIREDANCER VOTER V1 */ 104 : 105 : #define MAX_FORK_WIDTH (128UL) 106 : 107 : struct fd_vote_stakes { 108 : ulong magic; 109 : ulong index_pool_off; 110 : ulong index_map_off; 111 : ulong index_map_multi_off; 112 : 113 : ulong fork_pool_off; 114 : ulong fork_dlist_off; 115 : 116 : ulong stakes_pool_off[ MAX_FORK_WIDTH ]; 117 : ulong stakes_map_off[ MAX_FORK_WIDTH ]; 118 : 119 : stakes_map_iter_t fork_iter; 120 : 121 : ushort max_fork_width; 122 : ushort root_idx; 123 : }; 124 : typedef struct fd_vote_stakes fd_vote_stakes_t; 125 : 126 : static inline index_ele_t * 127 1525 : get_index_pool( fd_vote_stakes_t const * vote_stakes ) { 128 1525 : return fd_type_pun( (uchar *)vote_stakes + vote_stakes->index_pool_off ); 129 1525 : } 130 : 131 : static inline index_map_t * 132 600 : get_index_map( fd_vote_stakes_t const * vote_stakes ) { 133 600 : return fd_type_pun( (uchar *)vote_stakes + vote_stakes->index_map_off ); 134 600 : } 135 : 136 : static inline index_map_multi_t * 137 624 : get_index_map_multi( fd_vote_stakes_t const * vote_stakes ) { 138 624 : return fd_type_pun( (uchar *)vote_stakes + vote_stakes->index_map_multi_off ); 139 624 : } 140 : 141 : static inline stake_t * 142 : get_stakes_pool( fd_vote_stakes_t const * vote_stakes, 143 4828 : ushort fork_idx ) { 144 4828 : return fd_type_pun( (uchar *)vote_stakes + vote_stakes->stakes_pool_off[ fork_idx ] ); 145 4828 : } 146 : 147 : static inline stakes_map_t * 148 : get_stakes_map( fd_vote_stakes_t const * vote_stakes, 149 4828 : ushort fork_idx ) { 150 4828 : return fd_type_pun( (uchar *)vote_stakes + vote_stakes->stakes_map_off[ fork_idx ] ); 151 4828 : } 152 : 153 : static inline fork_t * 154 2 : get_fork_pool( fd_vote_stakes_t const * vote_stakes ) { 155 2 : return fd_type_pun( (uchar *)vote_stakes + vote_stakes->fork_pool_off ); 156 2 : } 157 : 158 : static inline fork_dlist_t * 159 2 : get_fork_dlist( fd_vote_stakes_t const * vote_stakes ) { 160 2 : return fd_type_pun( (uchar *)vote_stakes + vote_stakes->fork_dlist_off ); 161 2 : } 162 : 163 : #endif /* HEADER_fd_src_flamenco_stakes_fd_vote_stakes_private_h */