sync: retry different peer after empty subchain heads response (#9753)
* If no subchain heads then try a different peer * Add log when useless chain head * Restrict ChainHead useless peer to ancient blocks * sync: replace `limit_reorg` with `block_set` condition
This commit is contained in:
parent
f4c421f77a
commit
9a2c4a34ee
@ -136,8 +136,6 @@ pub struct BlockDownloader {
|
|||||||
target_hash: Option<H256>,
|
target_hash: Option<H256>,
|
||||||
/// Probing range for seeking common best block.
|
/// Probing range for seeking common best block.
|
||||||
retract_step: u64,
|
retract_step: u64,
|
||||||
/// Whether reorg should be limited.
|
|
||||||
limit_reorg: bool,
|
|
||||||
/// consecutive useless headers this round
|
/// consecutive useless headers this round
|
||||||
useless_headers_count: usize,
|
useless_headers_count: usize,
|
||||||
}
|
}
|
||||||
@ -146,12 +144,12 @@ impl BlockDownloader {
|
|||||||
/// Create a new instance of syncing strategy.
|
/// Create a new instance of syncing strategy.
|
||||||
/// For BlockSet::NewBlocks this won't reorganize to before the last kept state.
|
/// For BlockSet::NewBlocks this won't reorganize to before the last kept state.
|
||||||
pub fn new(block_set: BlockSet, start_hash: &H256, start_number: BlockNumber) -> Self {
|
pub fn new(block_set: BlockSet, start_hash: &H256, start_number: BlockNumber) -> Self {
|
||||||
let (limit_reorg, sync_receipts) = match block_set {
|
let sync_receipts = match block_set {
|
||||||
BlockSet::NewBlocks => (true, false),
|
BlockSet::NewBlocks => false,
|
||||||
BlockSet::OldBlocks => (false, true)
|
BlockSet::OldBlocks => true
|
||||||
};
|
};
|
||||||
BlockDownloader {
|
BlockDownloader {
|
||||||
block_set: block_set,
|
block_set,
|
||||||
state: State::Idle,
|
state: State::Idle,
|
||||||
highest_block: None,
|
highest_block: None,
|
||||||
last_imported_block: start_number,
|
last_imported_block: start_number,
|
||||||
@ -164,7 +162,6 @@ impl BlockDownloader {
|
|||||||
download_receipts: sync_receipts,
|
download_receipts: sync_receipts,
|
||||||
target_hash: None,
|
target_hash: None,
|
||||||
retract_step: 1,
|
retract_step: 1,
|
||||||
limit_reorg: limit_reorg,
|
|
||||||
useless_headers_count: 0,
|
useless_headers_count: 0,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -321,12 +318,20 @@ impl BlockDownloader {
|
|||||||
self.state = State::Blocks;
|
self.state = State::Blocks;
|
||||||
return Ok(DownloadAction::Reset);
|
return Ok(DownloadAction::Reset);
|
||||||
} else {
|
} else {
|
||||||
|
trace_sync!(self, "No useful subchain heads received, expected hash {:?}", expected_hash);
|
||||||
let best = io.chain().chain_info().best_block_number;
|
let best = io.chain().chain_info().best_block_number;
|
||||||
let oldest_reorg = io.chain().pruning_info().earliest_state;
|
let oldest_reorg = io.chain().pruning_info().earliest_state;
|
||||||
let last = self.last_imported_block;
|
let last = self.last_imported_block;
|
||||||
if self.limit_reorg && best > last && (last == 0 || last < oldest_reorg) {
|
match self.block_set {
|
||||||
trace_sync!(self, "No common block, disabling peer");
|
BlockSet::NewBlocks if best > last && (last == 0 || last < oldest_reorg) => {
|
||||||
return Err(BlockDownloaderImportError::Invalid);
|
trace_sync!(self, "No common block, disabling peer");
|
||||||
|
return Err(BlockDownloaderImportError::Invalid)
|
||||||
|
},
|
||||||
|
BlockSet::OldBlocks => {
|
||||||
|
trace_sync!(self, "Expected some useful headers for downloading OldBlocks. Try a different peer");
|
||||||
|
return Err(BlockDownloaderImportError::Useless)
|
||||||
|
},
|
||||||
|
_ => (),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -429,7 +434,7 @@ impl BlockDownloader {
|
|||||||
} else {
|
} else {
|
||||||
let best = io.chain().chain_info().best_block_number;
|
let best = io.chain().chain_info().best_block_number;
|
||||||
let oldest_reorg = io.chain().pruning_info().earliest_state;
|
let oldest_reorg = io.chain().pruning_info().earliest_state;
|
||||||
if self.limit_reorg && best > start && start < oldest_reorg {
|
if self.block_set == BlockSet::NewBlocks && best > start && start < oldest_reorg {
|
||||||
debug_sync!(self, "Could not revert to previous ancient block, last: {} ({})", start, start_hash);
|
debug_sync!(self, "Could not revert to previous ancient block, last: {} ({})", start, start_hash);
|
||||||
self.reset();
|
self.reset();
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user