Line data Source code
1 : #ifndef HEADER_fd_src_flamenco_runtime_context_fd_exec_epoch_ctx_h 2 : #define HEADER_fd_src_flamenco_runtime_context_fd_exec_epoch_ctx_h 3 : 4 : #include "../../features/fd_features.h" 5 : #include "../../leaders/fd_leaders.h" 6 : #include "../fd_bank_hash_cmp.h" 7 : #include "../fd_rent_lists.h" 8 : 9 : /* fd_exec_epoch_ctx_t is the context that stays constant throughout 10 : an entire epoch. */ 11 : 12 : struct fd_exec_epoch_ctx_layout { 13 : ulong vote_acc_max; 14 : ulong footprint; 15 : 16 : ulong stake_votes_off; 17 : ulong stake_delegations_off; 18 : ulong stake_history_treap_off; 19 : ulong stake_history_pool_off; 20 : ulong next_epoch_stakes_off; 21 : ulong leaders_off; /* Current epoch only */ 22 : }; 23 : 24 : typedef struct fd_exec_epoch_ctx_layout fd_exec_epoch_ctx_layout_t; 25 : 26 : struct __attribute__((aligned(64UL))) fd_exec_epoch_ctx { 27 : ulong magic; /* ==FD_EXEC_EPOCH_CTX_MAGIC */ 28 : 29 : fd_exec_epoch_ctx_layout_t layout; 30 : 31 : fd_features_t features; 32 : fd_epoch_bank_t epoch_bank; 33 : 34 : fd_bank_hash_cmp_t * bank_hash_cmp; 35 : }; 36 : 37 548337 : #define FD_EXEC_EPOCH_CTX_ALIGN (4096UL) 38 108786 : #define FD_EXEC_EPOCH_CTX_MAGIC (0x3E64F44C9F44366AUL) /* random */ 39 : 40 : FD_PROTOTYPES_BEGIN 41 : 42 : void * 43 : fd_exec_epoch_ctx_new( void * mem, 44 : ulong vote_acc_max ); 45 : 46 : fd_exec_epoch_ctx_t * 47 : fd_exec_epoch_ctx_join( void * mem ); 48 : 49 : void * 50 : fd_exec_epoch_ctx_leave( fd_exec_epoch_ctx_t * ctx ); 51 : 52 : void * 53 : fd_exec_epoch_ctx_delete( void * mem ); 54 : 55 : void 56 : fd_exec_epoch_ctx_epoch_bank_delete( fd_exec_epoch_ctx_t * epoch_ctx ); 57 : 58 : ulong 59 : fd_exec_epoch_ctx_align( void ); 60 : 61 : ulong 62 : fd_exec_epoch_ctx_footprint( ulong vote_acc_max ); 63 : 64 : /* fd_exec_epoch_ctx_bank_mem_clear empties out the existing bank 65 : data structures (votes, delegations, stake history, next_epoch_stakes). 66 : This method should be used before decoding a bank from funk so as 67 : to not step on the work done while decoding. 68 : */ 69 : void 70 : fd_exec_epoch_ctx_bank_mem_clear( fd_exec_epoch_ctx_t * epoch_ctx ); 71 : 72 : /* fd_exec_epoch_ctx_bank_mem_setup initializes the bank 73 : data structures (votes, delegations, stake history, next_epoch_stakes) 74 : to have the correct pool initialization and layout. 75 : */ 76 : fd_epoch_bank_t * 77 : fd_exec_epoch_ctx_bank_mem_setup( fd_exec_epoch_ctx_t * epoch_ctx ); 78 : 79 : /* Accessors **********************************************************/ 80 : 81 : FD_FN_CONST static inline fd_epoch_bank_t * 82 1098345 : fd_exec_epoch_ctx_epoch_bank( fd_exec_epoch_ctx_t * ctx ) { 83 1098345 : return &ctx->epoch_bank; 84 1098345 : } 85 : 86 : FD_FN_CONST static inline fd_epoch_bank_t const * 87 1158 : fd_exec_epoch_ctx_epoch_bank_const( fd_exec_epoch_ctx_t const * ctx ) { 88 1158 : return &ctx->epoch_bank; 89 1158 : } 90 : 91 : FD_FN_PURE static inline fd_vote_accounts_pair_t_mapnode_t * 92 0 : fd_exec_epoch_ctx_stake_votes_join( fd_exec_epoch_ctx_t * ctx ) { 93 0 : void * mem = (void *)((ulong)ctx + ctx->layout.stake_votes_off); 94 0 : return fd_vote_accounts_pair_t_map_join( mem ); 95 0 : } 96 : 97 : FD_FN_PURE static inline fd_delegation_pair_t_mapnode_t * 98 0 : fd_exec_epoch_ctx_stake_delegations_join( fd_exec_epoch_ctx_t * ctx ) { 99 0 : void * mem = (void *)((ulong)ctx + ctx->layout.stake_delegations_off); 100 0 : return fd_delegation_pair_t_map_join( mem ); 101 0 : } 102 : 103 : FD_FN_PURE static inline fd_stake_history_treap_t * 104 0 : fd_exec_epoch_ctx_stake_history_treap_join( fd_exec_epoch_ctx_t * ctx ) { 105 0 : void * mem = (void *)((ulong)ctx + ctx->layout.stake_history_treap_off); 106 0 : return fd_stake_history_treap_join( mem ); 107 0 : } 108 : 109 : FD_FN_PURE static inline fd_stake_history_entry_t * 110 0 : fd_exec_epoch_ctx_stake_history_pool_join( fd_exec_epoch_ctx_t * ctx ) { 111 0 : void * mem = (void *)((ulong)ctx + ctx->layout.stake_history_pool_off); 112 0 : return fd_stake_history_pool_join( mem ); 113 0 : } 114 : 115 : FD_FN_PURE static inline fd_vote_accounts_pair_t_mapnode_t * 116 0 : fd_exec_epoch_ctx_next_epoch_stakes_join( fd_exec_epoch_ctx_t * ctx ) { 117 0 : void * mem = (void *)((ulong)ctx + ctx->layout.next_epoch_stakes_off); 118 0 : return fd_vote_accounts_pair_t_map_join( mem ); 119 0 : } 120 : 121 : FD_FN_PURE static inline fd_epoch_leaders_t * 122 0 : fd_exec_epoch_ctx_leaders( fd_exec_epoch_ctx_t * ctx ) { 123 0 : return (fd_epoch_leaders_t *)((uchar *)ctx + ctx->layout.leaders_off); 124 0 : } 125 : 126 : void 127 : fd_exec_epoch_ctx_from_prev( fd_exec_epoch_ctx_t * self, fd_exec_epoch_ctx_t * prev ); 128 : 129 : FD_PROTOTYPES_END 130 : 131 : #endif /* HEADER_fd_src_flamenco_runtime_context_fd_exec_epoch_ctx_h */