Kagome
Polkadot Runtime Engine in C++17
kagome::consensus::babe::BabeImpl Class Reference

#include <babe_impl.hpp>

Inheritance diagram for kagome::consensus::babe::BabeImpl:
Collaboration diagram for kagome::consensus::babe::BabeImpl:

Public Member Functions

 BabeImpl (const application::AppConfiguration &app_config, std::shared_ptr< application::AppStateManager > app_state_manager, std::shared_ptr< BabeLottery > lottery, std::shared_ptr< consensus::babe::BabeConfigRepository > babe_config_repo, std::shared_ptr< authorship::Proposer > proposer, std::shared_ptr< blockchain::BlockTree > block_tree, std::shared_ptr< network::BlockAnnounceTransmitter > block_announce_transmitter, std::shared_ptr< crypto::Sr25519Provider > sr25519_provider, const std::shared_ptr< crypto::Sr25519Keypair > &keypair, std::shared_ptr< clock::SystemClock > clock, std::shared_ptr< crypto::Hasher > hasher, std::unique_ptr< clock::Timer > timer, std::shared_ptr< authority::AuthorityUpdateObserver > authority_update_observer, std::shared_ptr< network::Synchronizer > synchronizer, std::shared_ptr< BabeUtil > babe_util, primitives::events::ChainSubscriptionEnginePtr chain_events_engine, std::shared_ptr< runtime::OffchainWorkerApi > offchain_worker_api, std::shared_ptr< runtime::Core > core, std::shared_ptr< babe::ConsistencyKeeper > consistency_keeper)
 
 ~BabeImpl () override=default
 
bool prepare ()
 
bool start ()
 
void stop ()
 
void runEpoch (EpochDescriptor epoch) override
 
State getCurrentState () const override
 
void onRemoteStatus (const libp2p::peer::PeerId &peer_id, const network::Status &status) override
 
void onBlockAnnounce (const libp2p::peer::PeerId &peer_id, const network::BlockAnnounce &announce) override
 
void onSynchronized () override
 
bool wasSynchronized () const override
 
- Public Member Functions inherited from kagome::consensus::babe::Babe
 ~Babe () override=default
 
- Public Member Functions inherited from kagome::network::BlockAnnounceObserver
virtual ~BlockAnnounceObserver ()=default
 

Private Member Functions

outcome::result< EpochDescriptorgetInitialEpochDescriptor ()
 
void adjustEpochDescriptor ()
 
void startCatchUp (const libp2p::peer::PeerId &peer_id, const primitives::BlockInfo &target_block)
 
void startStateSyncing (const libp2p::peer::PeerId &peer_id)
 
void runSlot ()
 
void processSlot ()
 
void processSlotLeadership (SlotType slot_type, std::optional< std::reference_wrapper< const crypto::VRFOutput >> output, primitives::AuthorityIndex authority_index)
 
void startNextEpoch ()
 
void changeLotteryEpoch (const EpochDescriptor &epoch, std::shared_ptr< const primitives::BabeConfiguration > babe_config) const
 
outcome::result< primitives::PreRuntimebabePreDigest (SlotType slot_type, std::optional< std::reference_wrapper< const crypto::VRFOutput >> output, primitives::AuthorityIndex authority_index) const
 
outcome::result< primitives::SealsealBlock (const primitives::Block &block) const
 

Private Attributes

const application::AppConfigurationapp_config_
 
std::shared_ptr< BabeLotterylottery_
 
std::shared_ptr< consensus::babe::BabeConfigRepositorybabe_config_repo_
 
std::shared_ptr< authorship::Proposerproposer_
 
std::shared_ptr< blockchain::BlockTreeblock_tree_
 
std::shared_ptr< network::BlockAnnounceTransmitterblock_announce_transmitter_
 
const std::shared_ptr< crypto::Sr25519Keypair > & keypair_
 
std::shared_ptr< clock::SystemClockclock_
 
std::shared_ptr< crypto::Hasherhasher_
 
std::shared_ptr< crypto::Sr25519Providersr25519_provider_
 
std::unique_ptr< clock::Timertimer_
 
std::shared_ptr< authority::AuthorityUpdateObserverauthority_update_observer_
 
std::shared_ptr< network::Synchronizersynchronizer_
 
std::shared_ptr< BabeUtilbabe_util_
 
