Line data Source code
1 : #ifndef HEADER_fd_src_flamenco_features_fd_features_h 2 : #define HEADER_fd_src_flamenco_features_fd_features_h 3 : 4 : #include "../fd_flamenco_base.h" 5 : #include "fd_features_generated.h" 6 : #include "../types/fd_types.h" 7 : /* Macro FEATURE_ID_CNT expands to the number of features in 8 : fd_features_t. */ 9 : 10 : //#define FD_FEATURE_ID_CNT (... see generated.h ...) 11 : 12 : /* FD_FEATURE_DISABLED is the sentinel value of the feature activation 13 : slot when the feature has not yet been activated. */ 14 : 15 1809657 : #define FD_FEATURE_DISABLED (ULONG_MAX) 16 : 17 : /* Convenience macros for checking features */ 18 : 19 7989 : #define FD_FEATURE_ACTIVE_(_slot, _features, _feature_name) (_slot >= (_features)-> _feature_name) 20 0 : #define FD_FEATURE_JUST_ACTIVATED_(_slot, _features, _feature_name) (_slot == (_features). _feature_name) 21 0 : #define FD_FEATURE_ACTIVE_OFFSET_(_slot, _features, _offset) (_slot >= (_features).f[_offset>>3]) 22 0 : #define FD_FEATURE_JUST_ACTIVATED_OFFSET_(_slot, _features, _offset) (_slot == (_features).f[_offset>>3] ) 23 : 24 0 : #define FD_FEATURE_SET_ACTIVE(_features, _feature_name, _slot) ((_features)-> _feature_name = _slot) 25 0 : #define FD_FEATURE_JUST_ACTIVATED(_slot_ctx, _feature_name) FD_FEATURE_JUST_ACTIVATED_( _slot_ctx->slot, fd_bank_features_get(_slot_ctx->bank), _feature_name ) 26 0 : #define FD_FEATURE_ACTIVE_OFFSET(_slot, _features, _offset) FD_FEATURE_ACTIVE_OFFSET_( _slot, _features, _offset ) 27 0 : #define FD_FEATURE_JUST_ACTIVATED_OFFSET(_slot_ctx, _offset) FD_FEATURE_JUST_ACTIVATED_OFFSET_( _slot_ctx->slot, fd_bank_features_get(_slot_ctx->bank), _offset ) 28 7989 : #define FD_FEATURE_ACTIVE(_slot, _features, _feature_name) FD_FEATURE_ACTIVE_(_slot, _features, _feature_name) 29 0 : #define FD_FEATURE_ACTIVE_BANK(_bank, _feature_name) FD_FEATURE_ACTIVE_(_bank->slot, fd_bank_features_query( _bank ), _feature_name ) 30 : 31 : 32 : /* fd_features_t is the current set of enabled feature flags. 33 : 34 : Each feature has a corresponding account in the account database, 35 : which are used to control activation. This structure contains an 36 : ulong of the activation slots of each feature for convenience (or 37 : FD_FEATURE_DISABLED if not yet activated). The feature params 38 : contained in this structure change over time, as activated features 39 : become default, and as new pending feature activations get added. 40 : 41 : Usage: 42 : 43 : fd_features_t * features; 44 : 45 : // Direct API 46 : ulong activation_slot = features->FEATURE_NAME; 47 : 48 : // Indirect API 49 : fd_feature_id_t const * id; 50 : ulong activation_slot = fd_features_get( id ); 51 : ... id->index safe in [0,FD_FEATURE_CNT) ... */ 52 : 53 : typedef union fd_features fd_features_t; 54 : 55 : /* fd_feature_id_t maps a feature ID (account address) to the byte 56 : offset in fd_features_t. */ 57 : 58 : struct fd_feature_id { 59 : ulong index; /* index of feature in fd_features_t */ 60 : fd_pubkey_t id; /* pubkey of feature */ 61 : char const * name; /* feature name cstr */ 62 : uint cleaned_up[3]; /* cleaned_up cluster version for feature */ 63 : uchar reverted; /* if the feature was reverted */ 64 : uchar activated_on_all_clusters; /* if the feature was activated on all clusters (currently only used for fuzzing) */ 65 : }; 66 : typedef struct fd_feature_id fd_feature_id_t; 67 : 68 : FD_PROTOTYPES_BEGIN 69 : 70 : /* fd_feature_ids is the list of known feature IDs. 71 : The last element has offset==ULONG_MAX. */ 72 : extern fd_feature_id_t const ids[]; 73 : 74 : /* fd_features_disable_all disables all features (cleaned_up or not). */ 75 : 76 : void 77 : fd_features_disable_all( fd_features_t * f ); 78 : 79 : /* fd_features_enable_all enables all features (supported or not). */ 80 : 81 : void 82 : fd_features_enable_all( fd_features_t * ); 83 : 84 : /* fd_features_enable_cleaned_up enables all features marked as "hard 85 : coded". These are features that are baked into the current version 86 : of the Firedancer software and can't be disabled. */ 87 : 88 : void 89 : fd_features_enable_cleaned_up( fd_features_t *, fd_cluster_version_t const * ); 90 : 91 : /* fd_features_enable_one_offs enables all manually passed in features. */ 92 : 93 : void 94 : fd_features_enable_one_offs( fd_features_t * features, 95 : char const * * one_offs, 96 : uint one_offs_cnt, 97 : ulong slot ); 98 : 99 : /* fd_feature_iter_{...} is an iterator-style API over all supported 100 : features in this version of Firedancer. Usage: 101 : 102 : for( fd_feature_id_t const * id = fd_feature_iter_init(); 103 : !fd_feature_iter_done( id ); 104 : id = fd_feature_iter_next( id ) ) { 105 : ... 106 : } */ 107 : 108 : static inline fd_feature_id_t const * 109 7692 : fd_feature_iter_init( void ) { 110 7692 : return ids; 111 7692 : } 112 : 113 : static inline int 114 1823004 : fd_feature_iter_done( fd_feature_id_t const * id ) { 115 1823004 : return id->index == ULONG_MAX; 116 1823004 : } 117 : 118 : static inline fd_feature_id_t const * 119 1815312 : fd_feature_iter_next( fd_feature_id_t const * id ) { 120 1815312 : return id+1; 121 1815312 : } 122 : 123 : /* fd_features_set sets the activation slot of the given feature ID. */ 124 : 125 : static inline void 126 : fd_features_set( fd_features_t * features, 127 : fd_feature_id_t const * id, 128 1818021 : ulong slot ) { 129 1818021 : features->f[ id->index ] = slot; 130 1818021 : } 131 : 132 : /* fd_features_get returns the activation slot of the given feature ID. 133 : Returns ULONG_MAX if the feature is not scheduled for activation. */ 134 : 135 : static inline ulong 136 : fd_features_get( fd_features_t const * features, 137 708 : fd_feature_id_t const * id ) { 138 708 : return features->f[ id->index ]; 139 708 : } 140 : 141 : /* fd_feature_id_query queries a feature ID given the first 8 bytes of 142 : the feature address (little-endian order). Returns pointer to ID in 143 : `ids` array on success, or NULL on failure. */ 144 : 145 : FD_FN_CONST fd_feature_id_t const * 146 : fd_feature_id_query( ulong prefix ); 147 : 148 : FD_PROTOTYPES_END 149 : 150 : #endif /* HEADER_fd_src_flamenco_features_fd_features_h */