Kagome
Polkadot Runtime Engine in C++17
kagome::authority::AuthorityManagerImpl Class Reference

#include <authority_manager_impl.hpp>

Inheritance diagram for kagome::authority::AuthorityManagerImpl:
Collaboration diagram for kagome::authority::AuthorityManagerImpl:

Classes

struct  Config
 

Public Member Functions

 AuthorityManagerImpl (Config config, std::shared_ptr< application::AppStateManager > app_state_manager, std::shared_ptr< blockchain::BlockTree > block_tree, std::shared_ptr< storage::trie::TrieStorage > trie_storage, std::shared_ptr< runtime::GrandpaApi > grandpa_api, std::shared_ptr< crypto::Hasher > hash, std::shared_ptr< storage::BufferStorage > persistent_storage, std::shared_ptr< blockchain::BlockHeaderRepository > header_repo)
 
 ~AuthorityManagerImpl () override
 
outcome::result< void > recalculateStoredState (primitives::BlockNumber last_finalized_number) override
 
bool prepare ()
 
primitives::BlockInfo base () const override
 
std::optional< std::shared_ptr< const primitives::AuthoritySet > > authorities (const primitives::BlockInfo &target_block, IsBlockFinalized finalized) const override
 Returns authorities according specified block. More...
 
outcome::result< void > applyScheduledChange (const primitives::BlockInfo &block, const primitives::AuthorityList &authorities, primitives::BlockNumber activate_at) override
 Schedule an authority set change after the given delay of N blocks, after next one would be finalized by the finality consensus engine. More...
 
outcome::result< void > applyForcedChange (const primitives::BlockInfo &block, const primitives::AuthorityList &authorities, primitives::BlockNumber delay_start, size_t delay) override
 Force an authority set change after the given delay of N blocks, after next one would be imported block which has been validated by the block production consensus engine. More...
 
outcome::result< void > applyOnDisabled (const primitives::BlockInfo &block, uint64_t authority_index) override
 An index of the individual authority in the current authority list that should be immediately disabled until the next authority set change. When an authority gets disabled, the node should stop performing any authority functionality from that authority, including authoring blocks and casting GRANDPA votes for finalization. Similarly, other nodes should ignore all messages from the indicated authority which pertain to their authority role. Once an authority set change after the given delay of N blocks, is an imported block which has been validated by the block production consensus engine. More...
 
outcome::result< void > applyPause (const primitives::BlockInfo &block, primitives::BlockNumber activate_at) override
 A signal to pause the current authority set after the given delay, is a block finalized by the finality consensus engine. After finalizing block, the authorities should stop voting. More...
 
outcome::result< void > applyResume (const primitives::BlockInfo &block, primitives::BlockNumber activate_at) override
 A signal to resume the current authority set after the given delay, is an imported block and validated by the block production consensus engine. After authoring the block B 0 , the authorities should resume voting. More...
 
outcome::result< void > onConsensus (const primitives::BlockInfo &block, const primitives::Consensus &message) override
 
void cancel (const primitives::BlockInfo &block) override
 Cancel changes. Should be called when the block is rolled back. More...
 
