Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

warp sync last justification #2324

Merged
merged 2 commits into from
Dec 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 23 additions & 31 deletions core/network/impl/synchronizer_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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<BlocksResponse> r) mutable {
outcome::result<WarpResponse> r) mutable {
auto self = weak.lock();
if (not self) {
return;
Expand All @@ -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;
for (auto &block : blocks) {
if (block.justification) {
self->grandpa_environment_->applyJustification(
{number, block.hash},
*block.justification,
[cb{std::move(cb)}](outcome::result<void> r) {
if (not r) {
cb(r.error());
} else {
cb(std::nullopt);
}
});
return;
}
++number;
auto &blocks = r.value().proofs;
for (const auto &block : blocks) {
self->grandpa_environment_->applyJustification(
block.justification.block_info,
{scale::encode(block.justification).value()},
[cb{std::move(cb)}](outcome::result<void> 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;
}

Expand Down
Loading