From b2891fcdda0de9128772f10c684f90d9fb5df310 Mon Sep 17 00:00:00 2001 From: Arkadiy Paronyan Date: Tue, 21 Jun 2016 16:00:34 +0200 Subject: [PATCH] Update sealing on new transactions (#1365) --- ethcore/src/client/client.rs | 4 ++-- ethcore/src/client/test_client.rs | 2 +- ethcore/src/miner/miner.rs | 18 ++++++++++++------ ethcore/src/miner/mod.rs | 2 +- rpc/src/v1/tests/helpers/miner_service.rs | 2 +- 5 files changed, 17 insertions(+), 11 deletions(-) diff --git a/ethcore/src/client/client.rs b/ethcore/src/client/client.rs index bf67a8772..25e61a986 100644 --- a/ethcore/src/client/client.rs +++ b/ethcore/src/client/client.rs @@ -381,7 +381,7 @@ impl Client where V: Verifier { balance: self.latest_balance(a), }; let tx = transactions.iter().filter_map(|bytes| UntrustedRlp::new(&bytes).as_val().ok()).collect(); - let results = self.miner.import_transactions(tx, fetch_account); + let results = self.miner.import_transactions(self, tx, fetch_account); results.len() } @@ -771,7 +771,7 @@ impl BlockChainClient for Client where V: Verifier { nonce: self.latest_nonce(a), balance: self.latest_balance(a), }; - self.miner.import_transactions(transactions, fetch_account) + self.miner.import_transactions(self, transactions, fetch_account) } fn queue_transactions(&self, transactions: Vec) { diff --git a/ethcore/src/client/test_client.rs b/ethcore/src/client/test_client.rs index b6cc946fc..29f91a1d6 100644 --- a/ethcore/src/client/test_client.rs +++ b/ethcore/src/client/test_client.rs @@ -490,7 +490,7 @@ impl BlockChainClient for TestBlockChainClient { balance: balances[a], }; - self.miner.import_transactions(transactions, &fetch_account) + self.miner.import_transactions(self, transactions, &fetch_account) } fn queue_transactions(&self, transactions: Vec) { diff --git a/ethcore/src/miner/miner.rs b/ethcore/src/miner/miner.rs index 735ad5cf4..9840a682e 100644 --- a/ethcore/src/miner/miner.rs +++ b/ethcore/src/miner/miner.rs @@ -376,13 +376,19 @@ impl MinerService for Miner { *self.gas_floor_target.read().unwrap() } - fn import_transactions(&self, transactions: Vec, fetch_account: T) -> + fn import_transactions(&self, chain: &MiningBlockChainClient, transactions: Vec, fetch_account: T) -> Vec> where T: Fn(&Address) -> AccountDetails { - let mut transaction_queue = self.transaction_queue.lock().unwrap(); - transactions.into_iter() - .map(|tx| transaction_queue.add(tx, &fetch_account, TransactionOrigin::External)) - .collect() + let results: Vec> = { + let mut transaction_queue = self.transaction_queue.lock().unwrap(); + transactions.into_iter() + .map(|tx| transaction_queue.add(tx, &fetch_account, TransactionOrigin::External)) + .collect() + }; + if !results.is_empty() { + self.update_sealing(chain); + } + results } fn import_own_transaction( @@ -564,7 +570,7 @@ impl MinerService for Miner { for tx in &txs { let _sender = tx.sender(); } - let _ = self.import_transactions(txs, |a| AccountDetails { + let _ = self.import_transactions(chain, txs, |a| AccountDetails { nonce: chain.latest_nonce(a), balance: chain.latest_balance(a), }); diff --git a/ethcore/src/miner/mod.rs b/ethcore/src/miner/mod.rs index 71727f51d..697f7513f 100644 --- a/ethcore/src/miner/mod.rs +++ b/ethcore/src/miner/mod.rs @@ -94,7 +94,7 @@ pub trait MinerService : Send + Sync { fn set_transactions_limit(&self, limit: usize); /// Imports transactions to transaction queue. - fn import_transactions(&self, transactions: Vec, fetch_account: T) -> + fn import_transactions(&self, chain: &MiningBlockChainClient, transactions: Vec, fetch_account: T) -> Vec> where T: Fn(&Address) -> AccountDetails, Self: Sized; diff --git a/rpc/src/v1/tests/helpers/miner_service.rs b/rpc/src/v1/tests/helpers/miner_service.rs index daa5c9497..7ec7fc1cc 100644 --- a/rpc/src/v1/tests/helpers/miner_service.rs +++ b/rpc/src/v1/tests/helpers/miner_service.rs @@ -115,7 +115,7 @@ impl MinerService for TestMinerService { } /// Imports transactions to transaction queue. - fn import_transactions(&self, transactions: Vec, fetch_account: T) -> + fn import_transactions(&self, _chain: &MiningBlockChainClient, transactions: Vec, fetch_account: T) -> Vec> where T: Fn(&Address) -> AccountDetails { // lets assume that all txs are valid