Fix sync stalling on moving head (best block) prior to the tip of the chain sometimes (#4091)

* Work around finalization woes

* Fixed check_block

* Added a test
This commit is contained in:
Arkadiy Paronyan
2019-11-12 13:54:11 +01:00
committed by Gavin Wood
parent c91d42712a
commit d40abed4a5
6 changed files with 184 additions and 55 deletions
@@ -95,6 +95,7 @@ pub enum ForkChoiceStrategy {
}
/// Data required to check validity of a Block.
#[derive(Debug, PartialEq, Eq, Clone)]
pub struct BlockCheckParams<Block: BlockT> {
/// Hash of the block that we verify.
pub hash: Block::Hash,
@@ -163,6 +163,8 @@ pub enum BlockImportError {
VerificationFailed(Option<Origin>, String),
/// Block is known to be Bad
BadBlock(Option<Origin>),
/// Parent state is missing.
MissingState,
/// Block has an unknown parent
UnknownParent,
/// Block import has been cancelled. This can happen if the parent block fails to be imported.
@@ -207,7 +209,7 @@ pub fn import_single_block<B: BlockT, V: Verifier<B>>(
Ok(ImportResult::Imported(aux)) => Ok(BlockImportResult::ImportedUnknown(number, aux, peer.clone())),
Ok(ImportResult::MissingState) => {
debug!(target: "sync", "Parent state is missing for {}: {:?}, parent: {:?}", number, hash, parent_hash);
Err(BlockImportError::UnknownParent)
Err(BlockImportError::MissingState)
},
Ok(ImportResult::UnknownParent) => {
debug!(target: "sync", "Block with unknown parent {}: {:?}, parent: {:?}", number, hash, parent_hash);