Kagome
Polkadot Runtime Engine in C++17
kagome::parachain::ParachainProcessorImpl Struct Reference

#include <parachain_processor.hpp>

Inheritance diagram for kagome::parachain::ParachainProcessorImpl:
Collaboration diagram for kagome::parachain::ParachainProcessorImpl:

Classes

struct  AttestingData
 
struct  FetchedCollationState
 
struct  ImportStatementSummary
 
struct  ValidateAndSecondResult
 

Public Types

enum  Error { Error::RESPONSE_ALREADY_RECEIVED = 1, Error::COLLATION_NOT_FOUND, Error::KEY_NOT_PRESENT }
 

Public Member Functions

 ParachainProcessorImpl (std::shared_ptr< network::PeerManager > pm, std::shared_ptr< crypto::Sr25519Provider > crypto_provider, std::shared_ptr< network::Router > router, std::shared_ptr< boost::asio::io_context > this_context, std::shared_ptr< crypto::Sr25519Keypair > keypair, std::shared_ptr< crypto::Hasher > hasher)
 
 ~ParachainProcessorImpl ()
 
bool start ()
 
void stop ()
 
bool prepare ()
 
void requestCollations (network::PendingCollation const &pending_collation)
 
void setAssignedParachain (std::optional< network::ParachainId > para_id)
 
void handleStatement (libp2p::peer::PeerId const &peer_id, primitives::BlockHash const &relay_parent, std::shared_ptr< network::Statement > const &statement)
 

Static Public Attributes

static constexpr uint64_t kBackgroundWorkers = 5
 

Private Types

enum  CollationState { CollationState::kFetched, CollationState::kSeconded }
 
enum  PoVDataState { PoVDataState::kComplete, PoVDataState::kFetchFromValidator }
 
enum  StatementType { StatementType::kSeconded = 0, StatementType::kValid }
 
using FetchedCollation = std::shared_ptr< FetchedCollationState >
 
using Commitments = std::shared_ptr< network::CandidateCommitments >
 
using PeerMap = std::unordered_map< libp2p::peer::PeerId, FetchedCollation >
 
using RelayParentMap = std::unordered_map< primitives::BlockHash, PeerMap >
 
using ParachainMap = std::unordered_map< network::ParachainId, RelayParentMap >
 
using BackgroundTask = std::function< void()>
 
using WorkersContext = boost::asio::io_context
 
using WorkGuard = boost::asio::executor_work_guard< boost::asio::io_context::executor_type >
 

Private Member Functions

outcome::result< void > validateCandidate (FetchedCollation &fetched_collation)
 
outcome::result< void > validateErasureCoding (FetchedCollation &fetched_collation)
 
template<typename F >
void validateAndMakeAvailable (libp2p::peer::PeerId const &peer_id, primitives::BlockHash const &relay_parent, FetchedCollation fetched_collation, F &&callback)
 
void requestPoV ()
 
void onValidationComplete (libp2p::peer::PeerId const &peer_id, ValidateAndSecondResult &&result)
 
void onAttestComplete (libp2p::peer::PeerId const &peer_id, ValidateAndSecondResult &&result)
 
void onAttestNoPoVComplete (libp2p::peer::PeerId const &peer_id, ValidateAndSecondResult &&result)
 
void appendAsyncValidationTask (network::ParachainId id, primitives::BlockHash const &relay_parent, libp2p::peer::PeerId const &peer_id)
 
void kickOffValidationWork (AttestingData &attesting_data)
 
void handleFetchedCollation (network::ParachainId id, primitives::BlockHash const &relay_parent, libp2p::peer::PeerId const &peer_id, network::CollationFetchingResponse &&response)
 
template<StatementType kStatementType>
std::shared_ptr< network::StatementcreateAndSignStatement (ValidateAndSecondResult &validation_result)
 
std::optional< ImportStatementSummaryimportStatement (std::shared_ptr< network::Statement > const &statement)
 
std::optional< network::ValidatorIndexgetOurIndex ()
 
primitives::BlockHash candidateHashFrom (FetchedCollationState const &fetched_collation_state)
 
network::CandidateDescriptor const & candidateDescriptorFrom (FetchedCollationState const &fetched_collation_state)
 
std::optional< std::reference_wrapper< network::CandidateDescriptor const > > candidateDescriptorFrom (std::shared_ptr< network::Statement > const &statement)
 
network::CollatorPublicKey const & collatorIdFromDescriptor (network::CandidateDescriptor const &descriptor)
 
primitives::BlockHash candidateHashFrom (std::shared_ptr< network::Statement > const &statement)
 
template<typename F >
void notify_internal (std::shared_ptr< WorkersContext > &context, F &&func)
 
void notifyBackedCandidate (std::shared_ptr< network::Statement > const &statement)
 
void notifyAvailableData ()
 
void notifyStatementDistributionSystem (std::shared_ptr< network::Statement > const &statement)
 
void notify (libp2p::peer::PeerId const &peer_id, primitives::BlockHash const &relay_parent, std::shared_ptr< network::Statement > const &statement)
 
void handleNotify (libp2p::peer::PeerId const &peer_id, primitives::BlockHash const &relay_parent)
 
outcome::result< FetchedCollationloadIntoResponseSlot (network::ParachainId id, primitives::BlockHash const &relay_parent, libp2p::peer::PeerId const &peer_id, network::CollationFetchingResponse &&response)
 
outcome::result< FetchedCollationgetFromSlot (network::ParachainId id, primitives::BlockHash const &relay_parent, libp2p::peer::PeerId const &peer_id)
 
template<typename T >
outcome::result< network::Signaturesign (T const &t) const
 
std::optional< ImportStatementSummaryimportStatementToTable (primitives::BlockHash const &candidate_hash, std::shared_ptr< network::Statement > const &statement)
 

Private Attributes

std::shared_ptr< network::PeerManagerpm_
 
std::shared_ptr< crypto::Sr25519Providercrypto_provider_
 
std::shared_ptr< network::Routerrouter_
 
log::Logger logger_
 
struct {
std::optional< network::ParachainIdassignment
 
std::optional< primitives::BlockHashseconded
 
std::optional< network::CollatorPublicKeyrequired_collator
 
std::unordered_set< primitives::BlockHashawaiting_validation
 
std::unordered_set< primitives::BlockHashissued_statements
 
std::unordered_map< primitives::BlockHash, AttestingDatafallbacks
 
std::unordered_map< libp2p::peer::PeerId, std::deque< std::shared_ptr< network::Statement > > > seconded_statements
 
our_current_state_
 
std::shared_ptr< WorkersContextcontext_
 
std::shared_ptr< WorkGuardwork_guard_
 
std::unique_ptr< std::thread > workers_ [kBackgroundWorkers]
 
SafeObject< ParachainMapcollations_
 
std::shared_ptr< WorkersContextthis_context_
 
std::shared_ptr< crypto::Sr25519Keypairkeypair_
 
std::shared_ptr< crypto::Hasherhasher_
 

Detailed Description

Definition at line 43 of file parachain_processor.hpp.


Class Documentation

struct kagome::parachain::ParachainProcessorImpl::AttestingData

Definition at line 117 of file parachain_processor.hpp.

Collaboration diagram for kagome::parachain::ParachainProcessorImpl::AttestingData:
Class Members
queue< ValidatorIndex > backing
BlockHash candidate_hash
ValidatorIndex from_validator
BlockHash pov_hash
shared_ptr< Statement > statement
struct kagome::parachain::ParachainProcessorImpl::ImportStatementSummary

Definition at line 52 of file parachain_processor.hpp.

Collaboration diagram for kagome::parachain::ParachainProcessorImpl::ImportStatementSummary:
Class Members
bool attested Attested more than threshold.
BlockHash candidate The digest of the candidate.
ParachainId group_id The group that the candidate is in.
uint64_t validity_votes How many validity votes are currently witnessed.
struct kagome::parachain::ParachainProcessorImpl::ValidateAndSecondResult

Definition at line 110 of file parachain_processor.hpp.

Collaboration diagram for kagome::parachain::ParachainProcessorImpl::ValidateAndSecondResult:
Class Members
Commitments commitments
FetchedCollation fetched_collation
BlockHash relay_parent
result< void > result

Member Typedef Documentation

using kagome::parachain::ParachainProcessorImpl::BackgroundTask = std::function<void()>
private

Definition at line 105 of file parachain_processor.hpp.

using kagome::parachain::ParachainProcessorImpl::PeerMap = std::unordered_map<libp2p::peer::PeerId, FetchedCollation>
private

Definition at line 101 of file parachain_processor.hpp.

using kagome::parachain::ParachainProcessorImpl::WorkersContext = boost::asio::io_context
private

Definition at line 106 of file parachain_processor.hpp.

using kagome::parachain::ParachainProcessorImpl::WorkGuard = boost::asio::executor_work_guard< boost::asio::io_context::executor_type>
private

Definition at line 108 of file parachain_processor.hpp.

Member Enumeration Documentation

Enumerator
kFetched 
kSeconded 

Definition at line 82 of file parachain_processor.hpp.

Enumerator
RESPONSE_ALREADY_RECEIVED 
COLLATION_NOT_FOUND 
KEY_NOT_PRESENT 

Definition at line 45 of file parachain_processor.hpp.

Enumerator
kComplete 
kFetchFromValidator 

Definition at line 83 of file parachain_processor.hpp.

Enumerator
kSeconded 
kValid 

Definition at line 84 of file parachain_processor.hpp.

Constructor & Destructor Documentation

kagome::parachain::ParachainProcessorImpl::ParachainProcessorImpl ( std::shared_ptr< network::PeerManager pm,
std::shared_ptr< crypto::Sr25519Provider crypto_provider,
std::shared_ptr< network::Router router,
std::shared_ptr< boost::asio::io_context >  this_context,
std::shared_ptr< crypto::Sr25519Keypair keypair,
std::shared_ptr< crypto::Hasher hasher 
)

Definition at line 36 of file parachain_processor.cpp.

kagome::parachain::ParachainProcessorImpl::~ParachainProcessorImpl ( )

check that all workers are stopped.

Definition at line 56 of file parachain_processor.cpp.

Member Function Documentation

void kagome::parachain::ParachainProcessorImpl::appendAsyncValidationTask ( network::ParachainId  id,
primitives::BlockHash const &  relay_parent,
libp2p::peer::PeerId const &  peer_id 
)
private

TODO(iceseer): add to awaiting_validation to be sure no doublicated validations

Definition at line 218 of file parachain_processor.cpp.

network::CandidateDescriptor const& kagome::parachain::ParachainProcessorImpl::candidateDescriptorFrom ( FetchedCollationState const &  fetched_collation_state)
inlineprivate

Definition at line 177 of file parachain_processor.hpp.

std::optional<std::reference_wrapper<network::CandidateDescriptor const> > kagome::parachain::ParachainProcessorImpl::candidateDescriptorFrom ( std::shared_ptr< network::Statement > const &  statement)
inlineprivate

Definition at line 188 of file parachain_processor.hpp.

primitives::BlockHash kagome::parachain::ParachainProcessorImpl::candidateHashFrom ( FetchedCollationState const &  fetched_collation_state)
inlineprivate

Definition at line 166 of file parachain_processor.hpp.

primitives::BlockHash kagome::parachain::ParachainProcessorImpl::candidateHashFrom ( std::shared_ptr< network::Statement > const &  statement)
inlineprivate

Definition at line 210 of file parachain_processor.hpp.

network::CollatorPublicKey const& kagome::parachain::ParachainProcessorImpl::collatorIdFromDescriptor ( network::CandidateDescriptor const &  descriptor)
inlineprivate

Definition at line 205 of file parachain_processor.hpp.

template<ParachainProcessorImpl::StatementType kStatementType>
std::shared_ptr< network::Statement > kagome::parachain::ParachainProcessorImpl::createAndSignStatement ( ValidateAndSecondResult validation_result)
private
outcome::result< ParachainProcessorImpl::FetchedCollation > kagome::parachain::ParachainProcessorImpl::getFromSlot ( network::ParachainId  id,
primitives::BlockHash const &  relay_parent,
libp2p::peer::PeerId const &  peer_id 
)
private

Definition at line 103 of file parachain_processor.cpp.

std::optional< network::ValidatorIndex > kagome::parachain::ParachainProcessorImpl::getOurIndex ( )
private

Definition at line 262 of file parachain_processor.cpp.

void kagome::parachain::ParachainProcessorImpl::handleFetchedCollation ( network::ParachainId  id,
primitives::BlockHash const &  relay_parent,
libp2p::peer::PeerId const &  peer_id,
network::CollationFetchingResponse &&  response 
)
private

Definition at line 144 of file parachain_processor.cpp.

void kagome::parachain::ParachainProcessorImpl::handleNotify ( libp2p::peer::PeerId const &  peer_id,
primitives::BlockHash const &  relay_parent 
)
private

Definition at line 404 of file parachain_processor.cpp.

void kagome::parachain::ParachainProcessorImpl::handleStatement ( libp2p::peer::PeerId const &  peer_id,
primitives::BlockHash const &  relay_parent,
std::shared_ptr< network::Statement > const &  statement 
)

Definition at line 267 of file parachain_processor.cpp.

std::optional< ParachainProcessorImpl::ImportStatementSummary > kagome::parachain::ParachainProcessorImpl::importStatement ( std::shared_ptr< network::Statement > const &  statement)
private

Definition at line 339 of file parachain_processor.cpp.

std::optional< ParachainProcessorImpl::ImportStatementSummary > kagome::parachain::ParachainProcessorImpl::importStatementToTable ( primitives::BlockHash const &  candidate_hash,
std::shared_ptr< network::Statement > const &  statement 
)
private

Definition at line 324 of file parachain_processor.cpp.

void kagome::parachain::ParachainProcessorImpl::kickOffValidationWork ( AttestingData attesting_data)
private

TODO(iceseer): add to awaiting_validation to be sure no doublicated validations

request PoV

validate PoV

Definition at line 193 of file parachain_processor.cpp.

outcome::result< ParachainProcessorImpl::FetchedCollation > kagome::parachain::ParachainProcessorImpl::loadIntoResponseSlot ( network::ParachainId  id,
primitives::BlockHash const &  relay_parent,
libp2p::peer::PeerId const &  peer_id,
network::CollationFetchingResponse &&  response 
)
private

Definition at line 123 of file parachain_processor.cpp.

void kagome::parachain::ParachainProcessorImpl::notify ( libp2p::peer::PeerId const &  peer_id,
primitives::BlockHash const &  relay_parent,
std::shared_ptr< network::Statement > const &  statement 
)
private

Definition at line 461 of file parachain_processor.cpp.

template<typename F >
void kagome::parachain::ParachainProcessorImpl::notify_internal ( std::shared_ptr< WorkersContext > &  context,
F &&  func 
)
inlineprivate

Definition at line 235 of file parachain_processor.hpp.

void kagome::parachain::ParachainProcessorImpl::notifyAvailableData ( )
private

Definition at line 514 of file parachain_processor.cpp.

void kagome::parachain::ParachainProcessorImpl::notifyBackedCandidate ( std::shared_ptr< network::Statement > const &  statement)
private

Definition at line 331 of file parachain_processor.cpp.

void kagome::parachain::ParachainProcessorImpl::notifyStatementDistributionSystem ( std::shared_ptr< network::Statement > const &  statement)
private

Not implemented yet

Definition at line 497 of file parachain_processor.cpp.

void kagome::parachain::ParachainProcessorImpl::onAttestComplete ( libp2p::peer::PeerId const &  peer_id,
ValidateAndSecondResult &&  result 
)
private

Definition at line 566 of file parachain_processor.cpp.

void kagome::parachain::ParachainProcessorImpl::onAttestNoPoVComplete ( libp2p::peer::PeerId const &  peer_id,
ValidateAndSecondResult &&  result 
)
private

Definition at line 583 of file parachain_processor.cpp.

void kagome::parachain::ParachainProcessorImpl::onValidationComplete ( libp2p::peer::PeerId const &  peer_id,
ValidateAndSecondResult &&  result 
)
private

Definition at line 469 of file parachain_processor.cpp.

bool kagome::parachain::ParachainProcessorImpl::prepare ( )

Definition at line 65 of file parachain_processor.cpp.

void kagome::parachain::ParachainProcessorImpl::requestCollations ( network::PendingCollation const &  pending_collation)

Definition at line 608 of file parachain_processor.cpp.

void kagome::parachain::ParachainProcessorImpl::requestPoV ( )
private

Definition at line 189 of file parachain_processor.cpp.

void kagome::parachain::ParachainProcessorImpl::setAssignedParachain ( std::optional< network::ParachainId para_id)

Definition at line 603 of file parachain_processor.cpp.

template<typename T >
outcome::result< network::Signature > kagome::parachain::ParachainProcessorImpl::sign ( T const &  t) const
private

Definition at line 254 of file parachain_processor.cpp.

bool kagome::parachain::ParachainProcessorImpl::start ( )

Definition at line 71 of file parachain_processor.cpp.

void kagome::parachain::ParachainProcessorImpl::stop ( )

Definition at line 87 of file parachain_processor.cpp.

template<typename F >
void kagome::parachain::ParachainProcessorImpl::validateAndMakeAvailable ( libp2p::peer::PeerId const &  peer_id,
primitives::BlockHash const &  relay_parent,
FetchedCollation  fetched_collation,
F &&  callback 
)
private

Definition at line 519 of file parachain_processor.cpp.

outcome::result< void > kagome::parachain::ParachainProcessorImpl::validateCandidate ( FetchedCollation fetched_collation)
private

Definition at line 502 of file parachain_processor.cpp.

outcome::result< void > kagome::parachain::ParachainProcessorImpl::validateErasureCoding ( FetchedCollation fetched_collation)
private

Definition at line 508 of file parachain_processor.cpp.

Member Data Documentation

SafeObject<ParachainMap> kagome::parachain::ParachainProcessorImpl::collations_
private

Definition at line 291 of file parachain_processor.hpp.

std::shared_ptr<WorkersContext> kagome::parachain::ParachainProcessorImpl::context_
private

Definition at line 287 of file parachain_processor.hpp.

std::shared_ptr<crypto::Sr25519Provider> kagome::parachain::ParachainProcessorImpl::crypto_provider_
private

Definition at line 269 of file parachain_processor.hpp.

std::shared_ptr<crypto::Hasher> kagome::parachain::ParachainProcessorImpl::hasher_
private

Definition at line 294 of file parachain_processor.hpp.

constexpr uint64_t kagome::parachain::ParachainProcessorImpl::kBackgroundWorkers = 5
static

Definition at line 50 of file parachain_processor.hpp.

std::shared_ptr<crypto::Sr25519Keypair> kagome::parachain::ParachainProcessorImpl::keypair_
private

Definition at line 293 of file parachain_processor.hpp.

log::Logger kagome::parachain::ParachainProcessorImpl::logger_
private
Initial value:
=
log::createLogger("ParachainProcessorImpl", "parachain")

Definition at line 271 of file parachain_processor.hpp.

struct { ... } kagome::parachain::ParachainProcessorImpl::our_current_state_
std::shared_ptr<network::PeerManager> kagome::parachain::ParachainProcessorImpl::pm_
private

Definition at line 268 of file parachain_processor.hpp.

std::shared_ptr<network::Router> kagome::parachain::ParachainProcessorImpl::router_
private

Definition at line 270 of file parachain_processor.hpp.

std::shared_ptr<WorkersContext> kagome::parachain::ParachainProcessorImpl::this_context_
private

Definition at line 292 of file parachain_processor.hpp.

std::shared_ptr<WorkGuard> kagome::parachain::ParachainProcessorImpl::work_guard_
private

Definition at line 288 of file parachain_processor.hpp.

std::unique_ptr<std::thread> kagome::parachain::ParachainProcessorImpl::workers_[kBackgroundWorkers]
private

Definition at line 289 of file parachain_processor.hpp.


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