Remove all (non-dev) client references from frame, activate dependency enforcer (#4184)

* Move transaction pool to primitives

* move backend, errors into primitives

* remove unused client depencies

* Move rpc-api into primitives

* Move peerset back to client

* Move rpc/api back to client, move palette/support/rpc into utils

* move support-rpc into subfolder

* move system-rpc into utils

* move transaction-pool  and -graph back into client

* fix broken imports

* Clean up test primitives

* Make support test utils independent of frame

* remove unnecessary node dependencies from service

* Reactivate dependency script:
 - only enforce the now achieved status quo will remain
 - allow for primitives to depend on /client for now without failing
 - more discriptive error message so people understand, what it wants
 - minor fix to differentiative between ../client and /client (which may be a subfolder)
 - don't allow this to fail anylonger.

* fix doc comment

* 'Should not' rather than 'must not'.

* Revert unwanted dependency changes

* fix faulty import

* fixup derive_more version

* fix wrong import path
This commit is contained in:
Benjamin Kampmann
2019-11-26 21:38:28 +01:00
committed by GitHub
parent b2aab98e69
commit bd652793db
130 changed files with 836 additions and 816 deletions
+50 -51
View File
@@ -30,10 +30,9 @@ use state_machine::backend::{Backend as StateBackend, InMemory};
use state_machine::{self, InMemoryChangesTrieStorage, ChangesTrieAnchorBlockId, ChangesTrieTransaction};
use hash_db::{Hasher, Prefix};
use trie::MemoryDB;
use header_metadata::{CachedHeaderMetadata, HeaderMetadata};
use sp_blockchain::{CachedHeaderMetadata, HeaderMetadata};
use client_api::{
error,
backend::{self, NewBlockState, StorageCollection, ChildStorageCollection},
blockchain::{
self, BlockStatus, HeaderBackend, well_known_cache_keys::Id as CacheKeyId
@@ -158,7 +157,7 @@ impl<Block: BlockT> Blockchain<Block> {
justification: Option<Justification>,
body: Option<Vec<<Block as BlockT>::Extrinsic>>,
new_state: NewBlockState,
) -> client_api::error::Result<()> {
) -> sp_blockchain::Result<()> {
let number = header.number().clone();
if new_state.is_best() {
self.apply_head(&header)?;
@@ -208,16 +207,16 @@ impl<Block: BlockT> Blockchain<Block> {
}
/// Set an existing block as head.
pub fn set_head(&self, id: BlockId<Block>) -> error::Result<()> {
pub fn set_head(&self, id: BlockId<Block>) -> sp_blockchain::Result<()> {
let header = match self.header(id)? {
Some(h) => h,
None => return Err(error::Error::UnknownBlock(format!("{}", id))),
None => return Err(sp_blockchain::Error::UnknownBlock(format!("{}", id))),
};
self.apply_head(&header)
}
fn apply_head(&self, header: &<Block as BlockT>::Header) -> error::Result<()> {
fn apply_head(&self, header: &<Block as BlockT>::Header) -> sp_blockchain::Result<()> {
let hash = header.hash();
let number = header.number();
@@ -228,7 +227,7 @@ impl<Block: BlockT> Blockchain<Block> {
if &best_hash == header.parent_hash() {
None
} else {
let route = header_metadata::tree_route(self, best_hash, *header.parent_hash())?;
let route = sp_blockchain::tree_route(self, best_hash, *header.parent_hash())?;
Some(route)
}
};
@@ -255,10 +254,10 @@ impl<Block: BlockT> Blockchain<Block> {
Ok(())
}
fn finalize_header(&self, id: BlockId<Block>, justification: Option<Justification>) -> error::Result<()> {
fn finalize_header(&self, id: BlockId<Block>, justification: Option<Justification>) -> sp_blockchain::Result<()> {
let hash = match self.header(id)? {
Some(h) => h.hash(),
None => return Err(error::Error::UnknownBlock(format!("{}", id))),
None => return Err(sp_blockchain::Error::UnknownBlock(format!("{}", id))),
};
let mut storage = self.storage.write();
@@ -290,7 +289,7 @@ impl<Block: BlockT> Blockchain<Block> {
}
impl<Block: BlockT> HeaderBackend<Block> for Blockchain<Block> {
fn header(&self, id: BlockId<Block>) -> error::Result<Option<<Block as BlockT>::Header>> {
fn header(&self, id: BlockId<Block>) -> sp_blockchain::Result<Option<<Block as BlockT>::Header>> {
Ok(self.id(id).and_then(|hash| {
self.storage.read().blocks.get(&hash).map(|b| b.header().clone())
}))
@@ -307,28 +306,28 @@ impl<Block: BlockT> HeaderBackend<Block> for Blockchain<Block> {
}
}
fn status(&self, id: BlockId<Block>) -> error::Result<BlockStatus> {
fn status(&self, id: BlockId<Block>) -> sp_blockchain::Result<BlockStatus> {
match self.id(id).map_or(false, |hash| self.storage.read().blocks.contains_key(&hash)) {
true => Ok(BlockStatus::InChain),
false => Ok(BlockStatus::Unknown),
}
}
fn number(&self, hash: Block::Hash) -> error::Result<Option<NumberFor<Block>>> {
fn number(&self, hash: Block::Hash) -> sp_blockchain::Result<Option<NumberFor<Block>>> {
Ok(self.storage.read().blocks.get(&hash).map(|b| *b.header().number()))
}
fn hash(&self, number: <<Block as BlockT>::Header as HeaderT>::Number) -> error::Result<Option<Block::Hash>> {
fn hash(&self, number: <<Block as BlockT>::Header as HeaderT>::Number) -> sp_blockchain::Result<Option<Block::Hash>> {
Ok(self.id(BlockId::Number(number)))
}
}
impl<Block: BlockT> HeaderMetadata<Block> for Blockchain<Block> {
type Error = error::Error;
type Error = sp_blockchain::Error;
fn header_metadata(&self, hash: Block::Hash) -> Result<CachedHeaderMetadata<Block>, Self::Error> {
self.header(BlockId::hash(hash))?.map(|header| CachedHeaderMetadata::from(&header))
.ok_or(error::Error::UnknownBlock(format!("header not found: {}", hash)))
.ok_or(sp_blockchain::Error::UnknownBlock(format!("header not found: {}", hash)))
}
fn insert_header_metadata(&self, _hash: Block::Hash, _metadata: CachedHeaderMetadata<Block>) {
@@ -340,20 +339,20 @@ impl<Block: BlockT> HeaderMetadata<Block> for Blockchain<Block> {
}
impl<Block: BlockT> blockchain::Backend<Block> for Blockchain<Block> {
fn body(&self, id: BlockId<Block>) -> error::Result<Option<Vec<<Block as BlockT>::Extrinsic>>> {
fn body(&self, id: BlockId<Block>) -> sp_blockchain::Result<Option<Vec<<Block as BlockT>::Extrinsic>>> {
Ok(self.id(id).and_then(|hash| {
self.storage.read().blocks.get(&hash)
.and_then(|b| b.extrinsics().map(|x| x.to_vec()))
}))
}
fn justification(&self, id: BlockId<Block>) -> error::Result<Option<Justification>> {
fn justification(&self, id: BlockId<Block>) -> sp_blockchain::Result<Option<Justification>> {
Ok(self.id(id).and_then(|hash| self.storage.read().blocks.get(&hash).and_then(|b|
b.justification().map(|x| x.clone()))
))
}
fn last_finalized(&self) -> error::Result<Block::Hash> {
fn last_finalized(&self) -> sp_blockchain::Result<Block::Hash> {
Ok(self.storage.read().finalized_hash.clone())
}
@@ -361,11 +360,11 @@ impl<Block: BlockT> blockchain::Backend<Block> for Blockchain<Block> {
None
}
fn leaves(&self) -> error::Result<Vec<Block::Hash>> {
fn leaves(&self) -> sp_blockchain::Result<Vec<Block::Hash>> {
Ok(self.storage.read().leaves.hashes())
}
fn children(&self, _parent_hash: Block::Hash) -> error::Result<Vec<Block::Hash>> {
fn children(&self, _parent_hash: Block::Hash) -> sp_blockchain::Result<Vec<Block::Hash>> {
unimplemented!()
}
}
@@ -383,7 +382,7 @@ impl<Block: BlockT> backend::AuxStore for Blockchain<Block> {
'c: 'a,
I: IntoIterator<Item=&'a(&'c [u8], &'c [u8])>,
D: IntoIterator<Item=&'a &'b [u8]>,
>(&self, insert: I, delete: D) -> error::Result<()> {
>(&self, insert: I, delete: D) -> sp_blockchain::Result<()> {
let mut storage = self.storage.write();
for (k, v) in insert {
storage.aux.insert(k.to_vec(), v.to_vec());
@@ -394,7 +393,7 @@ impl<Block: BlockT> backend::AuxStore for Blockchain<Block> {
Ok(())
}
fn get_aux(&self, key: &[u8]) -> error::Result<Option<Vec<u8>>> {
fn get_aux(&self, key: &[u8]) -> sp_blockchain::Result<Option<Vec<u8>>> {
Ok(self.storage.read().aux.get(key).cloned())
}
}
@@ -409,7 +408,7 @@ impl<Block: BlockT> client_api::light::Storage<Block> for Blockchain<Block>
_cache: HashMap<CacheKeyId, Vec<u8>>,
state: NewBlockState,
aux_ops: Vec<(Vec<u8>, Option<Vec<u8>>)>,
) -> error::Result<()> {
) -> sp_blockchain::Result<()> {
let hash = header.hash();
self.insert(hash, header, None, None, state)?;
@@ -417,15 +416,15 @@ impl<Block: BlockT> client_api::light::Storage<Block> for Blockchain<Block>
Ok(())
}
fn set_head(&self, id: BlockId<Block>) -> error::Result<()> {
fn set_head(&self, id: BlockId<Block>) -> sp_blockchain::Result<()> {
Blockchain::set_head(self, id)
}
fn last_finalized(&self) -> error::Result<Block::Hash> {
fn last_finalized(&self) -> sp_blockchain::Result<Block::Hash> {
Ok(self.storage.read().finalized_hash.clone())
}
fn finalize_header(&self, id: BlockId<Block>) -> error::Result<()> {
fn finalize_header(&self, id: BlockId<Block>) -> sp_blockchain::Result<()> {
Blockchain::finalize_header(self, id, None)
}
@@ -433,18 +432,18 @@ impl<Block: BlockT> client_api::light::Storage<Block> for Blockchain<Block>
&self,
_cht_size: NumberFor<Block>,
block: NumberFor<Block>,
) -> error::Result<Block::Hash> {
) -> sp_blockchain::Result<Block::Hash> {
self.storage.read().header_cht_roots.get(&block).cloned()
.ok_or_else(|| error::Error::Backend(format!("Header CHT for block {} not exists", block)))
.ok_or_else(|| sp_blockchain::Error::Backend(format!("Header CHT for block {} not exists", block)))
}
fn changes_trie_cht_root(
&self,
_cht_size: NumberFor<Block>,
block: NumberFor<Block>,
) -> error::Result<Block::Hash> {
) -> sp_blockchain::Result<Block::Hash> {
self.storage.read().changes_trie_cht_roots.get(&block).cloned()
.ok_or_else(|| error::Error::Backend(format!("Changes trie CHT for block {} not exists", block)))
.ok_or_else(|| sp_blockchain::Error::Backend(format!("Changes trie CHT for block {} not exists", block)))
}
fn cache(&self) -> Option<Arc<dyn blockchain::Cache<Block>>> {
@@ -473,7 +472,7 @@ where
{
type State = InMemory<H>;
fn state(&self) -> error::Result<Option<&Self::State>> {
fn state(&self) -> sp_blockchain::Result<Option<&Self::State>> {
Ok(Some(&self.old_state))
}
@@ -483,7 +482,7 @@ where
body: Option<Vec<<Block as BlockT>::Extrinsic>>,
justification: Option<Justification>,
state: NewBlockState,
) -> error::Result<()> {
) -> sp_blockchain::Result<()> {
assert!(self.pending_block.is_none(), "Only one block per operation is allowed");
self.pending_block = Some(PendingBlock {
block: StoredBlock::new(header, body, justification),
@@ -496,17 +495,17 @@ where
self.pending_cache = cache;
}
fn update_db_storage(&mut self, update: <InMemory<H> as StateBackend<H>>::Transaction) -> error::Result<()> {
fn update_db_storage(&mut self, update: <InMemory<H> as StateBackend<H>>::Transaction) -> sp_blockchain::Result<()> {
self.new_state = Some(self.old_state.update(update));
Ok(())
}
fn update_changes_trie(&mut self, update: ChangesTrieTransaction<H, NumberFor<Block>>) -> error::Result<()> {
fn update_changes_trie(&mut self, update: ChangesTrieTransaction<H, NumberFor<Block>>) -> sp_blockchain::Result<()> {
self.changes_trie_update = Some(update.0);
Ok(())
}
fn reset_storage(&mut self, top: StorageOverlay, children: ChildrenStorageOverlay) -> error::Result<H::Out> {
fn reset_storage(&mut self, top: StorageOverlay, children: ChildrenStorageOverlay) -> sp_blockchain::Result<H::Out> {
check_genesis_storage(&top, &children)?;
let child_delta = children.into_iter()
@@ -522,7 +521,7 @@ where
Ok(root)
}
fn insert_aux<I>(&mut self, ops: I) -> error::Result<()>
fn insert_aux<I>(&mut self, ops: I) -> sp_blockchain::Result<()>
where I: IntoIterator<Item=(Vec<u8>, Option<Vec<u8>>)>
{
self.aux.append(&mut ops.into_iter().collect());
@@ -533,16 +532,16 @@ where
&mut self,
_update: StorageCollection,
_child_update: ChildStorageCollection,
) -> error::Result<()> {
) -> sp_blockchain::Result<()> {
Ok(())
}
fn mark_finalized(&mut self, block: BlockId<Block>, justification: Option<Justification>) -> error::Result<()> {
fn mark_finalized(&mut self, block: BlockId<Block>, justification: Option<Justification>) -> sp_blockchain::Result<()> {
self.finalized_blocks.push((block, justification));
Ok(())
}
fn mark_head(&mut self, block: BlockId<Block>) -> error::Result<()> {
fn mark_head(&mut self, block: BlockId<Block>) -> sp_blockchain::Result<()> {
assert!(self.pending_block.is_none(), "Only one set block per operation is allowed");
self.set_head = Some(block);
Ok(())
@@ -594,11 +593,11 @@ where
'c: 'a,
I: IntoIterator<Item=&'a(&'c [u8], &'c [u8])>,
D: IntoIterator<Item=&'a &'b [u8]>,
>(&self, insert: I, delete: D) -> error::Result<()> {
>(&self, insert: I, delete: D) -> sp_blockchain::Result<()> {
self.blockchain.insert_aux(insert, delete)
}
fn get_aux(&self, key: &[u8]) -> error::Result<Option<Vec<u8>>> {
fn get_aux(&self, key: &[u8]) -> sp_blockchain::Result<Option<Vec<u8>>> {
self.blockchain.get_aux(key)
}
}
@@ -615,7 +614,7 @@ where
type ChangesTrieStorage = ChangesTrieStorage<Block, H>;
type OffchainStorage = OffchainStorage;
fn begin_operation(&self) -> error::Result<Self::BlockImportOperation> {
fn begin_operation(&self) -> sp_blockchain::Result<Self::BlockImportOperation> {
let old_state = self.state_at(BlockId::Hash(Default::default()))?;
Ok(BlockImportOperation {
pending_block: None,
@@ -629,12 +628,12 @@ where
})
}
fn begin_state_operation(&self, operation: &mut Self::BlockImportOperation, block: BlockId<Block>) -> error::Result<()> {
fn begin_state_operation(&self, operation: &mut Self::BlockImportOperation, block: BlockId<Block>) -> sp_blockchain::Result<()> {
operation.old_state = self.state_at(block)?;
Ok(())
}
fn commit_operation(&self, operation: Self::BlockImportOperation) -> error::Result<()> {
fn commit_operation(&self, operation: Self::BlockImportOperation) -> sp_blockchain::Result<()> {
if !operation.finalized_blocks.is_empty() {
for (block, justification) in operation.finalized_blocks {
self.blockchain.finalize_header(block, justification)?;
@@ -674,7 +673,7 @@ where
Ok(())
}
fn finalize_block(&self, block: BlockId<Block>, justification: Option<Justification>) -> error::Result<()> {
fn finalize_block(&self, block: BlockId<Block>, justification: Option<Justification>) -> sp_blockchain::Result<()> {
self.blockchain.finalize_header(block, justification)
}
@@ -694,7 +693,7 @@ where
None
}
fn state_at(&self, block: BlockId<Block>) -> error::Result<Self::State> {
fn state_at(&self, block: BlockId<Block>) -> sp_blockchain::Result<Self::State> {
match block {
BlockId::Hash(h) if h == Default::default() => {
return Ok(Self::State::default());
@@ -704,11 +703,11 @@ where
match self.blockchain.id(block).and_then(|id| self.states.read().get(&id).cloned()) {
Some(state) => Ok(state),
None => Err(error::Error::UnknownBlock(format!("{}", block))),
None => Err(sp_blockchain::Error::UnknownBlock(format!("{}", block))),
}
}
fn revert(&self, _n: NumberFor<Block>) -> error::Result<NumberFor<Block>> {
fn revert(&self, _n: NumberFor<Block>) -> sp_blockchain::Result<NumberFor<Block>> {
Ok(Zero::zero())
}
@@ -797,13 +796,13 @@ impl<Block, H> state_machine::ChangesTrieStorage<H, NumberFor<Block>> for Change
}
/// Check that genesis storage is valid.
pub fn check_genesis_storage(top: &StorageOverlay, children: &ChildrenStorageOverlay) -> error::Result<()> {
pub fn check_genesis_storage(top: &StorageOverlay, children: &ChildrenStorageOverlay) -> sp_blockchain::Result<()> {
if top.iter().any(|(k, _)| well_known_keys::is_child_storage_key(k)) {
return Err(error::Error::GenesisInvalid.into());
return Err(sp_blockchain::Error::GenesisInvalid.into());
}
if children.keys().any(|child_key| !well_known_keys::is_child_storage_key(&child_key)) {
return Err(error::Error::GenesisInvalid.into());
return Err(sp_blockchain::Error::GenesisInvalid.into());
}
Ok(())