diff --git a/substrate/Cargo.lock b/substrate/Cargo.lock index e7afec8f6a..a3d4a00f88 100644 --- a/substrate/Cargo.lock +++ b/substrate/Cargo.lock @@ -623,6 +623,17 @@ name = "data-encoding" version = "2.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "derive_more" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 0.6.11 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.26 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "difference" version = "2.0.0" @@ -3670,7 +3681,7 @@ dependencies = [ name = "substrate-client" version = "1.0.0" dependencies = [ - "error-chain 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", + "derive_more 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)", "fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", "hash-db 0.12.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -5160,6 +5171,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum cuckoofilter 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "8dd43f7cfaffe0a386636a10baea2ee05cc50df3b77bea4a456c9572a939bf1f" "checksum curve25519-dalek 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "dae47cc3529cdab597dbc8b606e565707209b506e55848f3c15679214a56c956" "checksum data-encoding 2.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f4f47ca1860a761136924ddd2422ba77b2ea54fe8cc75b9040804a0d9d32ad97" +"checksum derive_more 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fbe9f11be34f800b3ecaaed0ec9ec2e015d1d0ba0c8644c1310f73d6e8994615" "checksum difference 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "524cbf6897b527295dff137cec09ecf3a05f4fddffd7dfcd1585403449e74198" "checksum digest 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e5b29bf156f3f4b3c4f610a25ff69370616ae6e0657d416de22645483e72af0a" "checksum digest 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "05f47366984d3ad862010e22c7ce81a7dbcaebbdfb37241a620f8b6596ee135c" diff --git a/substrate/core/basic-authorship/src/basic_authorship.rs b/substrate/core/basic-authorship/src/basic_authorship.rs index e9b6c909ad..bab86ea420 100644 --- a/substrate/core/basic-authorship/src/basic_authorship.rs +++ b/substrate/core/basic-authorship/src/basic_authorship.rs @@ -232,7 +232,7 @@ impl Proposer where Ok(()) => { debug!("[{:?}] Pushed to the block.", pending.hash); } - Err(error::Error(error::ErrorKind::ApplyExtrinsicFailed(ApplyError::FullBlock), _)) => { + Err(error::Error::ApplyExtrinsicFailed(ApplyError::FullBlock)) => { if is_first { debug!("[{:?}] Invalid transaction: FullBlock on empty block", pending.hash); unqueue_invalid.push(pending.hash.clone()); diff --git a/substrate/core/cli/src/error.rs b/substrate/core/cli/src/error.rs index e368cc6d96..07d14eb479 100644 --- a/substrate/core/cli/src/error.rs +++ b/substrate/core/cli/src/error.rs @@ -29,9 +29,7 @@ error_chain! { Io(::std::io::Error) #[doc="IO error"]; Cli(::clap::Error) #[doc="CLI error"]; Service(::service::Error) #[doc="Substrate service error"]; - } - links { - Client(client::error::Error, client::error::ErrorKind) #[doc="Client error"]; + Client(client::error::Error) #[doc="Client error"]; } errors { /// Input error. diff --git a/substrate/core/client/Cargo.toml b/substrate/core/client/Cargo.toml index d36468c4d7..f1b7a903ff 100644 --- a/substrate/core/client/Cargo.toml +++ b/substrate/core/client/Cargo.toml @@ -5,7 +5,7 @@ authors = ["Parity Technologies "] edition = "2018" [dependencies] -error-chain = { version = "0.12", optional = true } +derive_more = { version = "0.14.0", optional = true } fnv = { version = "1.0", optional = true } log = { version = "0.4", optional = true } parking_lot = { version = "0.7.1", optional = true } @@ -44,7 +44,7 @@ std = [ "hash-db/std", "consensus", "parking_lot", - "error-chain", + "derive_more", "fnv", "log", "hex", diff --git a/substrate/core/client/db/src/cache/list_cache.rs b/substrate/core/client/db/src/cache/list_cache.rs index 1e641534f9..67e09b580d 100644 --- a/substrate/core/client/db/src/cache/list_cache.rs +++ b/substrate/core/client/db/src/cache/list_cache.rs @@ -43,7 +43,7 @@ use std::collections::BTreeSet; use log::warn; -use client::error::{ErrorKind as ClientErrorKind, Result as ClientResult}; +use client::error::{Error as ClientError, Result as ClientResult}; use runtime_primitives::traits::{Block as BlockT, NumberFor, As, Zero}; use crate::cache::{CacheItemT, ComplexBlockId}; @@ -537,10 +537,10 @@ mod chain { ) -> ClientResult { let (begin, end) = if block1 > block2 { (block2, block1) } else { (block1, block2) }; let mut current = storage.read_header(&end.hash)? - .ok_or_else(|| ClientErrorKind::UnknownBlock(format!("{}", end.hash)))?; + .ok_or_else(|| ClientError::UnknownBlock(format!("{}", end.hash)))?; while *current.number() > begin.number { current = storage.read_header(current.parent_hash())? - .ok_or_else(|| ClientErrorKind::UnknownBlock(format!("{}", current.parent_hash())))?; + .ok_or_else(|| ClientError::UnknownBlock(format!("{}", current.parent_hash())))?; } Ok(begin.hash == current.hash()) diff --git a/substrate/core/client/db/src/cache/list_storage.rs b/substrate/core/client/db/src/cache/list_storage.rs index 659a30507e..6271f892bc 100644 --- a/substrate/core/client/db/src/cache/list_storage.rs +++ b/substrate/core/client/db/src/cache/list_storage.rs @@ -20,7 +20,7 @@ use std::sync::Arc; use kvdb::{KeyValueDB, DBTransaction}; -use client::error::{Error as ClientError, ErrorKind as ClientErrorKind, Result as ClientResult}; +use client::error::{Error as ClientError, Result as ClientResult}; use parity_codec::{Encode, Decode}; use runtime_primitives::generic::BlockId; use runtime_primitives::traits::{Block as BlockT, Header as HeaderT, NumberFor}; @@ -59,7 +59,7 @@ pub trait Storage { self.read_entry(at) .and_then(|entry| entry .ok_or_else(|| ClientError::from( - ClientErrorKind::Backend(format!("Referenced cache entry at {:?} is not found", at))))) + ClientError::Backend(format!("Referenced cache entry at {:?} is not found", at))))) } } @@ -151,7 +151,7 @@ impl Storage for DbStorage { .map_err(db_err) .and_then(|entry| match entry { Some(entry) => StorageEntry::::decode(&mut &entry[..]) - .ok_or_else(|| ClientErrorKind::Backend("Failed to decode cache entry".into()).into()) + .ok_or_else(|| ClientError::Backend("Failed to decode cache entry".into())) .map(Some), None => Ok(None), }) @@ -236,9 +236,9 @@ mod meta { pub fn decode(encoded: &[u8]) -> ClientResult> { let input = &mut &*encoded; let finalized: Option> = Decode::decode(input) - .ok_or_else(|| ClientError::from(ClientErrorKind::Backend("Error decoding cache meta".into())))?; + .ok_or_else(|| ClientError::from(ClientError::Backend("Error decoding cache meta".into())))?; let unfinalized: Vec> = Decode::decode(input) - .ok_or_else(|| ClientError::from(ClientErrorKind::Backend("Error decoding cache meta".into())))?; + .ok_or_else(|| ClientError::from(ClientError::Backend("Error decoding cache meta".into())))?; Ok(Metadata { finalized, unfinalized }) } @@ -253,19 +253,19 @@ pub mod tests { impl Storage for FaultyStorage { fn read_id(&self, _at: NumberFor) -> ClientResult> { - Err(ClientErrorKind::Backend("TestError".into()).into()) + Err(ClientError::Backend("TestError".into())) } fn read_header(&self, _at: &Block::Hash) -> ClientResult> { - Err(ClientErrorKind::Backend("TestError".into()).into()) + Err(ClientError::Backend("TestError".into())) } fn read_meta(&self) -> ClientResult> { - Err(ClientErrorKind::Backend("TestError".into()).into()) + Err(ClientError::Backend("TestError".into())) } fn read_entry(&self, _at: &ComplexBlockId) -> ClientResult>> { - Err(ClientErrorKind::Backend("TestError".into()).into()) + Err(ClientError::Backend("TestError".into())) } } diff --git a/substrate/core/client/db/src/lib.rs b/substrate/core/client/db/src/lib.rs index ac22bcbb01..d876296546 100644 --- a/substrate/core/client/db/src/lib.rs +++ b/substrate/core/client/db/src/lib.rs @@ -225,7 +225,7 @@ impl client::blockchain::Backend for BlockchainDb { match read_db(&*self.db, columns::KEY_LOOKUP, columns::BODY, id)? { Some(body) => match Decode::decode(&mut &body[..]) { Some(body) => Ok(Some(body)), - None => return Err(client::error::ErrorKind::Backend("Error decoding body".into()).into()), + None => return Err(client::error::Error::Backend("Error decoding body".into())), } None => Ok(None), } @@ -235,7 +235,7 @@ impl client::blockchain::Backend for BlockchainDb { match read_db(&*self.db, columns::KEY_LOOKUP, columns::JUSTIFICATION, id)? { Some(justification) => match Decode::decode(&mut &justification[..]) { Some(justification) => Ok(Some(justification)), - None => return Err(client::error::ErrorKind::Backend("Error decoding justification".into()).into()), + None => return Err(client::error::Error::Backend("Error decoding justification".into())), } None => Ok(None), } @@ -326,14 +326,14 @@ where Block: BlockT, fn reset_storage(&mut self, mut top: StorageOverlay, children: ChildrenStorageOverlay) -> Result { if top.iter().any(|(k, _)| well_known_keys::is_child_storage_key(k)) { - return Err(client::error::ErrorKind::GenesisInvalid.into()); + return Err(client::error::Error::GenesisInvalid.into()); } let mut transaction: PrefixedMemoryDB = Default::default(); for (child_key, child_map) in children { if !well_known_keys::is_child_storage_key(&child_key) { - return Err(client::error::ErrorKind::GenesisInvalid.into()); + return Err(client::error::Error::GenesisInvalid.into()); } let (root, is_default, update) = self.old_state.child_storage_root(&child_key, child_map.into_iter().map(|(k, v)| (k, Some(v)))); @@ -684,7 +684,7 @@ impl> Backend { (&r.number, &r.hash) ); - return Err(::client::error::ErrorKind::NotInFinalizedChain.into()); + return Err(::client::error::Error::NotInFinalizedChain.into()); } retracted.push(r.hash.clone()); @@ -726,7 +726,7 @@ impl> Backend { ) -> Result<(), client::error::Error> { let last_finalized = last_finalized.unwrap_or_else(|| self.blockchain.meta.read().finalized_hash); if *header.parent_hash() != last_finalized { - return Err(::client::error::ErrorKind::NonSequentialFinalization( + return Err(::client::error::Error::NonSequentialFinalization( format!("Last finalized {:?} not parent of {:?}", last_finalized, header.hash()), ).into()); } @@ -926,7 +926,7 @@ impl> Backend { (number.clone(), hash.clone()) )?; } else { - return Err(client::error::ErrorKind::UnknownBlock(format!("Cannot set head {:?}", set_head)).into()) + return Err(client::error::Error::UnknownBlock(format!("Cannot set head {:?}", set_head))) } } @@ -1138,12 +1138,12 @@ impl client::backend::Backend for Backend whe Some(commit) => { apply_state_commit(&mut transaction, commit); let removed = self.blockchain.header(BlockId::Number(best))?.ok_or_else( - || client::error::ErrorKind::UnknownBlock( + || client::error::Error::UnknownBlock( format!("Error reverting to {}. Block hash not found.", best)))?; best -= As::sa(1); // prev block let hash = self.blockchain.hash(best)?.ok_or_else( - || client::error::ErrorKind::UnknownBlock( + || client::error::Error::UnknownBlock( format!("Error reverting to {}. Block hash not found.", best)))?; let key = utils::number_and_hash_to_lookup_key(best.clone(), &hash); transaction.put(columns::META, meta_keys::BEST_BLOCK, &key); @@ -1185,10 +1185,10 @@ impl client::backend::Backend for Backend whe let state = DbState::new(self.storage.clone(), root); Ok(CachingState::new(state, self.shared_cache.clone(), Some(hash))) } else { - Err(client::error::ErrorKind::UnknownBlock(format!("State already discarded for {:?}", block)).into()) + Err(client::error::Error::UnknownBlock(format!("State already discarded for {:?}", block))) } }, - Ok(None) => Err(client::error::ErrorKind::UnknownBlock(format!("Unknown state for block {:?}", block)).into()), + Ok(None) => Err(client::error::Error::UnknownBlock(format!("Unknown state for block {:?}", block))), Err(e) => Err(e), } } diff --git a/substrate/core/client/db/src/light.rs b/substrate/core/client/db/src/light.rs index 62b6486f54..a571ffe142 100644 --- a/substrate/core/client/db/src/light.rs +++ b/substrate/core/client/db/src/light.rs @@ -26,7 +26,7 @@ use client::blockchain::{BlockStatus, Cache as BlockchainCache, HeaderBackend as BlockchainHeaderBackend, Info as BlockchainInfo}; use client::cht; use client::leaves::{LeafSet, FinalizationDisplaced}; -use client::error::{ErrorKind as ClientErrorKind, Result as ClientResult}; +use client::error::{Error as ClientError, Result as ClientResult}; use client::light::blockchain::Storage as LightBlockchainStorage; use parity_codec::{Decode, Encode}; use primitives::Blake2Hasher; @@ -256,7 +256,7 @@ impl LightStorage { ) -> ClientResult<()> { let meta = self.meta.read(); if &meta.finalized_hash != header.parent_hash() { - return Err(::client::error::ErrorKind::NonSequentialFinalization( + return Err(::client::error::Error::NonSequentialFinalization( format!("Last finalized {:?} not parent of {:?}", meta.finalized_hash, hash), ).into()) @@ -330,7 +330,7 @@ impl LightStorage { cht_size: u64, block: NumberFor ) -> ClientResult { - let no_cht_for_block = || ClientErrorKind::Backend(format!("CHT for block {} not exists", block)).into(); + let no_cht_for_block = || ClientError::Backend(format!("CHT for block {} not exists", block)); let cht_number = cht::block_to_cht_number(cht_size, block).ok_or_else(no_cht_for_block)?; let cht_start = cht::start_number(cht_size, cht_number); @@ -474,7 +474,7 @@ impl LightBlockchainStorage for LightStorage self.db.write(transaction).map_err(db_err)?; Ok(()) } else { - Err(ClientErrorKind::UnknownBlock(format!("Cannot set head {:?}", id)).into()) + Err(ClientError::UnknownBlock(format!("Cannot set head {:?}", id))) } } @@ -514,7 +514,7 @@ impl LightBlockchainStorage for LightStorage Ok(()) } else { - Err(ClientErrorKind::UnknownBlock(format!("Cannot finalize block {:?}", id)).into()) + Err(ClientError::UnknownBlock(format!("Cannot finalize block {:?}", id))) } } diff --git a/substrate/core/client/db/src/utils.rs b/substrate/core/client/db/src/utils.rs index ce843a93a2..b51faae6de 100644 --- a/substrate/core/client/db/src/utils.rs +++ b/substrate/core/client/db/src/utils.rs @@ -105,7 +105,7 @@ pub fn number_and_hash_to_lookup_key(number: N, hash: H) -> Vec where /// all block lookup keys start with the block number. pub fn lookup_key_to_number(key: &[u8]) -> client::error::Result where N: As { if key.len() < 4 { - return Err(client::error::ErrorKind::Backend("Invalid block key".into()).into()); + return Err(client::error::Error::Backend("Invalid block key".into())); } Ok((key[0] as u64) << 24 | (key[1] as u64) << 16 @@ -187,21 +187,21 @@ pub fn block_id_to_lookup_key( /// Maps database error to client error pub fn db_err(err: io::Error) -> client::error::Error { use std::error::Error; - client::error::ErrorKind::Backend(err.description().into()).into() + client::error::Error::Backend(err.description().into()) } /// Open RocksDB database. pub fn open_database(config: &DatabaseSettings, col_meta: Option, db_type: &str) -> client::error::Result> { let mut db_config = DatabaseConfig::with_columns(Some(NUM_COLUMNS)); db_config.memory_budget = config.cache_size; - let path = config.path.to_str().ok_or_else(|| client::error::ErrorKind::Backend("Invalid database path".into()))?; + let path = config.path.to_str().ok_or_else(|| client::error::Error::Backend("Invalid database path".into()))?; let db = Database::open(&db_config, &path).map_err(db_err)?; // check database type match db.get(col_meta, meta_keys::TYPE).map_err(db_err)? { Some(stored_type) => { if db_type.as_bytes() != &*stored_type { - return Err(client::error::ErrorKind::Backend( + return Err(client::error::Error::Backend( format!("Unexpected database type. Expected: {}", db_type)).into()); } }, @@ -237,7 +237,7 @@ pub fn read_header( Some(header) => match Block::Header::decode(&mut &header[..]) { Some(header) => Ok(Some(header)), None => return Err( - client::error::ErrorKind::Backend("Error decoding header".into()).into() + client::error::Error::Backend("Error decoding header".into()) ), } None => Ok(None), @@ -252,7 +252,7 @@ pub fn require_header( id: BlockId, ) -> client::error::Result { read_header(db, col_index, col, id) - .and_then(|header| header.ok_or_else(|| client::error::ErrorKind::UnknownBlock(format!("{}", id)).into())) + .and_then(|header| header.ok_or_else(|| client::error::Error::UnknownBlock(format!("{}", id)))) } /// Read meta from the database. @@ -266,7 +266,7 @@ pub fn read_meta(db: &KeyValueDB, col_meta: Option, col_header: Opti let genesis_hash: Block::Hash = match db.get(col_meta, meta_keys::GENESIS_HASH).map_err(db_err)? { Some(h) => match Decode::decode(&mut &h[..]) { Some(h) => h, - None => return Err(client::error::ErrorKind::Backend("Error decoding genesis hash".into()).into()), + None => return Err(client::error::Error::Backend("Error decoding genesis hash".into())), }, None => return Ok(Meta { best_hash: Default::default(), diff --git a/substrate/core/client/src/block_builder/block_builder.rs b/substrate/core/client/src/block_builder/block_builder.rs index fd1ce4aefb..5c168b2f05 100644 --- a/substrate/core/client/src/block_builder/block_builder.rs +++ b/substrate/core/client/src/block_builder/block_builder.rs @@ -51,11 +51,11 @@ where /// build upon. pub fn at_block(block_id: &BlockId, api: &'a A) -> error::Result { let number = api.block_number_from_id(block_id)? - .ok_or_else(|| error::ErrorKind::UnknownBlock(format!("{}", block_id)))? + .ok_or_else(|| error::Error::UnknownBlock(format!("{}", block_id)))? + One::one(); let parent_hash = api.block_hash_from_id(block_id)? - .ok_or_else(|| error::ErrorKind::UnknownBlock(format!("{}", block_id)))?; + .ok_or_else(|| error::Error::UnknownBlock(format!("{}", block_id)))?; let header = <::Header as HeaderT>::new( number, Default::default(), @@ -89,7 +89,7 @@ where Ok(()) } Err(e) => { - Err(error::ErrorKind::ApplyExtrinsicFailed(e).into()) + Err(error::Error::ApplyExtrinsicFailed(e)) } } }) diff --git a/substrate/core/client/src/blockchain.rs b/substrate/core/client/src/blockchain.rs index 5d7b2a9c23..b0e7c2943a 100644 --- a/substrate/core/client/src/blockchain.rs +++ b/substrate/core/client/src/blockchain.rs @@ -23,7 +23,7 @@ use runtime_primitives::generic::BlockId; use runtime_primitives::Justification; use consensus::well_known_cache_keys; -use crate::error::{ErrorKind, Result}; +use crate::error::{Error, Result}; /// Blockchain database header backend. Does not perform any validation. pub trait HeaderBackend: Send + Sync { @@ -56,19 +56,19 @@ pub trait HeaderBackend: Send + Sync { /// Get block header. Returns `UnknownBlock` error if block is not found. fn expect_header(&self, id: BlockId) -> Result { - self.header(id)?.ok_or_else(|| ErrorKind::UnknownBlock(format!("{}", id)).into()) + self.header(id)?.ok_or_else(|| Error::UnknownBlock(format!("{}", id))) } /// Convert an arbitrary block ID into a block number. Returns `UnknownBlock` error if block is not found. fn expect_block_number_from_id(&self, id: &BlockId) -> Result> { self.block_number_from_id(id) - .and_then(|n| n.ok_or_else(|| ErrorKind::UnknownBlock(format!("{}", id)).into())) + .and_then(|n| n.ok_or_else(|| Error::UnknownBlock(format!("{}", id)))) } /// Convert an arbitrary block ID into a block hash. Returns `UnknownBlock` error if block is not found. fn expect_block_hash_from_id(&self, id: &BlockId) -> Result { self.block_hash_from_id(id) - .and_then(|n| n.ok_or_else(|| ErrorKind::UnknownBlock(format!("{}", id)).into())) + .and_then(|n| n.ok_or_else(|| Error::UnknownBlock(format!("{}", id)))) } } @@ -196,7 +196,7 @@ pub fn tree_route>( let load_header = |id: BlockId| { match backend.header(id) { Ok(Some(hdr)) => Ok(hdr), - Ok(None) => Err(ErrorKind::UnknownBlock(format!("Unknown block {:?}", id)).into()), + Ok(None) => Err(Error::UnknownBlock(format!("Unknown block {:?}", id))), Err(e) => Err(e), } }; diff --git a/substrate/core/client/src/call_executor.rs b/substrate/core/client/src/call_executor.rs index b0bf9b4c2c..4f6f02c94c 100644 --- a/substrate/core/client/src/call_executor.rs +++ b/substrate/core/client/src/call_executor.rs @@ -274,7 +274,7 @@ where let mut overlay = OverlayedChanges::default(); let state = self.backend.state_at(*id)?; let mut ext = Ext::new(&mut overlay, &state, self.backend.changes_trie_storage(), NeverOffchainExt::new()); - self.executor.runtime_version(&mut ext).ok_or(error::ErrorKind::VersionInvalid.into()) + self.executor.runtime_version(&mut ext).ok_or(error::Error::VersionInvalid.into()) } fn call_at_state< diff --git a/substrate/core/client/src/children.rs b/substrate/core/client/src/children.rs index 48b39d18cd..3a9f0a6bea 100644 --- a/substrate/core/client/src/children.rs +++ b/substrate/core/client/src/children.rs @@ -32,7 +32,7 @@ pub fn read_children< let raw_val_opt = match db.get(column, &buf[..]) { Ok(raw_val_opt) => raw_val_opt, - Err(_) => return Err(error::ErrorKind::Backend("Error reading value from database".into()).into()), + Err(_) => return Err(error::Error::Backend("Error reading value from database".into())), }; let raw_val = match raw_val_opt { @@ -42,7 +42,7 @@ pub fn read_children< let children: Vec = match Decode::decode(&mut &raw_val[..]) { Some(children) => children, - None => return Err(error::ErrorKind::Backend("Error decoding children".into()).into()), + None => return Err(error::Error::Backend("Error decoding children".into())), }; Ok(children) @@ -118,4 +118,4 @@ mod tests { assert_eq!(r1, vec![1_3, 1_5]); assert_eq!(r2.len(), 0); } -} \ No newline at end of file +} diff --git a/substrate/core/client/src/cht.rs b/substrate/core/client/src/cht.rs index d8e7ffbff3..13db1c67eb 100644 --- a/substrate/core/client/src/cht.rs +++ b/substrate/core/client/src/cht.rs @@ -35,7 +35,7 @@ use state_machine::backend::InMemory as InMemoryState; use state_machine::{MemoryDB, TrieBackend, Backend as StateBackend, prove_read_on_trie_backend, read_proof_check, read_proof_check_on_proving_backend}; -use crate::error::{Error as ClientError, ErrorKind as ClientErrorKind, Result as ClientResult}; +use crate::error::{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. @@ -160,11 +160,11 @@ fn do_check_proof( let root: Hasher::Out = convert_hash(&local_root); let local_cht_key = encode_cht_key(local_number); let local_cht_value = checker(root, &local_cht_key)?; - let local_cht_value = local_cht_value.ok_or_else(|| ClientErrorKind::InvalidCHTProof)?; - let local_hash = decode_cht_value(&local_cht_value).ok_or_else(|| ClientErrorKind::InvalidCHTProof)?; + let local_cht_value = local_cht_value.ok_or_else(|| ClientError::InvalidCHTProof)?; + let local_hash = decode_cht_value(&local_cht_value).ok_or_else(|| ClientError::InvalidCHTProof)?; match &local_hash[..] == remote_hash.as_ref() { true => Ok(()), - false => Err(ClientErrorKind::InvalidCHTProof.into()), + false => Err(ClientError::InvalidCHTProof.into()), } } @@ -186,7 +186,7 @@ pub fn for_each_cht_group( for block in blocks { let new_cht_num = match block_to_cht_number(cht_size, block.as_()) { Some(new_cht_num) => new_cht_num, - None => return Err(ClientErrorKind::Backend(format!( + None => return Err(ClientError::Backend(format!( "Cannot compute CHT root for the block #{}", block)).into() ), }; @@ -234,7 +234,7 @@ fn build_pairs( let mut hash_number = start_num; for hash in hashes.into_iter().take(cht_size as usize) { let hash = hash?.ok_or_else(|| ClientError::from( - ClientErrorKind::MissingHashRequiredForCHT(cht_num.as_(), hash_number.as_()) + ClientError::MissingHashRequiredForCHT(cht_num.as_(), hash_number.as_()) ))?; pairs.push(( encode_cht_key(hash_number).to_vec(), @@ -246,7 +246,7 @@ fn build_pairs( if pairs.len() as u64 == cht_size { Ok(pairs) } else { - Err(ClientErrorKind::MissingHashRequiredForCHT(cht_num.as_(), hash_number.as_()).into()) + Err(ClientError::MissingHashRequiredForCHT(cht_num.as_(), hash_number.as_())) } } diff --git a/substrate/core/client/src/client.rs b/substrate/core/client/src/client.rs index 041933cfff..89896fb6eb 100644 --- a/substrate/core/client/src/client.rs +++ b/substrate/core/client/src/client.rs @@ -57,7 +57,7 @@ use executor::{RuntimeVersion, RuntimeInfo}; use crate::notifications::{StorageNotifications, StorageEventStream}; use crate::light::{call_executor::prove_execution, fetcher::ChangesProof}; use crate::cht; -use crate::error::{self, ErrorKind}; +use crate::error; use crate::in_mem; use crate::block_builder::{self, api::BlockBuilder as BlockBuilderAPI}; use crate::genesis; @@ -65,7 +65,6 @@ use consensus; use substrate_telemetry::{telemetry, SUBSTRATE_INFO}; use log::{info, trace, warn}; -use error_chain::bail; /// Type that implements `futures::Stream` of block import events. pub type ImportNotifications = mpsc::UnboundedReceiver>; @@ -383,7 +382,7 @@ impl Client where /// Reads given header and generates CHT-based header proof for CHT of given size. pub fn header_proof_with_cht_size(&self, id: &BlockId, cht_size: u64) -> error::Result<(Block::Header, Vec>)> { - let proof_error = || error::ErrorKind::Backend(format!("Failed to generate header proof for {:?}", id)); + let proof_error = || error::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)?; @@ -409,7 +408,7 @@ impl Client where let first = first.as_(); let last_num = self.backend.blockchain().expect_block_number_from_id(&last)?.as_(); if first > last_num { - return Err(error::ErrorKind::ChangesTrieAccessFailed("Invalid changes trie range".into()).into()); + return Err(error::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.as_()); @@ -440,7 +439,7 @@ impl Client where self.backend.blockchain().info()?.best_number.as_(), &key.0) .and_then(|r| r.map(|r| r.map(|(block, tx)| (As::sa(block), tx))).collect::>()) - .map_err(|err| error::ErrorKind::ChangesTrieAccessFailed(err).into()) + .map_err(|err| error::Error::ChangesTrieAccessFailed(err)) } /// Get proof for computation of (block, extrinsic) pairs where key has been changed at given blocks range. @@ -532,7 +531,7 @@ impl Client where max_number.as_(), &key.0 ) - .map_err(|err| error::Error::from(error::ErrorKind::ChangesTrieAccessFailed(err)))?; + .map_err(|err| error::Error::from(error::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 @@ -586,7 +585,7 @@ impl Client where let storage = self.backend.changes_trie_storage(); match (config, storage) { (Some(config), Some(storage)) => Ok((config, storage)), - _ => Err(error::ErrorKind::ChangesTriesNotSupported.into()), + _ => Err(error::Error::ChangesTriesNotSupported.into()), } } @@ -910,7 +909,7 @@ impl Client where warn!("Safety violation: attempted to revert finalized block {:?} which is not in the \ same chain as last finalized {:?}", retracted, last_finalized); - bail!(error::ErrorKind::NotInFinalizedChain); + return Err(error::Error::NotInFinalizedChain); } let route_from_best = crate::blockchain::tree_route( @@ -1241,7 +1240,7 @@ impl Client where let load_header = |id: Block::Hash| -> error::Result { match self.backend.blockchain().header(BlockId::Hash(id))? { Some(hdr) => Ok(hdr), - None => Err(ErrorKind::UnknownBlock(format!("Unknown block {:?}", id)).into()), + None => Err(Error::UnknownBlock(format!("Unknown block {:?}", id))), } }; diff --git a/substrate/core/client/src/error.rs b/substrate/core/client/src/error.rs index 3ee3c0e2a1..050f867dfc 100644 --- a/substrate/core/client/src/error.rs +++ b/substrate/core/client/src/error.rs @@ -16,159 +16,117 @@ //! Substrate client possible errors. -// Silence: `use of deprecated item 'std::error::Error::cause': replaced by Error::source, which can support downcasting` -// https://github.com/paritytech/substrate/issues/1547 -#![allow(deprecated)] -#![allow(missing_docs)] - -use std; +use std::{self, error, result}; use state_machine; use runtime_primitives::ApplyError; use consensus; -use error_chain::*; +use derive_more::{Display, From}; -error_chain! { - links { - Consensus(consensus::Error, consensus::ErrorKind); - } - errors { - /// Backend error. - Backend(s: String) { - description("Unrecoverable backend error"), - display("Backend error: {}", s), - } +/// Client Result type alias +pub type Result = result::Result; - /// Unknown block. - UnknownBlock(h: String) { - description("unknown block"), - display("UnknownBlock: {}", &*h), - } +/// Substrate Client error +#[derive(Debug, Display, From)] +pub enum Error { + /// Consensus Error + #[display(fmt = "Consensus: {}", _0)] + Consensus(consensus::Error), + /// Backend error. + #[display(fmt = "Backend error: {}", _0)] + Backend(String), + /// Unknown block. + #[display(fmt = "UnknownBlock: {}", _0)] + UnknownBlock(String), + /// Applying extrinsic error. + #[display(fmt = "Extrinsic error: {:?}", _0)] + ApplyExtrinsicFailed(ApplyError), + /// Execution error. + #[display(fmt = "Execution: {}", _0)] + Execution(Box), + /// Blockchain error. + #[display(fmt = "Blockchain: {}", _0)] + Blockchain(Box), + /// Invalid authorities set received from the runtime. + #[display(fmt = "Current state of blockchain has invalid authorities set")] + InvalidAuthoritiesSet, + /// Could not get runtime version. + #[display(fmt = "On-chain runtime does not specify version")] + VersionInvalid, + /// Genesis config is invalid. + #[display(fmt = "Genesis config provided is invalid")] + GenesisInvalid, + /// Bad justification for header. + #[display(fmt = "bad justification for header: {}", _0)] + BadJustification(String), + /// Not available on light client. + #[display(fmt = "This method is not currently available when running in light client mode")] + NotAvailableOnLightClient, + /// Invalid remote CHT-based proof. + #[display(fmt = "Remote node has responded with invalid header proof")] + InvalidCHTProof, + /// Remote fetch has been cancelled. + #[display(fmt = "Remote data fetch has been cancelled")] + RemoteFetchCancelled, + /// Remote fetch has been failed. + #[display(fmt = "Remote data fetch has been failed")] + RemoteFetchFailed, + /// Error decoding call result. + #[display(fmt = "Error decoding call result of {}", _0)] + CallResultDecode(&'static str), + /// Error converting a parameter between runtime and node. + #[display(fmt = "Error converting `{}` between runtime and node", _0)] + RuntimeParamConversion(&'static str), + /// Changes tries are not supported. + #[display(fmt = "Changes tries are not supported by the runtime")] + ChangesTriesNotSupported, + /// Key changes query has failed. + #[display(fmt = "Failed to check changes proof: {}", _0)] + ChangesTrieAccessFailed(String), + /// Last finalized block not parent of current. + #[display(fmt = "Did not finalize blocks in sequential order.")] + NonSequentialFinalization(String), + /// Safety violation: new best block not descendent of last finalized. + #[display(fmt = "Potential long-range attack: block not in finalized chain.")] + NotInFinalizedChain, + /// Hash that is required for building CHT is missing. + #[display(fmt = "Failed to get hash of block#{} for building CHT#{}", _0, _1)] + MissingHashRequiredForCHT(u64, u64), + /// A convenience variant for String + #[display(fmt = "{}", _0)] + Msg(String), +} - /// Applying extrinsic error. - ApplyExtrinsicFailed(e: ApplyError) { - description("Extrinsic error"), - display("Extrinsic error: {:?}", e), - } - - /// Execution error. - Execution(e: Box) { - description("execution error"), - display("Execution: {}", e), - } - - /// Blockchain error. - Blockchain(e: Box) { - description("Blockchain error"), - display("Blockchain: {}", e), - } - - /// Could not get runtime version. - VersionInvalid { - description("Runtime version error"), - display("On-chain runtime does not specify version"), - } - - /// Genesis config is invalid. - GenesisInvalid { - description("Genesis config error"), - display("Genesis config provided is invalid"), - } - - /// Bad justification for header. - BadJustification(h: String) { - description("bad justification for header"), - display("bad justification for header: {}", &*h), - } - - /// Not available on light client. - NotAvailableOnLightClient { - description("not available on light client"), - display("This method is not currently available when running in light client mode"), - } - - /// Invalid remote CHT-based proof. - InvalidCHTProof { - description("invalid header proof"), - display("Remote node has responded with invalid header proof"), - } - - /// Remote fetch has been cancelled. - RemoteFetchCancelled { - description("remote fetch cancelled"), - display("Remote data fetch has been cancelled"), - } - - /// Remote fetch has been failed. - RemoteFetchFailed { - description("remote fetch failed"), - display("Remote data fetch has been failed"), - } - - /// Error decoding call result. - CallResultDecode(method: &'static str) { - description("Error decoding call result") - display("Error decoding call result of {}", method) - } - - /// Error converting a parameter between runtime and node. - RuntimeParamConversion(param: &'static str) { - description("Error converting parameter between runtime and node") - display("Error converting `{}` between runtime and node", param) - } - - /// Changes tries are not supported. - ChangesTriesNotSupported { - description("changes tries are not supported"), - display("Changes tries are not supported by the runtime"), - } - - /// Key changes query has failed. - ChangesTrieAccessFailed(e: String) { - description("invalid changes proof"), - display("Failed to check changes proof: {}", e), - } - - /// Last finalized block not parent of current. - NonSequentialFinalization(s: String) { - description("Did not finalize blocks in sequential order."), - display("Did not finalize blocks in sequential order."), - } - - /// Safety violation: new best block not descendent of last finalized. - NotInFinalizedChain { - description("Potential long-range attack: block not in finalized chain."), - display("Potential long-range attack: block not in finalized chain."), - } - - /// Hash that is required for building CHT is missing. - MissingHashRequiredForCHT(cht_num: u64, block_number: u64) { - description("missed hash required for building CHT"), - display("Failed to get hash of block#{} for building CHT#{}", block_number, cht_num), +impl error::Error for Error { + fn source(&self) -> Option<&(error::Error + 'static)> { + match self { + Error::Consensus(e) => Some(e), + Error::Blockchain(e) => Some(e), + _ => None, } } } -impl From> for Error { - fn from(e: Box) -> Self { - ErrorKind::Execution(e).into() +impl From for Error { + fn from(s: String) -> Self { + Error::Msg(s) } } -impl From for Error { - fn from(e: state_machine::backend::Void) -> Self { - match e {} +impl<'a> From<&'a str> for Error { + fn from(s: &'a str) -> Self { + Error::Msg(s.into()) } } impl Error { /// Chain a blockchain error. - pub fn from_blockchain(e: Box) -> Self { - ErrorKind::Blockchain(e).into() + pub fn from_blockchain(e: Box) -> Self { + Error::Blockchain(e) } /// Chain a state error. pub fn from_state(e: Box) -> Self { - ErrorKind::Execution(e).into() + Error::Execution(e) } } diff --git a/substrate/core/client/src/in_mem.rs b/substrate/core/client/src/in_mem.rs index 29256169f9..5d436b0c89 100644 --- a/substrate/core/client/src/in_mem.rs +++ b/substrate/core/client/src/in_mem.rs @@ -207,7 +207,7 @@ impl Blockchain { pub fn set_head(&self, id: BlockId) -> error::Result<()> { let header = match self.header(id)? { Some(h) => h, - None => return Err(error::ErrorKind::UnknownBlock(format!("{}", id)).into()), + None => return Err(error::Error::UnknownBlock(format!("{}", id))), }; self.apply_head(&header) @@ -258,7 +258,7 @@ impl Blockchain { fn finalize_header(&self, id: BlockId, justification: Option) -> error::Result<()> { let hash = match self.header(id)? { Some(h) => h.hash(), - None => return Err(error::ErrorKind::UnknownBlock(format!("{}", id)).into()), + None => return Err(error::Error::UnknownBlock(format!("{}", id))), }; let mut storage = self.storage.write(); @@ -416,12 +416,12 @@ impl light::blockchain::Storage for Blockchain fn header_cht_root(&self, _cht_size: u64, block: NumberFor) -> error::Result { self.storage.read().header_cht_roots.get(&block).cloned() - .ok_or_else(|| error::ErrorKind::Backend(format!("Header CHT for block {} not exists", block)).into()) + .ok_or_else(|| error::Error::Backend(format!("Header CHT for block {} not exists", block))) } fn changes_trie_cht_root(&self, _cht_size: u64, block: NumberFor) -> error::Result { self.storage.read().changes_trie_cht_roots.get(&block).cloned() - .ok_or_else(|| error::ErrorKind::Backend(format!("Changes trie CHT for block {} not exists", block)).into()) + .ok_or_else(|| error::Error::Backend(format!("Changes trie CHT for block {} not exists", block))) } fn cache(&self) -> Option>> { @@ -665,7 +665,7 @@ where match self.blockchain.id(block).and_then(|id| self.states.read().get(&id).cloned()) { Some(state) => Ok(state), - None => Err(error::ErrorKind::UnknownBlock(format!("{}", block)).into()), + None => Err(error::Error::UnknownBlock(format!("{}", block))), } } @@ -717,11 +717,11 @@ impl state_machine::ChangesTrieStorage for ChangesTrieStorage w /// Check that genesis storage is valid. pub fn check_genesis_storage(top: &StorageOverlay, children: &ChildrenStorageOverlay) -> error::Result<()> { if top.iter().any(|(k, _)| well_known_keys::is_child_storage_key(k)) { - return Err(error::ErrorKind::GenesisInvalid.into()); + return Err(error::Error::GenesisInvalid.into()); } if children.keys().any(|child_key| !well_known_keys::is_child_storage_key(&child_key)) { - return Err(error::ErrorKind::GenesisInvalid.into()); + return Err(error::Error::GenesisInvalid.into()); } Ok(()) diff --git a/substrate/core/client/src/leaves.rs b/substrate/core/client/src/leaves.rs index cc906d59a4..144237f777 100644 --- a/substrate/core/client/src/leaves.rs +++ b/substrate/core/client/src/leaves.rs @@ -85,11 +85,11 @@ impl LeafSet where let raw_hash = &mut &key[prefix.len()..]; let hash = match Decode::decode(raw_hash) { Some(hash) => hash, - None => return Err(error::ErrorKind::Backend("Error decoding hash".into()).into()), + None => return Err(error::Error::Backend("Error decoding hash".into())), }; let number = match Decode::decode(&mut &value[..]) { Some(number) => number, - None => return Err(error::ErrorKind::Backend("Error decoding number".into()).into()), + None => return Err(error::Error::Backend("Error decoding number".into())), }; storage.entry(Reverse(number)).or_insert_with(Vec::new).push(hash); } diff --git a/substrate/core/client/src/light/backend.rs b/substrate/core/client/src/light/backend.rs index b4b805f3c6..b0e0aa3687 100644 --- a/substrate/core/client/src/light/backend.rs +++ b/substrate/core/client/src/light/backend.rs @@ -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 ClientBackend for Backend where } fn revert(&self, _n: NumberFor) -> ClientResult> { - 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>> { - Err(ClientErrorKind::NotAvailableOnLightClient.into()) + Err(ClientError::NotAvailableOnLightClient.into()) } fn for_keys_with_prefix(&self, _prefix: &[u8], _action: A) { diff --git a/substrate/core/client/src/light/blockchain.rs b/substrate/core/client/src/light/blockchain.rs index e081c14d1a..b43247034f 100644 --- a/substrate/core/client/src/light/blockchain.rs +++ b/substrate/core/client/src/light/blockchain.rs @@ -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 BlockchainHeaderBackend for Blockchain 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 for DummyStorage { fn header(&self, _id: BlockId) -> ClientResult> { - Err(ClientErrorKind::Backend("Test error".into()).into()) + Err(ClientError::Backend("Test error".into())) } fn info(&self) -> ClientResult> { - Err(ClientErrorKind::Backend("Test error".into()).into()) + Err(ClientError::Backend("Test error".into())) } fn status(&self, _id: BlockId) -> ClientResult { - Err(ClientErrorKind::Backend("Test error".into()).into()) + Err(ClientError::Backend("Test error".into())) } fn number(&self, hash: Hash) -> ClientResult>> { 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) -> ClientResult<()> { - Err(ClientErrorKind::Backend("Test error".into()).into()) + Err(ClientError::Backend("Test error".into())) } fn finalize_header(&self, _block: BlockId) -> ClientResult<()> { - Err(ClientErrorKind::Backend("Test error".into()).into()) + Err(ClientError::Backend("Test error".into())) } fn last_finalized(&self) -> ClientResult { - Err(ClientErrorKind::Backend("Test error".into()).into()) + Err(ClientError::Backend("Test error".into())) } fn header_cht_root(&self, _cht_size: u64, _block: u64) -> ClientResult { - 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 { 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()) } diff --git a/substrate/core/client/src/light/call_executor.rs b/substrate/core/client/src/light/call_executor.rs index 1e50d3398e..6fcd2f4052 100644 --- a/substrate/core/client/src/light/call_executor.rs +++ b/substrate/core/client/src/light/call_executor.rs @@ -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> where ExecutionManager: 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) -> ClientResult { 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, _side_effects_handler: Option<&mut O>, ) -> ClientResult<(NativeOrEncoded, S::Transaction, Option>)> { - Err(ClientErrorKind::NotAvailableOnLightClient.into()) + Err(ClientError::NotAvailableOnLightClient.into()) } fn prove_at_trie_state>( @@ -166,7 +166,7 @@ where _method: &str, _call_data: &[u8] ) -> ClientResult<(Vec, Vec>)> { - Err(ClientErrorKind::NotAvailableOnLightClient.into()) + Err(ClientError::NotAvailableOnLightClient.into()) } fn native_runtime_version(&self) -> Option<&NativeVersion> { @@ -275,7 +275,7 @@ impl CallExecutor 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 CallExecutor 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 CallExecutor 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>( diff --git a/substrate/core/client/src/light/fetcher.rs b/substrate/core/client/src/light/fetcher.rs index 4cbbc819b3..3f724c31c4 100644 --- a/substrate/core/client/src/light/fetcher.rs +++ b/substrate/core/client/src/light/fetcher.rs @@ -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, F> LightDataChecker 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, F> LightDataChecker= 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, F> LightDataChecker, F> LightDataChecker FetchChecker for LightDataChecker> ) -> ClientResult { 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::( 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 diff --git a/substrate/core/consensus/aura/slots/src/lib.rs b/substrate/core/consensus/aura/slots/src/lib.rs index cfad5b69cd..cca8732b78 100644 --- a/substrate/core/consensus/aura/slots/src/lib.rs +++ b/substrate/core/consensus/aura/slots/src/lib.rs @@ -226,7 +226,7 @@ impl SlotDuration { match client.get_aux(SLOT_KEY)? { Some(v) => u64::decode(&mut &v[..]) .map(SlotDuration) - .ok_or_else(|| ::client::error::ErrorKind::Backend( + .ok_or_else(|| ::client::error::Error::Backend( format!("Aura slot duration kept in invalid format"), ).into()), None => { diff --git a/substrate/core/finality-grandpa/src/aux_schema.rs b/substrate/core/finality-grandpa/src/aux_schema.rs index 104284538c..99cecb98d5 100644 --- a/substrate/core/finality-grandpa/src/aux_schema.rs +++ b/substrate/core/finality-grandpa/src/aux_schema.rs @@ -20,7 +20,7 @@ use std::fmt::Debug; use std::sync::Arc; use parity_codec::{Encode, Decode}; use client::backend::AuxStore; -use client::error::{Result as ClientResult, Error as ClientError, ErrorKind as ClientErrorKind}; +use client::error::{Result as ClientResult, Error as ClientError}; use fork_tree::ForkTree; use grandpa::round::State as RoundState; use runtime_primitives::traits::{Block as BlockT, NumberFor}; @@ -109,7 +109,7 @@ fn load_decode(backend: &B, key: &[u8]) -> ClientResult< None => Ok(None), Some(t) => T::decode(&mut &t[..]) .ok_or_else( - || ClientErrorKind::Backend(format!("GRANDPA DB is corrupted.")).into(), + || ClientError::Backend(format!("GRANDPA DB is corrupted.")), ) .map(Some) } @@ -314,8 +314,8 @@ pub(crate) fn load_persistent( set_state: set_state.into(), }); } - }, - Some(other) => return Err(ClientErrorKind::Backend( + } + Some(other) => return Err(ClientError::Backend( format!("Unsupported GRANDPA DB version: {:?}", other) ).into()), } diff --git a/substrate/core/finality-grandpa/src/finality_proof.rs b/substrate/core/finality-grandpa/src/finality_proof.rs index 2a28cca3a8..a3147ce338 100644 --- a/substrate/core/finality-grandpa/src/finality_proof.rs +++ b/substrate/core/finality-grandpa/src/finality_proof.rs @@ -33,7 +33,7 @@ use grandpa::voter_set::VoterSet; use client::{ blockchain::Backend as BlockchainBackend, - error::{Error as ClientError, ErrorKind as ClientErrorKind, Result as ClientResult}, + error::{Error as ClientError, Result as ClientResult}, light::fetcher::RemoteCallRequest, }; use parity_codec::{Encode, Decode}; @@ -73,7 +73,7 @@ pub fn prove_finality( // early-return if we sure that the block is NOT a part of canonical chain let canonical_block = blockchain.expect_block_hash_from_id(&BlockId::Number(block_number))?; if block != canonical_block { - return Err(ClientErrorKind::Backend( + return Err(ClientError::Backend( "Cannot generate finality proof for non-canonical block".into() ).into()); } @@ -111,7 +111,7 @@ pub fn prove_finality( } } - Err(ClientErrorKind::Backend( + Err(ClientError::Backend( "cannot find justification for finalized block".into() ).into()) } @@ -156,16 +156,16 @@ fn do_check_finality_proof, C, J>( { // decode finality proof let proof = FinalityProof::::decode(&mut &remote_proof[..]) - .ok_or_else(|| ClientErrorKind::BadJustification("failed to decode finality proof".into()))?; + .ok_or_else(|| ClientError::BadJustification("failed to decode finality proof".into()))?; // check that the first header in finalization path is the block itself { let finalized_header = proof.finalization_path.first() - .ok_or_else(|| ClientError::from(ClientErrorKind::BadJustification( + .ok_or_else(|| ClientError::from(ClientError::BadJustification( "finality proof: finalized path is empty".into() )))?; if *finalized_header.number() != block.0 || finalized_header.hash() != block.1 { - return Err(ClientErrorKind::BadJustification( + return Err(ClientError::BadJustification( "finality proof: block is not a part of finalized path".into() ).into()); } @@ -177,7 +177,7 @@ fn do_check_finality_proof, C, J>( let finalized_header = proof.finalization_path.last() .expect("checked above that proof.finalization_path is not empty; qed"); if *finalized_header.number() != just_block.0 || finalized_header.hash() != just_block.1 { - return Err(ClientErrorKind::BadJustification( + return Err(ClientError::BadJustification( "finality proof: target justification block is not a part of finalized path".into() ).into()); } @@ -192,7 +192,7 @@ fn do_check_finality_proof, C, J>( retry_count: None, })?; let grandpa_authorities: Vec<(AuthorityId, u64)> = Decode::decode(&mut &grandpa_authorities[..]) - .ok_or_else(|| ClientErrorKind::BadJustification("failed to decode GRANDPA authorities set proof".into()))?; + .ok_or_else(|| ClientError::BadJustification("failed to decode GRANDPA authorities set proof".into()))?; // and now check justification proof.justification.verify(set_id, &grandpa_authorities.into_iter().collect())?; @@ -392,7 +392,7 @@ mod tests { fn target_block(&self) -> (u64, H256) { (3, header(3).hash()) } fn verify(&self, _set_id: u64, _authorities: &VoterSet) -> ClientResult<()> { - Err(ClientErrorKind::Backend("test error".into()).into()) + Err(ClientError::Backend("test error".into())) } } diff --git a/substrate/core/finality-grandpa/src/justification.rs b/substrate/core/finality-grandpa/src/justification.rs index 57ea3a344c..5b55acec85 100644 --- a/substrate/core/finality-grandpa/src/justification.rs +++ b/substrate/core/finality-grandpa/src/justification.rs @@ -19,7 +19,7 @@ use std::collections::{HashMap, HashSet}; use client::{CallExecutor, Client}; use client::backend::Backend; use client::blockchain::HeaderBackend; -use client::error::{Error as ClientError, ErrorKind as ClientErrorKind}; +use client::error::Error as ClientError; use parity_codec::{Encode, Decode}; use grandpa::voter_set::VoterSet; use grandpa::{Error as GrandpaError}; @@ -64,7 +64,7 @@ impl> GrandpaJustification { let error = || { let msg = "invalid precommits for target commit".to_string(); - Err(Error::Client(ClientErrorKind::BadJustification(msg).into())) + Err(Error::Client(ClientError::BadJustification(msg))) }; for signed in commit.precommits.iter() { @@ -104,12 +104,12 @@ impl> GrandpaJustification { { let justification = GrandpaJustification::::decode(&mut &*encoded).ok_or_else(|| { let msg = "failed to decode grandpa justification".to_string(); - ClientError::from(ClientErrorKind::BadJustification(msg)) + ClientError::from(ClientError::BadJustification(msg)) })?; if (justification.commit.target_hash, justification.commit.target_number) != finalized_target { let msg = "invalid commit target in grandpa justification".to_string(); - Err(ClientErrorKind::BadJustification(msg).into()) + Err(ClientError::BadJustification(msg)) } else { justification.verify(set_id, voters).map(|_| justification) } @@ -132,7 +132,7 @@ impl> GrandpaJustification { Ok(ref result) if result.ghost().is_some() => {}, _ => { let msg = "invalid commit in grandpa justification".to_string(); - return Err(ClientErrorKind::BadJustification(msg).into()); + return Err(ClientError::BadJustification(msg)); } } @@ -145,7 +145,7 @@ impl> GrandpaJustification { self.round, set_id, ) { - return Err(ClientErrorKind::BadJustification( + return Err(ClientError::BadJustification( "invalid signature for precommit in grandpa justification".to_string()).into()); } @@ -162,7 +162,7 @@ impl> GrandpaJustification { } }, _ => { - return Err(ClientErrorKind::BadJustification( + return Err(ClientError::BadJustification( "invalid precommit ancestry proof in grandpa justification".to_string()).into()); }, } @@ -174,7 +174,7 @@ impl> GrandpaJustification { .collect(); if visited_hashes != ancestry_hashes { - return Err(ClientErrorKind::BadJustification( + return Err(ClientError::BadJustification( "invalid precommit ancestries in grandpa justification with unused headers".to_string()).into()); } diff --git a/substrate/core/network/src/error.rs b/substrate/core/network/src/error.rs index bf687f9969..87b967765c 100644 --- a/substrate/core/network/src/error.rs +++ b/substrate/core/network/src/error.rs @@ -27,10 +27,7 @@ use client; error_chain! { foreign_links { Io(IoError) #[doc = "IO error."]; - } - - links { - Client(client::error::Error, client::error::ErrorKind) #[doc="Client error"]; + Client(client::error::Error) #[doc="Client error"]; } errors { diff --git a/substrate/core/network/src/on_demand.rs b/substrate/core/network/src/on_demand.rs index e02355cb5e..ca2d04a662 100644 --- a/substrate/core/network/src/on_demand.rs +++ b/substrate/core/network/src/on_demand.rs @@ -25,7 +25,7 @@ use futures::sync::oneshot::{channel, Receiver, Sender as OneShotSender}; use linked_hash_map::LinkedHashMap; use linked_hash_map::Entry; use parking_lot::Mutex; -use client::{error::{Error as ClientError, ErrorKind as ClientErrorKind}}; +use client::error::Error as ClientError; use client::light::fetcher::{Fetcher, FetchChecker, RemoteHeaderRequest, RemoteCallRequest, RemoteReadRequest, RemoteChangesRequest, ChangesProof}; use crate::message; @@ -121,7 +121,7 @@ impl Future for RemoteResponse { fn poll(&mut self) -> Poll { self.receiver.poll() - .map_err(|_| ClientErrorKind::RemoteFetchCancelled.into()) + .map_err(|_| ClientError::RemoteFetchCancelled.into()) .and_then(|r| match r { Async::Ready(Ok(ready)) => Ok(Async::Ready(ready)), Async::Ready(Err(error)) => Err(error), @@ -194,7 +194,7 @@ impl OnDemand where (retry_count - 1, Some(retry_request_data)) } else { trace!(target: "sync", "Failed to get remote {} response for given number of retries", rtype); - retry_request_data.fail(ClientErrorKind::RemoteFetchFailed.into()); + retry_request_data.fail(ClientError::RemoteFetchFailed.into()); (0, None) } }, @@ -527,7 +527,7 @@ pub mod tests { use std::time::Instant; use futures::Future; use runtime_primitives::traits::NumberFor; - use client::{error::{ErrorKind as ClientErrorKind, Result as ClientResult}}; + use client::{error::{Error as ClientError, Result as ClientResult}}; use client::light::fetcher::{Fetcher, FetchChecker, RemoteHeaderRequest, RemoteCallRequest, RemoteReadRequest, RemoteChangesRequest, ChangesProof}; use crate::config::Roles; @@ -549,28 +549,28 @@ pub mod tests { ) -> ClientResult
{ match self.ok { true if header.is_some() => Ok(header.unwrap()), - _ => Err(ClientErrorKind::Backend("Test error".into()).into()), + _ => Err(ClientError::Backend("Test error".into())), } } fn check_read_proof(&self, _: &RemoteReadRequest
, _: Vec>) -> ClientResult>> { match self.ok { true => Ok(Some(vec![42])), - false => Err(ClientErrorKind::Backend("Test error".into()).into()), + false => Err(ClientError::Backend("Test error".into())), } } fn check_execution_proof(&self, _: &RemoteCallRequest
, _: Vec>) -> ClientResult> { match self.ok { true => Ok(vec![42]), - false => Err(ClientErrorKind::Backend("Test error".into()).into()), + false => Err(ClientError::Backend("Test error".into())), } } fn check_changes_proof(&self, _: &RemoteChangesRequest
, _: ChangesProof
) -> ClientResult, u32)>> { match self.ok { true => Ok(vec![(100, 2)]), - false => Err(ClientErrorKind::Backend("Test error".into()).into()), + false => Err(ClientError::Backend("Test error".into())), } } } diff --git a/substrate/core/rpc/src/author/error.rs b/substrate/core/rpc/src/author/error.rs index 9c1ec23225..0084c4da8f 100644 --- a/substrate/core/rpc/src/author/error.rs +++ b/substrate/core/rpc/src/author/error.rs @@ -24,9 +24,11 @@ use crate::rpc; use crate::errors; error_chain! { + foreign_links { + Client(client::error::Error) #[doc = "Client error"]; + } links { Pool(txpool::error::Error, txpool::error::ErrorKind) #[doc = "Pool error"]; - Client(client::error::Error, client::error::ErrorKind) #[doc = "Client error"]; } errors { /// Not implemented yet diff --git a/substrate/core/rpc/src/chain/error.rs b/substrate/core/rpc/src/chain/error.rs index c52d44eddc..81fe01a19d 100644 --- a/substrate/core/rpc/src/chain/error.rs +++ b/substrate/core/rpc/src/chain/error.rs @@ -20,8 +20,8 @@ use crate::rpc; use crate::errors; error_chain! { - links { - Client(client::error::Error, client::error::ErrorKind) #[doc = "Client error"]; + foreign_links { + Client(client::error::Error) #[doc = "Client error"]; } errors { /// Not implemented yet diff --git a/substrate/core/rpc/src/state/error.rs b/substrate/core/rpc/src/state/error.rs index bd85664099..d4b3013abb 100644 --- a/substrate/core/rpc/src/state/error.rs +++ b/substrate/core/rpc/src/state/error.rs @@ -20,8 +20,8 @@ use crate::rpc; use crate::errors; error_chain! { - links { - Client(client::error::Error, client::error::ErrorKind) #[doc = "Client error"]; + foreign_links { + Client(client::error::Error) #[doc = "Client error"]; } errors { diff --git a/substrate/core/rpc/src/state/tests.rs b/substrate/core/rpc/src/state/tests.rs index a63b8489eb..09ef303a64 100644 --- a/substrate/core/rpc/src/state/tests.rs +++ b/substrate/core/rpc/src/state/tests.rs @@ -44,7 +44,7 @@ fn should_call_contract() { assert_matches!( client.call("balanceOf".into(), Bytes(vec![1,2,3]), Some(genesis_hash).into()), - Err(Error(ErrorKind::Client(client::error::ErrorKind::Execution(_)), _)) + Err(Error(ErrorKind::Client(client::error::Error::Execution(_)), _)) ) } diff --git a/substrate/core/service/src/error.rs b/substrate/core/service/src/error.rs index 4832efb2ab..3155d781ad 100644 --- a/substrate/core/service/src/error.rs +++ b/substrate/core/service/src/error.rs @@ -28,12 +28,12 @@ use error_chain::*; error_chain! { foreign_links { + Client(client::error::Error) #[doc="Client error"]; Io(::std::io::Error) #[doc="IO error"]; } links { - Client(client::error::Error, client::error::ErrorKind) #[doc="Client error"]; - Consensus(consensus_common::Error, consensus_common::ErrorKind) #[doc="Consesus error"]; + Consensus(consensus_common::Error, consensus_common::ErrorKind) #[doc="Consensus error"]; Network(network::error::Error, network::error::ErrorKind) #[doc="Network error"]; Keystore(keystore::Error, keystore::ErrorKind) #[doc="Keystore error"]; } diff --git a/substrate/core/sr-api-macros/src/decl_runtime_apis.rs b/substrate/core/sr-api-macros/src/decl_runtime_apis.rs index 1f390267a9..109b37d875 100644 --- a/substrate/core/sr-api-macros/src/decl_runtime_apis.rs +++ b/substrate/core/sr-api-macros/src/decl_runtime_apis.rs @@ -637,7 +637,7 @@ impl<'a> ToClientSideDecl<'a> { #crate_::runtime_api::NativeOrEncoded::Encoded(r) => { <#ret_type as #crate_::runtime_api::Decode>::decode(&mut &r[..]) .ok_or_else(|| - #crate_::error::ErrorKind::CallResultDecode( + #crate_::error::Error::CallResultDecode( #function_name ).into() ) diff --git a/substrate/core/test-runtime/wasm/Cargo.lock b/substrate/core/test-runtime/wasm/Cargo.lock index 7df0a26524..bcc431c828 100644 --- a/substrate/core/test-runtime/wasm/Cargo.lock +++ b/substrate/core/test-runtime/wasm/Cargo.lock @@ -435,6 +435,17 @@ name = "data-encoding" version = "2.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "derive_more" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 0.6.11 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.29 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "digest" version = "0.6.2" @@ -2259,7 +2270,7 @@ dependencies = [ name = "substrate-client" version = "1.0.0" dependencies = [ - "error-chain 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", + "derive_more 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)", "fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", "hash-db 0.12.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3052,6 +3063,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum cuckoofilter 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "8dd43f7cfaffe0a386636a10baea2ee05cc50df3b77bea4a456c9572a939bf1f" "checksum curve25519-dalek 1.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "e1f8a6fc0376eb52dc18af94915cc04dfdf8353746c0e8c550ae683a0815e5c1" "checksum data-encoding 2.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f4f47ca1860a761136924ddd2422ba77b2ea54fe8cc75b9040804a0d9d32ad97" +"checksum derive_more 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fbe9f11be34f800b3ecaaed0ec9ec2e015d1d0ba0c8644c1310f73d6e8994615" "checksum digest 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e5b29bf156f3f4b3c4f610a25ff69370616ae6e0657d416de22645483e72af0a" "checksum digest 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "05f47366984d3ad862010e22c7ce81a7dbcaebbdfb37241a620f8b6596ee135c" "checksum discard 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "212d0f5754cb6769937f4501cc0e67f4f4483c8d2c3e1e922ee9edbe4ab4c7c0" diff --git a/substrate/core/transaction-pool/src/error.rs b/substrate/core/transaction-pool/src/error.rs index e1223c537d..d4cc0acee8 100644 --- a/substrate/core/transaction-pool/src/error.rs +++ b/substrate/core/transaction-pool/src/error.rs @@ -16,6 +16,10 @@ //! Transaction pool error. +// Silence: `use of deprecated item 'std::error::Error::cause': replaced by Error::source, which can support downcasting` +// https://github.com/paritytech/substrate/issues/1547 +#![allow(deprecated)] + use client; use txpool; use error_chain::{ @@ -23,8 +27,10 @@ use error_chain::{ }; error_chain! { + foreign_links { + Client(client::error::Error) #[doc = "Client error"]; + } links { - Client(client::error::Error, client::error::ErrorKind) #[doc = "Client error"]; Pool(txpool::error::Error, txpool::error::ErrorKind) #[doc = "Pool error"]; } } diff --git a/substrate/node-template/runtime/wasm/Cargo.lock b/substrate/node-template/runtime/wasm/Cargo.lock index 9d6c917b15..a427ab7690 100644 --- a/substrate/node-template/runtime/wasm/Cargo.lock +++ b/substrate/node-template/runtime/wasm/Cargo.lock @@ -435,6 +435,17 @@ name = "data-encoding" version = "2.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "derive_more" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 0.6.11 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.29 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "digest" version = "0.6.2" @@ -2421,7 +2432,7 @@ dependencies = [ name = "substrate-client" version = "1.0.0" dependencies = [ - "error-chain 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", + "derive_more 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)", "fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", "hash-db 0.12.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3179,6 +3190,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum cuckoofilter 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "8dd43f7cfaffe0a386636a10baea2ee05cc50df3b77bea4a456c9572a939bf1f" "checksum curve25519-dalek 1.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "e1f8a6fc0376eb52dc18af94915cc04dfdf8353746c0e8c550ae683a0815e5c1" "checksum data-encoding 2.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f4f47ca1860a761136924ddd2422ba77b2ea54fe8cc75b9040804a0d9d32ad97" +"checksum derive_more 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fbe9f11be34f800b3ecaaed0ec9ec2e015d1d0ba0c8644c1310f73d6e8994615" "checksum digest 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e5b29bf156f3f4b3c4f610a25ff69370616ae6e0657d416de22645483e72af0a" "checksum digest 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "05f47366984d3ad862010e22c7ce81a7dbcaebbdfb37241a620f8b6596ee135c" "checksum discard 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "212d0f5754cb6769937f4501cc0e67f4f4483c8d2c3e1e922ee9edbe4ab4c7c0" diff --git a/substrate/node/runtime/src/lib.rs b/substrate/node/runtime/src/lib.rs index e9764ef1c0..432a8119ff 100644 --- a/substrate/node/runtime/src/lib.rs +++ b/substrate/node/runtime/src/lib.rs @@ -60,7 +60,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { impl_name: create_runtime_str!("substrate-node"), authoring_version: 10, spec_version: 59, - impl_version: 59, + impl_version: 60, apis: RUNTIME_API_VERSIONS, }; diff --git a/substrate/node/runtime/wasm/Cargo.lock b/substrate/node/runtime/wasm/Cargo.lock index 792c68b39e..f525b16073 100644 --- a/substrate/node/runtime/wasm/Cargo.lock +++ b/substrate/node/runtime/wasm/Cargo.lock @@ -435,6 +435,17 @@ name = "data-encoding" version = "2.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "derive_more" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 0.6.11 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.29 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "digest" version = "0.6.2" @@ -2564,7 +2575,7 @@ dependencies = [ name = "substrate-client" version = "1.0.0" dependencies = [ - "error-chain 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", + "derive_more 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)", "fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", "hash-db 0.12.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3333,6 +3344,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum cuckoofilter 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "8dd43f7cfaffe0a386636a10baea2ee05cc50df3b77bea4a456c9572a939bf1f" "checksum curve25519-dalek 1.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "e1f8a6fc0376eb52dc18af94915cc04dfdf8353746c0e8c550ae683a0815e5c1" "checksum data-encoding 2.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f4f47ca1860a761136924ddd2422ba77b2ea54fe8cc75b9040804a0d9d32ad97" +"checksum derive_more 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fbe9f11be34f800b3ecaaed0ec9ec2e015d1d0ba0c8644c1310f73d6e8994615" "checksum digest 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e5b29bf156f3f4b3c4f610a25ff69370616ae6e0657d416de22645483e72af0a" "checksum digest 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "05f47366984d3ad862010e22c7ce81a7dbcaebbdfb37241a620f8b6596ee135c" "checksum discard 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "212d0f5754cb6769937f4501cc0e67f4f4483c8d2c3e1e922ee9edbe4ab4c7c0"