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

#include <babe_block_validator.hpp>

Inheritance diagram for kagome::consensus::BabeBlockValidator:
Collaboration diagram for kagome::consensus::BabeBlockValidator:

Public Types

enum  ValidationError {
  ValidationError::NO_AUTHORITIES = 1, ValidationError::INVALID_SIGNATURE, ValidationError::INVALID_VRF, ValidationError::TWO_BLOCKS_IN_SLOT,
  ValidationError::SECONDARY_SLOT_ASSIGNMENTS_DISABLED
}
 

Public Member Functions

 ~BabeBlockValidator () override=default
 
 BabeBlockValidator (std::shared_ptr< blockchain::BlockTree > block_tree, std::shared_ptr< runtime::TaggedTransactionQueue > tx_queue, std::shared_ptr< crypto::Hasher > hasher, std::shared_ptr< crypto::VRFProvider > vrf_provider, std::shared_ptr< crypto::Sr25519Provider > sr25519_provider)
 
outcome::result< void > validateHeader (const primitives::BlockHeader &header, const EpochNumber epoch_number, const primitives::AuthorityId &authority_id, const Threshold &threshold, const primitives::BabeConfiguration &babe_config) const override
 
- Public Member Functions inherited from kagome::consensus::BlockValidator
virtual ~BlockValidator ()=default
 

Private Member Functions

bool verifySignature (const primitives::BlockHeader &header, const BabeBlockHeader &babe_header, const Seal &seal, const primitives::BabeSessionKey &public_key) const
 
bool verifyVRF (const BabeBlockHeader &babe_header, const EpochNumber epoch_number, const primitives::BabeSessionKey &public_key, const Threshold &threshold, const Randomness &randomness, const bool checkThreshold) const
 

Private Attributes

std::shared_ptr< blockchain::BlockTreeblock_tree_
 
std::shared_ptr< runtime::TaggedTransactionQueuetx_queue_
 
std::shared_ptr< crypto::Hasherhasher_
 
std::shared_ptr< crypto::VRFProvidervrf_provider_
 
std::shared_ptr< crypto::Sr25519Providersr25519_provider_
 
std::unordered_map< BabeSlotNumber, std::unordered_set< primitives::AuthorityIndex > > blocks_producers_
 
log::Logger log_
 

Detailed Description

Validation of blocks in BABE system. Based on the algorithm described here: https://research.web3.foundation/en/latest/polkadot/BABE/Babe/#2-normal-phase

Definition at line 36 of file babe_block_validator.hpp.

Member Enumeration Documentation

Enumerator
NO_AUTHORITIES 
INVALID_SIGNATURE 
INVALID_VRF 
TWO_BLOCKS_IN_SLOT 
SECONDARY_SLOT_ASSIGNMENTS_DISABLED 

Definition at line 55 of file babe_block_validator.hpp.

Constructor & Destructor Documentation

kagome::consensus::BabeBlockValidator::~BabeBlockValidator ( )
overridedefault
kagome::consensus::BabeBlockValidator::BabeBlockValidator ( std::shared_ptr< blockchain::BlockTree block_tree,
std::shared_ptr< runtime::TaggedTransactionQueue tx_queue,
std::shared_ptr< crypto::Hasher hasher,
std::shared_ptr< crypto::VRFProvider vrf_provider,
std::shared_ptr< crypto::Sr25519Provider sr25519_provider 
)

Create an instance of BabeBlockValidator

Parameters
block_treeto be used by this instance
tx_queueto validate the extrinsics
hasherto take hashes
vrf_providerfor VRF-specific operations
configurationBabe configuration from genesis

Definition at line 41 of file babe_block_validator.cpp.

Member Function Documentation

outcome::result< void > kagome::consensus::BabeBlockValidator::validateHeader ( const primitives::BlockHeader block_header,
const EpochNumber  epoch_number,
const primitives::AuthorityId authority_id,
const Threshold threshold,
const primitives::BabeConfiguration config 
) const
overridevirtual

Validate the block header

Parameters
blockto be validated
authority_idauthority that sent this block
thresholdis vrf threshold for this epoch
configis babe config for this epoch
Returns
nothing or validation error

Implements kagome::consensus::BlockValidator.

Definition at line 60 of file babe_block_validator.cpp.

bool kagome::consensus::BabeBlockValidator::verifySignature ( const primitives::BlockHeader header,
const BabeBlockHeader babe_header,
const Seal seal,
const primitives::BabeSessionKey public_key 
) const
private

Verify that block is signed by valid signature

Parameters
headerHeader to be checked
babe_headerBabeBlockHeader corresponding to (fetched from) header
sealSeal corresponding to (fetched from) header
public_keypublic key that corresponds to the authority by authority index
Returns
true if signature is valid, false otherwise

Definition at line 123 of file babe_block_validator.cpp.

bool kagome::consensus::BabeBlockValidator::verifyVRF ( const BabeBlockHeader babe_header,
const EpochNumber  epoch_number,
const primitives::BabeSessionKey public_key,
const Threshold threshold,
const Randomness randomness,
const bool  checkThreshold 
) const
private

Verify that vrf value contained in babe_header is less than threshold and was generated by the creator of the block

Parameters
babe_headerBabeBlockHeader corresponding to (fetched from) header
public_keyPublic key of creator of the block
thresholdthreshold value for that epoch
randomnessrandomness for that epoch
Returns
true if vrf is valid, false otherwise

Definition at line 143 of file babe_block_validator.cpp.

Member Data Documentation

std::shared_ptr<blockchain::BlockTree> kagome::consensus::BabeBlockValidator::block_tree_
private

Definition at line 101 of file babe_block_validator.hpp.

std::unordered_map<BabeSlotNumber, std::unordered_set<primitives::AuthorityIndex> > kagome::consensus::BabeBlockValidator::blocks_producers_
mutableprivate

Definition at line 109 of file babe_block_validator.hpp.

std::shared_ptr<crypto::Hasher> kagome::consensus::BabeBlockValidator::hasher_
private

Definition at line 103 of file babe_block_validator.hpp.

log::Logger kagome::consensus::BabeBlockValidator::log_
private

Definition at line 111 of file babe_block_validator.hpp.

std::shared_ptr<crypto::Sr25519Provider> kagome::consensus::BabeBlockValidator::sr25519_provider_
private

Definition at line 105 of file babe_block_validator.hpp.

std::shared_ptr<runtime::TaggedTransactionQueue> kagome::consensus::BabeBlockValidator::tx_queue_
private

Definition at line 102 of file babe_block_validator.hpp.

std::shared_ptr<crypto::VRFProvider> kagome::consensus::BabeBlockValidator::vrf_provider_
private

Definition at line 104 of file babe_block_validator.hpp.


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