Synchronize state cache on finalization (#3246)

* Reorg test

* Fixed informant misreporting reorgs

* Update cache when reorg is caused by applying finality

* Test for finality reorg

* Simplified test

* Typo

Co-Authored-By: André Silva <andre.beat@gmail.com>
This commit is contained in:
Arkadiy Paronyan
2019-07-30 23:07:57 +02:00
committed by André Silva
parent 1295260f2b
commit 1d5cd20c44
8 changed files with 195 additions and 61 deletions
@@ -34,6 +34,10 @@ pub trait ClientExt<Block: BlockT>: Sized {
fn import(&self, origin: BlockOrigin, block: Block)
-> Result<(), ConsensusError>;
/// Import a block and make it our best block if possible.
fn import_as_best(&self, origin: BlockOrigin, block: Block)
-> Result<(), ConsensusError>;
/// Import block with justification, finalizes block.
fn import_justified(
&self,
@@ -78,6 +82,24 @@ 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_best(&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: false,
auxiliary: Vec::new(),
fork_choice: ForkChoiceStrategy::Custom(true),
};
BlockImport::import_block(&mut (&*self), import, HashMap::new()).map(|_| ())
}
fn import_justified(
&self,
origin: BlockOrigin,