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