Kagome
Polkadot Runtime Engine in C++17
propagate_transactions_protocol.hpp
Go to the documentation of this file.
1 
6 #ifndef KAGOME_NETWORK_PROPAGATETRANSACTIONSPROTOCOL
7 #define KAGOME_NETWORK_PROPAGATETRANSACTIONSPROTOCOL
8 
10 
11 #include <memory>
12 
13 #include <libp2p/connection/stream.hpp>
14 #include <libp2p/host/host.hpp>
15 
18 #include "consensus/babe/babe.hpp"
20 #include "log/logger.hpp"
21 #include "metrics/metrics.hpp"
30 #include "utils/non_copyable.hpp"
31 
32 namespace kagome::network {
33 
34  KAGOME_DECLARE_CACHE(PropagateTransactionsProtocol,
35  KAGOME_CACHE_UNIT(PropagatedExtrinsics));
36 
38  : public ProtocolBase,
39  public std::enable_shared_from_this<PropagateTransactionsProtocol>,
41  NonMovable {
42  public:
44  ~PropagateTransactionsProtocol() override = default;
45 
47  libp2p::Host &host,
48  const application::AppConfiguration &app_config,
49  const application::ChainSpec &chain_spec,
50  std::shared_ptr<consensus::babe::Babe> babe,
51  std::shared_ptr<ExtrinsicObserver> extrinsic_observer,
52  std::shared_ptr<StreamEngine> stream_engine,
53  std::shared_ptr<primitives::events::ExtrinsicSubscriptionEngine>
54  extrinsic_events_engine,
55  std::shared_ptr<subscription::ExtrinsicEventKeyRepository>
56  ext_event_key_repo);
57 
58  bool start() override;
59  bool stop() override;
60 
61  const std::string &protocolName() const override {
63  }
64 
65  void onIncomingStream(std::shared_ptr<Stream> stream) override;
66  void newOutgoingStream(
67  const PeerInfo &peer_info,
68  std::function<void(outcome::result<std::shared_ptr<Stream>>)> &&cb)
69  override;
70 
71  void propagateTransactions(gsl::span<const primitives::Transaction> txs);
72 
73  private:
74  enum class Direction { INCOMING, OUTGOING };
75  void readHandshake(std::shared_ptr<Stream> stream,
76  Direction direction,
77  std::function<void(outcome::result<void>)> &&cb);
78 
79  void writeHandshake(std::shared_ptr<Stream> stream,
80  Direction direction,
81  std::function<void(outcome::result<void>)> &&cb);
82 
83  void readPropagatedExtrinsics(std::shared_ptr<Stream> stream);
84 
85  const static inline auto kPropogateTransacionsProtocolName =
86  "PropagateTransactionsProtocol"s;
89  std::shared_ptr<consensus::babe::Babe> babe_;
90  std::shared_ptr<ExtrinsicObserver> extrinsic_observer_;
91  std::shared_ptr<StreamEngine> stream_engine_;
92  std::shared_ptr<primitives::events::ExtrinsicSubscriptionEngine>
94  std::shared_ptr<subscription::ExtrinsicEventKeyRepository>
96 
97  // Metrics
100  };
101 
102 } // namespace kagome::network
103 
104 #endif // KAGOME_NETWORK_PROPAGATETRANSACTIONSPROTOCOL
void readPropagatedExtrinsics(std::shared_ptr< Stream > stream)
KAGOME_DECLARE_CACHE(BlockAnnounceProtocol, KAGOME_CACHE_UNIT(BlockAnnounce))
void readHandshake(std::shared_ptr< Stream > stream, Direction direction, std::function< void(outcome::result< void >)> &&cb)
#define KAGOME_CACHE_UNIT(type)
void writeHandshake(std::shared_ptr< Stream > stream, Direction direction, std::function< void(outcome::result< void >)> &&cb)
std::unique_ptr< Registry > RegistryPtr
Definition: metrics.hpp:15
RegistryPtr createRegistry()
std::shared_ptr< subscription::ExtrinsicEventKeyRepository > ext_event_key_repo_
libp2p::peer::PeerInfo PeerInfo
std::shared_ptr< primitives::events::ExtrinsicSubscriptionEngine > extrinsic_events_engine_
void newOutgoingStream(const PeerInfo &peer_info, std::function< void(outcome::result< std::shared_ptr< Stream >>)> &&cb) override
void onIncomingStream(std::shared_ptr< Stream > stream) override
void propagateTransactions(gsl::span< const primitives::Transaction > txs)
A counter metric to represent a monotonically increasing value.
Definition: metrics.hpp:27