Kagome
Polkadot Runtime Engine in C++17
kagome::network::GrandpaProtocol Class Referencefinal

#include <grandpa_protocol.hpp>

Inheritance diagram for kagome::network::GrandpaProtocol:
Collaboration diagram for kagome::network::GrandpaProtocol:

Public Member Functions

 GrandpaProtocol ()=delete
 
 ~GrandpaProtocol () override=default
 
 GrandpaProtocol (libp2p::Host &host, std::shared_ptr< boost::asio::io_context > io_context, const application::AppConfiguration &app_config, std::shared_ptr< consensus::grandpa::GrandpaObserver > grandpa_observer, const OwnPeerInfo &own_info, std::shared_ptr< StreamEngine > stream_engine, std::shared_ptr< PeerManager > peer_manager, const primitives::BlockHash &genesis_hash, std::shared_ptr< libp2p::basic::Scheduler > scheduler)
 
bool start () override
 
bool stop () override
 
const std::string & protocolName () const override
 
void onIncomingStream (std::shared_ptr< Stream > stream) override
 
void newOutgoingStream (const PeerInfo &peer_info, std::function< void(outcome::result< std::shared_ptr< Stream >>)> &&cb) override
 
void vote (network::GrandpaVote &&vote_message, std::optional< const libp2p::peer::PeerId > peer_id)
 
void neighbor (GrandpaNeighborMessage &&msg)
 
void finalize (FullCommitMessage &&msg, std::optional< const libp2p::peer::PeerId > peer_id)
 
void catchUpRequest (const libp2p::peer::PeerId &peer_id, CatchUpRequest &&catch_up_request)
 
void catchUpResponse (const libp2p::peer::PeerId &peer_id, CatchUpResponse &&catch_up_response)
 
- Public Member Functions inherited from kagome::network::ProtocolBase
 ProtocolBase ()=default
 
 ProtocolBase (ProtocolBase &&) noexcept=delete
 
 ProtocolBase (const ProtocolBase &)=delete
 
virtual ~ProtocolBase ()=default
 
ProtocolBaseoperator= (ProtocolBase &&) noexcept=delete
 
ProtocolBaseoperator= (ProtocolBase const &)=delete
 

Private Types

enum  Direction { Direction::INCOMING, Direction::OUTGOING }
 

Private Member Functions

void readHandshake (std::shared_ptr< Stream > stream, Direction direction, std::function< void(outcome::result< void >)> &&cb)
 
void writeHandshake (std::shared_ptr< Stream > stream, Direction direction, std::function< void(outcome::result< void >)> &&cb)
 
void read (std::shared_ptr< Stream > stream)
 
void write (std::shared_ptr< Stream > stream, const int &msg, std::function< void(outcome::result< std::shared_ptr< Stream >>)> &&cb)
 
- Private Member Functions inherited from NonCopyable
 NonCopyable (NonCopyable const &)=delete
 
NonCopyableoperator= (NonCopyable const &)=delete
 
 NonCopyable ()=default
 
 ~NonCopyable ()=default
 
- Private Member Functions inherited from NonMovable
 NonMovable (NonMovable &&)=delete
 
NonMovableoperator= (NonMovable &&)=delete
 
 NonMovable ()=default
 
 ~NonMovable ()=default
 

Private Attributes

ProtocolBaseImpl base_
 
std::shared_ptr< boost::asio::io_context > io_context_
 
const application::AppConfigurationapp_config_
 
std::shared_ptr< consensus::grandpa::GrandpaObservergrandpa_observer_
 
const OwnPeerInfoown_info_
 
std::shared_ptr< StreamEnginestream_engine_
 
std::shared_ptr< PeerManagerpeer_manager_
 
std::shared_ptr< libp2p::basic::Scheduler > scheduler_
 
std::set< std::tuple< consensus::grandpa::RoundNumber, consensus::grandpa::VoterSetId > > recent_catchup_requests_by_round_
 
std::set< libp2p::peer::PeerId > recent_catchup_requests_by_peer_
 

Static Private Attributes

static const auto kGrandpaProtocolName = "GrandpaProtocol"s
 
static constexpr std::chrono::milliseconds kRecentnessDuration
 

Detailed Description

Definition at line 35 of file grandpa_protocol.hpp.

Member Enumeration Documentation

Enumerator
INCOMING 
OUTGOING 

Definition at line 84 of file grandpa_protocol.hpp.

Constructor & Destructor Documentation

kagome::network::GrandpaProtocol::GrandpaProtocol ( )
delete
kagome::network::GrandpaProtocol::~GrandpaProtocol ( )
overridedefault
kagome::network::GrandpaProtocol::GrandpaProtocol ( libp2p::Host &  host,
std::shared_ptr< boost::asio::io_context >  io_context,
const application::AppConfiguration app_config,
std::shared_ptr< consensus::grandpa::GrandpaObserver grandpa_observer,
const OwnPeerInfo own_info,
std::shared_ptr< StreamEngine stream_engine,
std::shared_ptr< PeerManager peer_manager,
const primitives::BlockHash genesis_hash,
std::shared_ptr< libp2p::basic::Scheduler >  scheduler 
)

Definition at line 23 of file grandpa_protocol.cpp.

Member Function Documentation

