Line data Source code
1 : #include "fd_ghost.h" 2 : 3 : /* fd_ghost_vtr_t keeps track of what a voter's previously voted for. */ 4 : 5 : struct fd_ghost_vtr { 6 : fd_pubkey_t addr; /* map key, vote account address */ 7 : uint hash; /* reserved for fd_map_dynamic */ 8 : ulong prev_stake; /* previous vote stake (vote can be from prior epoch) */ 9 : ulong prev_slot; /* previous vote slot */ 10 : fd_hash_t prev_block_id; /* previous vote block_id */ 11 : }; 12 : typedef struct fd_ghost_vtr fd_ghost_vtr_t; 13 : 14 : #define POOL_NAME pool 15 0 : #define POOL_T fd_ghost_blk_t 16 : #include "../../util/tmpl/fd_pool.c" 17 : 18 : #define MAP_NAME blk_map 19 : #define MAP_ELE_T fd_ghost_blk_t 20 0 : #define MAP_KEY id 21 : #define MAP_KEY_T fd_hash_t 22 0 : #define MAP_KEY_EQ(k0,k1) (!memcmp((k0),(k1), sizeof(fd_hash_t))) 23 0 : #define MAP_KEY_HASH(key,seed) (fd_hash((seed),(key),sizeof(fd_hash_t))) 24 0 : #define MAP_NEXT next 25 : #include "../../util/tmpl/fd_map_chain.c" 26 : 27 : #define MAP_NAME vtr_map 28 0 : #define MAP_T fd_ghost_vtr_t 29 0 : #define MAP_KEY addr 30 0 : #define MAP_KEY_T fd_pubkey_t 31 0 : #define MAP_KEY_NULL pubkey_null 32 : #define MAP_KEY_EQUAL_IS_SLOW 1 33 0 : #define MAP_KEY_INVAL(k) MAP_KEY_EQUAL((k),MAP_KEY_NULL) 34 0 : #define MAP_KEY_EQUAL(k0,k1) (!memcmp( (k0).key, (k1).key, 32UL )) 35 0 : #define MAP_KEY_HASH(key,s) ((MAP_HASH_T)( (key).ul[1] )) 36 : #include "../../util/tmpl/fd_map_dynamic.c" 37 : 38 : /* fd_ghost_t is the top-level structure that holds the root of the 39 : tree, as well as the memory pools and map structures for tracking 40 : ghost eles and votes. 41 : 42 : These structures are bump-allocated and laid out contiguously in 43 : memory from the fd_ghost_t * pointer which points to the beginning of 44 : the memory region. 45 : 46 : ---------------------- <- fd_ghost_t * 47 : | root | 48 : ---------------------- 49 : | pool | 50 : ---------------------- 51 : | map | 52 : ---------------------- 53 : | bid | 54 : ---------------------- 55 : | vtr | 56 : ---------------------- */ 57 : 58 : struct __attribute__((aligned(128UL))) fd_ghost { 59 : ulong root; /* pool idx of the root tree element */ 60 : fd_ghost_blk_t * pool; /* pool of tree elements (blocks) */ 61 : blk_map_t * blk_map; /* map of block_id->ghost_blk for fast O(1) querying */ 62 : fd_ghost_vtr_t * vtr_map; /* map of pubkey->prior vote */ 63 : }; 64 : typedef struct fd_ghost fd_ghost_t;