Skip to content
Snippets Groups Projects
Unverified Commit 515fcc95 authored by Liu-Cheng Xu's avatar Liu-Cheng Xu Committed by GitHub
Browse files

Avoid unnecessary state reset of `allowed_requests` when no block requests are sent (#5774)

This PR is cherry-picked from
https://github.com/paritytech/polkadot-sdk/pull/5663 so that I can
maintain a smaller polkadot-sdk diff downstream sooner than later.

cc @lexnv @dmitry-markin



---------

Co-authored-by: default avatarAlexandru Vasile <60601340+lexnv@users.noreply.github.com>
Co-authored-by: default avatarDmitry Markin <dmitry@markin.tech>
parent 5a431470
No related merge requests found
Pipeline #498054 waiting for manual action with stages
in 1 hour, 42 minutes, and 55 seconds
title: Avoid unnecessary state reset of allowed_requests when no block requests are sent
doc:
- audience: Node Dev
description: |
Previously, the state of `allowed_requests` was always reset to the default
even if there were no new block requests. This could cause an edge case
because `peer_block_request()` will return early next time when there are no ongoing block requests.
This patch fixes it by checking whether block requests are empty before updating the state.
crates:
- name: sc-network-sync
bump: patch
......@@ -148,6 +148,7 @@ impl Metrics {
}
}
#[derive(Debug, Clone)]
enum AllowedRequests {
Some(HashSet<PeerId>),
All,
......@@ -1714,13 +1715,14 @@ where
let best_queued = self.best_queued_number;
let client = &self.client;
let queue_blocks = &self.queue_blocks;
let allowed_requests = self.allowed_requests.take();
let allowed_requests = self.allowed_requests.clone();
let max_parallel = if is_major_syncing { 1 } else { self.max_parallel_downloads };
let max_blocks_per_request = self.max_blocks_per_request;
let gap_sync = &mut self.gap_sync;
let disconnected_peers = &mut self.disconnected_peers;
let metrics = self.metrics.as_ref();
self.peers
let requests = self
.peers
.iter_mut()
.filter_map(move |(&id, peer)| {
if !peer.state.is_available() ||
......@@ -1819,7 +1821,15 @@ where
None
}
})
.collect()
.collect::<Vec<_>>();
// Clear the allowed_requests state when sending new block requests
// to prevent multiple inflight block requests from being issued.
if !requests.is_empty() {
self.allowed_requests.take();
}
requests
}
/// Get a state request scheduled by sync to be sent out (if any).
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment