Kagome
Polkadot Runtime Engine in C++17
environment.hpp
Go to the documentation of this file.
1 
6 #ifndef KAGOME_CORE_CONSENSUS_GRANDPA_ENVIRONMENT_HPP
7 #define KAGOME_CORE_CONSENSUS_GRANDPA_ENVIRONMENT_HPP
8 
10 
11 #include <functional>
12 #include <memory>
13 
17 #include "primitives/block_id.hpp"
18 
19 namespace kagome::blockchain {
20  class BlockHeaderRepository;
21  class BlockTree;
22 } // namespace kagome::blockchain
23 
24 namespace kagome::primitives {
25  struct Justification;
26 }
27 namespace libp2p::peer {
28  class PeerId;
29 }
31  struct JustificationObserver;
32 }
33 
35 
36  class Grandpa;
37 
42  struct Environment : public virtual Chain {
43  using CompleteHandler =
44  std::function<void(outcome::result<MovableRoundState>)>;
45 
46  ~Environment() override = default;
47 
51  virtual void setJustificationObserver(
52  std::weak_ptr<JustificationObserver> justification_observer) = 0;
53 
57  virtual outcome::result<void> onCatchUpRequested(
58  const libp2p::peer::PeerId &peer_id,
59  VoterSetId set_id,
60  RoundNumber round_number) = 0;
61 
65  virtual outcome::result<void> onCatchUpRespond(
66  const libp2p::peer::PeerId &peer_id,
67  VoterSetId set_id,
68  RoundNumber round_number,
69  std::vector<SignedPrevote> prevote_justification,
70  std::vector<SignedPrecommit> precommit_justification,
71  BlockInfo best_final_candidate) = 0;
72 
76  virtual void sendState(const libp2p::peer::PeerId &peer_id,
77  const MovableRoundState &state,
78  VoterSetId voter_set_id) = 0;
79 
85  virtual outcome::result<void> onVoted(RoundNumber round,
86  VoterSetId set_id,
87  const SignedMessage &vote) = 0;
88 
94  virtual outcome::result<void> onCommitted(
95  RoundNumber round,
96  VoterSetId voter_ser_id,
97  const BlockInfo &vote,
98  const GrandpaJustification &justification) = 0;
99 
106  virtual outcome::result<void> onNeighborMessageSent(
107  RoundNumber round, VoterSetId set_id, BlockNumber last_finalized) = 0;
108 
117  virtual outcome::result<void> applyJustification(
118  const BlockInfo &block_info,
119  const primitives::Justification &justification) = 0;
120 
125  virtual outcome::result<void> finalize(
126  VoterSetId id, const GrandpaJustification &justification) = 0;
127 
135  virtual outcome::result<GrandpaJustification> getJustification(
136  const BlockHash &block_hash) = 0;
137  };
138 
139 } // namespace kagome::consensus::grandpa
140 
141 #endif // KAGOME_CORE_CONSENSUS_GRANDPA_ENVIRONMENT_HPP
std::function< void(outcome::result< MovableRoundState >)> CompleteHandler
Definition: environment.hpp:44
libp2p::peer::PeerId PeerId
primitives::BlockNumber BlockNumber
Definition: common.hpp:24
Stores the current state of the round.