void kagome::network::GrandpaProtocol::catchUpRequest ( const libp2p::peer::PeerId &  peer_id,
CatchUpRequest &&  catch_up_request 
)

Definition at line 549 of file grandpa_protocol.cpp.

void kagome::network::GrandpaProtocol::catchUpResponse ( const libp2p::peer::PeerId &  peer_id,
CatchUpResponse &&  catch_up_response 
)

Impolite to send a catch up request to a peer in a new different Set ID.

Avoid sending useless response (if peer is already caught up)

Definition at line 649 of file grandpa_protocol.cpp.

void kagome::network::GrandpaProtocol::finalize ( FullCommitMessage &&  msg,
std::optional< const libp2p::peer::PeerId >  peer_id 
)

Definition at line 459 of file grandpa_protocol.cpp.

void kagome::network::GrandpaProtocol::neighbor ( GrandpaNeighborMessage &&  msg)

Definition at line 440 of file grandpa_protocol.cpp.

void kagome::network::GrandpaProtocol::newOutgoingStream ( const PeerInfo peer_info)
overridevirtual

Implements kagome::network::ProtocolBase.

Definition at line 102 of file grandpa_protocol.cpp.

void kagome::network::GrandpaProtocol::onIncomingStream ( std::shared_ptr< Stream stream)
overridevirtual

Implements kagome::network::ProtocolBase.

Definition at line 59 of file grandpa_protocol.cpp.

const std::string& kagome::network::GrandpaProtocol::protocolName ( ) const
inlineoverridevirtual

Implements kagome::network::ProtocolBase.

Definition at line 62 of file grandpa_protocol.hpp.

void kagome::network::GrandpaProtocol::read ( std::shared_ptr< Stream stream)
private

Definition at line 285 of file grandpa_protocol.cpp.

void kagome::network::GrandpaProtocol::readHandshake ( std::shared_ptr< Stream stream,
Direction  direction,
std::function< void(outcome::result< void >)> &&  cb 
)
private

Definition at line 195 of file grandpa_protocol.cpp.

bool kagome::network::GrandpaProtocol::start ( )
overridevirtual

Sets handler for parytytech/grandpa/1 protocol

Returns
true if handler set successfully

Implements kagome::network::ProtocolBase.

Definition at line 45 of file grandpa_protocol.cpp.

bool kagome::network::GrandpaProtocol::stop ( )
overridevirtual

Implements kagome::network::ProtocolBase.

Definition at line 55 of file grandpa_protocol.cpp.

void kagome::network::GrandpaProtocol::vote ( network::GrandpaVote &&  vote_message,
std::optional< const libp2p::peer::PeerId >  peer_id 
)

Definition at line 348 of file grandpa_protocol.cpp.

void kagome::network::GrandpaProtocol::write ( std::shared_ptr< Stream stream,
const int &  msg 
)
private
void kagome::network::GrandpaProtocol::writeHandshake ( std::shared_ptr< Stream stream,
Direction  direction,
std::function< void(outcome::result< void >)> &&  cb 
)
private

Definition at line 238 of file grandpa_protocol.cpp.

Member Data Documentation

const application::AppConfiguration& kagome::network::GrandpaProtocol::app_config_
private

Definition at line 108 of file grandpa_protocol.hpp.

ProtocolBaseImpl kagome::network::GrandpaProtocol::base_
private

Definition at line 106 of file grandpa_protocol.hpp.

std::shared_ptr<consensus::grandpa::GrandpaObserver> kagome::network::GrandpaProtocol::grandpa_observer_
private

Definition at line 109 of file grandpa_protocol.hpp.

std::shared_ptr<boost::asio::io_context> kagome::network::GrandpaProtocol::io_context_
private

Definition at line 107 of file grandpa_protocol.hpp.

const auto kagome::network::GrandpaProtocol::kGrandpaProtocolName = "GrandpaProtocol"s
inlinestaticprivate

Definition at line 83 of file grandpa_protocol.hpp.

constexpr std::chrono::milliseconds kagome::network::GrandpaProtocol::kRecentnessDuration
staticprivate
Initial value:
=
std::chrono::seconds(300)

Node should send catch-up requests rarely to be polite, because processing of them consume more enough resources. How long replying outgoing catch-up requests must be suppressed

Definition at line 103 of file grandpa_protocol.hpp.

const OwnPeerInfo& kagome::network::GrandpaProtocol::own_info_
private

Definition at line 110 of file grandpa_protocol.hpp.

std::shared_ptr<PeerManager> kagome::network::GrandpaProtocol::peer_manager_
private

Definition at line 112 of file grandpa_protocol.hpp.

std::set<libp2p::peer::PeerId> kagome::network::GrandpaProtocol::recent_catchup_requests_by_peer_
private

Definition at line 119 of file grandpa_protocol.hpp.

std::set<std::tuple<consensus::grandpa::RoundNumber, consensus::grandpa::VoterSetId> > kagome::network::GrandpaProtocol::recent_catchup_requests_by_round_
private

Definition at line 117 of file grandpa_protocol.hpp.

std::shared_ptr<libp2p::basic::Scheduler> kagome::network::GrandpaProtocol::scheduler_
private

Definition at line 113 of file grandpa_protocol.hpp.

std::shared_ptr<StreamEngine> kagome::network::GrandpaProtocol::stream_engine_
private

Definition at line 111 of file grandpa_protocol.hpp.


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