void prune (const primitives::BlockInfo &block) override
 Prunes data which was needed only till {. More...
 
- Public Member Functions inherited from kagome::authority::AuthorityManager
virtual ~AuthorityManager ()=default
 
- Public Member Functions inherited from kagome::authority::AuthorityUpdateObserver
virtual ~AuthorityUpdateObserver ()=default
 

Static Public Attributes

static const std::vector< primitives::ConsensusEngineIdkKnownEngines {primitives::kBabeEngineId, primitives::kGrandpaEngineId}
 

Private Member Functions

outcome::result< void > initializeAt (const primitives::BlockInfo &root_block)
 
std::shared_ptr< ScheduleNodegetAppropriateAncestor (const primitives::BlockInfo &block) const
 Find schedule_node according to the block. More...
 
outcome::result< std::optional< primitives::AuthoritySetId > > readSetIdFromRuntime (primitives::BlockHeader const &targetBlock) const
 
bool directChainExists (const primitives::BlockInfo &ancestor, const primitives::BlockInfo &descendant) const
 Check if one block is direct ancestor of second one. More...
 
void reorganize (std::shared_ptr< ScheduleNode > node, std::shared_ptr< ScheduleNode > new_node)
 

Private Attributes

Config config_
 
std::shared_ptr< const blockchain::BlockTreeblock_tree_
 
std::shared_ptr< storage::trie::TrieStoragetrie_storage_
 
std::shared_ptr< runtime::GrandpaApigrandpa_api_
 
std::shared_ptr< crypto::Hasherhasher_
 
std::shared_ptr< storage::BufferStoragepersistent_storage_
 
std::shared_ptr< blockchain::BlockHeaderRepositoryheader_repo_
 
std::shared_ptr< ScheduleNoderoot_
 
log::Logger log_
 

Detailed Description

Definition at line 44 of file authority_manager_impl.hpp.


Class Documentation

struct kagome::authority::AuthorityManagerImpl::Config

Definition at line 50 of file authority_manager_impl.hpp.

Collaboration diagram for kagome::authority::AuthorityManagerImpl::Config:
Class Members
bool on_disable_enabled

Constructor & Destructor Documentation

kagome::authority::AuthorityManagerImpl::AuthorityManagerImpl ( Config  config,
std::shared_ptr< application::AppStateManager app_state_manager,
std::shared_ptr< blockchain::BlockTree block_tree,
std::shared_ptr< storage::trie::TrieStorage trie_storage,
std::shared_ptr< runtime::GrandpaApi grandpa_api,
std::shared_ptr< crypto::Hasher hash,
std::shared_ptr< storage::BufferStorage persistent_storage,
std::shared_ptr< blockchain::BlockHeaderRepository header_repo 
)

Definition at line 33 of file authority_manager_impl.cpp.

kagome::authority::AuthorityManagerImpl::~AuthorityManagerImpl ( )
override

Definition at line 246 of file authority_manager_impl.cpp.

Member Function Documentation

outcome::result< void > kagome::authority::AuthorityManagerImpl::applyForcedChange ( const primitives::BlockInfo block,
const primitives::AuthorityList authorities,
primitives::BlockNumber  delay_start,
size_t  delay 
)
overridevirtual

Force an authority set change after the given delay of N blocks, after next one would be imported block which has been validated by the block production consensus engine.

Parameters
blockthe block where a digest with this change was discovered
authoritiesnew authority set
delay_startblock at which the delay before this change is applied starts
delaythe chain length until the delay is over

Implements kagome::authority::AuthorityManager.

Definition at line 612 of file authority_manager_impl.cpp.

outcome::result< void > kagome::authority::AuthorityManagerImpl::applyOnDisabled ( const primitives::BlockInfo block,
uint64_t  authority_index 
)
overridevirtual

An index of the individual authority in the current authority list that should be immediately disabled until the next authority set change. When an authority gets disabled, the node should stop performing any authority functionality from that authority, including authoring blocks and casting GRANDPA votes for finalization. Similarly, other nodes should ignore all messages from the indicated authority which pertain to their authority role. Once an authority set change after the given delay of N blocks, is an imported block which has been validated by the block production consensus engine.

Parameters
blockthe block where a digest with this change was discovered
authority_indexis index of one authority in current authority set

Implements kagome::authority::AuthorityManager.

Definition at line 688 of file authority_manager_impl.cpp.

outcome::result< void > kagome::authority::AuthorityManagerImpl::applyPause ( const primitives::BlockInfo block,
primitives::BlockNumber  activate_at 
)
overridevirtual

A signal to pause the current authority set after the given delay, is a block finalized by the finality consensus engine. After finalizing block, the authorities should stop voting.

Parameters
blockthe block where a digest with this change was discovered
activateAtis number of block when changes will applied

Implements kagome::authority::AuthorityManager.

Definition at line 757 of file authority_manager_impl.cpp.

outcome::result< void > kagome::authority::AuthorityManagerImpl::applyResume ( const primitives::BlockInfo block,
primitives::BlockNumber  activate_at 
)
overridevirtual

A signal to resume the current authority set after the given delay, is an imported block and validated by the block production consensus engine. After authoring the block B 0 , the authorities should resume voting.

Parameters
blockthe block where a digest with this change was discovered
activateAtis number of block when changes will applied

Implements kagome::authority::AuthorityManager.

Definition at line 790 of file authority_manager_impl.cpp.

outcome::result< void > kagome::authority::AuthorityManagerImpl::applyScheduledChange ( const primitives::BlockInfo block,
const primitives::AuthorityList authorities,
primitives::BlockNumber  activate_at 
)
overridevirtual

Schedule an authority set change after the given delay of N blocks, after next one would be finalized by the finality consensus engine.

Parameters
blockthe block where a digest with this change was discovered
authoritiesis authority set for renewal
activateAtis number of block when changes will applied

Implements kagome::authority::AuthorityManager.

Definition at line 495 of file authority_manager_impl.cpp.

std::optional< std::shared_ptr< const primitives::AuthoritySet > > kagome::authority::AuthorityManagerImpl::authorities ( const primitives::BlockInfo block,
IsBlockFinalized  finalized 
) const
overridevirtual

Returns authorities according specified block.

Parameters
blockfor which authority set is requested
finalized- true if we consider that the provided block is finalized
Returns
outcome authority set

Implements kagome::authority::AuthorityManager.

Definition at line 457 of file authority_manager_impl.cpp.

primitives::BlockInfo kagome::authority::AuthorityManagerImpl::base ( ) const
overridevirtual
Returns
block associated with the root of scheduled changes tree

Implements kagome::authority::AuthorityManager.

Definition at line 448 of file authority_manager_impl.cpp.

void kagome::authority::AuthorityManagerImpl::cancel ( const primitives::BlockInfo block)
overridevirtual

Cancel changes. Should be called when the block is rolled back.

Parameters
block- corresponding block

Implements kagome::authority::AuthorityUpdateObserver.

Definition at line 984 of file authority_manager_impl.cpp.

bool kagome::authority::AuthorityManagerImpl::directChainExists ( const primitives::BlockInfo ancestor,
const primitives::BlockInfo descendant 
) const
private

Check if one block is direct ancestor of second one.

Parameters
ancestor- hash of block, which is at the top of the chain
descendant- hash of block, which is the bottom of the chain
Returns
true if
Parameters
ancestoris direct ancestor of
descendant

Definition at line 934 of file authority_manager_impl.cpp.

std::shared_ptr< ScheduleNode > kagome::authority::AuthorityManagerImpl::getAppropriateAncestor ( const primitives::BlockInfo block) const
private

Find schedule_node according to the block.

Parameters
blockfor which to find the schedule node
Returns
oldest schedule_node according to the block

Definition at line 904 of file authority_manager_impl.cpp.

outcome::result< void > kagome::authority::AuthorityManagerImpl::initializeAt ( const primitives::BlockInfo root_block)
private

Definition at line 259 of file authority_manager_impl.cpp.

outcome::result< void > kagome::authority::AuthorityManagerImpl::onConsensus ( const primitives::BlockInfo block,
const primitives::Consensus message 
)
overridevirtual

Processes consensus message in block digest

Parameters
message
Returns
failure or nothing

Implements kagome::authority::AuthorityUpdateObserver.

Definition at line 815 of file authority_manager_impl.cpp.

bool kagome::authority::AuthorityManagerImpl::prepare ( )

Definition at line 248 of file authority_manager_impl.cpp.

void kagome::authority::AuthorityManagerImpl::prune ( const primitives::BlockInfo block)
overridevirtual

Prunes data which was needed only till {.

Parameters
block}and won't be used anymore

Implements kagome::authority::AuthorityManager.

Definition at line 868 of file authority_manager_impl.cpp.

outcome::result< std::optional< AuthoritySetId > > kagome::authority::AuthorityManagerImpl::readSetIdFromRuntime ( primitives::BlockHeader const &  targetBlock) const
private

Definition at line 361 of file authority_manager_impl.cpp.

outcome::result< void > kagome::authority::AuthorityManagerImpl::recalculateStoredState ( primitives::BlockNumber  last_finalized_number)
overridevirtual

Recalculate the authority change graph starting from genesis and up to the last finalized block. The result shall be stored in the provided storage. This operation may take a considerable amount of time.

Returns
nothing on success, error otherwise

Implements kagome::authority::AuthorityManager.

Definition at line 397 of file authority_manager_impl.cpp.

void kagome::authority::AuthorityManagerImpl::reorganize ( std::shared_ptr< ScheduleNode node,
std::shared_ptr< ScheduleNode new_node 
)
private

Definition at line 953 of file authority_manager_impl.cpp.

Member Data Documentation

std::shared_ptr<const blockchain::BlockTree> kagome::authority::AuthorityManagerImpl::block_tree_
private

Definition at line 138 of file authority_manager_impl.hpp.

Config kagome::authority::AuthorityManagerImpl::config_
private

Definition at line 137 of file authority_manager_impl.hpp.

std::shared_ptr<runtime::GrandpaApi> kagome::authority::AuthorityManagerImpl::grandpa_api_
private

Definition at line 140 of file authority_manager_impl.hpp.

std::shared_ptr<crypto::Hasher> kagome::authority::AuthorityManagerImpl::hasher_
private

Definition at line 141 of file authority_manager_impl.hpp.

std::shared_ptr<blockchain::BlockHeaderRepository> kagome::authority::AuthorityManagerImpl::header_repo_
private

Definition at line 143 of file authority_manager_impl.hpp.

const std::vector<primitives::ConsensusEngineId> kagome::authority::AuthorityManagerImpl::kKnownEngines {primitives::kBabeEngineId, primitives::kGrandpaEngineId}
inlinestatic

Definition at line 48 of file authority_manager_impl.hpp.

log::Logger kagome::authority::AuthorityManagerImpl::log_
private

Definition at line 146 of file authority_manager_impl.hpp.

std::shared_ptr<storage::BufferStorage> kagome::authority::AuthorityManagerImpl::persistent_storage_
private

Definition at line 142 of file authority_manager_impl.hpp.

std::shared_ptr<ScheduleNode> kagome::authority::AuthorityManagerImpl::root_
private

Definition at line 145 of file authority_manager_impl.hpp.

std::shared_ptr<storage::trie::TrieStorage> kagome::authority::AuthorityManagerImpl::trie_storage_
private

Definition at line 139 of file authority_manager_impl.hpp.


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