Kagome
Polkadot Runtime Engine in C++17
schedule_node.cpp
Go to the documentation of this file.
1 
8 
9 namespace kagome::authority {
10 
12  const std::shared_ptr<const ScheduleNode> &ancestor,
14  : current_block(block), parent(ancestor) {
15  BOOST_ASSERT(ancestor != nullptr);
16  }
17 
18  std::shared_ptr<ScheduleNode> ScheduleNode::createAsRoot(
19  std::shared_ptr<const primitives::AuthoritySet> current_authorities,
20  primitives::BlockInfo block) {
21  auto fake_parent = std::make_shared<ScheduleNode>(ScheduleNode());
22  auto node = std::make_shared<ScheduleNode>(fake_parent, block);
23  node->current_authorities = current_authorities;
24  return node;
25  }
26 
28  if (auto scheduled_change = boost::get<ScheduledChange>(&action);
29  finalized && scheduled_change != nullptr) {
30  if (scheduled_change->applied_block <= current_block.number) {
31  current_authorities = std::move(scheduled_change->new_authorities);
32  action = NoAction{};
33  }
34  } else if (auto pause = boost::get<Pause>(&action);
35  finalized && pause != nullptr) {
36  if (pause->applied_block <= current_block.number) {
37  enabled = false;
38  action = NoAction{};
39  }
40  } else if (auto forced_change = boost::get<ForcedChange>(&action);
41  forced_change != nullptr) {
42  if (forced_change->delay_start + forced_change->delay_length
43  <= current_block.number) {
44  current_authorities = std::move(forced_change->new_authorities);
45  action = NoAction{};
46  }
47  } else if (auto resume = boost::get<Resume>(&action); resume != nullptr) {
48  if (resume->applied_block <= current_block.number) {
49  enabled = true;
50  action = NoAction{};
51  }
52  }
53  }
54 
55  std::shared_ptr<ScheduleNode> ScheduleNode::makeDescendant(
56  const primitives::BlockInfo &target_block,
57  IsBlockFinalized finalized) const {
58  auto node =
59  std::make_shared<ScheduleNode>(shared_from_this(), target_block);
60  node->current_authorities = current_authorities;
61  node->enabled = enabled;
62  node->action = action;
63  node->adjust(finalized);
64  return node;
65  }
66 } // namespace kagome::authority
std::shared_ptr< const primitives::AuthoritySet > current_authorities
const primitives::BlockInfo current_block
std::shared_ptr< ScheduleNode > makeDescendant(const primitives::BlockInfo &block, IsBlockFinalized finalized) const
static std::shared_ptr< ScheduleNode > createAsRoot(std::shared_ptr< const primitives::AuthoritySet > current_authorities, primitives::BlockInfo block)
void adjust(IsBlockFinalized finalized)
boost::variant< NoAction, ScheduledChange, ForcedChange, Pause, Resume > action