Kagome
Polkadot Runtime Engine in C++17
protocol_factory.cpp
Go to the documentation of this file.
1 
7 #include "primitives/common.hpp"
8 
9 namespace kagome::network {
10 
12  libp2p::Host &host,
13  const application::AppConfiguration &app_config,
14  const application::ChainSpec &chain_spec,
15  const OwnPeerInfo &own_info,
16  std::shared_ptr<boost::asio::io_context> io_context,
17  std::shared_ptr<crypto::Hasher> hasher,
18  std::shared_ptr<StreamEngine> stream_engine,
19  std::shared_ptr<primitives::events::ExtrinsicSubscriptionEngine>
20  extrinsic_events_engine,
21  std::shared_ptr<subscription::ExtrinsicEventKeyRepository>
22  ext_event_key_repo,
23  std::shared_ptr<ReputationRepository> reputation_repository,
24  std::shared_ptr<libp2p::basic::Scheduler> scheduler)
25  : host_(host),
26  app_config_(app_config),
27  chain_spec_(chain_spec),
28  own_info_(own_info),
29  io_context_(std::move(io_context)),
30  hasher_(std::move(hasher)),
31  stream_engine_(std::move(stream_engine)),
32  extrinsic_events_engine_{std::move(extrinsic_events_engine)},
33  ext_event_key_repo_{std::move(ext_event_key_repo)},
34  reputation_repository_{std::move(reputation_repository)},
35  scheduler_{std::move(scheduler)} {
36  BOOST_ASSERT(io_context_ != nullptr);
37  BOOST_ASSERT(hasher_ != nullptr);
38  BOOST_ASSERT(stream_engine_ != nullptr);
39  BOOST_ASSERT(extrinsic_events_engine_ != nullptr);
40  BOOST_ASSERT(ext_event_key_repo_ != nullptr);
41  BOOST_ASSERT(reputation_repository_ != nullptr);
42  BOOST_ASSERT(scheduler_ != nullptr);
43  }
44 
45  std::shared_ptr<BlockAnnounceProtocol>
47  return std::make_shared<BlockAnnounceProtocol>(host_,
51  block_tree_.lock(),
52  babe_.lock(),
53  peer_manager_.lock());
54  }
55 
56  std::shared_ptr<GrandpaProtocol> ProtocolFactory::makeGrandpaProtocol()
57  const {
58  auto block_tree = block_tree_.lock();
59  BOOST_ASSERT(block_tree != nullptr);
60  auto genesisBlockHash = block_tree->getGenesisBlockHash();
61 
62  return std::make_shared<GrandpaProtocol>(host_,
65  grandpa_observer_.lock(),
66  own_info_,
68  peer_manager_.lock(),
69  genesisBlockHash,
70  scheduler_);
71  }
72 
73  std::shared_ptr<CollationProtocol> ProtocolFactory::makeCollationProtocol()
74  const {
75  return std::make_shared<CollationProtocol>(
77  }
78 
79  std::shared_ptr<ReqCollationProtocol>
81  return std::make_shared<ReqCollationProtocol>(
83  }
84 
85  std::shared_ptr<PropagateTransactionsProtocol>
87  return std::make_shared<PropagateTransactionsProtocol>(
88  host_,
91  babe_.lock(),
92  extrinsic_observer_.lock(),
96  }
97 
98  std::shared_ptr<StateProtocol> ProtocolFactory::makeStateProtocol() const {
99  return std::make_shared<StateProtocolImpl>(
101  }
102 
103  std::shared_ptr<SyncProtocol> ProtocolFactory::makeSyncProtocol() const {
104  return std::make_shared<SyncProtocolImpl>(
106  }
107 
108 } // namespace kagome::network
std::shared_ptr< GrandpaProtocol > makeGrandpaProtocol() const
std::weak_ptr< consensus::grandpa::GrandpaObserver > grandpa_observer_
std::shared_ptr< CollationProtocol > makeCollationProtocol() const
std::shared_ptr< StateProtocol > makeStateProtocol() const
std::weak_ptr< StateProtocolObserver > state_observer_
STL namespace.
std::weak_ptr< consensus::babe::Babe > babe_
std::weak_ptr< ReqCollationObserver > req_collation_observer_
std::shared_ptr< ReqCollationProtocol > makeReqCollationProtocol() const
std::weak_ptr< ExtrinsicObserver > extrinsic_observer_
ProtocolFactory(libp2p::Host &host, const application::AppConfiguration &app_config, const application::ChainSpec &chain_spec, const OwnPeerInfo &own_info, std::shared_ptr< boost::asio::io_context > io_context, std::shared_ptr< crypto::Hasher > hasher, std::shared_ptr< StreamEngine > stream_engine, std::shared_ptr< primitives::events::ExtrinsicSubscriptionEngine > extrinsic_events_engine, std::shared_ptr< subscription::ExtrinsicEventKeyRepository > ext_event_key_repo, std::shared_ptr< ReputationRepository > reputation_repository, std::shared_ptr< libp2p::basic::Scheduler > scheduler)
std::weak_ptr< PeerManager > peer_manager_
std::shared_ptr< StreamEngine > stream_engine_
std::weak_ptr< blockchain::BlockTree > block_tree_
std::shared_ptr< SyncProtocol > makeSyncProtocol() const
std::shared_ptr< primitives::events::ExtrinsicSubscriptionEngine > extrinsic_events_engine_
std::weak_ptr< SyncProtocolObserver > sync_observer_
std::shared_ptr< PropagateTransactionsProtocol > makePropagateTransactionsProtocol() const
std::weak_ptr< CollationObserver > collation_observer_
const application::ChainSpec & chain_spec_
const application::AppConfiguration & app_config_
std::shared_ptr< BlockAnnounceProtocol > makeBlockAnnounceProtocol() const
std::shared_ptr< boost::asio::io_context > io_context_
std::shared_ptr< crypto::Hasher > hasher_
std::shared_ptr< libp2p::basic::Scheduler > scheduler_
std::shared_ptr< subscription::ExtrinsicEventKeyRepository > ext_event_key_repo_
std::shared_ptr< ReputationRepository > reputation_repository_