Kagome
Polkadot Runtime Engine in C++17
event_types.hpp
Go to the documentation of this file.
1 
6 #ifndef KAGOME_CORE_PRIMITIVES_EVENT_TYPES_HPP
7 #define KAGOME_CORE_PRIMITIVES_EVENT_TYPES_HPP
8 
9 #include <cstdint>
10 #include <memory>
11 
12 #include <boost/none_t.hpp>
13 #include <boost/variant.hpp>
14 #include <libp2p/peer/peer_id.hpp>
15 
16 #include "common/buffer.hpp"
17 #include "primitives/block_id.hpp"
18 #include "primitives/extrinsic.hpp"
19 #include "primitives/version.hpp"
22 
23 namespace kagome::api {
24  class Session;
25 } // namespace kagome::api
26 
27 namespace kagome::primitives {
28  struct BlockHeader;
29 }
30 
32 
33  template <typename T>
34  using ref_t = std::reference_wrapper<const T>;
35 
36  enum struct ChainEventType : uint32_t {
37  kNewHeads = 1,
38  kFinalizedHeads = 2,
39  kAllHeads = 3,
41  kNewRuntime = 5
42  };
43 
47 
48  using ChainEventParams = boost::variant<std::nullopt_t,
52 
77  enum class ExtrinsicEventType {
78  FUTURE,
79  READY,
80  BROADCAST,
81  IN_BLOCK,
82  RETRACTED,
84  FINALIZED,
85  USURPED,
86  DROPPED,
87  INVALID
88  };
89 
90  using Hash256Span = gsl::span<const uint8_t, common::Hash256::size()>;
91 
93  gsl::span<const libp2p::peer::PeerId> peers;
94  };
95 
98  };
101  };
102 
105  };
106 
109  };
110 
113  };
114 
119  using SubscribedExtrinsicId = uint32_t;
120 
122  // mind that although sometimes std::nullopt is used in variants to skip a
123  // parameter, here it literally represents the type of event parameters when
124  // there are none
125  using Params = boost::variant<std::nullopt_t,
132 
135  id, ExtrinsicEventType::FUTURE, Params{std::nullopt}};
136  }
137 
140  id, ExtrinsicEventType::READY, Params{std::nullopt}};
141  }
142 
144  SubscribedExtrinsicId id, gsl::span<const libp2p::peer::PeerId> peers) {
146  id,
147  ExtrinsicEventType::BROADCAST,
148  Params{BroadcastEventParams{.peers = std::move(peers)}}};
149  }
150 
152  Hash256Span block) {
154  id,
155  ExtrinsicEventType::IN_BLOCK,
156  Params{InBlockEventParams{.block = std::move(block)}}};
157  }
158 
160  Hash256Span retracted_block) {
162  id,
163  ExtrinsicEventType::RETRACTED,
164  Params{RetractedEventParams{.retracted_block =
165  std::move(retracted_block)}}};
166  }
167 
169  Hash256Span block) {
171  id,
172  ExtrinsicEventType::FINALITY_TIMEOUT,
173  Params{FinalizedEventParams{.block = std::move(block)}}};
174  }
175 
177  Hash256Span block) {
179  id,
180  ExtrinsicEventType::FINALIZED,
181  Params{FinalizedEventParams{.block = std::move(block)}}};
182  }
183 
185  Hash256Span transaction_hash) {
187  id,
188  ExtrinsicEventType::USURPED,
190  std::move(transaction_hash)}}};
191  }
192 
195  id, ExtrinsicEventType::DROPPED, Params{std::nullopt}};
196  }
197 
200  id, ExtrinsicEventType::INVALID, Params{std::nullopt}};
201  }
202 
205 
207 
208  private:
210  ExtrinsicEventType type,
211  Params params)
212  : id{id}, type{type}, params{std::move(params)} {}
213  };
214 
215  // SubscriptionEngine for changes in trie storage
218  std::shared_ptr<api::Session>,
219  std::optional<common::Buffer>,
222  std::shared_ptr<StorageSubscriptionEngine>;
223 
225  using StorageEventSubscriberPtr = std::shared_ptr<StorageEventSubscriber>;
226 
229  std::shared_ptr<api::Session>,
231  using ChainSubscriptionEnginePtr = std::shared_ptr<ChainSubscriptionEngine>;
232 
234  using ChainEventSubscriberPtr = std::shared_ptr<ChainEventSubscriber>;
235 
238  std::shared_ptr<api::Session>,
241  std::shared_ptr<ExtrinsicSubscriptionEngine>;
242 
244  using ExtrinsicEventSubscriberPtr = std::shared_ptr<ExtrinsicEventSubscriber>;
245 
246 } // namespace kagome::primitives::events
247 
248 #endif // KAGOME_CORE_PRIMITIVES_EVENT_TYPES_HPP
gsl::span< const uint8_t, common::Hash256::size()> Hash256Span
Definition: event_types.hpp:90
static ExtrinsicLifecycleEvent Invalid(SubscribedExtrinsicId id)
ref_t< const primitives::BlockHash > NewRuntimeEventParams
Definition: event_types.hpp:46
static ExtrinsicLifecycleEvent Broadcast(SubscribedExtrinsicId id, gsl::span< const libp2p::peer::PeerId > peers)
std::shared_ptr< ExtrinsicEventSubscriber > ExtrinsicEventSubscriberPtr
std::shared_ptr< StorageSubscriptionEngine > StorageSubscriptionEnginePtr
static ExtrinsicLifecycleEvent Dropped(SubscribedExtrinsicId id)
static ExtrinsicLifecycleEvent Retracted(SubscribedExtrinsicId id, Hash256Span retracted_block)
ref_t< const primitives::Version > RuntimeVersionEventParams
Definition: event_types.hpp:45
static ExtrinsicLifecycleEvent Ready(SubscribedExtrinsicId id)
static ExtrinsicLifecycleEvent Usurped(SubscribedExtrinsicId id, Hash256Span transaction_hash)
static ExtrinsicLifecycleEvent FinalityTimeout(SubscribedExtrinsicId id, Hash256Span block)
boost::variant< std::nullopt_t, HeadsEventParams, RuntimeVersionEventParams, NewRuntimeEventParams > ChainEventParams
Definition: event_types.hpp:51
std::shared_ptr< ChainEventSubscriber > ChainEventSubscriberPtr
static ExtrinsicLifecycleEvent Finalized(SubscribedExtrinsicId id, Hash256Span block)
static ExtrinsicLifecycleEvent Future(SubscribedExtrinsicId id)
SLBuffer< std::numeric_limits< size_t >::max()> Buffer
Definition: buffer.hpp:244
std::shared_ptr< ChainSubscriptionEngine > ChainSubscriptionEnginePtr
ExtrinsicLifecycleEvent(SubscribedExtrinsicId id, ExtrinsicEventType type, Params params)
static ExtrinsicLifecycleEvent InBlock(SubscribedExtrinsicId id, Hash256Span block)
std::shared_ptr< ExtrinsicSubscriptionEngine > ExtrinsicSubscriptionEnginePtr
std::shared_ptr< StorageEventSubscriber > StorageEventSubscriberPtr
gsl::span< const libp2p::peer::PeerId > peers
Definition: event_types.hpp:93
ref_t< const primitives::BlockHeader > HeadsEventParams
Definition: event_types.hpp:44
boost::variant< std::nullopt_t, BroadcastEventParams, InBlockEventParams, RetractedEventParams, FinalityTimeoutEventParams, FinalizedEventParams, UsurpedEventParams > Params
std::reference_wrapper< const T > ref_t
Definition: event_types.hpp:34