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
@@ -38,6 +38,10 @@ pub trait ClientExt<Block: BlockT>: Sized {
fn import_as_best(&self, origin: BlockOrigin, block: Block)
-> Result<(), ConsensusError>;
/// Import a block and finalize it.
fn import_as_final(&self, origin: BlockOrigin, block: Block)
-> Result<(), ConsensusError>;
/// Import block with justification, finalizes block.
fn import_justified(
&self,
@@ -102,6 +106,25 @@ impl<B, E, RA, Block> ClientExt<Block> for Client<B, E, Block, RA>
BlockImport::import_block(&mut (&*self), import, HashMap::new()).map(|_| ())
}
fn import_as_final(&self, origin: BlockOrigin, block: Block)
-> Result<(), ConsensusError>
{
let (header, extrinsics) = block.deconstruct();
let import = BlockImportParams {
origin,
header,
justification: None,
post_digests: vec![],
body: Some(extrinsics),
finalized: true,
auxiliary: Vec::new(),
fork_choice: ForkChoiceStrategy::Custom(true),
allow_missing_state: false,
};
BlockImport::import_block(&mut (&*self), import, HashMap::new()).map(|_| ())
}
fn import_justified(
&self,
origin: BlockOrigin,