Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
sysio::chain::protocol_feature_set Class Reference

#include <protocol_feature_manager.hpp>

Collaboration diagram for sysio::chain::protocol_feature_set:

Classes

class  const_iterator
 

Public Types

enum class  recognized_t { unrecognized , disabled , too_early , ready }
 
using const_reverse_iterator = std::reverse_iterator<const_iterator>
 

Public Member Functions

 protocol_feature_set ()
 
recognized_t is_recognized (const digest_type &feature_digest, time_point now) const
 
std::optional< digest_typeget_builtin_digest (builtin_protocol_feature_t feature_codename) const
 
const protocol_featureget_protocol_feature (const digest_type &feature_digest) const
 
bool validate_dependencies (const digest_type &feature_digest, const std::function< bool(const digest_type &)> &validator) const
 
const protocol_featureadd_feature (const builtin_protocol_feature &f)
 
const_iterator cbegin () const
 
const_iterator begin () const
 
const_iterator cend () const
 
const_iterator end () const
 
const_reverse_iterator crbegin () const
 
const_reverse_iterator rbegin () const
 
const_reverse_iterator crend () const
 
const_reverse_iterator rend () const
 
bool empty () const
 
std::size_t size () const
 
std::size_t max_size () const
 
template<typename K >
const_iterator find (const K &x) const
 
template<typename K >
const_iterator lower_bound (const K &x) const
 
template<typename K >
const_iterator upper_bound (const K &x) const
 

Static Public Member Functions

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)
 

Protected Types

using protocol_feature_set_type = std::set< protocol_feature, std::less<> >
 

Protected Attributes

protocol_feature_set_type _recognized_protocol_features
 
vector< protocol_feature_set_type::const_iterator > _recognized_builtin_protocol_features
 

Friends

class protocol_feature_manager
 

Detailed Description

Definition at line 131 of file protocol_feature_manager.hpp.

Member Typedef Documentation

◆ const_reverse_iterator

◆ protocol_feature_set_type

Definition at line 133 of file protocol_feature_manager.hpp.

Member Enumeration Documentation

◆ recognized_t

Constructor & Destructor Documentation

◆ protocol_feature_set()

sysio::chain::protocol_feature_set::protocol_feature_set ( )

Definition at line 410 of file protocol_feature_manager.cpp.

411 {
413 }
vector< protocol_feature_set_type::const_iterator > _recognized_builtin_protocol_features
const std::unordered_map< builtin_protocol_feature_t, builtin_protocol_feature_spec, enum_hash< builtin_protocol_feature_t > > builtin_protocol_feature_codenames

Member Function Documentation

◆ add_feature()

const protocol_feature & sysio::chain::protocol_feature_set::add_feature ( const builtin_protocol_feature & f)

Definition at line 491 of file protocol_feature_manager.cpp.

