Kagome
Polkadot Runtime Engine in C++17
voting_round.hpp
Go to the documentation of this file.
1 
6 #ifndef KAGOME_CONSENSUS_GRANDPA_VOTINGROUND
7 #define KAGOME_CONSENSUS_GRANDPA_VOTINGROUND
8 
9 #include "common/tagged.hpp"
12 
14 
18  class VotingRound : public std::enable_shared_from_this<VotingRound> {
19  public:
20  virtual ~VotingRound() = default;
21 
22  // Getters
23 
24  virtual RoundNumber roundNumber() const = 0;
25 
26  virtual VoterSetId voterSetId() const = 0;
27 
28  virtual bool completable() const = 0;
29 
30  virtual BlockInfo lastFinalizedBlock() const = 0;
31 
32  virtual BlockInfo bestPrevoteCandidate() = 0;
33 
34  virtual BlockInfo bestFinalCandidate() = 0;
35 
36  virtual const std::optional<BlockInfo> &finalizedBlock() const = 0;
37 
38  virtual MovableRoundState state() const = 0;
39 
40  // Control lifecycle
41 
42  virtual void play() = 0;
43  virtual void end() = 0;
44 
45  // Doing some activity
46 
57  virtual void doProposal() = 0;
58 
60  virtual void doPrevote() = 0;
61 
63  virtual void doPrecommit() = 0;
64 
66  virtual void doFinalize() = 0;
67 
69  virtual void doCommit() = 0;
70 
73  virtual void doCatchUpResponse(const libp2p::peer::PeerId &peer_id) = 0;
74 
75  // Handling incoming messages
76 
77  enum class Propagation : bool { NEEDLESS = false, REQUESTED = true };
78 
79  virtual void onProposal(const SignedMessage &primary_propose,
80  Propagation propagation) = 0;
81 
82  virtual bool onPrevote(const SignedMessage &prevote,
83  Propagation propagation) = 0;
84 
85  virtual bool onPrecommit(const SignedMessage &precommit,
86  Propagation propagation) = 0;
87 
91 
99  virtual void update(IsPreviousRoundChanged is_previous_round_changed,
100  IsPrevotesChanged is_prevotes_changed,
101  IsPrecommitsChanged is_precommits_changed) = 0;
102 
103  // Auxiliary methods
104 
108  virtual std::shared_ptr<VotingRound> getPreviousRound() const = 0;
109 
113  virtual void forgetPreviousRound() = 0;
114 
115  virtual outcome::result<void> applyJustification(
116  const BlockInfo &block_info,
117  const GrandpaJustification &justification) = 0;
118 
120  virtual void attemptToFinalizeRound() = 0;
121  };
122 
123 } // namespace kagome::consensus::grandpa
124 
125 #endif // KAGOME_CONSENSUS_GRANDPA_VOTINGROUND
virtual bool onPrecommit(const SignedMessage &precommit, Propagation propagation)=0
virtual std::shared_ptr< VotingRound > getPreviousRound() const =0
virtual void doFinalize()=0
Collect and save justifications finalizing this round.
virtual bool completable() const =0
virtual BlockInfo lastFinalizedBlock() const =0
virtual BlockInfo bestPrevoteCandidate()=0
virtual outcome::result< void > applyJustification(const BlockInfo &block_info, const GrandpaJustification &justification)=0
virtual void onProposal(const SignedMessage &primary_propose, Propagation propagation)=0
virtual void update(IsPreviousRoundChanged is_previous_round_changed, IsPrevotesChanged is_prevotes_changed, IsPrecommitsChanged is_precommits_changed)=0
virtual const std::optional< BlockInfo > & finalizedBlock() const =0
virtual bool onPrevote(const SignedMessage &prevote, Propagation propagation)=0
virtual RoundNumber roundNumber() const =0
libp2p::peer::PeerId PeerId
virtual void doPrevote()=0
Calculate prevote and broadcast signed prevote message.
Stores the current state of the round.
virtual VoterSetId voterSetId() const =0
virtual void doPrecommit()=0
Calculate precommit and broadcast signed precommit message.
virtual MovableRoundState state() const =0
virtual void attemptToFinalizeRound()=0
executes algorithm Attempt-To-Finalize-Round
virtual void doCatchUpResponse(const libp2p::peer::PeerId &peer_id)=0
virtual BlockInfo bestFinalCandidate()=0
virtual void doCommit()=0
Broadcast commit message.