Kagome
Polkadot Runtime Engine in C++17
babe_config_node.cpp
Go to the documentation of this file.
1 
6 #include "babe_config_node.hpp"
7 
8 namespace kagome::consensus {
9 
11  const std::shared_ptr<const BabeConfigNode> &ancestor,
13  : block(block), parent(ancestor) {
14  BOOST_ASSERT(ancestor != nullptr);
15  }
16 
17  std::shared_ptr<BabeConfigNode> BabeConfigNode::createAsRoot(
19  std::shared_ptr<const primitives::BabeConfiguration> config) {
20  auto fake_parent = std::make_shared<BabeConfigNode>();
21  auto node = std::make_shared<BabeConfigNode>(fake_parent, block);
22  node->epoch = std::numeric_limits<decltype(node->epoch)>::max();
23  node->config = std::move(config);
24  return node;
25  }
26 
27  std::shared_ptr<BabeConfigNode> BabeConfigNode::makeDescendant(
28  const primitives::BlockInfo &target_block,
29  std::optional<EpochNumber> target_epoch_number) const {
30  auto node =
31  std::make_shared<BabeConfigNode>(shared_from_this(), target_block);
32  node->epoch = target_epoch_number.value_or(epoch);
33  node->epoch_changed = node->epoch != epoch;
34  if (not node->epoch_changed) {
35  node->config = config;
36  node->next_config = next_config;
37  } else {
38  node->config = next_config.value_or(config);
39  node->next_config.reset();
40  }
41 
42  return node;
43  }
44 
45 } // namespace kagome::consensus
std::optional< std::shared_ptr< const primitives::BabeConfiguration > > next_config
std::shared_ptr< const primitives::BabeConfiguration > config
const primitives::BlockInfo block
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)