Expunge error-chain (feat. tomaka) (#2662)

* Remove error_chain

* Expunge error-chain from rpc and service.

* Expunge from transaction pool.

* Expunge from node/cli

* Expunge from keystore.

* Remove some boilerplate.

* Fix remaining stuff.

* Improve on deprecation message.

* Fix issues.

* Fix trnsaction pool tests.

* Fix the rest.

* Fix borked merge.

* Update lock
This commit is contained in:
Tomasz Drwięga
2019-05-24 11:35:31 +02:00
committed by Gavin Wood
parent 69ffec5822
commit c162fc5ff1
68 changed files with 951 additions and 1158 deletions
@@ -25,7 +25,6 @@ use std::{
sync::Arc,
};
use error_chain::bail;
use log::{trace, debug, warn};
use serde::Serialize;
use substrate_primitives::hexdisplay::HexDisplay;
@@ -184,7 +183,7 @@ impl<Hash: hash::Hash + Member + Serialize, Ex: ::std::fmt::Debug> BasePool<Hash
tx: Transaction<Hash, Ex>,
) -> error::Result<Imported<Hash, Ex>> {
if self.future.contains(&tx.hash) || self.ready.contains(&tx.hash) {
bail!(error::ErrorKind::AlreadyImported(Box::new(tx.hash.clone())))
return Err(error::Error::AlreadyImported(Box::new(tx.hash.clone())))
}
let tx = WaitingTransaction::new(
@@ -259,7 +258,7 @@ impl<Hash: hash::Hash + Member + Serialize, Ex: ::std::fmt::Debug> BasePool<Hash
self.ready.remove_invalid(&promoted);
debug!(target: "txpool", "[{:?}] Cycle detected, bailing.", hash);
bail!(error::ErrorKind::CycleDetected)
return Err(error::Error::CycleDetected)
}
Ok(Imported::Ready {
@@ -742,9 +741,9 @@ mod tests {
assert_eq!(it.next(), None);
assert_eq!(pool.ready.len(), 0);
assert_eq!(pool.future.len(), 0);
if let error::ErrorKind::CycleDetected = *err.kind() {
if let error::Error::CycleDetected = err {
} else {
assert!(false, "Invalid error kind: {:?}", err.kind());
assert!(false, "Invalid error kind: {:?}", err);
}
}
@@ -17,50 +17,45 @@
//! Transaction pool errors.
use sr_primitives::transaction_validity::TransactionPriority as Priority;
use error_chain::{
error_chain, error_chain_processing, impl_error_chain_processed, impl_extract_backtrace, impl_error_chain_kind
};
error_chain! {
errors {
/// Transaction is not verifiable yet, but might be in the future.
UnknownTransactionValidity(e: i8) {
description("Runtime cannot determine validity of the transaction yet."),
display("Unkown Transaction Validity. Error code: {}", e),
}
/// Transaction is invalid
InvalidTransaction(e: i8) {
description("Runtime check for the transaction failed."),
display("Invalid Transaction. Error Code: {}", e),
}
/// The transaction is temporarily banned
TemporarilyBanned {
description("Transaction is temporarily banned from importing to the pool."),
display("Temporarily Banned"),
}
/// The transaction is already in the pool.
AlreadyImported(hash: Box<::std::any::Any + Send>) {
description("Transaction is already in the pool"),
display("[{:?}] Already imported", hash),
}
/// The transaction cannot be imported cause it's a replacement and has too low priority.
TooLowPriority(old: Priority, new: Priority) {
description("The priority is too low to replace transactions already in the pool."),
display("Too low priority ({} > {})", old, new)
}
/// Deps cycle detected and we couldn't import transaction.
CycleDetected {
description("Transaction was not imported because of detected cycle."),
display("Cycle Detected"),
}
/// Transaction was dropped immediately after it got inserted.
ImmediatelyDropped {
description("Transaction couldn't enter the pool because of the limit."),
display("Immediately Dropped"),
}
}
/// Transaction pool result.
pub type Result<T> = std::result::Result<T, Error>;
/// Transaction pool error type.
#[derive(Debug, derive_more::Display, derive_more::From)]
pub enum Error {
/// Transaction is not verifiable yet, but might be in the future.
#[display(fmt="Unkown Transaction Validity. Error code: {}", _0)]
UnknownTransactionValidity(i8),
/// Transaction is invalid.
#[display(fmt="Invalid Transaction. Error Code: {}", _0)]
InvalidTransaction(i8),
/// The transaction is temporarily banned.
#[display(fmt="Temporarily Banned")]
TemporarilyBanned,
/// The transaction is already in the pool.
#[display(fmt="[{:?}] Already imported", _0)]
AlreadyImported(Box<std::any::Any + Send>),
/// The transaction cannot be imported cause it's a replacement and has too low priority.
#[display(fmt="Too low priority ({} > {})", old, new)]
TooLowPriority {
/// Transaction already in the pool.
old: Priority,
/// Transaction entering the pool.
new: Priority
},
/// Deps cycle etected and we couldn't import transaction.
#[display(fmt="Cycle Detected")]
CycleDetected,
/// Transaction was dropped immediately after it got inserted.
#[display(fmt="Transaction couldn't enter the pool because of the limit.")]
ImmediatelyDropped,
/// Invalid block id.
InvalidBlockId(String),
}
impl std::error::Error for Error {}
/// Transaction pool error conversion.
pub trait IntoPoolError: ::std::error::Error + Send + Sized {
/// Try to extract original `Error`
@@ -27,7 +27,6 @@ use crate::listener::Listener;
use crate::rotator::PoolRotator;
use crate::watcher::Watcher;
use serde::Serialize;
use error_chain::bail;
use log::debug;
use futures::sync::mpsc;
@@ -119,14 +118,14 @@ impl<B: ChainApi> Pool<B> {
T: IntoIterator<Item=ExtrinsicFor<B>>
{
let block_number = self.api.block_id_to_number(at)?
.ok_or_else(|| error::ErrorKind::Msg(format!("Invalid block id: {:?}", at)).into())?;
.ok_or_else(|| error::Error::InvalidBlockId(format!("{:?}", at)).into())?;
let results = xts
.into_iter()
.map(|xt| -> Result<_, B::Error> {
let (hash, bytes) = self.api.hash_and_length(&xt);
if self.rotator.is_banned(&hash) {
bail!(error::Error::from(error::ErrorKind::TemporarilyBanned))
return Err(error::Error::TemporarilyBanned.into())
}
match self.api.validate_transaction(at, xt.clone())? {
@@ -144,11 +143,11 @@ impl<B: ChainApi> Pool<B> {
})
},
TransactionValidity::Invalid(e) => {
bail!(error::Error::from(error::ErrorKind::InvalidTransaction(e)))
Err(error::Error::InvalidTransaction(e).into())
},
TransactionValidity::Unknown(e) => {
self.listener.write().invalid(&hash);
bail!(error::Error::from(error::ErrorKind::UnknownTransactionValidity(e)))
Err(error::Error::UnknownTransactionValidity(e).into())
},
}
})
@@ -168,7 +167,7 @@ impl<B: ChainApi> Pool<B> {
let removed = self.enforce_limits();
Ok(results.into_iter().map(|res| match res {
Ok(ref hash) if removed.contains(hash) => Err(error::Error::from(error::ErrorKind::ImmediatelyDropped).into()),
Ok(ref hash) if removed.contains(hash) => Err(error::Error::ImmediatelyDropped.into()),
other => other,
}).collect())
}
@@ -308,10 +307,7 @@ impl<B: ChainApi> Pool<B> {
// Collect the hashes of transactions that now became invalid (meaning that they are succesfully pruned).
let hashes = results.into_iter().enumerate().filter_map(|(idx, r)| match r.map_err(error::IntoPoolError::into_pool_error) {
Err(Ok(err)) => match err.kind() {
error::ErrorKind::InvalidTransaction(_) => Some(hashes[idx].clone()),
_ => None,
},
Err(Ok(error::Error::InvalidTransaction(_))) => Some(hashes[idx].clone()),
_ => None,
});
// Fire `pruned` notifications for collected hashes and make sure to include
@@ -319,7 +315,7 @@ impl<B: ChainApi> Pool<B> {
let hashes = hashes.chain(known_imported_hashes.into_iter());
{
let header_hash = self.api.block_id_to_hash(at)?
.ok_or_else(|| error::ErrorKind::Msg(format!("Invalid block id: {:?}", at)).into())?;
.ok_or_else(|| error::Error::InvalidBlockId(format!("{:?}", at)).into())?;
let mut listener = self.listener.write();
for h in hashes {
listener.pruned(header_hash, &h);
@@ -338,7 +334,7 @@ impl<B: ChainApi> Pool<B> {
/// See `prune_tags` if you want this.
pub fn clear_stale(&self, at: &BlockId<B::Block>) -> Result<(), B::Error> {
let block_number = self.api.block_id_to_number(at)?
.ok_or_else(|| error::ErrorKind::Msg(format!("Invalid block id: {:?}", at)).into())?
.ok_or_else(|| error::Error::InvalidBlockId(format!("{:?}", at)).into())?
.saturated_into::<u64>();
let now = time::Instant::now();
let to_remove = {
@@ -569,7 +565,7 @@ mod tests {
assert_eq!(pool.status().future, 0);
// then
assert_matches!(res.unwrap_err().kind(), error::ErrorKind::TemporarilyBanned);
assert_matches!(res.unwrap_err(), error::Error::TemporarilyBanned);
}
#[test]
@@ -23,7 +23,6 @@ use std::{
use serde::Serialize;
use log::debug;
use error_chain::bail;
use parking_lot::RwLock;
use sr_primitives::traits::Member;
use sr_primitives::transaction_validity::{
@@ -376,7 +375,7 @@ impl<Hash: hash::Hash + Member + Serialize, Ex> ReadyTransactions<Hash, Ex> {
// bail - the transaction has too low priority to replace the old ones
if old_priority >= tx.priority {
bail!(error::ErrorKind::TooLowPriority(old_priority, tx.priority))
return Err(error::Error::TooLowPriority { old: old_priority, new: tx.priority })
}
replace_hashes.into_iter().cloned().collect::<Vec<_>>()