-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature: request chunk protocol v2 (#2144)
* feature: add type for chunk index Signed-off-by: Dmitriy Khaustov aka xDimon <[email protected]> * refactor: add prefix "-obsolete" for previous protocol version and related data/types Signed-off-by: Dmitriy Khaustov aka xDimon <[email protected]> * draft Signed-off-by: Dmitriy Khaustov aka xDimon <[email protected]> * draft Signed-off-by: Dmitriy Khaustov aka xDimon <[email protected]> * feature: extent node feature and add function to compute chunk_index by val_index Signed-off-by: Dmitriy Khaustov aka xDimon <[email protected]> * refactor: signature some funcs Signed-off-by: Dmitriy Khaustov aka xDimon <[email protected]> * feature: zombietest 0013-systematic-chunk-recovery Signed-off-by: Dmitriy Khaustov aka xDimon <[email protected]> * Update and enable 13 test * Return 4 kagome validators in 0001 * Add empty line * feature: add metrics of total number of started/finished recoveries Signed-off-by: Dmitriy Khaustov aka xDimon <[email protected]> * feature: add metrics of total number of started/finished recoveries Signed-off-by: Dmitriy Khaustov aka xDimon <[email protected]> * hotfix Signed-off-by: Dmitriy Khaustov aka xDimon <[email protected]> * fix: review issues Signed-off-by: Dmitriy Khaustov aka xDimon <[email protected]> * fix: exception Signed-off-by: Dmitriy Khaustov aka xDimon <[email protected]> --------- Signed-off-by: Dmitriy Khaustov aka xDimon <[email protected]> Co-authored-by: kamilsa <[email protected]>
- Loading branch information
Showing
33 changed files
with
707 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 96 additions & 0 deletions
96
core/network/impl/protocols/protocol_fetch_chunk_obsolete.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
/** | ||
* Copyright Quadrivium LLC | ||
* All Rights Reserved | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include "network/protocol_base.hpp" | ||
|
||
#include <memory> | ||
|
||
#include <libp2p/connection/stream.hpp> | ||
#include <libp2p/host/host.hpp> | ||
|
||
#include "blockchain/genesis_block_hash.hpp" | ||
#include "log/logger.hpp" | ||
#include "network/common.hpp" | ||
#include "network/impl/protocols/request_response_protocol.hpp" | ||
#include "network/impl/stream_engine.hpp" | ||
#include "parachain/validator/parachain_processor.hpp" | ||
#include "utils/non_copyable.hpp" | ||
|
||
namespace kagome::network { | ||
|
||
struct ReqPovProtocolImpl; | ||
|
||
/// Implementation of first implementation of | ||
/// fetching chunk protocol aka 'req_chunk/1' | ||
/// | ||
/// In response index of systematic chunk is corresponding validator index. | ||
class FetchChunkProtocolObsolete final | ||
: public RequestResponseProtocol<FetchChunkRequest, | ||
FetchChunkResponseObsolete, | ||
ScaleMessageReadWriter>, | ||
NonCopyable, | ||
NonMovable { | ||
public: | ||
FetchChunkProtocolObsolete() = delete; | ||
~FetchChunkProtocolObsolete() override = default; | ||
|
||
FetchChunkProtocolObsolete( | ||
libp2p::Host &host, | ||
const application::ChainSpec & /*chain_spec*/, | ||
const blockchain::GenesisBlockHash &genesis_hash, | ||
std::shared_ptr<parachain::ParachainProcessorImpl> pp) | ||
: RequestResponseProtocol< | ||
FetchChunkRequest, | ||
FetchChunkResponseObsolete, | ||
ScaleMessageReadWriter>{kFetchChunkProtocolName, | ||
host, | ||
make_protocols(kFetchChunkProtocolObsolete, | ||
genesis_hash, | ||
kProtocolPrefixPolkadot), | ||
log::createLogger(kFetchChunkProtocolName, | ||
"req_chunk_protocol")}, | ||
pp_{std::move(pp)} { | ||
BOOST_ASSERT(pp_); | ||
} | ||
|
||
private: | ||
std::optional<outcome::result<ResponseType>> onRxRequest( | ||
RequestType request, std::shared_ptr<Stream> /*stream*/) override { | ||
base().logger()->info("Fetching chunk request.(chunk={}, candidate={})", | ||
request.chunk_index, | ||
request.candidate); | ||
auto res = pp_->OnFetchChunkRequest(std::move(request)); | ||
if (res.has_error()) { | ||
base().logger()->error("Fetching chunk response failed.(error={})", | ||
res.error()); | ||
return res.as_failure(); | ||
} | ||
|
||
if (auto chunk = if_type<const network::Chunk>(res.value())) { | ||
base().logger()->info("Fetching chunk response with data."); | ||
return outcome::success(network::ChunkObsolete{ | ||
.data = std::move(chunk.value().get().data), | ||
.proof = std::move(chunk.value().get().proof), | ||
}); | ||
} | ||
|
||
base().logger()->info("Fetching chunk response empty."); | ||
return outcome::success(network::Empty{}); | ||
} | ||
|
||
void onTxRequest(const RequestType &request) override { | ||
base().logger()->debug("Fetching chunk candidate: {}, index: {}", | ||
request.candidate, | ||
request.chunk_index); | ||
} | ||
|
||
inline static const auto kFetchChunkProtocolName = "FetchChunkProtocol_v1"s; | ||
std::shared_ptr<parachain::ParachainProcessorImpl> pp_; | ||
}; | ||
|
||
} // namespace kagome::network |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.