primitives::events::ChainSubscriptionEnginePtr chain_events_engine_
 
std::shared_ptr< primitives::events::ChainEventSubscriberchain_sub_
 
std::optional< primitives::Versionactual_runtime_version_
 
std::shared_ptr< runtime::OffchainWorkerApioffchain_worker_api_
 
std::shared_ptr< runtime::Coreruntime_core_
 
std::shared_ptr< babe::ConsistencyKeeperconsistency_keeper_
 
State current_state_ {State::WAIT_REMOTE_STATUS}
 
bool was_synchronized_ {false}
 
std::atomic_bool active_ {false}
 
EpochDescriptor current_epoch_
 
BabeSlotNumber current_slot_ {}
 
primitives::BlockInfo best_block_ {}
 
metrics::RegistryPtr metrics_registry_ = metrics::createRegistry()
 
metrics::Histogrammetric_block_proposal_time_
 
log::Logger log_
 
telemetry::Telemetry telemetry_
 

Additional Inherited Members

- Public Types inherited from kagome::consensus::babe::Babe
enum  State {
  State::WAIT_REMOTE_STATUS, State::HEADERS_LOADING, State::HEADERS_LOADED, State::STATE_LOADING,
  State::CATCHING_UP, State::WAIT_BLOCK_ANNOUNCE, State::SYNCHRONIZED
}
 

Detailed Description

Definition at line 69 of file babe_impl.hpp.

Constructor & Destructor Documentation

kagome::consensus::babe::BabeImpl::BabeImpl ( const application::AppConfiguration app_config,
std::shared_ptr< application::AppStateManager app_state_manager,
std::shared_ptr< BabeLottery lottery,
std::shared_ptr< consensus::babe::BabeConfigRepository babe_config_repo,
std::shared_ptr< authorship::Proposer proposer,
std::shared_ptr< blockchain::BlockTree block_tree,
std::shared_ptr< network::BlockAnnounceTransmitter block_announce_transmitter,
std::shared_ptr< crypto::Sr25519Provider sr25519_provider,
const std::shared_ptr< crypto::Sr25519Keypair > &  keypair,
std::shared_ptr< clock::SystemClock clock,
std::shared_ptr< crypto::Hasher hasher,
std::unique_ptr< clock::Timer timer,
std::shared_ptr< authority::AuthorityUpdateObserver authority_update_observer,
std::shared_ptr< network::Synchronizer synchronizer,
std::shared_ptr< BabeUtil babe_util,
primitives::events::ChainSubscriptionEnginePtr  chain_events_engine,
std::shared_ptr< runtime::OffchainWorkerApi offchain_worker_api,
std::shared_ptr< runtime::Core core,
std::shared_ptr< babe::ConsistencyKeeper consistency_keeper 
)

Create an instance of Babe implementation

Definition at line 43 of file babe_impl.cpp.

kagome::consensus::babe::BabeImpl::~BabeImpl ( )
overridedefault

Member Function Documentation

void kagome::consensus::babe::BabeImpl::adjustEpochDescriptor ( )
private

Definition at line 269 of file babe_impl.cpp.

outcome::result< primitives::PreRuntime > kagome::consensus::babe::BabeImpl::babePreDigest ( SlotType  slot_type,
std::optional< std::reference_wrapper< const crypto::VRFOutput >>  output,
primitives::AuthorityIndex  authority_index 
) const
private

Definition at line 771 of file babe_impl.cpp.

void kagome::consensus::babe::BabeImpl::changeLotteryEpoch ( const EpochDescriptor epoch,
std::shared_ptr< const primitives::BabeConfiguration babe_config 
) const
private

Definition at line 1031 of file babe_impl.cpp.

Babe::State kagome::consensus::babe::BabeImpl::getCurrentState ( ) const
overridevirtual
Returns
current state

Implements kagome::consensus::babe::Babe.

Definition at line 334 of file babe_impl.cpp.

outcome::result< EpochDescriptor > kagome::consensus::babe::BabeImpl::getInitialEpochDescriptor ( )
private

Definition at line 238 of file babe_impl.cpp.

void kagome::consensus::babe::BabeImpl::onBlockAnnounce ( const libp2p::peer::PeerId &  peer_id,
const network::BlockAnnounce announce 
)
overridevirtual

Triggered when a BlockAnnounce message arrives

