Move authorities interface from Core to consensus (#1412)

* Move authorities interface from Core to consensus

f

* notify all caches of block insert + create with up-to-date best_fin

* merged authorities_are_cached from light_grandpa_import2

* Add ProvideCache trait

* Create helper function for 'get_cache'

* Fix some formatting

* Bump impl version

* Resolve wasm conflicts

* Apply review comments

* Use try_for_each

* Move authorities interface from Core to consensus

f

* notify all caches of block insert + create with up-to-date best_fin

* merged authorities_are_cached from light_grandpa_import2

* Add ProvideCache trait

* Create helper function for 'get_cache'

* Fix some formatting

* Bump impl version

* Resolve wasm conflicts

* Apply review comments

* Use try_for_each

* Move authorities interface from Core to consensus

f

* notify all caches of block insert + create with up-to-date best_fin

* merged authorities_are_cached from light_grandpa_import2

* Add ProvideCache trait

* Create helper function for 'get_cache'

* Fix some formatting

* Bump impl version

* Resolve wasm conflicts

* Apply review comments

* Use try_for_each

* Increment impl_version

* Update lib.rs
This commit is contained in:
Stanislav Tkach
2019-03-29 18:41:22 +02:00
committed by Gav Wood
parent 55788fdf77
commit cbfc36b39f
44 changed files with 650 additions and 409 deletions
+14 -8
View File
@@ -17,16 +17,16 @@
//! Light client blockchin backend. Only stores headers and justifications of recent
//! blocks. CHT roots are stored for headers of ancient blocks.
use std::sync::Weak;
use std::{sync::{Weak, Arc}, collections::HashMap};
use futures::{Future, IntoFuture};
use parking_lot::Mutex;
use runtime_primitives::{Justification, generic::BlockId};
use runtime_primitives::traits::{Block as BlockT, Header as HeaderT, NumberFor, Zero, AuthorityIdFor};
use runtime_primitives::traits::{Block as BlockT, Header as HeaderT, NumberFor, Zero};
use crate::backend::{AuxStore, NewBlockState};
use crate::blockchain::{Backend as BlockchainBackend, BlockStatus, Cache as BlockchainCache,
HeaderBackend as BlockchainHeaderBackend, Info as BlockchainInfo};
HeaderBackend as BlockchainHeaderBackend, Info as BlockchainInfo, ProvideCache};
use crate::cht;
use crate::error::{ErrorKind as ClientErrorKind, Result as ClientResult};
use crate::light::fetcher::{Fetcher, RemoteHeaderRequest};
@@ -40,7 +40,7 @@ pub trait Storage<Block: BlockT>: AuxStore + BlockchainHeaderBackend<Block> {
fn import_header(
&self,
header: Block::Header,
authorities: Option<Vec<AuthorityIdFor<Block>>>,
cache: HashMap<Vec<u8>, Vec<u8>>,
state: NewBlockState,
aux_ops: Vec<(Vec<u8>, Option<Vec<u8>>)>,
) -> ClientResult<()>;
@@ -61,7 +61,7 @@ pub trait Storage<Block: BlockT>: AuxStore + BlockchainHeaderBackend<Block> {
fn changes_trie_cht_root(&self, cht_size: u64, block: NumberFor<Block>) -> ClientResult<Block::Hash>;
/// Get storage cache.
fn cache(&self) -> Option<&BlockchainCache<Block>>;
fn cache(&self) -> Option<Arc<BlockchainCache<Block>>>;
}
/// Light client blockchain.
@@ -156,7 +156,7 @@ impl<S, F, Block> BlockchainBackend<Block> for Blockchain<S, F> where Block: Blo
self.storage.last_finalized()
}
fn cache(&self) -> Option<&BlockchainCache<Block>> {
fn cache(&self) -> Option<Arc<BlockchainCache<Block>>> {
self.storage.cache()
}
@@ -169,6 +169,12 @@ impl<S, F, Block> BlockchainBackend<Block> for Blockchain<S, F> where Block: Blo
}
}
impl<S: Storage<Block>, F, Block: BlockT> ProvideCache<Block> for Blockchain<S, F> {
fn cache(&self) -> Option<Arc<BlockchainCache<Block>>> {
self.storage.cache()
}
}
#[cfg(test)]
pub mod tests {
use std::collections::HashMap;
@@ -246,7 +252,7 @@ pub mod tests {
fn import_header(
&self,
_header: Header,
_authorities: Option<Vec<AuthorityIdFor<Block>>>,
_cache: HashMap<Vec<u8>, Vec<u8>>,
_state: NewBlockState,
_aux_ops: Vec<(Vec<u8>, Option<Vec<u8>>)>,
) -> ClientResult<()> {
@@ -278,7 +284,7 @@ pub mod tests {
).into())
}
fn cache(&self) -> Option<&BlockchainCache<Block>> {
fn cache(&self) -> Option<Arc<BlockchainCache<Block>>> {
None
}
}