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
+8 -10
View File
@@ -31,9 +31,7 @@ use primitives::{
traits::CodeExecutor,
};
use sr_api::{ProofRecorder, InitializeBlock};
use client_api::{
error, backend, call_executor::CallExecutor,
};
use client_api::{backend, call_executor::CallExecutor};
/// Call executor that executes methods locally, querying all required
/// data from local backend.
@@ -79,7 +77,7 @@ where
call_data: &[u8],
strategy: ExecutionStrategy,
extensions: Option<Extensions>,
) -> error::Result<Vec<u8>> {
) -> sp_blockchain::Result<Vec<u8>> {
let mut changes = OverlayedChanges::default();
let state = self.backend.state_at(*id)?;
let return_data = StateMachine::new(
@@ -105,7 +103,7 @@ where
fn contextual_call<
'a,
IB: Fn() -> error::Result<()>,
IB: Fn() -> sp_blockchain::Result<()>,
EM: Fn(
Result<NativeOrEncoded<R>, Self::Error>,
Result<NativeOrEncoded<R>, Self::Error>
@@ -124,7 +122,7 @@ where
native_call: Option<NC>,
recorder: &Option<ProofRecorder<Block>>,
extensions: Option<Extensions>,
) -> Result<NativeOrEncoded<R>, error::Error> where ExecutionManager<EM>: Clone {
) -> Result<NativeOrEncoded<R>, sp_blockchain::Error> where ExecutionManager<EM>: Clone {
match initialize_block {
InitializeBlock::Do(ref init_block)
if init_block.borrow().as_ref().map(|id| id != at).unwrap_or(true) => {
@@ -189,7 +187,7 @@ where
Ok(result)
}
fn runtime_version(&self, id: &BlockId<Block>) -> error::Result<RuntimeVersion> {
fn runtime_version(&self, id: &BlockId<Block>) -> sp_blockchain::Result<RuntimeVersion> {
let mut overlay = OverlayedChanges::default();
let state = self.backend.state_at(*id)?;
@@ -204,7 +202,7 @@ where
let _lock = self.backend.get_import_lock().read();
self.backend.destroy_state(state)?;
}
version.ok_or(error::Error::VersionInvalid.into())
version.ok_or(sp_blockchain::Error::VersionInvalid.into())
}
fn call_at_state<
@@ -223,7 +221,7 @@ where
manager: ExecutionManager<F>,
native_call: Option<NC>,
extensions: Option<Extensions>,
) -> error::Result<(
) -> sp_blockchain::Result<(
NativeOrEncoded<R>,
(S::Transaction, <Blake2Hasher as Hasher>::Out),
Option<ChangesTrieTransaction<Blake2Hasher, NumberFor<Block>>>,
@@ -255,7 +253,7 @@ where
overlay: &mut OverlayedChanges,
method: &str,
call_data: &[u8]
) -> Result<(Vec<u8>, StorageProof), error::Error> {
) -> Result<(Vec<u8>, StorageProof), sp_blockchain::Error> {
state_machine::prove_execution_on_trie_backend(
trie_state,
overlay,
+1 -1
View File
@@ -33,7 +33,7 @@ use state_machine::backend::InMemory as InMemoryState;
use state_machine::{MemoryDB, TrieBackend, Backend as StateBackend, StorageProof,
prove_read_on_trie_backend, read_proof_check, read_proof_check_on_proving_backend};
use client_api::error::{Error as ClientError, Result as ClientResult};
use sp_blockchain::{Error as ClientError, Result as ClientResult};
/// The size of each CHT. This value is passed to every CHT-related function from
/// production code. Other values are passed from tests.
+96 -97
View File
@@ -52,7 +52,12 @@ use consensus::{
ImportResult, BlockOrigin, ForkChoiceStrategy,
SelectChain, self,
};
use header_metadata::{HeaderMetadata, CachedHeaderMetadata};
use sp_blockchain::{self as blockchain,
Backend as ChainBackend,
HeaderBackend as ChainHeaderBackend, ProvideCache, Cache,
well_known_cache_keys::Id as CacheKeyId,
HeaderMetadata, CachedHeaderMetadata,
};
use sr_api::{CallRuntimeAt, ConstructRuntimeApi, Core as CoreApi, ProofRecorder, InitializeBlock};
use block_builder::BlockBuilderApi;
@@ -62,11 +67,6 @@ pub use client_api::{
self, BlockImportOperation, PrunableStateChangesTrieStorage,
ClientImportOperation, Finalizer, ImportSummary, NewBlockState,
},
blockchain::{
self, Backend as ChainBackend,
HeaderBackend as ChainHeaderBackend, ProvideCache, Cache,
well_known_cache_keys::Id as CacheKeyId,
},
client::{
ImportNotifications, FinalityNotification, FinalityNotifications, BlockImportNotification,
ClientInfo, BlockchainEvents, BlockBody, ProvideUncles, ForkBlocks,
@@ -74,10 +74,9 @@ pub use client_api::{
},
execution_extensions::{ExecutionExtensions, ExecutionStrategies},
notifications::{StorageNotifications, StorageEventStream},
error::Error,
error,
CallExecutor,
};
use sp_blockchain::Error;
use crate::{
call_executor::LocalCallExecutor,
@@ -146,7 +145,7 @@ pub fn new_in_mem<E, Block, S, RA>(
executor: E,
genesis_storage: S,
keystore: Option<primitives::traits::BareCryptoStorePtr>,
) -> error::Result<Client<
) -> sp_blockchain::Result<Client<
in_mem::Backend<Block, Blake2Hasher>,
LocalCallExecutor<in_mem::Backend<Block, Blake2Hasher>, E>,
Block,
@@ -166,7 +165,7 @@ pub fn new_with_backend<B, E, Block, S, RA>(
executor: E,
build_genesis_storage: S,
keystore: Option<primitives::traits::BareCryptoStorePtr>,
) -> error::Result<Client<B, LocalCallExecutor<B, E>, Block, RA>>
) -> sp_blockchain::Result<Client<B, LocalCallExecutor<B, E>, Block, RA>>
where
E: CodeExecutor + RuntimeInfo,
S: BuildStorage,
@@ -198,7 +197,7 @@ impl<B, E, Block, RA> Client<B, E, Block, RA> where
build_genesis_storage: S,
fork_blocks: ForkBlocks<Block>,
execution_extensions: ExecutionExtensions<Block>,
) -> error::Result<Self> {
) -> sp_blockchain::Result<Self> {
if backend.blockchain().header(BlockId::Number(Zero::zero()))?.is_none() {
let (genesis_storage, children_genesis_storage) = build_genesis_storage.build_storage()?;
let mut op = backend.begin_operation()?;
@@ -237,29 +236,29 @@ impl<B, E, Block, RA> Client<B, E, Block, RA> where
}
/// Get a reference to the state at a given block.
pub fn state_at(&self, block: &BlockId<Block>) -> error::Result<B::State> {
pub fn state_at(&self, block: &BlockId<Block>) -> sp_blockchain::Result<B::State> {
self.backend.state_at(*block)
}
/// Given a `BlockId` and a key prefix, return the matching child storage keys in that block.
pub fn storage_keys(&self, id: &BlockId<Block>, key_prefix: &StorageKey) -> error::Result<Vec<StorageKey>> {
pub fn storage_keys(&self, id: &BlockId<Block>, key_prefix: &StorageKey) -> sp_blockchain::Result<Vec<StorageKey>> {
let keys = self.state_at(id)?.keys(&key_prefix.0).into_iter().map(StorageKey).collect();
Ok(keys)
}
/// Given a `BlockId` and a key, return the value under the key in that block.
pub fn storage(&self, id: &BlockId<Block>, key: &StorageKey) -> error::Result<Option<StorageData>> {
pub fn storage(&self, id: &BlockId<Block>, key: &StorageKey) -> sp_blockchain::Result<Option<StorageData>> {
Ok(self.state_at(id)?
.storage(&key.0).map_err(|e| error::Error::from_state(Box::new(e)))?
.storage(&key.0).map_err(|e| sp_blockchain::Error::from_state(Box::new(e)))?
.map(StorageData)
)
}
/// Given a `BlockId` and a key, return the value under the hash in that block.
pub fn storage_hash(&self, id: &BlockId<Block>, key: &StorageKey)
-> error::Result<Option<Block::Hash>> {
-> sp_blockchain::Result<Option<Block::Hash>> {
Ok(self.state_at(id)?
.storage_hash(&key.0).map_err(|e| error::Error::from_state(Box::new(e)))?
.storage_hash(&key.0).map_err(|e| sp_blockchain::Error::from_state(Box::new(e)))?
)
}
@@ -269,7 +268,7 @@ impl<B, E, Block, RA> Client<B, E, Block, RA> where
id: &BlockId<Block>,
child_storage_key: &StorageKey,
key_prefix: &StorageKey
) -> error::Result<Vec<StorageKey>> {
) -> sp_blockchain::Result<Vec<StorageKey>> {
let keys = self.state_at(id)?
.child_keys(&child_storage_key.0, &key_prefix.0)
.into_iter()
@@ -284,9 +283,9 @@ impl<B, E, Block, RA> Client<B, E, Block, RA> where
id: &BlockId<Block>,
child_storage_key: &StorageKey,
key: &StorageKey
) -> error::Result<Option<StorageData>> {
) -> sp_blockchain::Result<Option<StorageData>> {
Ok(self.state_at(id)?
.child_storage(&child_storage_key.0, &key.0).map_err(|e| error::Error::from_state(Box::new(e)))?
.child_storage(&child_storage_key.0, &key.0).map_err(|e| sp_blockchain::Error::from_state(Box::new(e)))?
.map(StorageData))
}
@@ -296,21 +295,21 @@ impl<B, E, Block, RA> Client<B, E, Block, RA> where
id: &BlockId<Block>,
child_storage_key: &StorageKey,
key: &StorageKey
) -> error::Result<Option<Block::Hash>> {
) -> sp_blockchain::Result<Option<Block::Hash>> {
Ok(self.state_at(id)?
.child_storage_hash(&child_storage_key.0, &key.0).map_err(|e| error::Error::from_state(Box::new(e)))?
.child_storage_hash(&child_storage_key.0, &key.0).map_err(|e| sp_blockchain::Error::from_state(Box::new(e)))?
)
}
/// Get the code at a given block.
pub fn code_at(&self, id: &BlockId<Block>) -> error::Result<Vec<u8>> {
pub fn code_at(&self, id: &BlockId<Block>) -> sp_blockchain::Result<Vec<u8>> {
Ok(self.storage(id, &StorageKey(well_known_keys::CODE.to_vec()))?
.expect("None is returned if there's no value stored for the given key;\
':code' key is always defined; qed").0)
}
/// Get the RuntimeVersion at a given block.
pub fn runtime_version_at(&self, id: &BlockId<Block>) -> error::Result<RuntimeVersion> {
pub fn runtime_version_at(&self, id: &BlockId<Block>) -> sp_blockchain::Result<RuntimeVersion> {
self.executor.runtime_version(id)
}
@@ -320,7 +319,7 @@ impl<B, E, Block, RA> Client<B, E, Block, RA> where
}
/// Reads storage value at a given block + key, returning read proof.
pub fn read_proof<I>(&self, id: &BlockId<Block>, keys: I) -> error::Result<StorageProof> where
pub fn read_proof<I>(&self, id: &BlockId<Block>, keys: I) -> sp_blockchain::Result<StorageProof> where
I: IntoIterator,
I::Item: AsRef<[u8]>,
{
@@ -336,7 +335,7 @@ impl<B, E, Block, RA> Client<B, E, Block, RA> where
id: &BlockId<Block>,
storage_key: &[u8],
keys: I,
) -> error::Result<StorageProof> where
) -> sp_blockchain::Result<StorageProof> where
I: IntoIterator,
I::Item: AsRef<[u8]>,
{
@@ -353,21 +352,21 @@ impl<B, E, Block, RA> Client<B, E, Block, RA> where
id: &BlockId<Block>,
method: &str,
call_data: &[u8]
) -> error::Result<(Vec<u8>, StorageProof)> {
) -> sp_blockchain::Result<(Vec<u8>, StorageProof)> {
let state = self.state_at(id)?;
let header = self.prepare_environment_block(id)?;
prove_execution(state, header, &self.executor, method, call_data)
}
/// Reads given header and generates CHT-based header proof.
pub fn header_proof(&self, id: &BlockId<Block>) -> error::Result<(Block::Header, StorageProof)> {
pub fn header_proof(&self, id: &BlockId<Block>) -> sp_blockchain::Result<(Block::Header, StorageProof)> {
self.header_proof_with_cht_size(id, cht::size())
}
/// Get block hash by number.
pub fn block_hash(&self,
block_number: <<Block as BlockT>::Header as HeaderT>::Number
) -> error::Result<Option<Block::Hash>> {
) -> sp_blockchain::Result<Option<Block::Hash>> {
self.backend.blockchain().hash(block_number)
}
@@ -376,8 +375,8 @@ impl<B, E, Block, RA> Client<B, E, Block, RA> where
&self,
id: &BlockId<Block>,
cht_size: NumberFor<Block>,
) -> error::Result<(Block::Header, StorageProof)> {
let proof_error = || error::Error::Backend(format!("Failed to generate header proof for {:?}", id));
) -> sp_blockchain::Result<(Block::Header, StorageProof)> {
let proof_error = || sp_blockchain::Error::Backend(format!("Failed to generate header proof for {:?}", id));
let header = self.backend.blockchain().expect_header(*id)?;
let block_num = *header.number();
let cht_num = cht::block_to_cht_number(cht_size, block_num).ok_or_else(proof_error)?;
@@ -401,14 +400,14 @@ impl<B, E, Block, RA> Client<B, E, Block, RA> where
&self,
first: NumberFor<Block>,
last: BlockId<Block>,
) -> error::Result<Option<(NumberFor<Block>, BlockId<Block>)>> {
) -> sp_blockchain::Result<Option<(NumberFor<Block>, BlockId<Block>)>> {
let (config, storage) = match self.require_changes_trie().ok() {
Some((config, storage)) => (config, storage),
None => return Ok(None),
};
let last_num = self.backend.blockchain().expect_block_number_from_id(&last)?;
if first > last_num {
return Err(error::Error::ChangesTrieAccessFailed("Invalid changes trie range".into()));
return Err(sp_blockchain::Error::ChangesTrieAccessFailed("Invalid changes trie range".into()));
}
let finalized_number = self.backend.blockchain().info().finalized_number;
let oldest = storage.oldest_changes_trie_block(&config, finalized_number);
@@ -426,7 +425,7 @@ impl<B, E, Block, RA> Client<B, E, Block, RA> where
last: BlockId<Block>,
storage_key: Option<&StorageKey>,
key: &StorageKey
) -> error::Result<Vec<(NumberFor<Block>, u32)>> {
) -> sp_blockchain::Result<Vec<(NumberFor<Block>, u32)>> {
let (config, storage) = self.require_changes_trie()?;
let last_number = self.backend.blockchain().expect_block_number_from_id(&last)?;
let last_hash = self.backend.blockchain().expect_block_hash_from_id(&last)?;
@@ -450,7 +449,7 @@ impl<B, E, Block, RA> Client<B, E, Block, RA> where
storage_key.as_ref().map(|sk| sk.0.as_slice()),
&key.0)
.and_then(|r| r.map(|r| r.map(|(block, tx)| (block, tx))).collect::<Result<_, _>>())
.map_err(|err| error::Error::ChangesTrieAccessFailed(err))
.map_err(|err| sp_blockchain::Error::ChangesTrieAccessFailed(err))
}
/// Get proof for computation of (block, extrinsic) pairs where key has been changed at given blocks range.
@@ -467,7 +466,7 @@ impl<B, E, Block, RA> Client<B, E, Block, RA> where
max: Block::Hash,
storage_key: Option<&StorageKey>,
key: &StorageKey,
) -> error::Result<ChangesProof<Block::Header>> {
) -> sp_blockchain::Result<ChangesProof<Block::Header>> {
self.key_changes_proof_with_cht_size(
first,
last,
@@ -489,7 +488,7 @@ impl<B, E, Block, RA> Client<B, E, Block, RA> where
storage_key: Option<&StorageKey>,
key: &StorageKey,
cht_size: NumberFor<Block>,
) -> error::Result<ChangesProof<Block::Header>> {
) -> sp_blockchain::Result<ChangesProof<Block::Header>> {
struct AccessedRootsRecorder<'a, Block: BlockT> {
storage: &'a dyn ChangesTrieStorage<Blake2Hasher, NumberFor<Block>>,
min: NumberFor<Block>,
@@ -575,7 +574,7 @@ impl<B, E, Block, RA> Client<B, E, Block, RA> where
storage_key.as_ref().map(|sk| sk.0.as_slice()),
&key.0,
)
.map_err(|err| error::Error::from(error::Error::ChangesTrieAccessFailed(err)))?;
.map_err(|err| sp_blockchain::Error::from(sp_blockchain::Error::ChangesTrieAccessFailed(err)))?;
// now gather proofs for all changes tries roots that were touched during key_changes_proof
// execution AND are unknown (i.e. replaced with CHT) to the requester
@@ -595,7 +594,7 @@ impl<B, E, Block, RA> Client<B, E, Block, RA> where
&self,
cht_size: NumberFor<Block>,
blocks: I
) -> error::Result<StorageProof> {
) -> sp_blockchain::Result<StorageProof> {
// most probably we have touched several changes tries that are parts of the single CHT
// => GroupBy changes tries by CHT number and then gather proof for the whole group at once
let mut proofs = Vec::new();
@@ -615,7 +614,7 @@ impl<B, E, Block, RA> Client<B, E, Block, RA> where
cht_size: NumberFor<Block>,
cht_num: NumberFor<Block>,
blocks: Vec<NumberFor<Block>>
) -> error::Result<StorageProof> {
) -> sp_blockchain::Result<StorageProof> {
let cht_start = cht::start_number(cht_size, cht_num);
let mut current_num = cht_start;
let cht_range = ::std::iter::from_fn(|| {
@@ -631,12 +630,12 @@ impl<B, E, Block, RA> Client<B, E, Block, RA> where
}
/// Returns changes trie configuration and storage or an error if it is not supported.
fn require_changes_trie(&self) -> error::Result<(ChangesTrieConfiguration, &B::ChangesTrieStorage)> {
fn require_changes_trie(&self) -> sp_blockchain::Result<(ChangesTrieConfiguration, &B::ChangesTrieStorage)> {
let config = self.changes_trie_config()?;
let storage = self.backend.changes_trie_storage();
match (config, storage) {
(Some(config), Some(storage)) => Ok((config, storage)),
_ => Err(error::Error::ChangesTriesNotSupported.into()),
_ => Err(sp_blockchain::Error::ChangesTriesNotSupported.into()),
}
}
@@ -644,7 +643,7 @@ impl<B, E, Block, RA> Client<B, E, Block, RA> where
pub fn new_block(
&self,
inherent_digests: DigestFor<Block>,
) -> error::Result<block_builder::BlockBuilder<Block, Self>> where
) -> sp_blockchain::Result<block_builder::BlockBuilder<Block, Self>> where
E: Clone + Send + Sync,
RA: Send + Sync,
Self: ProvideRuntimeApi,
@@ -665,7 +664,7 @@ impl<B, E, Block, RA> Client<B, E, Block, RA> where
&self,
parent: &BlockId<Block>,
inherent_digests: DigestFor<Block>,
) -> error::Result<block_builder::BlockBuilder<Block, Self>> where
) -> sp_blockchain::Result<block_builder::BlockBuilder<Block, Self>> where
E: Clone + Send + Sync,
RA: Send + Sync,
Self: ProvideRuntimeApi,
@@ -689,7 +688,7 @@ impl<B, E, Block, RA> Client<B, E, Block, RA> where
&self,
parent: &BlockId<Block>,
inherent_digests: DigestFor<Block>,
) -> error::Result<block_builder::BlockBuilder<Block, Self>> where
) -> sp_blockchain::Result<block_builder::BlockBuilder<Block, Self>> where
E: Clone + Send + Sync,
RA: Send + Sync,
Self: ProvideRuntimeApi,
@@ -707,7 +706,7 @@ impl<B, E, Block, RA> Client<B, E, Block, RA> where
/// Lock the import lock, and run operations inside.
pub fn lock_import_and_run<R, Err, F>(&self, f: F) -> Result<R, Err> where
F: FnOnce(&mut ClientImportOperation<Block, Blake2Hasher, B>) -> Result<R, Err>,
Err: From<error::Error>,
Err: From<sp_blockchain::Error>,
{
let inner = || {
let _import_lock = self.backend.get_import_lock().write();
@@ -744,7 +743,7 @@ impl<B, E, Block, RA> Client<B, E, Block, RA> where
operation: &mut ClientImportOperation<Block, Blake2Hasher, B>,
import_block: BlockImportParams<Block>,
new_cache: HashMap<CacheKeyId, Vec<u8>>,
) -> error::Result<ImportResult> where
) -> sp_blockchain::Result<ImportResult> where
E: CallExecutor<Block, Blake2Hasher> + Send + Sync + Clone,
{
let BlockImportParams {
@@ -829,7 +828,7 @@ impl<B, E, Block, RA> Client<B, E, Block, RA> where
aux: Vec<(Vec<u8>, Option<Vec<u8>>)>,
fork_choice: ForkChoiceStrategy,
enact_state: bool,
) -> error::Result<ImportResult> where
) -> sp_blockchain::Result<ImportResult> where
E: CallExecutor<Block, Blake2Hasher> + Send + Sync + Clone,
{
let parent_hash = import_headers.post().parent_hash().clone();
@@ -843,7 +842,7 @@ impl<B, E, Block, RA> Client<B, E, Block, RA> where
// the block is lower than our last finalized block so it must revert
// finality, refusing import.
if *import_headers.post().number() <= info.finalized_number {
return Err(error::Error::NotInFinalizedChain);
return Err(sp_blockchain::Error::NotInFinalizedChain);
}
// this is a fairly arbitrary choice of where to draw the line on making notifications,
@@ -902,7 +901,7 @@ impl<B, E, Block, RA> Client<B, E, Block, RA> where
};
let retracted = if is_new_best {
let route_from_best = header_metadata::tree_route(
let route_from_best = sp_blockchain::tree_route(
self.backend.blockchain(),
info.best_hash,
parent_hash,
@@ -948,7 +947,7 @@ impl<B, E, Block, RA> Client<B, E, Block, RA> where
origin: BlockOrigin,
hash: Block::Hash,
body: &[Block::Extrinsic],
) -> error::Result<(
) -> sp_blockchain::Result<(
Option<StorageUpdate<B, Block>>,
Option<Option<ChangesUpdate<Block>>>,
Option<(
@@ -1009,7 +1008,7 @@ impl<B, E, Block, RA> Client<B, E, Block, RA> where
let (top, children) = overlay.into_committed();
let children = children.map(|(sk, it)| (sk, it.collect())).collect();
if import_headers.post().state_root() != &storage_update.1 {
return Err(error::Error::InvalidStateRoot);
return Err(sp_blockchain::Error::InvalidStateRoot);
}
Ok((Some(storage_update.0), Some(changes_update), Some((top.collect(), children))))
@@ -1025,7 +1024,7 @@ impl<B, E, Block, RA> Client<B, E, Block, RA> where
justification: Option<Justification>,
best_block: Block::Hash,
notify: bool,
) -> error::Result<()> {
) -> sp_blockchain::Result<()> {
// find tree route from last finalized to given block.
let last_finalized = self.backend.blockchain().last_finalized()?;
@@ -1034,16 +1033,16 @@ impl<B, E, Block, RA> Client<B, E, Block, RA> where
return Ok(());
}
let route_from_finalized = header_metadata::tree_route(self.backend.blockchain(), last_finalized, block)?;
let route_from_finalized = sp_blockchain::tree_route(self.backend.blockchain(), last_finalized, block)?;
if let Some(retracted) = route_from_finalized.retracted().get(0) {
warn!("Safety violation: attempted to revert finalized block {:?} which is not in the \
same chain as last finalized {:?}", retracted, last_finalized);
return Err(error::Error::NotInFinalizedChain);
return Err(sp_blockchain::Error::NotInFinalizedChain);
}
let route_from_best = header_metadata::tree_route(self.backend.blockchain(), best_block, block)?;
let route_from_best = sp_blockchain::tree_route(self.backend.blockchain(), best_block, block)?;
// if the block is not a direct ancestor of the current best chain,
// then some other block is the common ancestor.
@@ -1083,7 +1082,7 @@ impl<B, E, Block, RA> Client<B, E, Block, RA> where
fn notify_finalized(
&self,
notify_finalized: Vec<Block::Hash>,
) -> error::Result<()> {
) -> sp_blockchain::Result<()> {
let mut sinks = self.finality_notification_sinks.lock();
for finalized_hash in notify_finalized {
@@ -1106,7 +1105,7 @@ impl<B, E, Block, RA> Client<B, E, Block, RA> where
Ok(())
}
fn notify_imported(&self, notify_import: ImportSummary<Block>) -> error::Result<()> {
fn notify_imported(&self, notify_import: ImportSummary<Block>) -> sp_blockchain::Result<()> {
if let Some(storage_changes) = notify_import.storage_changes {
// TODO [ToDr] How to handle re-orgs? Should we re-emit all storage changes?
self.storage_notifications.lock()
@@ -1133,7 +1132,7 @@ impl<B, E, Block, RA> Client<B, E, Block, RA> where
/// Attempts to revert the chain by `n` blocks. Returns the number of blocks that were
/// successfully reverted.
pub fn revert(&self, n: NumberFor<Block>) -> error::Result<NumberFor<Block>> {
pub fn revert(&self, n: NumberFor<Block>) -> sp_blockchain::Result<NumberFor<Block>> {
Ok(self.backend.revert(n)?)
}
@@ -1147,7 +1146,7 @@ impl<B, E, Block, RA> Client<B, E, Block, RA> where
}
/// Get block status.
pub fn block_status(&self, id: &BlockId<Block>) -> error::Result<BlockStatus> {
pub fn block_status(&self, id: &BlockId<Block>) -> sp_blockchain::Result<BlockStatus> {
// this can probably be implemented more efficiently
if let BlockId::Hash(ref h) = id {
if self.importing_block.read().as_ref().map_or(false, |importing| h == importing) {
@@ -1171,23 +1170,23 @@ impl<B, E, Block, RA> Client<B, E, Block, RA> where
}
/// Get block header by id.
pub fn header(&self, id: &BlockId<Block>) -> error::Result<Option<<Block as BlockT>::Header>> {
pub fn header(&self, id: &BlockId<Block>) -> sp_blockchain::Result<Option<<Block as BlockT>::Header>> {
self.backend.blockchain().header(*id)
}
/// Get block body by id.
pub fn body(&self, id: &BlockId<Block>) -> error::Result<Option<Vec<<Block as BlockT>::Extrinsic>>> {
pub fn body(&self, id: &BlockId<Block>) -> sp_blockchain::Result<Option<Vec<<Block as BlockT>::Extrinsic>>> {
self.backend.blockchain().body(*id)
}
/// Get block justification set by id.
pub fn justification(&self, id: &BlockId<Block>) -> error::Result<Option<Justification>> {
pub fn justification(&self, id: &BlockId<Block>) -> sp_blockchain::Result<Option<Justification>> {
self.backend.blockchain().justification(*id)
}
/// Get full block by id.
pub fn block(&self, id: &BlockId<Block>)
-> error::Result<Option<SignedBlock<Block>>>
-> sp_blockchain::Result<Option<SignedBlock<Block>>>
{
Ok(match (self.header(id)?, self.body(id)?, self.justification(id)?) {
(Some(header), Some(extrinsics), justification) =>
@@ -1197,8 +1196,8 @@ impl<B, E, Block, RA> Client<B, E, Block, RA> where
}
/// Gets the uncles of the block with `target_hash` going back `max_generation` ancestors.
pub fn uncles(&self, target_hash: Block::Hash, max_generation: NumberFor<Block>) -> error::Result<Vec<Block::Hash>> {
let load_header = |id: Block::Hash| -> error::Result<Block::Header> {
pub fn uncles(&self, target_hash: Block::Hash, max_generation: NumberFor<Block>) -> sp_blockchain::Result<Vec<Block::Hash>> {
let load_header = |id: Block::Hash| -> sp_blockchain::Result<Block::Header> {
match self.backend.blockchain().header(BlockId::Hash(id))? {
Some(hdr) => Ok(hdr),
None => Err(Error::UnknownBlock(format!("{:?}", id))),
@@ -1230,12 +1229,12 @@ impl<B, E, Block, RA> Client<B, E, Block, RA> where
fn changes_trie_config(&self) -> Result<Option<ChangesTrieConfiguration>, Error> {
Ok(self.backend.state_at(BlockId::Number(self.backend.blockchain().info().best_number))?
.storage(well_known_keys::CHANGES_TRIE_CONFIG)
.map_err(|e| error::Error::from_state(Box::new(e)))?
.map_err(|e| sp_blockchain::Error::from_state(Box::new(e)))?
.and_then(|c| Decode::decode(&mut &*c).ok()))
}
/// Prepare in-memory header that is used in execution environment.
fn prepare_environment_block(&self, parent: &BlockId<Block>) -> error::Result<Block::Header> {
fn prepare_environment_block(&self, parent: &BlockId<Block>) -> sp_blockchain::Result<Block::Header> {
let parent_header = self.backend.blockchain().expect_header(*parent)?;
Ok(<<Block as BlockT>::Header as HeaderT>::new(
self.backend.blockchain().expect_block_number_from_id(parent)? + One::one(),
@@ -1252,7 +1251,7 @@ impl<B, E, Block, RA> HeaderMetadata<Block> for Client<B, E, Block, RA> where
E: CallExecutor<Block, Blake2Hasher>,
Block: BlockT<Hash=H256>,
{
type Error = error::Error;
type Error = sp_blockchain::Error;
fn header_metadata(&self, hash: Block::Hash) -> Result<CachedHeaderMetadata<Block>, Self::Error> {
self.backend.blockchain().header_metadata(hash)
@@ -1272,7 +1271,7 @@ impl<B, E, Block, RA> ProvideUncles<Block> for Client<B, E, Block, RA> where
E: CallExecutor<Block, Blake2Hasher>,
Block: BlockT<Hash=H256>,
{
fn uncles(&self, target_hash: Block::Hash, max_generation: NumberFor<Block>) -> error::Result<Vec<Block::Header>> {
fn uncles(&self, target_hash: Block::Hash, max_generation: NumberFor<Block>) -> sp_blockchain::Result<Vec<Block::Header>> {
Ok(Client::uncles(self, target_hash, max_generation)?
.into_iter()
.filter_map(|hash| Client::header(self, &BlockId::Hash(hash)).unwrap_or(None))
@@ -1287,7 +1286,7 @@ impl<B, E, Block, RA> ChainHeaderBackend<Block> for Client<B, E, Block, RA> wher
Block: BlockT<Hash=H256>,
RA: Send + Sync,
{
fn header(&self, id: BlockId<Block>) -> error::Result<Option<Block::Header>> {
fn header(&self, id: BlockId<Block>) -> sp_blockchain::Result<Option<Block::Header>> {
self.backend.blockchain().header(id)
}
@@ -1295,15 +1294,15 @@ impl<B, E, Block, RA> ChainHeaderBackend<Block> for Client<B, E, Block, RA> wher
self.backend.blockchain().info()
}
fn status(&self, id: BlockId<Block>) -> error::Result<blockchain::BlockStatus> {
fn status(&self, id: BlockId<Block>) -> sp_blockchain::Result<blockchain::BlockStatus> {
self.backend.blockchain().status(id)
}
fn number(&self, hash: Block::Hash) -> error::Result<Option<<<Block as BlockT>::Header as HeaderT>::Number>> {
fn number(&self, hash: Block::Hash) -> sp_blockchain::Result<Option<<<Block as BlockT>::Header as HeaderT>::Number>> {
self.backend.blockchain().number(hash)
}
fn hash(&self, number: NumberFor<Block>) -> error::Result<Option<Block::Hash>> {
fn hash(&self, number: NumberFor<Block>) -> sp_blockchain::Result<Option<Block::Hash>> {
self.backend.blockchain().hash(number)
}
}
@@ -1316,11 +1315,11 @@ impl<B, E, Block, RA> sr_primitives::traits::BlockIdTo<Block> for Client<B, E, B
{
type Error = Error;
fn to_hash(&self, block_id: &BlockId<Block>) -> error::Result<Option<Block::Hash>> {
fn to_hash(&self, block_id: &BlockId<Block>) -> sp_blockchain::Result<Option<Block::Hash>> {
self.block_hash_from_id(block_id)
}
fn to_number(&self, block_id: &BlockId<Block>) -> error::Result<Option<NumberFor<Block>>> {
fn to_number(&self, block_id: &BlockId<Block>) -> sp_blockchain::Result<Option<NumberFor<Block>>> {
self.block_number_from_id(block_id)
}
}
@@ -1331,7 +1330,7 @@ impl<B, E, Block, RA> ChainHeaderBackend<Block> for &Client<B, E, Block, RA> whe
Block: BlockT<Hash=H256>,
RA: Send + Sync,
{
fn header(&self, id: BlockId<Block>) -> error::Result<Option<Block::Header>> {
fn header(&self, id: BlockId<Block>) -> sp_blockchain::Result<Option<Block::Header>> {
(**self).backend.blockchain().header(id)
}
@@ -1339,15 +1338,15 @@ impl<B, E, Block, RA> ChainHeaderBackend<Block> for &Client<B, E, Block, RA> whe
(**self).backend.blockchain().info()
}
fn status(&self, id: BlockId<Block>) -> error::Result<blockchain::BlockStatus> {
fn status(&self, id: BlockId<Block>) -> sp_blockchain::Result<blockchain::BlockStatus> {
(**self).status(id)
}
fn number(&self, hash: Block::Hash) -> error::Result<Option<<<Block as BlockT>::Header as HeaderT>::Number>> {
fn number(&self, hash: Block::Hash) -> sp_blockchain::Result<Option<<<Block as BlockT>::Header as HeaderT>::Number>> {
(**self).number(hash)
}
fn hash(&self, number: NumberFor<Block>) -> error::Result<Option<Block::Hash>> {
fn hash(&self, number: NumberFor<Block>) -> sp_blockchain::Result<Option<Block::Hash>> {
(**self).hash(number)
}
}
@@ -1397,7 +1396,7 @@ impl<B, E, Block, RA> CallRuntimeAt<Block> for Client<B, E, Block, RA> where
native_call: Option<NC>,
context: ExecutionContext,
recorder: &Option<ProofRecorder<Block>>,
) -> error::Result<NativeOrEncoded<R>> {
) -> sp_blockchain::Result<NativeOrEncoded<R>> {
let (manager, extensions) = self.execution_extensions.manager_and_extensions(at, context);
self.executor.contextual_call::<_, fn(_,_) -> _,_,_>(
|| core_api.initialize_block(at, &self.prepare_environment_block(at)?),
@@ -1413,7 +1412,7 @@ impl<B, E, Block, RA> CallRuntimeAt<Block> for Client<B, E, Block, RA> where
)
}
fn runtime_version_at(&self, at: &BlockId<Block>) -> error::Result<RuntimeVersion> {
fn runtime_version_at(&self, at: &BlockId<Block>) -> sp_blockchain::Result<RuntimeVersion> {
self.runtime_version_at(at)
}
}
@@ -1529,13 +1528,13 @@ impl<B, E, Block, RA> Finalizer<Block, Blake2Hasher, B> for Client<B, E, Block,
id: BlockId<Block>,
justification: Option<Justification>,
notify: bool,
) -> error::Result<()> {
) -> sp_blockchain::Result<()> {
let last_best = self.backend.blockchain().info().best_hash;
let to_finalize_hash = self.backend.blockchain().expect_block_hash_from_id(&id)?;
self.apply_finality_with_block_hash(operation, to_finalize_hash, justification, last_best, notify)
}
fn finalize_block(&self, id: BlockId<Block>, justification: Option<Justification>, notify: bool) -> error::Result<()> {
fn finalize_block(&self, id: BlockId<Block>, justification: Option<Justification>, notify: bool) -> sp_blockchain::Result<()> {
self.lock_import_and_run(|operation| {
self.apply_finality(operation, id, justification, notify)
})
@@ -1553,11 +1552,11 @@ impl<B, E, Block, RA> Finalizer<Block, Blake2Hasher, B> for &Client<B, E, Block,
id: BlockId<Block>,
justification: Option<Justification>,
notify: bool,
) -> error::Result<()> {
) -> sp_blockchain::Result<()> {
(**self).apply_finality(operation, id, justification, notify)
}
fn finalize_block(&self, id: BlockId<Block>, justification: Option<Justification>, notify: bool) -> error::Result<()> {
fn finalize_block(&self, id: BlockId<Block>, justification: Option<Justification>, notify: bool) -> sp_blockchain::Result<()> {
(**self).finalize_block(id, justification, notify)
}
}
@@ -1585,7 +1584,7 @@ where
&self,
filter_keys: Option<&[StorageKey]>,
child_filter_keys: Option<&[(StorageKey, Option<Vec<StorageKey>>)]>,
) -> error::Result<StorageEventStream<Block::Hash>> {
) -> sp_blockchain::Result<StorageEventStream<Block::Hash>> {
Ok(self.storage_notifications.lock().listen(filter_keys, child_filter_keys))
}
}
@@ -1620,7 +1619,7 @@ where
}
}
fn best_block_header(&self) -> error::Result<<Block as BlockT>::Header> {
fn best_block_header(&self) -> sp_blockchain::Result<<Block as BlockT>::Header> {
let info = self.backend.blockchain().info();
let import_lock = self.backend.get_import_lock();
let best_hash = self.backend.blockchain().best_containing(info.best_hash, None, import_lock)?
@@ -1630,7 +1629,7 @@ where
.expect("given block hash was fetched from block in db; qed"))
}
fn leaves(&self) -> Result<Vec<<Block as BlockT>::Hash>, error::Error> {
fn leaves(&self) -> Result<Vec<<Block as BlockT>::Hash>, sp_blockchain::Error> {
self.backend.blockchain().leaves()
}
}
@@ -1670,7 +1669,7 @@ impl<B, E, Block, RA> BlockBody<Block> for Client<B, E, Block, RA>
E: CallExecutor<Block, Blake2Hasher>,
Block: BlockT<Hash=H256>,
{
fn block_body(&self, id: &BlockId<Block>) -> error::Result<Option<Vec<<Block as BlockT>::Extrinsic>>> {
fn block_body(&self, id: &BlockId<Block>) -> sp_blockchain::Result<Option<Vec<<Block as BlockT>::Extrinsic>>> {
self.body(id)
}
}
@@ -1688,7 +1687,7 @@ impl<B, E, Block, RA> backend::AuxStore for Client<B, E, Block, RA>
'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<()> {
// Import is locked here because we may have other block import
// operations that tries to set aux data. Note that for consensus
// layer, one can always use atomic operations to make sure
@@ -1698,7 +1697,7 @@ impl<B, E, Block, RA> backend::AuxStore for Client<B, E, Block, RA>
})
}
/// Query auxiliary data from key-value store.
fn get_aux(&self, key: &[u8]) -> error::Result<Option<Vec<u8>>> {
fn get_aux(&self, key: &[u8]) -> sp_blockchain::Result<Option<Vec<u8>>> {
backend::AuxStore::get_aux(&*self.backend, key)
}
}
@@ -1717,11 +1716,11 @@ impl<B, E, Block, RA> backend::AuxStore for &Client<B, E, Block, RA>
'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).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).get_aux(key)
}
}
@@ -1731,7 +1730,7 @@ pub fn apply_aux<'a, 'b: 'a, 'c: 'a, B, Block, H, D, I>(
operation: &mut ClientImportOperation<Block, H, B>,
insert: I,
delete: D
) -> error::Result<()>
) -> sp_blockchain::Result<()>
where
Block: BlockT,
H: Hasher<Out=Block::Hash>,
@@ -2702,7 +2701,7 @@ pub(crate) mod tests {
let import_err = client.import(BlockOrigin::Own, b3).err().unwrap();
let expected_err = ConsensusError::ClientImport(
error::Error::NotInFinalizedChain.to_string()
sp_blockchain::Error::NotInFinalizedChain.to_string()
);
assert_eq!(
@@ -2725,7 +2724,7 @@ pub(crate) mod tests {
let import_err = client.import(BlockOrigin::Own, c1).err().unwrap();
let expected_err = ConsensusError::ClientImport(
error::Error::NotInFinalizedChain.to_string()
sp_blockchain::Error::NotInFinalizedChain.to_string()
);
assert_eq!(
+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(())
+4 -4
View File
@@ -21,7 +21,7 @@ use std::cmp::Reverse;
use kvdb::{KeyValueDB, DBTransaction};
use sr_primitives::traits::SimpleArithmetic;
use codec::{Encode, Decode};
use client_api::error;
use sp_blockchain::{Error, Result};
#[derive(Debug, Clone, PartialEq, Eq)]
struct LeafSetItem<H, N> {
@@ -77,7 +77,7 @@ impl<H, N> LeafSet<H, N> where
}
/// Read the leaf list from the DB, using given prefix for keys.
pub fn read_from_db(db: &dyn KeyValueDB, column: Option<u32>, prefix: &[u8]) -> error::Result<Self> {
pub fn read_from_db(db: &dyn KeyValueDB, column: Option<u32>, prefix: &[u8]) -> Result<Self> {
let mut storage = BTreeMap::new();
for (key, value) in db.iter_from_prefix(column, prefix) {
@@ -85,11 +85,11 @@ impl<H, N> LeafSet<H, N> where
let raw_hash = &mut &key[prefix.len()..];
let hash = match Decode::decode(raw_hash) {
Ok(hash) => hash,
Err(_) => return Err(error::Error::Backend("Error decoding hash".into())),
Err(_) => return Err(Error::Backend("Error decoding hash".into())),
};
let number = match Decode::decode(&mut &value[..]) {
Ok(number) => number,
Err(_) => return Err(error::Error::Backend("Error decoding number".into())),
Err(_) => return Err(Error::Backend("Error decoding number".into())),
};
storage.entry(Reverse(number)).or_insert_with(Vec::new).push(hash);
}
-1
View File
@@ -84,7 +84,6 @@ mod call_executor;
mod client;
pub use client_api::{
error,
blockchain,
blockchain::well_known_cache_keys,
blockchain::Info as ChainInfo,
+1 -3
View File
@@ -26,6 +26,7 @@ use primitives::offchain::storage::InMemOffchainStorage;
use sr_primitives::{generic::BlockId, Justification, StorageOverlay, ChildrenStorageOverlay};
use sr_primitives::traits::{Block as BlockT, NumberFor, Zero, Header};
use crate::in_mem::{self, check_genesis_storage};
use sp_blockchain::{ Error as ClientError, Result as ClientResult };
use client_api::{
backend::{
AuxStore, Backend as ClientBackend, BlockImportOperation, RemoteBackend, NewBlockState,
@@ -34,9 +35,6 @@ use client_api::{
blockchain::{
HeaderBackend as BlockchainHeaderBackend, well_known_cache_keys,
},
error::{
Error as ClientError, Result as ClientResult
},
light::Storage as BlockchainStorage,
};
use crate::light::blockchain::Blockchain;
+4 -4
View File
@@ -23,7 +23,10 @@ use std::sync::Arc;
use sr_primitives::{Justification, generic::BlockId};
use sr_primitives::traits::{Block as BlockT, Header as HeaderT, NumberFor, Zero};
use header_metadata::{HeaderMetadata, CachedHeaderMetadata};
use sp_blockchain::{
HeaderMetadata, CachedHeaderMetadata,
Error as ClientError, Result as ClientResult,
};
pub use client_api::{
backend::{
AuxStore, NewBlockState
@@ -33,9 +36,6 @@ pub use client_api::{
HeaderBackend as BlockchainHeaderBackend, Info as BlockchainInfo, ProvideCache,
well_known_cache_keys,
},
error::{
Error as ClientError, Result as ClientResult
},
light::{
RemoteBlockchain, LocalOrRemote, Storage
}
+3 -2
View File
@@ -38,9 +38,10 @@ use hash_db::Hasher;
use sr_api::{ProofRecorder, InitializeBlock};
use sp_blockchain::{Error as ClientError, Result as ClientResult};
use client_api::{
backend::RemoteBackend,
error::{Error as ClientError, Result as ClientResult},
light::RemoteCallRequest,
call_executor::CallExecutor
};
@@ -450,7 +451,7 @@ mod tests {
),
);
match execution_result {
Err(client_api::error::Error::Execution(_)) => (),
Err(sp_blockchain::Error::Execution(_)) => (),
_ => panic!("Unexpected execution result: {:?}", execution_result),
}
}
+3 -7
View File
@@ -33,12 +33,10 @@ use state_machine::{
read_child_proof_check,
};
pub use state_machine::StorageProof;
use sp_blockchain::{Error as ClientError, Result as ClientResult};
use crate::cht;
pub use client_api::{
error::{
Error as ClientError, Result as ClientResult
},
light::{
RemoteCallRequest, RemoteHeaderRequest, RemoteReadRequest, RemoteReadChildRequest,
RemoteChangesRequest, ChangesProof, RemoteBodyRequest, Fetcher, FetchChecker,
@@ -329,10 +327,8 @@ pub mod tests {
use codec::Decode;
use crate::client::tests::prepare_client_with_key_changes;
use executor::{NativeExecutor, WasmExecutionMethod};
use client_api::{
backend::NewBlockState,
error::Error as ClientError,
};
use sp_blockchain::Error as ClientError;
use client_api::backend::NewBlockState;
use test_client::{
self, ClientExt, blockchain::HeaderBackend, AccountKeyring,
runtime::{self, Hash, Block, Header, Extrinsic}
+1 -1
View File
@@ -27,11 +27,11 @@ use executor::RuntimeInfo;
use primitives::{H256, Blake2Hasher, traits::CodeExecutor};
use sr_primitives::BuildStorage;
use sr_primitives::traits::Block as BlockT;
use sp_blockchain::Result as ClientResult;
use crate::call_executor::LocalCallExecutor;
use crate::client::Client;
use client_api::{
error::Result as ClientResult,
light::Storage as BlockchainStorage,
};
use crate::light::backend::Backend;