Parameters
announce- arrived message

Implements kagome::network::BlockAnnounceObserver.

Definition at line 372 of file babe_impl.cpp.

void kagome::consensus::babe::BabeImpl::onRemoteStatus ( const libp2p::peer::PeerId &  peer_id,
const network::Status remote_status 
)
overridevirtual

Triggered when a Status arrives (as handshake of block announce protocol)

Parameters
status- remote status

Implements kagome::network::BlockAnnounceObserver.

Definition at line 338 of file babe_impl.cpp.

void kagome::consensus::babe::BabeImpl::onSynchronized ( )
overridevirtual

Triggered when node is validator and received status from another validator node

Implements kagome::network::BlockAnnounceObserver.

Definition at line 564 of file babe_impl.cpp.

bool kagome::consensus::babe::BabeImpl::prepare ( )
See also
AppStateManager::takeControl

Definition at line 119 of file babe_impl.cpp.

void kagome::consensus::babe::BabeImpl::processSlot ( )
private

Process the current Babe slot

Definition at line 648 of file babe_impl.cpp.

void kagome::consensus::babe::BabeImpl::processSlotLeadership ( SlotType  slot_type,
std::optional< std::reference_wrapper< const crypto::VRFOutput >>  output,
primitives::AuthorityIndex  authority_index 
)
private

Gather block and broadcast it

Parameters
slot_type- kind of slot to compose correct block header
output- VRF proof if required (determined by slot_type)
authority_index- this node index in epoch authorities list

Definition at line 825 of file babe_impl.cpp.

void kagome::consensus::babe::BabeImpl::runEpoch ( EpochDescriptor  epoch)
overridevirtual

Start a Babe production

Parameters
epoch- epoch, which is going to be run epoch.starting_slot_finish_time - when the slot, from which the BABE starts, ends; for example, we start from 5th slot of the some epoch. Then, we need to set time when 5th slot finishes; most probably, that time will be calculated using Median algorithm
Note
the function will automatically continue launching all further epochs of the Babe production
in fact, it is an implementation of "Invoke-Block-Authoring" from the spec

Implements kagome::consensus::babe::Babe.

Definition at line 311 of file babe_impl.cpp.

void kagome::consensus::babe::BabeImpl::runSlot ( )
private

Definition at line 588 of file babe_impl.cpp.

outcome::result< primitives::Seal > kagome::consensus::babe::BabeImpl::sealBlock ( const primitives::Block block) const
private

Definition at line 803 of file babe_impl.cpp.

bool kagome::consensus::babe::BabeImpl::start ( )
See also
AppStateManager::takeControl

Definition at line 167 of file babe_impl.cpp.

void kagome::consensus::babe::BabeImpl::startCatchUp ( const libp2p::peer::PeerId &  peer_id,
const primitives::BlockInfo target_block 
)
private

Definition at line 445 of file babe_impl.cpp.

void kagome::consensus::babe::BabeImpl::startNextEpoch ( )
private

Finish the Babe epoch

Definition at line 1053 of file babe_impl.cpp.

void kagome::consensus::babe::BabeImpl::startStateSyncing ( const libp2p::peer::PeerId &  peer_id)
private

Definition at line 487 of file babe_impl.cpp.

void kagome::consensus::babe::BabeImpl::stop ( )
See also
AppStateManager::takeControl

Definition at line 217 of file babe_impl.cpp.

bool kagome::consensus::babe::BabeImpl::wasSynchronized ( ) const
overridevirtual

Checks whether the node was in a synchronized state at least once since startup.

Returns
true when current state was ever set to synchronized during the current run, otherwise - false.

Implements kagome::consensus::babe::Babe.

Definition at line 584 of file babe_impl.cpp.

Member Data Documentation

std::atomic_bool kagome::consensus::babe::BabeImpl::active_ {false}
private

Definition at line 194 of file babe_impl.hpp.

std::optional<primitives::Version> kagome::consensus::babe::BabeImpl::actual_runtime_version_
private

Definition at line 185 of file babe_impl.hpp.

const application::AppConfiguration& kagome::consensus::babe::BabeImpl::app_config_
private

Definition at line 167 of file babe_impl.hpp.

std::shared_ptr<authority::AuthorityUpdateObserver> kagome::consensus::babe::BabeImpl::authority_update_observer_
private

Definition at line 180 of file babe_impl.hpp.

std::shared_ptr<consensus::babe::BabeConfigRepository> kagome::consensus::babe::BabeImpl::babe_config_repo_
private

Definition at line 169 of file babe_impl.hpp.

std::shared_ptr<BabeUtil> kagome::consensus::babe::BabeImpl::babe_util_
private

Definition at line 182 of file babe_impl.hpp.

primitives::BlockInfo kagome::consensus::babe::BabeImpl::best_block_ {}
private

Definition at line 200 of file babe_impl.hpp.

std::shared_ptr<network::BlockAnnounceTransmitter> kagome::consensus::babe::BabeImpl::block_announce_transmitter_
private

Definition at line 173 of file babe_impl.hpp.

std::shared_ptr<blockchain::BlockTree> kagome::consensus::babe::BabeImpl::block_tree_
private

Definition at line 171 of file babe_impl.hpp.

primitives::events::ChainSubscriptionEnginePtr kagome::consensus::babe::BabeImpl::chain_events_engine_
private

Definition at line 183 of file babe_impl.hpp.

std::shared_ptr<primitives::events::ChainEventSubscriber> kagome::consensus::babe::BabeImpl::chain_sub_
private

Definition at line 184 of file babe_impl.hpp.

std::shared_ptr<clock::SystemClock> kagome::consensus::babe::BabeImpl::clock_
private

Definition at line 175 of file babe_impl.hpp.

std::shared_ptr<babe::ConsistencyKeeper> kagome::consensus::babe::BabeImpl::consistency_keeper_
private

Definition at line 188 of file babe_impl.hpp.

EpochDescriptor kagome::consensus::babe::BabeImpl::current_epoch_
private

Definition at line 196 of file babe_impl.hpp.

BabeSlotNumber kagome::consensus::babe::BabeImpl::current_slot_ {}
private

Definition at line 198 of file babe_impl.hpp.

State kagome::consensus::babe::BabeImpl::current_state_ {State::WAIT_REMOTE_STATUS}
private

Definition at line 190 of file babe_impl.hpp.

std::shared_ptr<crypto::Hasher> kagome::consensus::babe::BabeImpl::hasher_
private

Definition at line 176 of file babe_impl.hpp.

const std::shared_ptr<crypto::Sr25519Keypair>& kagome::consensus::babe::BabeImpl::keypair_
private

Definition at line 174 of file babe_impl.hpp.

log::Logger kagome::consensus::babe::BabeImpl::log_
private

Definition at line 206 of file babe_impl.hpp.

std::shared_ptr<BabeLottery> kagome::consensus::babe::BabeImpl::lottery_
private

Definition at line 168 of file babe_impl.hpp.

metrics::Histogram* kagome::consensus::babe::BabeImpl::metric_block_proposal_time_
private

Definition at line 204 of file babe_impl.hpp.

metrics::RegistryPtr kagome::consensus::babe::BabeImpl::metrics_registry_ = metrics::createRegistry()
private

Definition at line 203 of file babe_impl.hpp.

std::shared_ptr<runtime::OffchainWorkerApi> kagome::consensus::babe::BabeImpl::offchain_worker_api_
private

Definition at line 186 of file babe_impl.hpp.

std::shared_ptr<authorship::Proposer> kagome::consensus::babe::BabeImpl::proposer_
private

Definition at line 170 of file babe_impl.hpp.

std::shared_ptr<runtime::Core> kagome::consensus::babe::BabeImpl::runtime_core_
private

Definition at line 187 of file babe_impl.hpp.

std::shared_ptr<crypto::Sr25519Provider> kagome::consensus::babe::BabeImpl::sr25519_provider_
private

Definition at line 177 of file babe_impl.hpp.

std::shared_ptr<network::Synchronizer> kagome::consensus::babe::BabeImpl::synchronizer_
private

Definition at line 181 of file babe_impl.hpp.

telemetry::Telemetry kagome::consensus::babe::BabeImpl::telemetry_
private

Definition at line 207 of file babe_impl.hpp.

std::unique_ptr<clock::Timer> kagome::consensus::babe::BabeImpl::timer_
private

Definition at line 178 of file babe_impl.hpp.

bool kagome::consensus::babe::BabeImpl::was_synchronized_ {false}
private

Definition at line 192 of file babe_impl.hpp.


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