491 {
492 auto builtin_itr = builtin_protocol_feature_codenames.find( f._codename );
493 SYS_ASSERT( builtin_itr != builtin_protocol_feature_codenames.end(), protocol_feature_validation_exception,
494 "Builtin protocol feature has unsupported builtin_protocol_feature_t: ${codename}",
495 ("codename", static_cast<uint32_t>( f._codename )) );
496
497 uint32_t indx = static_cast<uint32_t>( f._codename );
498
499 if( indx < _recognized_builtin_protocol_features.size() ) {
501 protocol_feature_exception,
502 "builtin protocol feature with codename '${codename}' already added",
503 ("codename", f.builtin_feature_codename) );
504 }
505
506 auto feature_digest = f.digest();
507
508 const auto& expected_builtin_dependencies = builtin_itr->second.builtin_dependencies;
509 flat_set<builtin_protocol_feature_t> satisfied_builtin_dependencies;
510 satisfied_builtin_dependencies.reserve( expected_builtin_dependencies.size() );
511
512 for( const auto& d : f.dependencies ) {
513 auto itr = _recognized_protocol_features.find( d );
514 SYS_ASSERT( itr != _recognized_protocol_features.end(), protocol_feature_exception,
515 "builtin protocol feature with codename '${codename}' and digest of ${digest} has a dependency on a protocol feature with digest ${dependency_digest} that is not recognized",
516 ("codename", f.builtin_feature_codename)
517 ("digest", feature_digest)
518 ("dependency_digest", d )
519 );
520
521 if( itr->builtin_feature
522 && expected_builtin_dependencies.find( *itr->builtin_feature )
523 != expected_builtin_dependencies.end() )
524 {
525 satisfied_builtin_dependencies.insert( *itr->builtin_feature );
526 }
527 }
528
529 if( expected_builtin_dependencies.size() > satisfied_builtin_dependencies.size() ) {
530 flat_set<builtin_protocol_feature_t> missing_builtins;
531 missing_builtins.reserve( expected_builtin_dependencies.size() - satisfied_builtin_dependencies.size() );
532 std::set_difference( expected_builtin_dependencies.begin(), expected_builtin_dependencies.end(),
533 satisfied_builtin_dependencies.begin(), satisfied_builtin_dependencies.end(),
534 end_inserter( missing_builtins )
535 );
536
537 vector<string> missing_builtins_with_names;
538 missing_builtins_with_names.reserve( missing_builtins.size() );
539 for( const auto& builtin_codename : missing_builtins ) {
540 auto itr = builtin_protocol_feature_codenames.find( builtin_codename );
542 protocol_feature_exception,
543 "Unexpected error"
544 );
545 missing_builtins_with_names.emplace_back( itr->second.codename );
546 }
547
548 SYS_THROW( protocol_feature_validation_exception,
549 "Not all the builtin dependencies of the builtin protocol feature with codename '${codename}' and digest of ${digest} were satisfied.",
550 ("missing_dependencies", missing_builtins_with_names)
551 );
552 }
553
554 auto res = _recognized_protocol_features.insert( protocol_feature{
555 feature_digest,
556 f.description_digest,
557 f.dependencies,
558 f.subjective_restrictions.earliest_allowed_activation_time,
559 f.subjective_restrictions.preactivation_required,
560 f.subjective_restrictions.enabled,
561 f._codename
562 } );
563
564 SYS_ASSERT( res.second, protocol_feature_exception,
565 "builtin protocol feature with codename '${codename}' has a digest of ${digest} but another protocol feature with the same digest has already been added",
566 ("codename", f.builtin_feature_codename)("digest", feature_digest) );
567
568 if( indx >= _recognized_builtin_protocol_features.size() ) {
569 for( auto i =_recognized_builtin_protocol_features.size(); i <= indx; ++i ) {
571 }
572 }
573
575 return *res.first;
576 }
#define SYS_THROW(exc_type, FORMAT,...)
#define SYS_ASSERT(expr, exc_type, FORMAT,...)
Definition exceptions.hpp:7
protocol_feature_set_type _recognized_protocol_features
end_insert_iterator< Container > end_inserter(Container &c)
Definition types.hpp:303
unsigned int uint32_t
Definition stdint.h:126
Here is the call graph for this function:
Here is the caller graph for this function:

◆ begin()

const_iterator sysio::chain::protocol_feature_set::begin ( ) const
inline

Definition at line 227 of file protocol_feature_manager.hpp.

227{ return cbegin(); }
Here is the call graph for this function:

◆ cbegin()

const_iterator sysio::chain::protocol_feature_set::cbegin ( ) const
inline

Definition at line 226 of file protocol_feature_manager.hpp.

226{ return const_iterator( _recognized_protocol_features.cbegin() ); }
Here is the caller graph for this function:

◆ cend()

const_iterator sysio::chain::protocol_feature_set::cend ( ) const
inline

Definition at line 229 of file protocol_feature_manager.hpp.

229{ return const_iterator( _recognized_protocol_features.cend() ); }
Here is the caller graph for this function:

◆ crbegin()

const_reverse_iterator sysio::chain::protocol_feature_set::crbegin ( ) const
inline

Definition at line 232 of file protocol_feature_manager.hpp.

232{ return std::make_reverse_iterator( cend() ); }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ crend()

const_reverse_iterator sysio::chain::protocol_feature_set::crend ( ) const
inline

Definition at line 235 of file protocol_feature_manager.hpp.

235{ return std::make_reverse_iterator( cbegin() ); }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ empty()

bool sysio::chain::protocol_feature_set::empty ( ) const
inline

Definition at line 238 of file protocol_feature_manager.hpp.

238{ return _recognized_protocol_features.empty(); }

◆ end()

const_iterator sysio::chain::protocol_feature_set::end ( ) const
inline

Definition at line 230 of file protocol_feature_manager.hpp.

230{ return cend(); }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ find()

template<typename K >
const_iterator sysio::chain::protocol_feature_set::find ( const K & x) const
inline

Definition at line 243 of file protocol_feature_manager.hpp.

243 {
244 return const_iterator( _recognized_protocol_features.find( x ) );
245 }
Here is the caller graph for this function:

◆ get_builtin_digest()

std::optional< digest_type > sysio::chain::protocol_feature_set::get_builtin_digest ( builtin_protocol_feature_t feature_codename) const

Definition at line 432 of file protocol_feature_manager.cpp.

432 {
433 uint32_t indx = static_cast<uint32_t>( feature_codename );
434
435 if( indx >= _recognized_builtin_protocol_features.size() )
436 return {};
437
439 return {};
440
441 return _recognized_builtin_protocol_features[indx]->feature_digest;
442 }
Here is the caller graph for this function:

◆ get_protocol_feature()

