From f811fdc2cdfc134c55b1a156d90541bb3111358c Mon Sep 17 00:00:00 2001 From: debris Date: Thu, 26 May 2016 11:39:49 +0200 Subject: [PATCH 1/3] fixed pending transactions --- rpc/src/v1/impls/eth.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/rpc/src/v1/impls/eth.rs b/rpc/src/v1/impls/eth.rs index 4a4ee1643..fc22d2256 100644 --- a/rpc/src/v1/impls/eth.rs +++ b/rpc/src/v1/impls/eth.rs @@ -672,18 +672,22 @@ impl EthFilter for EthFilterClient where to_value(&hashes) }, PollFilter::PendingTransaction(ref mut previous_hashes) => { + // get hashes of pending transactions let current_hashes = take_weak!(self.miner).pending_transactions_hashes(); - // calculate diff let previous_hashes_set = previous_hashes.into_iter().map(|h| h.clone()).collect::>(); - let diff = current_hashes + + // find all new hashes + let new_hashes = current_hashes .iter() - .filter(|hash| previous_hashes_set.contains(&hash)) + .filter(|hash| !previous_hashes_set.contains(&hash)) .cloned() .collect::>(); + // save all hashes of pending transactions *previous_hashes = current_hashes; - to_value(&diff) + // return new hashes + to_value(&new_hashes) }, PollFilter::Logs(ref mut block_number, ref mut previous_logs, ref filter) => { // retrive the current block number From 5b0c936feefbd3d983c2d3cd31e29bd2ef73718a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Drwi=C4=99ga?= Date: Thu, 26 May 2016 11:49:58 +0200 Subject: [PATCH 2/3] Fixing clippy warnings --- miner/src/miner.rs | 2 +- parity/informant.rs | 1 + util/src/migration/db_impl.rs | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/miner/src/miner.rs b/miner/src/miner.rs index d03fcd524..f159cac1c 100644 --- a/miner/src/miner.rs +++ b/miner/src/miner.rs @@ -420,7 +420,7 @@ impl MinerService for Miner { fn transaction(&self, hash: &H256) -> Option { match (self.sealing_enabled.load(atomic::Ordering::Relaxed), self.sealing_work.lock().unwrap().peek_last_ref()) { - (true, Some(pending)) => pending.transactions().iter().find(|t| &t.hash() == hash).map(|t| t.clone()), + (true, Some(pending)) => pending.transactions().iter().find(|t| &t.hash() == hash).cloned(), _ => { let queue = self.transaction_queue.lock().unwrap(); queue.find(hash) diff --git a/parity/informant.rs b/parity/informant.rs index c69c8938e..0eaebe10f 100644 --- a/parity/informant.rs +++ b/parity/informant.rs @@ -75,6 +75,7 @@ impl Informant { } } + #[cfg_attr(feature="dev", allow(match_bool))] pub fn tick(&self, client: &Client, maybe_sync: Option<&EthSync>) { let elapsed = self.last_tick.read().unwrap().elapsed(); if elapsed < Duration::from_secs(5) { diff --git a/util/src/migration/db_impl.rs b/util/src/migration/db_impl.rs index 02c66d19b..760babe3c 100644 --- a/util/src/migration/db_impl.rs +++ b/util/src/migration/db_impl.rs @@ -14,7 +14,7 @@ // You should have received a copy of the GNU General Public License // along with Parity. If not, see . -//! kvdb::Database as migration::Destination +//! `kvdb::Database` as `migration::Destination` use std::collections::BTreeMap; use kvdb::{Database, DBTransaction}; From 6fd9780e602e6902896bebc0d9f88368b549ff85 Mon Sep 17 00:00:00 2001 From: debris Date: Thu, 26 May 2016 12:44:17 +0200 Subject: [PATCH 3/3] do not clone pending transaction hashes --- rpc/src/v1/impls/eth.rs | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/rpc/src/v1/impls/eth.rs b/rpc/src/v1/impls/eth.rs index fc22d2256..a13512357 100644 --- a/rpc/src/v1/impls/eth.rs +++ b/rpc/src/v1/impls/eth.rs @@ -674,14 +674,18 @@ impl EthFilter for EthFilterClient where PollFilter::PendingTransaction(ref mut previous_hashes) => { // get hashes of pending transactions let current_hashes = take_weak!(self.miner).pending_transactions_hashes(); - let previous_hashes_set = previous_hashes.into_iter().map(|h| h.clone()).collect::>(); - // find all new hashes - let new_hashes = current_hashes - .iter() - .filter(|hash| !previous_hashes_set.contains(&hash)) - .cloned() - .collect::>(); + let new_hashes = + { + let previous_hashes_set = previous_hashes.iter().collect::>(); + + // find all new hashes + current_hashes + .iter() + .filter(|hash| !previous_hashes_set.contains(hash)) + .cloned() + .collect::>() + }; // save all hashes of pending transactions *previous_hashes = current_hashes;