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 next_epoch_stakes_off; 19 : ulong leaders_off; /* Current epoch only */ 20 : }; 21 : 22 : typedef struct fd_exec_epoch_ctx_layout fd_exec_epoch_ctx_layout_t; 23 : 24 : struct __attribute__((aligned(64UL))) fd_exec_epoch_ctx { 25 : ulong magic; /* ==FD_EXEC_EPOCH_CTX_MAGIC */ 26 : 27 : fd_exec_epoch_ctx_layout_t layout; 28 : 29 : fd_features_t features; 30 : fd_epoch_bank_t epoch_bank; 31 : 32 : fd_bank_hash_cmp_t * bank_hash_cmp; 33 : 34 : int constipate_root; /* Used for constipation in offline replay .*/ 35 : ulong total_epoch_stake; 36 : }; 37 : 38 2046960 : #define FD_EXEC_EPOCH_CTX_ALIGN (4096UL) 39 407859 : #define FD_EXEC_EPOCH_CTX_MAGIC (0x3E64F44C9F44366AUL) /* random */ 40 : 41 : FD_PROTOTYPES_BEGIN 42 : 43 : void * 44 : fd_exec_epoch_ctx_new( void * mem, 45 : ulong vote_acc_max ); 46 : 47 : fd_exec_epoch_ctx_t * 48 : fd_exec_epoch_ctx_join( void * mem ); 49 : 50 : void * 51 : fd_exec_epoch_ctx_leave( fd_exec_epoch_ctx_t * ctx ); 52 : 53 : void * 54 : fd_exec_epoch_ctx_delete( void * mem ); 55 : 56 : void 57 : fd_exec_epoch_ctx_epoch_bank_delete( fd_exec_epoch_ctx_t * epoch_ctx ); 58 : 59 : ulong 60 : fd_exec_epoch_ctx_align( void ); 61 : 62 : ulong 63 : fd_exec_epoch_ctx_footprint( ulong vote_acc_max ); 64 : 65 : /* fd_exec_epoch_ctx_bank_mem_clear empties out the existing bank 66 : data structures (votes, delegations, stake history, next_epoch_stakes). 67 : This method should be used before decoding a bank from funk so as 68 : to not step on the work done while decoding. 69 : */ 70 : void 71 : fd_exec_epoch_ctx_bank_mem_clear( fd_exec_epoch_ctx_t * epoch_ctx ); 72 : 73 : /* fd_exec_epoch_ctx_bank_mem_setup initializes the bank 74 : data structures (votes, delegations, stake history, next_epoch_stakes) 75 : to have the correct pool initialization and layout. 76 : */ 77 : fd_epoch_bank_t * 78 : fd_exec_epoch_ctx_bank_mem_setup( fd_exec_epoch_ctx_t * epoch_ctx ); 79 : 80 : /* Accessors **********************************************************/ 81 : 82 : FD_FN_CONST static inline fd_epoch_bank_t * 83 1459293 : fd_exec_epoch_ctx_epoch_bank( fd_exec_epoch_ctx_t * ctx ) { 84 1459293 : return &ctx->epoch_bank; 85 1459293 : } 86 : 87 : FD_FN_CONST static inline fd_epoch_bank_t const * 88 1149 : fd_exec_epoch_ctx_epoch_bank_const( fd_exec_epoch_ctx_t const * ctx ) { 89 1149 : return &ctx->epoch_bank; 90 1149 : } 91 : 92 : FD_FN_PURE static inline fd_vote_accounts_pair_t_mapnode_t * 93 0 : fd_exec_epoch_ctx_stake_votes_join( fd_exec_epoch_ctx_t * ctx ) { 94 0 : void * mem = (void *)((ulong)ctx + ctx->layout.stake_votes_off); 95 0 : return fd_vote_accounts_pair_t_map_join( mem ); 96 0 : } 97 : 98 : FD_FN_PURE static inline fd_delegation_pair_t_mapnode_t * 99 0 : fd_exec_epoch_ctx_stake_delegations_join( fd_exec_epoch_ctx_t * ctx ) { 100 0 : void * mem = (void *)((ulong)ctx + ctx->layout.stake_delegations_off); 101 0 : return fd_delegation_pair_t_map_join( mem ); 102 0 : } 103 : 104 : FD_FN_PURE static inline fd_vote_accounts_pair_t_mapnode_t * 105 0 : fd_exec_epoch_ctx_next_epoch_stakes_join( fd_exec_epoch_ctx_t * ctx ) { 106 0 : void * mem = (void *)((ulong)ctx + ctx->layout.next_epoch_stakes_off); 107 0 : return fd_vote_accounts_pair_t_map_join( mem ); 108 0 : } 109 : 110 : FD_FN_PURE static inline fd_epoch_leaders_t * 111 0 : fd_exec_epoch_ctx_leaders( fd_exec_epoch_ctx_t * ctx ) { 112 0 : return (fd_epoch_leaders_t *)((uchar *)ctx + ctx->layout.leaders_off); 113 0 : } 114 : 115 : void 116 : fd_exec_epoch_ctx_from_prev( fd_exec_epoch_ctx_t * self, fd_exec_epoch_ctx_t * prev ); 117 : 118 : FD_PROTOTYPES_END 119 : 120 : #endif /* HEADER_fd_src_flamenco_runtime_context_fd_exec_epoch_ctx_h */