Line data Source code
1 : #ifndef HEADER_fd_src_choreo_trusted_slots_fd_trusted_slots_h 2 : #define HEADER_fd_src_choreo_trusted_slots_fd_trusted_slots_h 3 : 4 : #include "../../util/fd_util_base.h" 5 : 6 : /* fd_trusted_slots_t is a simple root-aware data structure for managing the 7 : slots which a validator has begun or did produce recently. */ 8 : struct fd_slot_ele { 9 : ulong parent_cidx; 10 : ulong left_cidx; 11 : ulong right_cidx; 12 : ulong prio_cidx; 13 : ulong key; 14 : }; 15 : typedef struct fd_slot_ele fd_slot_ele_t; 16 : 17 : #define POOL_NAME fd_slot_pool 18 0 : #define POOL_T fd_slot_ele_t 19 0 : #define POOL_NEXT parent_cidx 20 : #include "../../util/tmpl/fd_pool.c" 21 : 22 0 : FD_FN_CONST static inline int valcmp( ulong a, ulong b ) { 23 0 : int val = (a < b) ? -1 : 1; 24 0 : return (a == b) ? 0 : val; 25 0 : } 26 : 27 : #define TREAP_NAME fd_slot_treap 28 : #define TREAP_T fd_slot_ele_t 29 : #define TREAP_QUERY_T ulong 30 0 : #define TREAP_CMP(q,e) valcmp(q, e->key) 31 0 : #define TREAP_LT(e0,e1) (((ulong)((e0)->key)) < ((ulong)((e1)->key))) 32 0 : #define TREAP_IDX_T ulong 33 0 : #define TREAP_PARENT parent_cidx 34 0 : #define TREAP_LEFT left_cidx 35 0 : #define TREAP_RIGHT right_cidx 36 0 : #define TREAP_PRIO prio_cidx 37 : #define TREAP_IMPL_STYLE 0 38 : #include "../../util/tmpl/fd_treap.c" 39 : 40 : struct fd_trusted_slots { 41 : fd_slot_ele_t * slot_pool; 42 : fd_slot_treap_t * slot_treap; 43 : }; 44 : typedef struct fd_trusted_slots fd_trusted_slots_t; 45 : 46 : FD_PROTOTYPES_BEGIN 47 : 48 : ulong 49 : fd_trusted_slots_align( void ); 50 : 51 : /* slots_max should be the slots_per_epoch. */ 52 : ulong 53 : fd_trusted_slots_footprint( ulong slots_max ); 54 : 55 : void * 56 : fd_trusted_slots_new( void * shmem, ulong slot_max ); 57 : 58 : fd_trusted_slots_t * 59 : fd_trusted_slots_join( void * shmem ); 60 : 61 : /* Adds a slot to the trusted set of slots. */ 62 : void 63 : fd_trusted_slots_add( fd_trusted_slots_t * trusted_slots, 64 : ulong slot ); 65 : 66 : /* Finds a slot in the trusted set. Returns 1 if found, 0 if not found. */ 67 : int 68 : fd_trusted_slots_find( fd_trusted_slots_t * trusted_slots, 69 : ulong slot ); 70 : 71 : /* Publishes a root slot. Prunes out slots older than root. */ 72 : void 73 : fd_trusted_slots_publish( fd_trusted_slots_t * trusted_slots, 74 : ulong root ); 75 : 76 : FD_PROTOTYPES_END 77 : 78 : #endif /* HEADER_fd_src_choreo_trusted_slots_fd_trusted_slots_h */