Kagome
Polkadot Runtime Engine in C++17
consistency_keeper.hpp
Go to the documentation of this file.
1 
6 #ifndef KAGOME_CONSENSUS_BABE_CONSISTENCYKEEPER
7 #define KAGOME_CONSENSUS_BABE_CONSISTENCYKEEPER
8 
9 #include "primitives/common.hpp"
10 
11 namespace kagome::consensus::babe {
12 
16  public:
17  class Guard final {
18  public:
20  : keeper_(keeper), block_(block){};
21  ~Guard() {
22  rollback();
23  }
24 
25  void commit() {
26  if (block_.has_value()) {
27  keeper_.commit(block_.value());
28  block_.reset();
29  }
30  }
31  void rollback() {
32  if (block_.has_value()) {
33  keeper_.rollback(block_.value());
34  block_.reset();
35  }
36  }
37 
38  private:
40  std::optional<primitives::BlockInfo> block_;
41  };
42 
43  virtual ~ConsistencyKeeper() = default;
44 
45  virtual Guard start(primitives::BlockInfo block) = 0;
46 
47  protected:
48  virtual void commit(primitives::BlockInfo block) = 0;
49  virtual void rollback(primitives::BlockInfo block) = 0;
50  };
51 
52 } // namespace kagome::consensus::babe
53 
54 #endif // KAGOME_CONSENSUS_BABE_CONSISTENCYKEEPER
virtual Guard start(primitives::BlockInfo block)=0
std::optional< primitives::BlockInfo > block_
virtual void rollback(primitives::BlockInfo block)=0
Guard(ConsistencyKeeper &keeper, primitives::BlockInfo block)
virtual void commit(primitives::BlockInfo block)=0