const protocol_feature & sysio::chain::protocol_feature_set::get_protocol_feature ( const digest_type & feature_digest) const

Definition at line 444 of file protocol_feature_manager.cpp.

444 {
445 auto itr = _recognized_protocol_features.find( feature_digest );
446
447 SYS_ASSERT( itr != _recognized_protocol_features.end(), protocol_feature_exception,
448 "unrecognized protocol feature with digest: ${digest}",
449 ("digest", feature_digest)
450 );
451
452 return *itr;
453 }

◆ is_recognized()

protocol_feature_set::recognized_t sysio::chain::protocol_feature_set::is_recognized ( const digest_type & feature_digest,
time_point now ) const

Definition at line 417 of file protocol_feature_manager.cpp.

417 {
418 auto itr = _recognized_protocol_features.find( feature_digest );
419
420 if( itr == _recognized_protocol_features.end() )
422
423 if( !itr->enabled )
425
426 if( itr->earliest_allowed_activation_time > now )
428
429 return recognized_t::ready;
430 }

◆ lower_bound()

template<typename K >
const_iterator sysio::chain::protocol_feature_set::lower_bound ( const K & x) const
inline

Definition at line 248 of file protocol_feature_manager.hpp.

248 {
249 return const_iterator( _recognized_protocol_features.lower_bound( x ) );
250 }

◆ make_default_builtin_protocol_feature()

builtin_protocol_feature sysio::chain::protocol_feature_set::make_default_builtin_protocol_feature ( builtin_protocol_feature_t codename,
const std::function< digest_type(builtin_protocol_feature_t dependency)> & handle_dependency )
static

Definition at line 471 of file protocol_feature_manager.cpp.

474 {
475 auto itr = builtin_protocol_feature_codenames.find( codename );
476
477 SYS_ASSERT( itr != builtin_protocol_feature_codenames.end(), protocol_feature_validation_exception,
478 "Unsupported builtin_protocol_feature_t: ${codename}",
479 ("codename", static_cast<uint32_t>(codename)) );
480
481 flat_set<digest_type> dependencies;
482 dependencies.reserve( itr->second.builtin_dependencies.size() );
483
484 for( const auto& d : itr->second.builtin_dependencies ) {
485 dependencies.insert( handle_dependency( d ) );
486 }
487
488 return {itr->first, itr->second.description_digest, std::move(dependencies), itr->second.subjective_restrictions};
489 }
Here is the caller graph for this function:

◆ max_size()

std::size_t sysio::chain::protocol_feature_set::max_size ( ) const
inline

Definition at line 240 of file protocol_feature_manager.hpp.

240{ return _recognized_protocol_features.max_size(); }

◆ rbegin()

const_reverse_iterator sysio::chain::protocol_feature_set::rbegin ( ) const
inline

Definition at line 233 of file protocol_feature_manager.hpp.

233{ return crbegin(); }
Here is the call graph for this function:

◆ rend()

const_reverse_iterator sysio::chain::protocol_feature_set::rend ( ) const
inline

Definition at line 236 of file protocol_feature_manager.hpp.

236{ return crend(); }
Here is the call graph for this function:

◆ size()

std::size_t sysio::chain::protocol_feature_set::size ( ) const
inline

Definition at line 239 of file protocol_feature_manager.hpp.

239{ return _recognized_protocol_features.size(); }

◆ upper_bound()

template<typename K >
const_iterator sysio::chain::protocol_feature_set::upper_bound ( const K & x) const
inline

Definition at line 253 of file protocol_feature_manager.hpp.

253 {
254 return const_iterator( _recognized_protocol_features.upper_bound( x ) );
255 }

◆ validate_dependencies()

bool sysio::chain::protocol_feature_set::validate_dependencies ( const digest_type & feature_digest,
const std::function< bool(const digest_type &)> & validator ) const

Definition at line 455 of file protocol_feature_manager.cpp.

458 {
459 auto itr = _recognized_protocol_features.find( feature_digest );
460
461 if( itr == _recognized_protocol_features.end() ) return false;
462
463 for( const auto& d : itr->dependencies ) {
464 if( !validator(d) ) return false;
465 }
466
467 return true;
468 }

Friends And Related Symbol Documentation

◆ protocol_feature_manager

Definition at line 257 of file protocol_feature_manager.hpp.

Member Data Documentation

◆ _recognized_builtin_protocol_features

vector<protocol_feature_set_type::const_iterator> sysio::chain::protocol_feature_set::_recognized_builtin_protocol_features
protected

Definition at line 261 of file protocol_feature_manager.hpp.

◆ _recognized_protocol_features

protocol_feature_set_type sysio::chain::protocol_feature_set::_recognized_protocol_features
protected

Definition at line 260 of file protocol_feature_manager.hpp.


The documentation for this class was generated from the following files: