Kagome
Polkadot Runtime Engine in C++17
babe_block_validator.hpp
Go to the documentation of this file.
1 
6 #ifndef KAGOME_BABE_BLOCK_VALIDATOR_HPP
7 #define KAGOME_BABE_BLOCK_VALIDATOR_HPP
8 
9 #include <memory>
10 #include <unordered_map>
11 #include <unordered_set>
12 #include <utility>
13 
18 #include "crypto/hasher.hpp"
19 #include "crypto/vrf_provider.hpp"
20 #include "log/logger.hpp"
21 #include "primitives/authority.hpp"
25 
26 namespace kagome::crypto {
27  class Sr25519Provider;
28 }
29 
30 namespace kagome::consensus {
31 
37  public:
38  ~BabeBlockValidator() override = default;
39 
49  std::shared_ptr<blockchain::BlockTree> block_tree,
50  std::shared_ptr<runtime::TaggedTransactionQueue> tx_queue,
51  std::shared_ptr<crypto::Hasher> hasher,
52  std::shared_ptr<crypto::VRFProvider> vrf_provider,
53  std::shared_ptr<crypto::Sr25519Provider> sr25519_provider);
54 
55  enum class ValidationError {
56  NO_AUTHORITIES = 1,
58  INVALID_VRF,
59  TWO_BLOCKS_IN_SLOT,
60  SECONDARY_SLOT_ASSIGNMENTS_DISABLED
61  };
62 
63  outcome::result<void> validateHeader(
64  const primitives::BlockHeader &header,
65  const EpochNumber epoch_number,
66  const primitives::AuthorityId &authority_id,
67  const Threshold &threshold,
68  const primitives::BabeConfiguration &babe_config) const override;
69 
70  private:
80  bool verifySignature(const primitives::BlockHeader &header,
81  const BabeBlockHeader &babe_header,
82  const Seal &seal,
83  const primitives::BabeSessionKey &public_key) const;
84 
94  bool verifyVRF(const BabeBlockHeader &babe_header,
95  const EpochNumber epoch_number,
96  const primitives::BabeSessionKey &public_key,
97  const Threshold &threshold,
98  const Randomness &randomness,
99  const bool checkThreshold) const;
100 
101  std::shared_ptr<blockchain::BlockTree> block_tree_;
102  std::shared_ptr<runtime::TaggedTransactionQueue> tx_queue_;
103  std::shared_ptr<crypto::Hasher> hasher_;
104  std::shared_ptr<crypto::VRFProvider> vrf_provider_;
105  std::shared_ptr<crypto::Sr25519Provider> sr25519_provider_;
106 
107  mutable std::unordered_map<BabeSlotNumber,
108  std::unordered_set<primitives::AuthorityIndex>>
110 
112  };
113 } // namespace kagome::consensus
114 
117 
118 #endif // KAGOME_BABE_BLOCK_VALIDATOR_HPP
crypto::Sr25519PublicKey BabeSessionKey
Definition: session_key.hpp:17
std::shared_ptr< blockchain::BlockTree > block_tree_
std::shared_ptr< crypto::Sr25519Provider > sr25519_provider_
Configuration data used by the BABE consensus engine.
OUTCOME_HPP_DECLARE_ERROR(kagome::api, JRpcServerImpl::Error)
std::shared_ptr< runtime::TaggedTransactionQueue > tx_queue_
std::unordered_map< BabeSlotNumber, std::unordered_set< primitives::AuthorityIndex > > blocks_producers_
std::shared_ptr< soralog::Logger > Logger
Definition: logger.hpp:23
uint64_t BabeSlotNumber
slot number of the Babe production
Definition: common.hpp:24
uint64_t EpochNumber
number of the epoch in the Babe production
Definition: common.hpp:27
crypto::VRFThreshold Threshold
threshold, which must not be exceeded for the party to be a slot leader
Definition: common.hpp:33
std::shared_ptr< crypto::Hasher > hasher_
std::shared_ptr< crypto::VRFProvider > vrf_provider_