Skip to content

Commit

Permalink
Changes to handling partial responses
Browse files Browse the repository at this point in the history
Context: paritytech#493 (comment)

Problem: When downloading from a fork, the peer may send a partial response
that extends the current chain. Even though the response starts at a block
number after the current best number, the parent block from the fork is not
yet downloaded/imported. We currently try to import the partial response
in this scenario, which causes import to fail as parent is not found in the
backend. This causes sync to be aborted/restarted which may not converge.

Fix: when we receive a partial response in this scenario, hold on to the
partial blocks and try to download the missing blocks. And import when the
full range is downloaded.
  • Loading branch information
rahulksnv committed Sep 24, 2023
1 parent 6a897f0 commit 43dcd64
Show file tree
Hide file tree
Showing 2 changed files with 377 additions and 16 deletions.
11 changes: 9 additions & 2 deletions substrate/client/network/sync/src/extra_requests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -343,11 +343,12 @@ impl<'a, B: BlockT> Matcher<'a, B> {
#[cfg(test)]
mod tests {
use super::*;
use crate::PeerSync;
use crate::{PeerDownloadState, PeerSync};
use quickcheck::{Arbitrary, Gen, QuickCheck};
use sp_blockchain::Error as ClientError;
use sp_test_primitives::{Block, BlockNumber, Hash};
use std::collections::{HashMap, HashSet};
use std::ops::Range;

#[test]
fn requests_are_processed_in_order() {
Expand Down Expand Up @@ -542,7 +543,13 @@ mod tests {
let s = match u8::arbitrary(g) % 4 {
0 => PeerSyncState::Available,
// TODO: 1 => PeerSyncState::AncestorSearch(g.gen(), AncestorSearchState<B>),
1 => PeerSyncState::DownloadingNew(BlockNumber::arbitrary(g)),
1 => PeerSyncState::DownloadingNew(PeerDownloadState::new(
BlockNumber::arbitrary(g),
Range {
start: BlockNumber::arbitrary(g),
end: BlockNumber::arbitrary(g),
}
)),
2 => PeerSyncState::DownloadingStale(Hash::random()),
_ => PeerSyncState::DownloadingJustification(Hash::random()),
};
Expand Down
Loading

0 comments on commit 43dcd64

Please sign in to comment.