Kagome
Polkadot Runtime Engine in C++17
babe_config_node.hpp
Go to the documentation of this file.
1 
6 #ifndef KAGOME_CONSENSUS_BABECONFIGNODE
7 #define KAGOME_CONSENSUS_BABECONFIGNODE
8 
9 #include <memory>
10 
11 #include "primitives/block.hpp"
12 #include "scale/scale.hpp"
13 
14 namespace kagome::consensus {
15 
17 
18  class BabeConfigNode final
19  : public std::enable_shared_from_this<BabeConfigNode> {
20  public:
21  BabeConfigNode() = default;
22 
23  BabeConfigNode(const std::shared_ptr<const BabeConfigNode> &ancestor,
25 
30  static std::shared_ptr<BabeConfigNode> createAsRoot(
32  std::shared_ptr<const primitives::BabeConfiguration> config);
33 
39  std::shared_ptr<BabeConfigNode> makeDescendant(
40  const primitives::BlockInfo &block,
41  std::optional<EpochNumber> epoch_number = std::nullopt) const;
42 
43  friend inline ::scale::ScaleEncoderStream &operator<<(
44  ::scale::ScaleEncoderStream &s, const BabeConfigNode &node) {
45  return s << node.block << node.epoch << node.config << node.next_config;
46  }
47 
48  friend inline ::scale::ScaleDecoderStream &operator>>(
49  ::scale::ScaleDecoderStream &s, BabeConfigNode &node) {
50  return s >> const_cast<primitives::BlockInfo &>(node.block) >> node.epoch
51  >> node.config >> node.next_config;
52  }
53 
54  const primitives::BlockInfo block{};
55  std::weak_ptr<const BabeConfigNode> parent;
56  std::vector<std::shared_ptr<BabeConfigNode>> descendants{};
57 
59  bool epoch_changed = false;
60  std::shared_ptr<const primitives::BabeConfiguration> config;
61  std::optional<std::shared_ptr<const primitives::BabeConfiguration>>
63  };
64 
65 }; // namespace kagome::consensus
66 
67 #endif // KAGOME_CONSENSUS_BABECONFIGNODE
std::optional< std::shared_ptr< const primitives::BabeConfiguration > > next_config
std::shared_ptr< const primitives::BabeConfiguration > config
const primitives::BlockInfo block
std::vector< std::shared_ptr< BabeConfigNode > > descendants
std::weak_ptr< const BabeConfigNode > parent
std::shared_ptr< BabeConfigNode > makeDescendant(const primitives::BlockInfo &block, std::optional< EpochNumber > epoch_number=std::nullopt) const
static std::shared_ptr< BabeConfigNode > createAsRoot(primitives::BlockInfo block, std::shared_ptr< const primitives::BabeConfiguration > config)
uint64_t EpochNumber
number of the epoch in the Babe production
Definition: common.hpp:27
friend::scale::ScaleDecoderStream & operator>>(::scale::ScaleDecoderStream &s, BabeConfigNode &node)
friend::scale::ScaleEncoderStream & operator<<(::scale::ScaleEncoderStream &s, const BabeConfigNode &node)