From a29f751c9ae83b51c4cc4958fa7e3909341b459b Mon Sep 17 00:00:00 2001 From: turuslan Date: Tue, 24 Dec 2024 16:28:45 +0500 Subject: [PATCH 1/2] warp sync last justification Signed-off-by: turuslan --- core/network/impl/synchronizer_impl.cpp | 52 +++++++++++-------------- 1 file changed, 22 insertions(+), 30 deletions(-) diff --git a/core/network/impl/synchronizer_impl.cpp b/core/network/impl/synchronizer_impl.cpp index a2f9292b37..285b4596ac 100644 --- a/core/network/impl/synchronizer_impl.cpp +++ b/core/network/impl/synchronizer_impl.cpp @@ -23,6 +23,7 @@ #include "network/protocols/state_protocol.hpp" #include "network/protocols/sync_protocol.hpp" #include "network/types/block_attributes.hpp" +#include "network/warp/protocol.hpp" #include "primitives/common.hpp" #include "storage/predefined_keys.hpp" #include "storage/trie/serialization/trie_serializer.hpp" @@ -1326,20 +1327,18 @@ namespace kagome::network { bool SynchronizerImpl::fetchJustificationRange(primitives::BlockNumber min, FetchJustificationRangeCb cb) { - BlocksRequest request{ - .fields = BlockAttribute::JUSTIFICATION, - .from = min, - .direction = Direction::ASCENDING, - .max = std::nullopt, - .multiple_justifications = false, - }; - auto chosen = chooseJustificationPeer(min, request.fingerprint()); + auto hash_res = block_tree_->getHashByNumber(min); + if (not hash_res) { + return false; + } + auto &hash = hash_res.value(); + auto chosen = chooseJustificationPeer(min, min); if (not chosen) { return false; } busy_peers_.emplace(*chosen); auto cb2 = [weak{weak_from_this()}, min, cb{std::move(cb)}, peer{*chosen}]( - outcome::result r) mutable { + outcome::result r) mutable { auto self = weak.lock(); if (not self) { return; @@ -1348,30 +1347,23 @@ namespace kagome::network { if (not r) { return cb(r.error()); } - auto &blocks = r.value().blocks; - if (blocks.empty()) { - return cb(Error::EMPTY_RESPONSE); - } - auto number = min; + auto &blocks = r.value().proofs; for (auto &block : blocks) { - if (block.justification) { - self->grandpa_environment_->applyJustification( - {number, block.hash}, - *block.justification, - [cb{std::move(cb)}](outcome::result r) { - if (not r) { - cb(r.error()); - } else { - cb(std::nullopt); - } - }); - return; - } - ++number; + self->grandpa_environment_->applyJustification( + block.justification.block_info, + {scale::encode(block.justification).value()}, + [cb{std::move(cb)}](outcome::result r) { + if (not r) { + cb(r.error()); + } else { + cb(std::nullopt); + } + }); + return; } - cb(min + blocks.size()); + cb(min); }; - fetch(*chosen, std::move(request), "justification range", std::move(cb2)); + router_->getWarpProtocol()->doRequest(*chosen, hash, std::move(cb2)); return true; } From 91c3fa4325b3a73a28928163d782ad0b18fd93c5 Mon Sep 17 00:00:00 2001 From: Ruslan Tushov Date: Tue, 24 Dec 2024 17:04:00 +0500 Subject: [PATCH 2/2] pr comment Co-authored-by: kamilsa --- core/network/impl/synchronizer_impl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/network/impl/synchronizer_impl.cpp b/core/network/impl/synchronizer_impl.cpp index 285b4596ac..b7fe69878b 100644 --- a/core/network/impl/synchronizer_impl.cpp +++ b/core/network/impl/synchronizer_impl.cpp @@ -1348,7 +1348,7 @@ namespace kagome::network { return cb(r.error()); } auto &blocks = r.value().proofs; - for (auto &block : blocks) { + for (const auto &block : blocks) { self->grandpa_environment_->applyJustification( block.justification.block_info, {scale::encode(block.justification).value()},