Kagome
Polkadot Runtime Engine in C++17
block_appender_impl.hpp
Go to the documentation of this file.
1 
6 #ifndef KAGOME_CONSENSUS_BLOCKAPPENDERIMPL
7 #define KAGOME_CONSENSUS_BLOCKAPPENDERIMPL
8 
10 
11 #include <libp2p/peer/peer_id.hpp>
12 
14 #include "clock/timer.hpp"
18 #include "crypto/hasher.hpp"
19 #include "log/logger.hpp"
22 
23 namespace kagome::consensus::babe {
24  class BabeConfigRepository;
25  class ConsistencyKeeper;
26 } // namespace kagome::consensus::babe
27 
28 namespace kagome::blockchain {
29  class DigestTracker;
30 }
31 
32 namespace kagome::consensus {
33 
35  : public BlockAppender,
36  public std::enable_shared_from_this<BlockAppenderImpl> {
37  public:
38  enum class Error { INVALID_BLOCK = 1, PARENT_NOT_FOUND };
39 
41  std::shared_ptr<blockchain::BlockTree> block_tree,
42  std::shared_ptr<consensus::babe::BabeConfigRepository> babe_config_repo,
43  std::shared_ptr<BlockValidator> block_validator,
44  std::shared_ptr<grandpa::Environment> grandpa_environment,
45  std::shared_ptr<crypto::Hasher> hasher,
46  std::shared_ptr<blockchain::DigestTracker> digest_tracker,
47  std::shared_ptr<BabeUtil> babe_util,
48  std::shared_ptr<babe::ConsistencyKeeper> consistency_keeper);
49 
50  outcome::result<void> appendBlock(primitives::BlockData &&b) override;
51 
52  outcome::result<void> applyJustification(
53  const primitives::BlockInfo &block_info,
54  const primitives::Justification &justification) override;
55 
56  private:
57  std::shared_ptr<blockchain::BlockTree> block_tree_;
58  std::shared_ptr<consensus::babe::BabeConfigRepository> babe_config_repo_;
59  std::shared_ptr<BlockValidator> block_validator_;
60  std::shared_ptr<grandpa::Environment> grandpa_environment_;
61  std::shared_ptr<crypto::Hasher> hasher_;
62  std::shared_ptr<blockchain::DigestTracker> digest_tracker_;
63  std::shared_ptr<BabeUtil> babe_util_;
64  std::shared_ptr<babe::ConsistencyKeeper> consistency_keeper_;
65 
66  std::optional<primitives::BlockInfo> last_appended_;
67 
68  // Justification Store for Future Applying
69  std::map<primitives::BlockInfo, primitives::Justification> justifications_;
70 
71  struct {
72  std::chrono::high_resolution_clock::time_point time;
73  primitives::BlockNumber block_number;
74  } speed_data_ = {};
75 
77  };
78 
79 } // namespace kagome::consensus
80 
82 
83 #endif // KAGOME_CONSENSUS_BLOCKAPPENDERIMPL
std::shared_ptr< BabeUtil > babe_util_
std::map< primitives::BlockInfo, primitives::Justification > justifications_
uint32_t BlockNumber
Definition: common.hpp:18
std::shared_ptr< crypto::Hasher > hasher_
std::shared_ptr< grandpa::Environment > grandpa_environment_
std::shared_ptr< blockchain::BlockTree > block_tree_
std::shared_ptr< soralog::Logger > Logger
Definition: logger.hpp:23
OUTCOME_HPP_DECLARE_ERROR(kagome::consensus, BlockAppenderImpl::Error)
std::optional< primitives::BlockInfo > last_appended_
std::shared_ptr< consensus::babe::BabeConfigRepository > babe_config_repo_
std::shared_ptr< BlockValidator > block_validator_
std::shared_ptr< babe::ConsistencyKeeper > consistency_keeper_
std::shared_ptr< blockchain::DigestTracker > digest_tracker_