mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-12 18:11:10 +00:00
Replace error-chain for client error (#2231)
* WIP: convert client error * Remove error_chain for client error * Ignore tx-pool error deprecation warning * Update Cargo.lock files * Fix tests * Increment impl_version * Derive From impls, remove allow(missing_docs) * Remove space * Remove redundant into()s * Blockchain Error source * Bump impl version
This commit is contained in:
committed by
Bastian Köcher
parent
1e0c1d8850
commit
7f59cdb900
@@ -28,7 +28,7 @@ use runtime_primitives::traits::{Block as BlockT, NumberFor, Zero, Header};
|
||||
use crate::in_mem::{self, check_genesis_storage};
|
||||
use crate::backend::{AuxStore, Backend as ClientBackend, BlockImportOperation, RemoteBackend, NewBlockState};
|
||||
use crate::blockchain::HeaderBackend as BlockchainHeaderBackend;
|
||||
use crate::error::{Error as ClientError, ErrorKind as ClientErrorKind, Result as ClientResult};
|
||||
use crate::error::{Error as ClientError, Result as ClientResult};
|
||||
use crate::light::blockchain::{Blockchain, Storage as BlockchainStorage};
|
||||
use crate::light::fetcher::{Fetcher, RemoteReadRequest};
|
||||
use hash_db::Hasher;
|
||||
@@ -208,7 +208,7 @@ impl<S, F, Block, H> ClientBackend<Block, H> for Backend<S, F, H> where
|
||||
}
|
||||
|
||||
fn revert(&self, _n: NumberFor<Block>) -> ClientResult<NumberFor<Block>> {
|
||||
Err(ClientErrorKind::NotAvailableOnLightClient.into())
|
||||
Err(ClientError::NotAvailableOnLightClient.into())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -323,13 +323,13 @@ where
|
||||
let mut header = self.cached_header.read().clone();
|
||||
if header.is_none() {
|
||||
let cached_header = self.blockchain.upgrade()
|
||||
.ok_or_else(|| ClientErrorKind::UnknownBlock(format!("{}", self.block)).into())
|
||||
.ok_or_else(|| ClientError::UnknownBlock(format!("{}", self.block)))
|
||||
.and_then(|blockchain| blockchain.expect_header(BlockId::Hash(self.block)))?;
|
||||
header = Some(cached_header.clone());
|
||||
*self.cached_header.write() = Some(cached_header);
|
||||
}
|
||||
|
||||
self.fetcher.upgrade().ok_or(ClientErrorKind::NotAvailableOnLightClient)?
|
||||
self.fetcher.upgrade().ok_or(ClientError::NotAvailableOnLightClient)?
|
||||
.remote_read(RemoteReadRequest {
|
||||
block: self.block,
|
||||
header: header.expect("if block above guarantees that header is_some(); qed"),
|
||||
@@ -340,7 +340,7 @@ where
|
||||
}
|
||||
|
||||
fn child_storage(&self, _storage_key: &[u8], _key: &[u8]) -> ClientResult<Option<Vec<u8>>> {
|
||||
Err(ClientErrorKind::NotAvailableOnLightClient.into())
|
||||
Err(ClientError::NotAvailableOnLightClient.into())
|
||||
}
|
||||
|
||||
fn for_keys_with_prefix<A: FnMut(&[u8])>(&self, _prefix: &[u8], _action: A) {
|
||||
|
||||
@@ -29,7 +29,7 @@ use crate::backend::{AuxStore, NewBlockState};
|
||||
use crate::blockchain::{Backend as BlockchainBackend, BlockStatus, Cache as BlockchainCache,
|
||||
HeaderBackend as BlockchainHeaderBackend, Info as BlockchainInfo, ProvideCache};
|
||||
use crate::cht;
|
||||
use crate::error::{ErrorKind as ClientErrorKind, Result as ClientResult};
|
||||
use crate::error::{Error as ClientError, Result as ClientResult};
|
||||
use crate::light::fetcher::{Fetcher, RemoteHeaderRequest};
|
||||
|
||||
/// Light client blockchain storage.
|
||||
@@ -114,7 +114,7 @@ impl<S, F, Block> BlockchainHeaderBackend<Block> for Blockchain<S, F> where Bloc
|
||||
return Ok(None);
|
||||
}
|
||||
|
||||
self.fetcher().upgrade().ok_or(ClientErrorKind::NotAvailableOnLightClient)?
|
||||
self.fetcher().upgrade().ok_or(ClientError::NotAvailableOnLightClient)?
|
||||
.remote_header(RemoteHeaderRequest {
|
||||
cht_root: self.storage.header_cht_root(cht::SIZE, number)?,
|
||||
block: number,
|
||||
@@ -202,22 +202,22 @@ pub mod tests {
|
||||
|
||||
impl BlockchainHeaderBackend<Block> for DummyStorage {
|
||||
fn header(&self, _id: BlockId<Block>) -> ClientResult<Option<Header>> {
|
||||
Err(ClientErrorKind::Backend("Test error".into()).into())
|
||||
Err(ClientError::Backend("Test error".into()))
|
||||
}
|
||||
|
||||
fn info(&self) -> ClientResult<Info<Block>> {
|
||||
Err(ClientErrorKind::Backend("Test error".into()).into())
|
||||
Err(ClientError::Backend("Test error".into()))
|
||||
}
|
||||
|
||||
fn status(&self, _id: BlockId<Block>) -> ClientResult<BlockStatus> {
|
||||
Err(ClientErrorKind::Backend("Test error".into()).into())
|
||||
Err(ClientError::Backend("Test error".into()))
|
||||
}
|
||||
|
||||
fn number(&self, hash: Hash) -> ClientResult<Option<NumberFor<Block>>> {
|
||||
if hash == Default::default() {
|
||||
Ok(Some(Default::default()))
|
||||
} else {
|
||||
Err(ClientErrorKind::Backend("Test error".into()).into())
|
||||
Err(ClientError::Backend("Test error".into()))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -225,7 +225,7 @@ pub mod tests {
|
||||
if number == 0 {
|
||||
Ok(Some(Default::default()))
|
||||
} else {
|
||||
Err(ClientErrorKind::Backend("Test error".into()).into())
|
||||
Err(ClientError::Backend("Test error".into()))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -261,26 +261,26 @@ pub mod tests {
|
||||
}
|
||||
|
||||
fn set_head(&self, _block: BlockId<Block>) -> ClientResult<()> {
|
||||
Err(ClientErrorKind::Backend("Test error".into()).into())
|
||||
Err(ClientError::Backend("Test error".into()))
|
||||
}
|
||||
|
||||
fn finalize_header(&self, _block: BlockId<Block>) -> ClientResult<()> {
|
||||
Err(ClientErrorKind::Backend("Test error".into()).into())
|
||||
Err(ClientError::Backend("Test error".into()))
|
||||
}
|
||||
|
||||
fn last_finalized(&self) -> ClientResult<Hash> {
|
||||
Err(ClientErrorKind::Backend("Test error".into()).into())
|
||||
Err(ClientError::Backend("Test error".into()))
|
||||
}
|
||||
|
||||
fn header_cht_root(&self, _cht_size: u64, _block: u64) -> ClientResult<Hash> {
|
||||
Err(ClientErrorKind::Backend("Test error".into()).into())
|
||||
Err(ClientError::Backend("Test error".into()))
|
||||
}
|
||||
|
||||
fn changes_trie_cht_root(&self, cht_size: u64, block: u64) -> ClientResult<Hash> {
|
||||
cht::block_to_cht_number(cht_size, block)
|
||||
.and_then(|cht_num| self.changes_tries_cht_roots.get(&cht_num))
|
||||
.cloned()
|
||||
.ok_or_else(|| ClientErrorKind::Backend(
|
||||
.ok_or_else(|| ClientError::Backend(
|
||||
format!("Test error: CHT for block #{} not found", block)
|
||||
).into())
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ use hash_db::Hasher;
|
||||
use crate::backend::RemoteBackend;
|
||||
use crate::blockchain::Backend as ChainBackend;
|
||||
use crate::call_executor::CallExecutor;
|
||||
use crate::error::{Error as ClientError, ErrorKind as ClientErrorKind, Result as ClientResult};
|
||||
use crate::error::{Error as ClientError, Result as ClientResult};
|
||||
use crate::light::fetcher::{Fetcher, RemoteCallRequest};
|
||||
use executor::{RuntimeVersion, NativeVersion};
|
||||
use heapsize::HeapSizeOf;
|
||||
@@ -126,7 +126,7 @@ where
|
||||
) -> ClientResult<NativeOrEncoded<R>> where ExecutionManager<EM>: Clone {
|
||||
// it is only possible to execute contextual call if changes are empty
|
||||
if !changes.is_empty() || initialized_block.is_some() {
|
||||
return Err(ClientErrorKind::NotAvailableOnLightClient.into());
|
||||
return Err(ClientError::NotAvailableOnLightClient.into());
|
||||
}
|
||||
|
||||
self.call(at, method, call_data, (&execution_manager).into(), side_effects_handler).map(NativeOrEncoded::Encoded)
|
||||
@@ -135,7 +135,7 @@ where
|
||||
fn runtime_version(&self, id: &BlockId<Block>) -> ClientResult<RuntimeVersion> {
|
||||
let call_result = self.call(id, "version", &[], ExecutionStrategy::NativeElseWasm, NeverOffchainExt::new())?;
|
||||
RuntimeVersion::decode(&mut call_result.as_slice())
|
||||
.ok_or_else(|| ClientErrorKind::VersionInvalid.into())
|
||||
.ok_or_else(|| ClientError::VersionInvalid.into())
|
||||
}
|
||||
|
||||
fn call_at_state<
|
||||
@@ -156,7 +156,7 @@ where
|
||||
_native_call: Option<NC>,
|
||||
_side_effects_handler: Option<&mut O>,
|
||||
) -> ClientResult<(NativeOrEncoded<R>, S::Transaction, Option<MemoryDB<Blake2Hasher>>)> {
|
||||
Err(ClientErrorKind::NotAvailableOnLightClient.into())
|
||||
Err(ClientError::NotAvailableOnLightClient.into())
|
||||
}
|
||||
|
||||
fn prove_at_trie_state<S: state_machine::TrieBackendStorage<Blake2Hasher>>(
|
||||
@@ -166,7 +166,7 @@ where
|
||||
_method: &str,
|
||||
_call_data: &[u8]
|
||||
) -> ClientResult<(Vec<u8>, Vec<Vec<u8>>)> {
|
||||
Err(ClientErrorKind::NotAvailableOnLightClient.into())
|
||||
Err(ClientError::NotAvailableOnLightClient.into())
|
||||
}
|
||||
|
||||
fn native_runtime_version(&self) -> Option<&NativeVersion> {
|
||||
@@ -275,7 +275,7 @@ impl<Block, B, Remote, Local> CallExecutor<Block, Blake2Hasher> for
|
||||
ExecutionManager::NativeWhenPossible,
|
||||
native_call,
|
||||
side_effects_handler,
|
||||
).map_err(|e| ClientErrorKind::Execution(Box::new(e.to_string())).into()),
|
||||
).map_err(|e| ClientError::Execution(Box::new(e.to_string()))),
|
||||
false => CallExecutor::contextual_call::<
|
||||
_,
|
||||
_,
|
||||
@@ -296,7 +296,7 @@ impl<Block, B, Remote, Local> CallExecutor<Block, Blake2Hasher> for
|
||||
ExecutionManager::NativeWhenPossible,
|
||||
native_call,
|
||||
side_effects_handler,
|
||||
).map_err(|e| ClientErrorKind::Execution(Box::new(e.to_string())).into()),
|
||||
).map_err(|e| ClientError::Execution(Box::new(e.to_string()))),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -346,7 +346,7 @@ impl<Block, B, Remote, Local> CallExecutor<Block, Blake2Hasher> for
|
||||
ExecutionManager::NativeWhenPossible,
|
||||
native_call,
|
||||
side_effects_handler,
|
||||
).map_err(|e| ClientErrorKind::Execution(Box::new(e.to_string())).into())
|
||||
).map_err(|e| ClientError::Execution(Box::new(e.to_string())))
|
||||
}
|
||||
|
||||
fn prove_at_trie_state<S: state_machine::TrieBackendStorage<Blake2Hasher>>(
|
||||
|
||||
@@ -29,7 +29,7 @@ use state_machine::{CodeExecutor, ChangesTrieRootsStorage, ChangesTrieAnchorBloc
|
||||
TrieBackend, read_proof_check, key_changes_proof_check, create_proof_check_backend_storage};
|
||||
|
||||
use crate::cht;
|
||||
use crate::error::{Error as ClientError, ErrorKind as ClientErrorKind, Result as ClientResult};
|
||||
use crate::error::{Error as ClientError, Result as ClientResult};
|
||||
use crate::light::blockchain::{Blockchain, Storage as BlockchainStorage};
|
||||
use crate::light::call_executor::check_execution_proof;
|
||||
|
||||
@@ -193,7 +193,7 @@ impl<E, H, B: BlockT, S: BlockchainStorage<B>, F> LightDataChecker<E, H, B, S, F
|
||||
// since we need roots of all changes tries for the range begin..max
|
||||
// => remote node can't use max block greater that one that we have passed
|
||||
if remote_proof.max_block > request.max_block.0 || remote_proof.max_block < request.last_block.0 {
|
||||
return Err(ClientErrorKind::ChangesTrieAccessFailed(format!(
|
||||
return Err(ClientError::ChangesTrieAccessFailed(format!(
|
||||
"Invalid max_block used by the remote node: {}. Local: {}..{}..{}",
|
||||
remote_proof.max_block, request.first_block.0, request.last_block.0, request.max_block.0,
|
||||
)).into());
|
||||
@@ -209,7 +209,7 @@ impl<E, H, B: BlockT, S: BlockchainStorage<B>, F> LightDataChecker<E, H, B, S, F
|
||||
.map(|last_root| *last_root >= request.tries_roots.0)
|
||||
.unwrap_or(false);
|
||||
if is_extra_first_root || is_extra_last_root {
|
||||
return Err(ClientErrorKind::ChangesTrieAccessFailed(format!(
|
||||
return Err(ClientError::ChangesTrieAccessFailed(format!(
|
||||
"Extra changes tries roots proofs provided by the remote node: [{:?}..{:?}]. Expected in range: [{}; {})",
|
||||
remote_proof.roots.keys().next(), remote_proof.roots.keys().next_back(),
|
||||
request.first_block.0, request.tries_roots.0,
|
||||
@@ -247,7 +247,7 @@ impl<E, H, B: BlockT, S: BlockchainStorage<B>, F> LightDataChecker<E, H, B, S, F
|
||||
remote_max_block.as_(),
|
||||
&request.key)
|
||||
.map(|pairs| pairs.into_iter().map(|(b, x)| (As::sa(b), x)).collect())
|
||||
.map_err(|err| ClientErrorKind::ChangesTrieAccessFailed(err).into())
|
||||
.map_err(|err| ClientError::ChangesTrieAccessFailed(err))
|
||||
}
|
||||
|
||||
/// Check CHT-based proof for changes tries roots.
|
||||
@@ -283,7 +283,7 @@ impl<E, H, B: BlockT, S: BlockchainStorage<B>, F> LightDataChecker<E, H, B, S, F
|
||||
let mut cht_root = H::Out::default();
|
||||
cht_root.as_mut().copy_from_slice(local_cht_root.as_ref());
|
||||
if !storage.contains(&cht_root, &[]) {
|
||||
return Err(ClientErrorKind::InvalidCHTProof.into());
|
||||
return Err(ClientError::InvalidCHTProof.into());
|
||||
}
|
||||
|
||||
// check proof for single changes trie root
|
||||
@@ -320,7 +320,7 @@ impl<E, Block, H, S, F> FetchChecker<Block> for LightDataChecker<E, H, Block, S,
|
||||
remote_proof: Vec<Vec<u8>>
|
||||
) -> ClientResult<Block::Header> {
|
||||
let remote_header = remote_header.ok_or_else(||
|
||||
ClientError::from(ClientErrorKind::InvalidCHTProof))?;
|
||||
ClientError::from(ClientError::InvalidCHTProof))?;
|
||||
let remote_header_hash = remote_header.hash();
|
||||
cht::check_proof::<Block::Header, H>(
|
||||
request.cht_root,
|
||||
@@ -473,7 +473,7 @@ pub mod tests {
|
||||
let builder = remote_client.new_block().unwrap();
|
||||
remote_client.import(BlockOrigin::Own, builder.bake().unwrap()).unwrap();
|
||||
local_headers_hashes.push(remote_client.block_hash(i + 1)
|
||||
.map_err(|_| ClientErrorKind::Backend("TestError".into()).into()));
|
||||
.map_err(|_| ClientError::Backend("TestError".into())));
|
||||
}
|
||||
|
||||
// 'fetch' header proof from remote node
|
||||
|
||||
Reference in New Issue
Block a user