Finality notification streams (#791)

* finalization for in_mem

* fetch last finalized block

* pruning: use canonical term instead of final

* finalize blocks in full node

* begin to port light client DB

* add tree-route

* keep number index consistent in full nodes

* fix tests

* disable cache and finish porting light client

* add AsMut to system module

* final leaf is always best

* fix all tests

* Fix comment and trace

* removed unused Into call

* add comment on behavior of `finalize_block`

* move `tree_route` to client common

* tree_route tests

* return slices in TreeRoute

* apply finality up to parent

* add `finalize_block` call

* adjust formatting

* finality notifications and add last finalized block to chain info

* exhaustive match and comments

* fix sync tests by using non-instant finality
This commit is contained in:
Robert Habermeier
2018-09-24 17:45:37 +01:00
committed by Arkadiy Paronyan
parent ef97973178
commit b02c274374
14 changed files with 665 additions and 225 deletions
+10 -3
View File
@@ -18,7 +18,7 @@
use client::{self, Client};
use keyring::Keyring;
use runtime_primitives::StorageMap;
use runtime_primitives::{generic::BlockId, StorageMap};
use runtime::genesismap::{GenesisConfig, additional_storage_with_genesis};
use executor::NativeExecutor;
use runtime;
@@ -30,9 +30,12 @@ pub trait TestClient {
/// Crates new client instance for tests.
fn new_for_tests() -> Self;
/// Justify and import block to the chain. Instant finality.
/// Justify and import block to the chain. No finality.
fn justify_and_import(&self, origin: client::BlockOrigin, block: runtime::Block) -> client::error::Result<()>;
/// Finalize a block.
fn finalize_block(&self, id: BlockId<runtime::Block>) -> client::error::Result<()>;
/// Returns hash of the genesis block.
fn genesis_hash(&self) -> runtime::Hash;
}
@@ -45,11 +48,15 @@ impl TestClient for Client<Backend, Executor, runtime::Block> {
fn justify_and_import(&self, origin: client::BlockOrigin, block: runtime::Block) -> client::error::Result<()> {
let justification = fake_justify(&block.header);
let justified = self.check_justification(block.header, justification)?;
self.import_block(origin, justified, Some(block.extrinsics), true)?;
self.import_block(origin, justified, Some(block.extrinsics), false)?;
Ok(())
}
fn finalize_block(&self, id: BlockId<runtime::Block>) -> client::error::Result<()> {
self.finalize_block(id, true)
}
fn genesis_hash(&self) -> runtime::Hash {
self.block_hash(0).unwrap().unwrap()
}