Line data Source code
1 : #include "fd_ghost.h" 2 : 3 : #define POOL_NAME blk_pool 4 96 : #define POOL_T fd_ghost_blk_t 5 : #include "../../util/tmpl/fd_pool.c" 6 : 7 : #define MAP_NAME blk_map 8 : #define MAP_ELE_T fd_ghost_blk_t 9 933 : #define MAP_KEY id 10 : #define MAP_KEY_T fd_hash_t 11 1824 : #define MAP_KEY_EQ(k0,k1) (!memcmp((k0),(k1), sizeof(fd_hash_t))) 12 2748 : #define MAP_KEY_HASH(key,seed) (fd_hash((seed),(key),sizeof(fd_hash_t))) 13 2634 : #define MAP_NEXT next 14 : #include "../../util/tmpl/fd_map_chain.c" 15 : 16 : #define POOL_NAME vtr_pool 17 96 : #define POOL_T fd_ghost_vtr_t 18 : #include "../../util/tmpl/fd_pool.c" 19 : 20 : #define MAP_NAME vtr_map 21 : #define MAP_ELE_T fd_ghost_vtr_t 22 9 : #define MAP_KEY addr 23 : #define MAP_KEY_T fd_pubkey_t 24 9 : #define MAP_KEY_EQ(k0,k1) (!memcmp((k0),(k1), sizeof(fd_pubkey_t))) 25 27 : #define MAP_KEY_HASH(key,seed) (fd_hash((seed),(key),sizeof(fd_pubkey_t))) 26 9 : #define MAP_NEXT next 27 : #include "../../util/tmpl/fd_map_chain.c" 28 : 29 : /* fd_ghost_t is the top-level structure that holds the root of the 30 : tree, as well as the memory pools and map structures for tracking 31 : ghost eles and votes. 32 : 33 : These structures are bump-allocated and laid out contiguously in 34 : memory from the fd_ghost_t * pointer which points to the beginning of 35 : the memory region. 36 : 37 : ---------------------- <- fd_ghost_t * 38 : | root | 39 : ---------------------- 40 : | pool | 41 : ---------------------- 42 : | blk_map | 43 : ---------------------- 44 : | vtr_map | 45 : ---------------------- */ 46 : 47 : struct __attribute__((aligned(128UL))) fd_ghost { 48 : ulong root; /* pool idx of the root tree element */ 49 : ulong wksp_gaddr; /* wksp gaddr of fd_ghost in the backing wksp */ 50 : ulong blk_pool_gaddr; /* memory offset of the blk_pool */ 51 : ulong blk_map_gaddr; /* memory offset of the blk_map */ 52 : ulong vtr_pool_gaddr; /* memory offset of the vtr_pool */ 53 : ulong vtr_map_gaddr; /* memory offset of the vtr_map */ 54 : ulong width; /* incrementally updated width of the fork tree */ 55 : }; 56 : typedef struct fd_ghost fd_ghost_t; 57 : 58 : typedef fd_ghost_blk_t blk_pool_t; 59 : typedef fd_ghost_vtr_t vtr_pool_t; 60 : 61 : /* wksp returns the local join to the wksp backing the 62 : ghost. The lifetime of the returned pointer is at least as 63 : long as the lifetime of the local join. Assumes ghost is a 64 : current local join. */ 65 : 66 : FD_FN_PURE static inline fd_wksp_t * 67 6540 : wksp( fd_ghost_t const * ghost ) { 68 6540 : return (fd_wksp_t *)( ((ulong)ghost) - ghost->wksp_gaddr ); 69 6540 : } 70 : 71 : static inline blk_pool_t * 72 4056 : blk_pool( fd_ghost_t * ghost ) { 73 4056 : return (blk_pool_t *)fd_wksp_laddr_fast( wksp( ghost ), ghost->blk_pool_gaddr ); 74 4056 : } 75 : 76 : static inline blk_pool_t const * 77 0 : blk_pool_const( fd_ghost_t const * ghost ) { 78 0 : return (blk_pool_t const *)fd_wksp_laddr_fast( wksp( ghost ), ghost->blk_pool_gaddr ); 79 0 : } 80 : 81 : static inline blk_map_t * 82 2421 : blk_map( fd_ghost_t * ghost ) { 83 2421 : return (blk_map_t *)fd_wksp_laddr_fast( wksp( ghost ), ghost->blk_map_gaddr ); 84 2421 : } 85 : 86 : static inline blk_map_t const * 87 0 : blk_map_const( fd_ghost_t const * ghost ) { 88 0 : return (blk_map_t const *)fd_wksp_laddr_fast( wksp( ghost ), ghost->blk_map_gaddr ); 89 0 : } 90 : 91 : static inline vtr_pool_t * 92 36 : vtr_pool( fd_ghost_t * ghost ) { 93 36 : return (vtr_pool_t *)fd_wksp_laddr_fast( wksp( ghost ), ghost->vtr_pool_gaddr ); 94 36 : } 95 : 96 : static inline vtr_pool_t const * 97 0 : vtr_pool_const( fd_ghost_t const * ghost ) { 98 0 : return (vtr_pool_t const *)fd_wksp_laddr_fast( wksp( ghost ), ghost->vtr_pool_gaddr ); 99 0 : } 100 : 101 : static inline vtr_map_t * 102 27 : vtr_map( fd_ghost_t * ghost ) { 103 27 : return (vtr_map_t *)fd_wksp_laddr_fast( wksp( ghost ), ghost->vtr_map_gaddr ); 104 27 : } 105 : 106 : static inline vtr_map_t const * 107 0 : vtr_map_const( fd_ghost_t const * ghost ) { 108 0 : return (vtr_map_t const *)fd_wksp_laddr_fast( wksp( ghost ), ghost->vtr_map_gaddr ); 109 0 : }