Kagome
Polkadot Runtime Engine in C++17
environment_impl.hpp
Go to the documentation of this file.
1 
6 #ifndef KAGOME_CHAIN_IMPL_HPP
7 #define KAGOME_CHAIN_IMPL_HPP
8 
10 
12 #include "log/logger.hpp"
13 
14 namespace kagome::network {
15  class GrandpaTransmitter;
16 }
17 
19 
20  class EnvironmentImpl : public Environment {
21  public:
23  std::shared_ptr<blockchain::BlockTree> block_tree,
24  std::shared_ptr<blockchain::BlockHeaderRepository> header_repository,
25  std::shared_ptr<authority::AuthorityManager> authority_manager,
26  std::shared_ptr<network::GrandpaTransmitter> transmitter);
27 
28  ~EnvironmentImpl() override = default;
29 
30  // Back link to Grandpa
31 
33  std::weak_ptr<JustificationObserver> justification_observer) override {
34  BOOST_ASSERT(justification_observer_.expired());
35  justification_observer_ = std::move(justification_observer);
36  }
37 
38  // Chain methods
39 
40  outcome::result<bool> hasBlock(
41  const primitives::BlockHash &block) const override;
42 
43  outcome::result<std::vector<primitives::BlockHash>> getAncestry(
44  const primitives::BlockHash &base,
45  const primitives::BlockHash &block) const override;
46 
47  bool hasAncestry(const primitives::BlockHash &base,
48  const primitives::BlockHash &block) const override;
49 
50  outcome::result<BlockInfo> bestChainContaining(
51  const primitives::BlockHash &base,
52  std::optional<VoterSetId> voter_set_id) const override;
53 
54  // Environment methods
55 
56  outcome::result<void> onCatchUpRequested(
57  const libp2p::peer::PeerId &peer_id,
58  VoterSetId set_id,
59  RoundNumber round_number) override;
60 
61  outcome::result<void> onCatchUpRespond(
62  const libp2p::peer::PeerId &peer_id,
63  VoterSetId set_id,
64  RoundNumber round_number,
65  std::vector<SignedPrevote> prevote_justification,
66  std::vector<SignedPrecommit> precommit_justification,
67  BlockInfo best_final_candidate) override;
68 
69  void sendState(const libp2p::peer::PeerId &peer_id,
70  const MovableRoundState &state,
71  VoterSetId voter_set_id) override;
72 
73  outcome::result<void> onVoted(RoundNumber round,
74  VoterSetId set_id,
75  const SignedMessage &vote) override;
76 
77  outcome::result<void> onCommitted(
78  RoundNumber round,
79  VoterSetId voter_ser_id,
80  const BlockInfo &vote,
81  const GrandpaJustification &justification) override;
82 
83  outcome::result<void> onNeighborMessageSent(
84  RoundNumber round,
85  VoterSetId set_id,
86  BlockNumber last_finalized) override;
87 
88  outcome::result<void> applyJustification(
89  const BlockInfo &block_info,
90  const primitives::Justification &justification) override;
91 
92  outcome::result<void> finalize(
93  VoterSetId id,
94  const GrandpaJustification &justification) override;
95 
96  // Getters
97 
98  outcome::result<GrandpaJustification> getJustification(
99  const BlockHash &block_hash) override;
100 
101  private:
102  std::shared_ptr<blockchain::BlockTree> block_tree_;
103  std::shared_ptr<blockchain::BlockHeaderRepository> header_repository_;
104  std::shared_ptr<authority::AuthorityManager> authority_manager_;
105  std::shared_ptr<network::GrandpaTransmitter> transmitter_;
106  std::weak_ptr<JustificationObserver> justification_observer_;
107 
109  };
110 
111 } // namespace kagome::consensus::grandpa
112 
113 #endif // KAGOME_CHAIN_IMPL_HPP
void setJustificationObserver(std::weak_ptr< JustificationObserver > justification_observer) override
libp2p::peer::PeerId PeerId
std::shared_ptr< soralog::Logger > Logger
Definition: logger.hpp:23
primitives::BlockNumber BlockNumber
Definition: common.hpp:24
std::shared_ptr< blockchain::BlockHeaderRepository > header_repository_
std::shared_ptr< authority::AuthorityManager > authority_manager_
std::weak_ptr< JustificationObserver > justification_observer_
Stores the current state of the round.
std::shared_ptr< network::GrandpaTransmitter > transmitter_
std::shared_ptr< blockchain::BlockTree > block_tree_