Kagome
Polkadot Runtime Engine in C++17
babe_configuration.hpp
Go to the documentation of this file.
1 
6 #ifndef KAGOME_CORE_PRIMITIVES_BABE_CONFIGURATION_HPP
7 #define KAGOME_CORE_PRIMITIVES_BABE_CONFIGURATION_HPP
8 
9 #include <fmt/core.h>
10 
11 #include "common/blob.hpp"
13 #include "crypto/sr25519_types.hpp"
14 #include "primitives/authority.hpp"
15 
16 namespace kagome::primitives {
17 
18  using BabeSlotNumber = uint64_t;
22 
23  enum class AllowedSlots : uint8_t {
27  };
28 
29  inline std::string_view to_string(AllowedSlots s) {
30  switch (s) {
32  return "Primary only";
34  return "Primary and Secondary Plain";
36  return "Primary and Secondary VRF";
37  }
38  return "Unknown";
39  }
40 
47  BabeDuration slot_duration{}; // must be permanent
48 
49  BabeSlotNumber epoch_length{}; // must be permanent
50 
58  std::pair<uint64_t, uint64_t> leadership_rate; // changes by NextConfigData
59 
61  AuthorityList authorities; // can be changed by NextEpochData & OnDisabled
62 
64  Randomness randomness; // can be changed by NextEpochData
65 
67  AllowedSlots allowed_slots; // can be changed by NextConfigData
68 
69  bool isSecondarySlotsAllowed() const {
71  or allowed_slots
73  }
74  };
75 
76  template <class Stream,
77  typename = std::enable_if_t<Stream::is_encoder_stream>>
78  Stream &operator<<(Stream &s, const BabeConfiguration &config) {
79  size_t slot_duration_u64 =
80  std::chrono::duration_cast<std::chrono::milliseconds>(
81  config.slot_duration)
82  .count();
83  return s << slot_duration_u64 << config.epoch_length
84  << config.leadership_rate << config.authorities
85  << config.randomness << static_cast<uint8_t>(config.allowed_slots);
86  }
87 
88  template <class Stream,
89  typename = std::enable_if_t<Stream::is_decoder_stream>>
91  size_t slot_duration_u64{};
92  uint8_t allowed_slots;
93  s >> slot_duration_u64 >> config.epoch_length >> config.leadership_rate
94  >> config.authorities >> config.randomness >> allowed_slots;
95  config.slot_duration = std::chrono::milliseconds(slot_duration_u64);
96  config.allowed_slots = static_cast<AllowedSlots>(allowed_slots);
97  return s;
98  }
99 } // namespace kagome::primitives
100 
101 #endif // KAGOME_CORE_PRIMITIVES_BABE_CONFIGURATION_HPP
Randomness randomness
The randomness for the genesis epoch.
AuthorityList authorities
The authorities for block production.
Configuration data used by the BABE consensus engine.
Stream & operator>>(Stream &s, ArithmeticError &v)
std::string_view to_string(AllowedSlots s)
AllowedSlots allowed_slots
Type of allowed slots.
Clock< std::chrono::system_clock > SystemClock
Definition: clock.hpp:57
Stream & operator<<(Stream &s, const ArithmeticError &v)
BabeClock::Duration BabeDuration
std::pair< uint64_t, uint64_t > leadership_rate
libp2p::connection::Stream Stream
typename ClockType::duration Duration
Definition: clock.hpp:23