Kagome
Polkadot Runtime Engine in C++17
sync_protocol_observer_impl.hpp
Go to the documentation of this file.
1 
6 #ifndef KAGOME_SYNC_PROTOCOL_OBSERVER_IMPL
7 #define KAGOME_SYNC_PROTOCOL_OBSERVER_IMPL
8 
10 
11 #include <libp2p/host/host.hpp>
12 #include <libp2p/peer/peer_info.hpp>
13 
16 #include "log/logger.hpp"
18 #include "primitives/common.hpp"
19 
20 namespace kagome::network {
21 
23  : public SyncProtocolObserver,
24  public std::enable_shared_from_this<SyncProtocolObserverImpl> {
25  public:
26  enum class Error { DUPLICATE_REQUEST_ID = 1 };
27 
29  std::shared_ptr<blockchain::BlockTree> block_tree,
30  std::shared_ptr<blockchain::BlockHeaderRepository> blocks_headers);
31 
32  ~SyncProtocolObserverImpl() override = default;
33 
34  outcome::result<BlocksResponse> onBlocksRequest(
35  const BlocksRequest &request) const override;
36 
37  private:
39  const network::BlocksRequest &request,
40  const primitives::BlockHash &from_hash) const;
41 
42  void fillBlocksResponse(
43  const network::BlocksRequest &request,
44  network::BlocksResponse &response,
45  const std::vector<primitives::BlockHash> &hash_chain) const;
46 
47  std::shared_ptr<blockchain::BlockTree> block_tree_;
48  std::shared_ptr<blockchain::BlockHeaderRepository> blocks_headers_;
49 
50  mutable std::unordered_set<BlocksRequest::Fingerprint> requested_ids_;
51 
53  };
54 
55 } // namespace kagome::network
56 
58 
59 #endif // KAGOME_SYNC_PROTOCOL_OBSERVER_IMPL
blockchain::BlockTree::BlockHashVecRes retrieveRequestedHashes(const network::BlocksRequest &request, const primitives::BlockHash &from_hash) const
std::shared_ptr< blockchain::BlockTree > block_tree_
std::shared_ptr< soralog::Logger > Logger
Definition: logger.hpp:23
outcome::result< std::vector< primitives::BlockHash >> BlockHashVecRes
Definition: block_tree.hpp:32
outcome::result< BlocksResponse > onBlocksRequest(const BlocksRequest &request) const override
SyncProtocolObserverImpl(std::shared_ptr< blockchain::BlockTree > block_tree, std::shared_ptr< blockchain::BlockHeaderRepository > blocks_headers)
std::unordered_set< BlocksRequest::Fingerprint > requested_ids_
OUTCOME_HPP_DECLARE_ERROR(kagome::network, SyncProtocolObserverImpl::Error)
void fillBlocksResponse(const network::BlocksRequest &request, network::BlocksResponse &response, const std::vector< primitives::BlockHash > &hash_chain) const
std::shared_ptr< blockchain::BlockHeaderRepository > blocks_headers_