mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-27 17:28:00 +00:00
Do not request blocks below the common number when syncing (#2045)
This changes `BlockCollection` logic so we don't download block ranges from peers with which we have these ranges already in sync. Improves situation with https://github.com/paritytech/polkadot-sdk/issues/1915.
This commit is contained in:
@@ -520,12 +520,15 @@ where
|
||||
Err(BadPeer(who, rep::BLOCKCHAIN_READ_ERROR))
|
||||
},
|
||||
Ok(BlockStatus::KnownBad) => {
|
||||
info!("💔 New peer with known bad best block {} ({}).", best_hash, best_number);
|
||||
info!("💔 New peer {who} with known bad best block {best_hash} ({best_number}).");
|
||||
Err(BadPeer(who, rep::BAD_BLOCK))
|
||||
},
|
||||
Ok(BlockStatus::Unknown) => {
|
||||
if best_number.is_zero() {
|
||||
info!("💔 New peer with unknown genesis hash {} ({}).", best_hash, best_number);
|
||||
info!(
|
||||
"💔 New peer {} with unknown genesis hash {} ({}).",
|
||||
who, best_hash, best_number,
|
||||
);
|
||||
return Err(BadPeer(who, rep::GENESIS_MISMATCH))
|
||||
}
|
||||
|
||||
@@ -535,7 +538,8 @@ where
|
||||
if self.queue_blocks.len() > MAJOR_SYNC_BLOCKS.into() {
|
||||
debug!(
|
||||
target:LOG_TARGET,
|
||||
"New peer with unknown best hash {} ({}), assuming common block.",
|
||||
"New peer {} with unknown best hash {} ({}), assuming common block.",
|
||||
who,
|
||||
self.best_queued_hash,
|
||||
self.best_queued_number
|
||||
);
|
||||
@@ -556,7 +560,7 @@ where
|
||||
let (state, req) = if self.best_queued_number.is_zero() {
|
||||
debug!(
|
||||
target:LOG_TARGET,
|
||||
"New peer with best hash {best_hash} ({best_number}).",
|
||||
"New peer {who} with best hash {best_hash} ({best_number}).",
|
||||
);
|
||||
|
||||
(PeerSyncState::Available, None)
|
||||
@@ -565,7 +569,8 @@ where
|
||||
|
||||
debug!(
|
||||
target:LOG_TARGET,
|
||||
"New peer with unknown best hash {} ({}), searching for common ancestor.",
|
||||
"New peer {} with unknown best hash {} ({}), searching for common ancestor.",
|
||||
who,
|
||||
best_hash,
|
||||
best_number
|
||||
);
|
||||
@@ -613,7 +618,7 @@ where
|
||||
Ok(BlockStatus::InChainPruned) => {
|
||||
debug!(
|
||||
target: LOG_TARGET,
|
||||
"New peer with known best hash {best_hash} ({best_number}).",
|
||||
"New peer {who} with known best hash {best_hash} ({best_number}).",
|
||||
);
|
||||
self.peers.insert(
|
||||
who,
|
||||
@@ -848,8 +853,22 @@ where
|
||||
// We've made progress on this chain since the search was started.
|
||||
// Opportunistically set common number to updated number
|
||||
// instead of the one that started the search.
|
||||
trace!(
|
||||
target: LOG_TARGET,
|
||||
"Ancestry search: opportunistically updating peer {} common number from={} => to={}.",
|
||||
*who,
|
||||
peer.common_number,
|
||||
self.best_queued_number,
|
||||
);
|
||||
peer.common_number = self.best_queued_number;
|
||||
} else if peer.common_number < *current {
|
||||
trace!(
|
||||
target: LOG_TARGET,
|
||||
"Ancestry search: updating peer {} common number from={} => to={}.",
|
||||
*who,
|
||||
peer.common_number,
|
||||
*current,
|
||||
);
|
||||
peer.common_number = *current;
|
||||
}
|
||||
}
|
||||
@@ -1338,6 +1357,13 @@ where
|
||||
// should be kept in that state.
|
||||
if let PeerSyncState::DownloadingJustification(_) = p.state {
|
||||
// We make sure our commmon number is at least something we have.
|
||||
trace!(
|
||||
target: LOG_TARGET,
|
||||
"Keeping peer {} after restart, updating common number from={} => to={} (our best).",
|
||||
peer_id,
|
||||
p.common_number,
|
||||
self.best_queued_number,
|
||||
);
|
||||
p.common_number = self.best_queued_number;
|
||||
self.peers.insert(peer_id, p);
|
||||
return None
|
||||
|
||||
Reference in New Issue
Block a user