diff --git a/transaction-pool/Cargo.toml b/transaction-pool/Cargo.toml index 70aba5d04..bd351160e 100644 --- a/transaction-pool/Cargo.toml +++ b/transaction-pool/Cargo.toml @@ -9,4 +9,4 @@ authors = ["Parity Technologies "] error-chain = "0.11" log = "0.3" smallvec = "0.4" -ethereum-types = { version = "0.1", features = ["heapsizeof"] } +ethereum-types = { version = "0.2", features = ["heapsizeof"] } diff --git a/transaction-pool/src/error.rs b/transaction-pool/src/error.rs index 57fffebc0..706a5b77b 100644 --- a/transaction-pool/src/error.rs +++ b/transaction-pool/src/error.rs @@ -18,16 +18,19 @@ use ethereum_types::H256; error_chain! { errors { + /// Transaction is already imported AlreadyImported(hash: H256) { - description("transaction is already in the queue"), + description("transaction is already in the pool"), display("[{:?}] transaction already imported", hash) } + /// Transaction is too cheap to enter the queue TooCheapToEnter(hash: H256) { description("the pool is full and transaction is too cheap to replace any transaction"), display("[{:?}] transaction too cheap to enter the pool", hash) } + /// Transaction is too cheap to replace existing transaction that occupies the same slot. TooCheapToReplace(old_hash: H256, hash: H256) { - description("transaction is too cheap to replace existing transaction in the queue"), + description("transaction is too cheap to replace existing transaction in the pool"), display("[{:?}] transaction too cheap to replace: {:?}", hash, old_hash) } } diff --git a/transaction-pool/src/lib.rs b/transaction-pool/src/lib.rs index 987fdfc40..29353a100 100644 --- a/transaction-pool/src/lib.rs +++ b/transaction-pool/src/lib.rs @@ -92,7 +92,7 @@ pub mod scoring; pub use self::listener::{Listener, NoopListener}; pub use self::options::Options; -pub use self::pool::Pool; +pub use self::pool::{Pool, PendingIterator}; pub use self::ready::{Ready, Readiness}; pub use self::scoring::Scoring; pub use self::status::{LightStatus, Status}; diff --git a/transaction-pool/src/listener.rs b/transaction-pool/src/listener.rs index 36a5d9de2..2fc55528f 100644 --- a/transaction-pool/src/listener.rs +++ b/transaction-pool/src/listener.rs @@ -44,5 +44,6 @@ pub trait Listener { } /// A no-op implementation of `Listener`. +#[derive(Debug)] pub struct NoopListener; impl Listener for NoopListener {} diff --git a/transaction-pool/src/pool.rs b/transaction-pool/src/pool.rs index 5978acf60..4f4a63920 100644 --- a/transaction-pool/src/pool.rs +++ b/transaction-pool/src/pool.rs @@ -109,6 +109,8 @@ impl Pool where ensure!(!self.by_hash.contains_key(transaction.hash()), error::ErrorKind::AlreadyImported(*transaction.hash())); + // TODO [ToDr] Most likely move this after the transsaction is inserted. + // Avoid using should_replace, but rather use scoring for that. { let remove_worst = |s: &mut Self, transaction| { match s.remove_worst(&transaction) { @@ -288,7 +290,7 @@ impl Pool where /// Removes single transaction from the pool. /// Depending on the `is_invalid` flag the listener /// will either get a `cancelled` or `invalid` notification. - pub fn remove(&mut self, hash: &H256, is_invalid: bool) -> bool { + pub fn remove(&mut self, hash: &H256, is_invalid: bool) -> Option> { if let Some(tx) = self.finalize_remove(hash) { self.remove_from_set(tx.sender(), |set, scoring| { set.remove(&tx, scoring) @@ -298,9 +300,9 @@ impl Pool where } else { self.listener.cancelled(&tx); } - true + Some(tx) } else { - false + None } } diff --git a/transaction-pool/src/ready.rs b/transaction-pool/src/ready.rs index 1d8e342db..735244432 100644 --- a/transaction-pool/src/ready.rs +++ b/transaction-pool/src/ready.rs @@ -40,3 +40,15 @@ impl Ready for F where F: FnMut(&T) -> Readiness { (*self)(tx) } } + +impl Ready for (A, B) where + A: Ready, + B: Ready, +{ + fn is_ready(&mut self, tx: &T) -> Readiness { + match self.0.is_ready(tx) { + Readiness::Ready => self.1.is_ready(tx), + r => r, + } + } +} diff --git a/transaction-pool/src/tests/mod.rs b/transaction-pool/src/tests/mod.rs index 326801162..05b72284b 100644 --- a/transaction-pool/src/tests/mod.rs +++ b/transaction-pool/src/tests/mod.rs @@ -261,7 +261,7 @@ fn should_remove_transaction() { assert_eq!(txq.light_status().transaction_count, 3); // when - assert!(txq.remove(&tx2.hash(), false)); + assert!(txq.remove(&tx2.hash(), false).is_some()); // then assert_eq!(txq.light_status().transaction_count, 2);