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
+18 -4
View File
@@ -26,7 +26,14 @@ use primitives::{Blake2Hasher, RlpCodec};
/// Local client abstraction for the network.
pub trait Client<Block: BlockT>: Send + Sync {
/// Import a new block. Parent is supposed to be existing in the blockchain.
fn import(&self, origin: BlockOrigin, header: Block::Header, justification: Justification<Block::Hash>, body: Option<Vec<Block::Extrinsic>>) -> Result<ImportResult, Error>;
fn import(
&self,
origin: BlockOrigin,
header: Block::Header,
justification: Justification<Block::Hash>,
body: Option<Vec<Block::Extrinsic>>,
finalized: bool,
) -> Result<ImportResult, Error>;
/// Get blockchain info.
fn info(&self) -> Result<ClientInfo<Block>, Error>;
@@ -61,10 +68,17 @@ impl<B, E, Block> Client<Block> for SubstrateClient<B, E, Block> where
E: CallExecutor<Block, Blake2Hasher, RlpCodec> + Send + Sync + 'static,
Block: BlockT,
{
fn import(&self, origin: BlockOrigin, header: Block::Header, justification: Justification<Block::Hash>, body: Option<Vec<Block::Extrinsic>>) -> Result<ImportResult, Error> {
// TODO: defer justification check and non-instant finality.
fn import(
&self,
origin: BlockOrigin,
header: Block::Header,
justification: Justification<Block::Hash>,
body: Option<Vec<Block::Extrinsic>>,
finalized: bool,
) -> Result<ImportResult, Error> {
// TODO: defer justification check and add finality.
let justified_header = self.check_justification(header, justification.into())?;
(self as &SubstrateClient<B, E, Block>).import_block(origin, justified_header, body, true)
(self as &SubstrateClient<B, E, Block>).import_block(origin, justified_header, body, finalized)
}
fn info(&self) -> Result<ClientInfo<Block>, Error> {