Kagome
Polkadot Runtime Engine in C++17
schedule_node.hpp
Go to the documentation of this file.
1 
6 #ifndef KAGOME_CONSENSUS_AUTHORITIES_SCHEDULE_NODE
7 #define KAGOME_CONSENSUS_AUTHORITIES_SCHEDULE_NODE
8 
9 #include <boost/variant.hpp>
10 
11 #include "common/empty.hpp"
12 #include "common/tagged.hpp"
13 #include "primitives/authority.hpp"
14 
15 namespace kagome::authority {
16 
17  using IsBlockFinalized = Tagged<bool, struct IsBlockFinalizedTag>;
18 
24  class ScheduleNode : public std::enable_shared_from_this<ScheduleNode> {
25  public:
26  ScheduleNode() = default;
27 
28  ScheduleNode(const std::shared_ptr<const ScheduleNode> &ancestor,
29  primitives::BlockInfo block);
30 
33  static std::shared_ptr<ScheduleNode> createAsRoot(
34  std::shared_ptr<const primitives::AuthoritySet> current_authorities,
35  primitives::BlockInfo block);
36 
37  void adjust(IsBlockFinalized finalized);
38 
43  std::shared_ptr<ScheduleNode> makeDescendant(
44  const primitives::BlockInfo &block, IsBlockFinalized finalized) const;
45 
46  using NoAction = Empty;
47 
48  struct ScheduledChange {
49  SCALE_TIE(2);
50 
52  std::shared_ptr<const primitives::AuthoritySet> new_authorities{};
53  };
54 
55  struct ForcedChange {
56  SCALE_TIE(3);
57 
58  primitives::BlockNumber delay_start{};
59  size_t delay_length{};
60  std::shared_ptr<const primitives::AuthoritySet> new_authorities{};
61  };
62 
63  struct Pause {
64  SCALE_TIE(1);
65 
67  };
68 
69  struct Resume {
70  SCALE_TIE(1);
71 
73  };
74 
75  friend inline ::scale::ScaleEncoderStream &operator<<(
76  ::scale::ScaleEncoderStream &s, const ScheduleNode &node) {
77  return s << node.enabled << node.current_block
78  << *node.current_authorities << node.action;
79  }
80 
81  friend inline ::scale::ScaleDecoderStream &operator>>(
82  ::scale::ScaleDecoderStream &s, ScheduleNode &node) {
83  return s >> node.enabled
84  >> const_cast<primitives::BlockInfo &>(node.current_block)
85  >> node.current_authorities >> node.action;
86  }
87 
89  std::weak_ptr<const ScheduleNode> parent;
90  std::vector<std::shared_ptr<ScheduleNode>> descendants{};
91  boost::variant<NoAction, ScheduledChange, ForcedChange, Pause, Resume>
93  std::shared_ptr<const primitives::AuthoritySet> current_authorities;
94  bool enabled = true;
95  };
96 
97 } // namespace kagome::authority
98 
99 #endif // KAGOME_CONSENSUS_AUTHORITIES_SCHEDULE_NODE
friend::scale::ScaleEncoderStream & operator<<(::scale::ScaleEncoderStream &s, const ScheduleNode &node)
friend::scale::ScaleDecoderStream & operator>>(::scale::ScaleDecoderStream &s, ScheduleNode &node)
std::weak_ptr< const ScheduleNode > parent
std::shared_ptr< const primitives::AuthoritySet > current_authorities
std::shared_ptr< const primitives::AuthoritySet > new_authorities
const primitives::BlockInfo current_block
std::shared_ptr< ScheduleNode > makeDescendant(const primitives::BlockInfo &block, IsBlockFinalized finalized) const
uint32_t BlockNumber
Definition: common.hpp:18
std::vector< std::shared_ptr< ScheduleNode > > descendants
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
Node of scheduler tree. Contains actual authorities for the accorded block and all its descendant blo...
Tagged< bool, struct IsBlockFinalizedTag > IsBlockFinalized