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 : 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 53438877 : #define FD_FEATURE_DISABLED (ULONG_MAX) 16 : 17 : /* fd_features_t is the current set of enabled feature flags. 18 : 19 : Each feature has a corresponding account in the account database, 20 : which are used to control activation. This structure contains an 21 : ulong of the activation slots of each feature for convenience (or 22 : FD_FEATURE_DISABLED if not yet activated). The feature params 23 : contained in this structure change over time, as activated features 24 : become default, and as new pending feature activations get added. 25 : 26 : Usage: 27 : 28 : fd_features_t * features; 29 : 30 : // Direct API 31 : ulong activation_slot = features->FEATURE_NAME; 32 : 33 : // Indirect API 34 : fd_feature_id_t const * id; 35 : ulong activation_slot = fd_features_get( id ); 36 : ... id->index safe in [0,FD_FEATURE_CNT) ... */ 37 : 38 : typedef union fd_features fd_features_t; 39 : 40 : /* fd_feature_id_t maps a feature ID (account address) to the byte 41 : offset in fd_features_t. */ 42 : 43 : struct fd_feature_id { 44 : ulong index; /* index of feature in fd_features_t */ 45 : fd_pubkey_t id; /* pubkey of feature */ 46 : char const * name; /* feature name cstr */ 47 : uint cleaned_up[3]; /* cleaned_up cluster version for feature */ 48 : uchar reverted; /* if the feature was reverted */ 49 : }; 50 : typedef struct fd_feature_id fd_feature_id_t; 51 : 52 : FD_PROTOTYPES_BEGIN 53 : 54 : /* fd_feature_ids is the list of known feature IDs. 55 : The last element has offset==ULONG_MAX. */ 56 : extern fd_feature_id_t const ids[]; 57 : 58 : /* fd_features_disable_all disables all features (cleaned_up or not). */ 59 : 60 : void 61 : fd_features_disable_all( fd_features_t * f ); 62 : 63 : /* fd_features_enable_all enables all features (supported or not). */ 64 : 65 : void 66 : fd_features_enable_all( fd_features_t * ); 67 : 68 : /* fd_features_enable_cleaned_up enables all features marked as "hard 69 : coded". These are features that are baked into the current version 70 : of the Firedancer software and can't be disabled. */ 71 : 72 : void 73 : fd_features_enable_cleaned_up( fd_features_t *, uint[3] ); 74 : 75 : /* fd_features_enable_one_offs enables all manually passed in features. */ 76 : 77 : void 78 : fd_features_enable_one_offs( fd_features_t * features, 79 : char const * * one_offs, 80 : uint one_offs_cnt, 81 : ulong slot ); 82 : 83 : /* fd_feature_iter_{...} is an iterator-style API over all supported 84 : features in this version of Firedancer. Usage: 85 : 86 : for( fd_feature_id_t const * id = fd_feature_iter_init(); 87 : !fd_feature_iter_done( id ); 88 : id = fd_feature_iter_next( id ) ) { 89 : ... 90 : } */ 91 : 92 : static inline fd_feature_id_t const * 93 330828 : fd_feature_iter_init( void ) { 94 330828 : return ids; 95 330828 : } 96 : 97 : static inline int 98 67487904 : fd_feature_iter_done( fd_feature_id_t const * id ) { 99 67487904 : return id->index == ULONG_MAX; 100 67487904 : } 101 : 102 : static inline fd_feature_id_t const * 103 67157076 : fd_feature_iter_next( fd_feature_id_t const * id ) { 104 67157076 : return id+1; 105 67157076 : } 106 : 107 : /* fd_features_set sets the activation slot of the given feature ID. */ 108 : 109 : static inline void 110 : fd_features_set( fd_features_t * features, 111 : fd_feature_id_t const * id, 112 81948771 : ulong slot ) { 113 81948771 : features->f[ id->index ] = slot; 114 81948771 : } 115 : 116 : /* fd_features_get returns the activation slot of the given feature ID. 117 : Returns ULONG_MAX if the feature is not scheduled for activation. */ 118 : 119 : static inline ulong 120 : fd_features_get( fd_features_t const * features, 121 609 : fd_feature_id_t const * id ) { 122 609 : return features->f[ id->index ]; 123 609 : } 124 : 125 : /* fd_feature_id_query queries a feature ID given the first 8 bytes of 126 : the feature address (little-endian order). Returns pointer to ID in 127 : `ids` array on success, or NULL on failure. */ 128 : 129 : FD_FN_CONST fd_feature_id_t const * 130 : fd_feature_id_query( ulong prefix ); 131 : 132 : FD_PROTOTYPES_END 133 : 134 : #endif /* HEADER_fd_src_flamenco_features_fd_features_h */