LCOV - code coverage report
Current view: top level - flamenco/features - fd_features.h (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 16 16 100.0 %
Date: 2025-03-20 12:08:36 Functions: 9 580 1.6 %

          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     1748313 : #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             :   uchar        activated_on_all_clusters; /* if the feature was activated on all clusters (currently only used for fuzzing) */
      50             : };
      51             : typedef struct fd_feature_id fd_feature_id_t;
      52             : 
      53             : FD_PROTOTYPES_BEGIN
      54             : 
      55             : /* fd_feature_ids is the list of known feature IDs.
      56             :    The last element has offset==ULONG_MAX. */
      57             : extern fd_feature_id_t const ids[];
      58             : 
      59             : /* fd_features_disable_all disables all features (cleaned_up or not). */
      60             : 
      61             : void
      62             : fd_features_disable_all( fd_features_t * f );
      63             : 
      64             : /* fd_features_enable_all enables all features (supported or not). */
      65             : 
      66             : void
      67             : fd_features_enable_all( fd_features_t * );
      68             : 
      69             : /* fd_features_enable_cleaned_up enables all features marked as "hard
      70             :    coded".  These are features that are baked into the current version
      71             :    of the Firedancer software and can't be disabled. */
      72             : 
      73             : void
      74             : fd_features_enable_cleaned_up( fd_features_t *, uint[3] );
      75             : 
      76             : /* fd_features_enable_one_offs enables all manually passed in features. */
      77             : 
      78             : void
      79             : fd_features_enable_one_offs( fd_features_t * features,
      80             :                              char const * *  one_offs,
      81             :                              uint            one_offs_cnt,
      82             :                              ulong           slot );
      83             : 
      84             : /* fd_feature_iter_{...} is an iterator-style API over all supported
      85             :    features in this version of Firedancer.  Usage:
      86             : 
      87             :      for( fd_feature_id_t const * id = fd_feature_iter_init();
      88             :                                       !fd_feature_iter_done( id );
      89             :                                   id = fd_feature_iter_next( id ) ) {
      90             :        ...
      91             :      } */
      92             : 
      93             : static inline fd_feature_id_t const *
      94        7692 : fd_feature_iter_init( void ) {
      95        7692 :   return ids;
      96        7692 : }
      97             : 
      98             : static inline int
      99     1761468 : fd_feature_iter_done( fd_feature_id_t const * id ) {
     100     1761468 :   return id->index == ULONG_MAX;
     101     1761468 : }
     102             : 
     103             : static inline fd_feature_id_t const *
     104     1753776 : fd_feature_iter_next( fd_feature_id_t const * id ) {
     105     1753776 :   return id+1;
     106     1753776 : }
     107             : 
     108             : /* fd_features_set sets the activation slot of the given feature ID. */
     109             : 
     110             : static inline void
     111             : fd_features_set( fd_features_t *         features,
     112             :                  fd_feature_id_t const * id,
     113     1756653 :                  ulong                   slot ) {
     114     1756653 :   features->f[ id->index ] = slot;
     115     1756653 : }
     116             : 
     117             : /* fd_features_get returns the activation slot of the given feature ID.
     118             :    Returns ULONG_MAX if the feature is not scheduled for activation. */
     119             : 
     120             : static inline ulong
     121             : fd_features_get( fd_features_t const *   features,
     122         684 :                  fd_feature_id_t const * id ) {
     123         684 :   return features->f[ id->index ];
     124         684 : }
     125             : 
     126             : /* fd_feature_id_query queries a feature ID given the first 8 bytes of
     127             :    the feature address (little-endian order).  Returns pointer to ID in
     128             :    `ids` array on success, or NULL on failure. */
     129             : 
     130             : FD_FN_CONST fd_feature_id_t const *
     131             : fd_feature_id_query( ulong prefix );
     132             : 
     133             : FD_PROTOTYPES_END
     134             : 
     135             : #endif /* HEADER_fd_src_flamenco_features_fd_features_h */

Generated by: LCOV version 1.14