Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
protocol_feature_manager.hpp
Go to the documentation of this file.
1#pragma once
2
4#include <iterator>
5
6namespace sysio { namespace chain {
7
8class deep_mind_handler;
9
10// Values are included in protocol digest, so values must remain constant
13};
14
15// Values are included in protocol digest, so values must remain constant
26 get_sender = 9,
28 webauthn_key = 11,
31 // 14 reserved
32 // 15 reserved
33 blockchain_parameters = 16, // matches release 2.1 value
34 get_code_hash = 17,
35 configurable_wasm_limits = 18, // configurable_wasm_limits2,
37 get_block_num = 20,
38 em_key = 21,
40};
41
47
54
55extern const std::unordered_map<builtin_protocol_feature_t, builtin_protocol_feature_spec, enum_hash<builtin_protocol_feature_t>> builtin_protocol_feature_codenames;
56
58
80
82public:
83 static const char* feature_type_string;
84
86
89 flat_set<digest_type>&& dependencies,
90 const protocol_feature_subjective_restrictions& restrictions );
91
92 void reflector_init();
93
94 digest_type digest()const;
95
97
99
100public:
102protected:
104};
105
109 flat_set<digest_type> dependencies;
112 bool enabled = false;
113 std::optional<builtin_protocol_feature_t> builtin_feature;
114
115 fc::variant to_variant( bool include_subjective_restrictions = true,
116 fc::mutable_variant_object* additional_fields = nullptr )const;
117
118 friend bool operator <( const protocol_feature& lhs, const protocol_feature& rhs ) {
119 return lhs.feature_digest < rhs.feature_digest;
120 }
121
122 friend bool operator <( const digest_type& lhs, const protocol_feature& rhs ) {
123 return lhs < rhs.feature_digest;
124 }
125
126 friend bool operator <( const protocol_feature& lhs, const digest_type& rhs ) {
127 return lhs.feature_digest < rhs;
128 }
129};
130
132protected:
133 using protocol_feature_set_type = std::set< protocol_feature, std::less<> >;
134
135public:
137
138 enum class recognized_t {
140 disabled,
141 too_early,
142 ready
143 };
144
145 recognized_t is_recognized( const digest_type& feature_digest, time_point now )const;
146
147 std::optional<digest_type> get_builtin_digest( builtin_protocol_feature_t feature_codename )const;
148
149 const protocol_feature& get_protocol_feature( const digest_type& feature_digest )const;
150
151 bool validate_dependencies( const digest_type& feature_digest,
152 const std::function<bool(const digest_type&)>& validator )const;
153
157 const std::function<digest_type(builtin_protocol_feature_t dependency)>& handle_dependency
158 );
159
161
163 public:
164 using iterator_category = std::bidirectional_iterator_tag;
166 using difference_type = std::ptrdiff_t;
167 using pointer = const protocol_feature*;
169
170 protected:
171 protocol_feature_set_type::const_iterator _itr;
172
173 protected:
174 explicit const_iterator( protocol_feature_set_type::const_iterator itr )
175 :_itr(itr)
176 {}
177
178 const protocol_feature* get_pointer()const { return &*_itr; }
179
181
182 public:
183 const_iterator() = default;
184
185 friend bool operator == ( const const_iterator& lhs, const const_iterator& rhs ) {
186 return (lhs._itr == rhs._itr);
187 }
188
189 friend bool operator != ( const const_iterator& lhs, const const_iterator& rhs ) {
190 return (lhs._itr != rhs._itr);
191 }
192
194 return *get_pointer();
195 }
196
198 return get_pointer();
199 }
200
202 ++_itr;
203 return *this;
204 }
205
207 --_itr;
208 return *this;
209 }
210
212 const_iterator result(*this);
213 ++(*this);
214 return result;
215 }
216
218 const_iterator result(*this);
219 --(*this);
220 return result;
221 }
222 };
223
224 using const_reverse_iterator = std::reverse_iterator<const_iterator>;
225
227 const_iterator begin()const { return cbegin(); }
228
230 const_iterator end()const { return cend(); }
231
232 const_reverse_iterator crbegin()const { return std::make_reverse_iterator( cend() ); }
234
235 const_reverse_iterator crend()const { return std::make_reverse_iterator( cbegin() ); }
236 const_reverse_iterator rend()const { return crend(); }
237
238 bool empty()const { return _recognized_protocol_features.empty(); }
239 std::size_t size()const { return _recognized_protocol_features.size(); }
240 std::size_t max_size()const { return _recognized_protocol_features.max_size(); }
241
242 template<typename K>
243 const_iterator find( const K& x )const {
245 }
246
247 template<typename K>
248 const_iterator lower_bound( const K& x )const {
249 return const_iterator( _recognized_protocol_features.lower_bound( x ) );
250 }
251
252 template<typename K>
253 const_iterator upper_bound( const K& x )const {
254 return const_iterator( _recognized_protocol_features.upper_bound( x ) );
255 }
256
258
259protected:
262};
263
264
266public:
267
268 protocol_feature_manager( protocol_feature_set&& pfs, std::function<deep_mind_handler*()> get_deep_mind_logger );
269
271 public:
272 using iterator_category = std::bidirectional_iterator_tag;
274 using difference_type = std::ptrdiff_t;
275 using pointer = const protocol_feature*;
277
278 protected:
280 std::size_t _index = 0;
281
282 protected:
283 static constexpr std::size_t end_index = std::numeric_limits<std::size_t>::max();
284
285 explicit const_iterator( const protocol_feature_manager* pfm, std::size_t i = end_index )
286 :_pfm(pfm)
287 ,_index(i)
288 {}
289
290 const protocol_feature* get_pointer()const;
291
293
294 public:
295 const_iterator() = default;
296
297 friend bool operator == ( const const_iterator& lhs, const const_iterator& rhs ) {
298 return std::tie( lhs._pfm, lhs._index ) == std::tie( rhs._pfm, rhs._index );
299 }
300
301 friend bool operator != ( const const_iterator& lhs, const const_iterator& rhs ) {
302 return !(lhs == rhs);
303 }
304
306
308
310 return *get_pointer();
311 }
312
314 return get_pointer();
315 }
316
318
320
322 const_iterator result(*this);
323 ++(*this);
324 return result;
325 }
326
328 const_iterator result(*this);
329 --(*this);
330 return result;
331 }
332 };
333
334 friend class const_iterator;
335
336 using const_reverse_iterator = std::reverse_iterator<const_iterator>;
337
338 void init( chainbase::database& db );
339
340 bool is_initialized()const { return _initialized; }
341
343
344 std::optional<digest_type> get_builtin_digest( builtin_protocol_feature_t feature_codename )const {
345 return _protocol_feature_set.get_builtin_digest( feature_codename );
346 }
347
348 // All methods below require is_initialized() as a precondition.
349
350 const_iterator cbegin()const;
351 const_iterator begin()const { return cbegin(); }
352
353 const_iterator cend()const { return const_iterator( this ); }
354 const_iterator end()const { return cend(); }
355
356 const_reverse_iterator crbegin()const { return std::make_reverse_iterator( cend() ); }
358
359 const_reverse_iterator crend()const { return std::make_reverse_iterator( cbegin() ); }
360 const_reverse_iterator rend()const { return crend(); }
361
362 const_iterator at_activation_ordinal( uint32_t activation_ordinal )const;
363
364 const_iterator lower_bound( uint32_t block_num )const;
365
366 const_iterator upper_bound( uint32_t block_num )const;
367
368
369 bool is_builtin_activated( builtin_protocol_feature_t feature_codename, uint32_t current_block_num )const;
370
371 void activate_feature( const digest_type& feature_digest, uint32_t current_block_num );
372 void popped_blocks_to( uint32_t block_num );
373
374protected:
375
380
382 static constexpr size_t no_previous = std::numeric_limits<size_t>::max();
383 static constexpr uint32_t not_active = std::numeric_limits<uint32_t>::max();
384
387 };
388
389protected:
394 bool _initialized = false;
395
396private:
397 std::function<deep_mind_handler*()> _get_deep_mind_logger;
398};
399
400} } // namespace sysio::chain
401
403 (earliest_allowed_activation_time)(preactivation_required)(enabled))
404
406 (protocol_feature_type)(dependencies)(description_digest)(subjective_restrictions))
407
409 (builtin_feature_codename))
An order-preserving dictionary of variants.
stores null, int64, uint64, double, bool, string, std::vector<variant>, and variant_object's.
Definition variant.hpp:191
builtin_protocol_feature_t get_codename() const
protocol_feature_subjective_restrictions subjective_restrictions
friend bool operator!=(const const_iterator &lhs, const const_iterator &rhs)
friend bool operator==(const const_iterator &lhs, const const_iterator &rhs)
const_iterator(const protocol_feature_manager *pfm, std::size_t i=end_index)
const_iterator at_activation_ordinal(uint32_t activation_ordinal) const
vector< builtin_protocol_feature_entry > _builtin_protocol_features
std::optional< digest_type > get_builtin_digest(builtin_protocol_feature_t feature_codename) const
vector< protocol_feature_entry > _activated_protocol_features
std::reverse_iterator< const_iterator > const_reverse_iterator
const protocol_feature_set & get_protocol_feature_set() const
void activate_feature(const digest_type &feature_digest, uint32_t current_block_num)
bool is_builtin_activated(builtin_protocol_feature_t feature_codename, uint32_t current_block_num) const
protocol_feature_manager(protocol_feature_set &&pfs, std::function< deep_mind_handler *()> get_deep_mind_logger)
const_iterator upper_bound(uint32_t block_num) const
const_iterator lower_bound(uint32_t block_num) const
friend bool operator!=(const const_iterator &lhs, const const_iterator &rhs)
friend bool operator==(const const_iterator &lhs, const const_iterator &rhs)
const_iterator(protocol_feature_set_type::const_iterator itr)
std::reverse_iterator< const_iterator > const_reverse_iterator
vector< protocol_feature_set_type::const_iterator > _recognized_builtin_protocol_features
static builtin_protocol_feature make_default_builtin_protocol_feature(builtin_protocol_feature_t codename, const std::function< digest_type(builtin_protocol_feature_t dependency)> &handle_dependency)
std::optional< digest_type > get_builtin_digest(builtin_protocol_feature_t feature_codename) const
std::set< protocol_feature, std::less<> > protocol_feature_set_type
recognized_t is_recognized(const digest_type &feature_digest, time_point now) const
const_iterator lower_bound(const K &x) const
const_iterator find(const K &x) const
bool validate_dependencies(const digest_type &feature_digest, const std::function< bool(const digest_type &)> &validator) const
const protocol_feature & add_feature(const builtin_protocol_feature &f)
const protocol_feature & get_protocol_feature(const digest_type &feature_digest) const
const_iterator upper_bound(const K &x) const
protocol_feature_set_type _recognized_protocol_features
void init()
Definition lib_test.cpp:3
const uint64 K
Definition make_512.cpp:78
const std::unordered_map< builtin_protocol_feature_t, builtin_protocol_feature_spec, enum_hash< builtin_protocol_feature_t > > builtin_protocol_feature_codenames
checksum_type digest_type
Definition types.hpp:237
const char * builtin_protocol_feature_codename(builtin_protocol_feature_t)
#define FC_REFLECT(TYPE, MEMBERS)
Specializes fc::reflector for TYPE.
Definition reflect.hpp:311
#define FC_REFLECT_DERIVED(TYPE, INHERITS, MEMBERS)
Specializes fc::reflector for TYPE where type inherits other reflected classes.
Definition reflect.hpp:298
unsigned int uint32_t
Definition stdint.h:126
flat_set< builtin_protocol_feature_t > builtin_dependencies
protocol_feature_subjective_restrictions subjective_restrictions
uint32_t activation_block_num
static constexpr size_t no_previous
static constexpr uint32_t not_active
size_t previous
uint32_t activation_block_num
protocol_feature_set::const_iterator iterator_to_protocol_feature
friend bool operator<(const protocol_feature &lhs, const protocol_feature &rhs)
std::optional< builtin_protocol_feature_t > builtin_feature
fc::variant to_variant(bool include_subjective_restrictions=true, fc::mutable_variant_object *additional_fields=nullptr) const