From 78b5c12cf915718df7ce343f9fca1076126e5ccc Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Thu, 24 Mar 2016 14:13:43 +0000 Subject: [PATCH 1/5] Fix mining. --- rpc/src/v1/impls/eth.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/rpc/src/v1/impls/eth.rs b/rpc/src/v1/impls/eth.rs index 638403c7d..a59c68ec6 100644 --- a/rpc/src/v1/impls/eth.rs +++ b/rpc/src/v1/impls/eth.rs @@ -197,6 +197,8 @@ impl EthClient } } +const MAX_QUEUE_SIZE_TO_MINE_ON: usize = 4; // because uncles go back 6. + impl Eth for EthClient where C: BlockChainClient + 'static, S: SyncProvider + 'static, @@ -401,7 +403,7 @@ impl Eth for EthClient // check if we're still syncing and return empty strings in that case { let sync = take_weak!(self.sync); - if sync.status().state != SyncState::Idle && client.queue_info().is_empty() { + if sync.status().state != SyncState::Idle && !client.queue_info().total_queue_size() > MAX_QUEUE_SIZE_TO_MINE_ON { trace!(target: "miner", "Syncing. Cannot give any work."); return to_value(&(String::new(), String::new(), String::new())); } From 36c5525e3fac30fd9d13d091e98bf0c46717bacc Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Thu, 24 Mar 2016 14:15:55 +0000 Subject: [PATCH 2/5] Fix logic error. --- rpc/src/v1/impls/eth.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rpc/src/v1/impls/eth.rs b/rpc/src/v1/impls/eth.rs index a59c68ec6..6695aa6b8 100644 --- a/rpc/src/v1/impls/eth.rs +++ b/rpc/src/v1/impls/eth.rs @@ -403,7 +403,7 @@ impl Eth for EthClient // check if we're still syncing and return empty strings in that case { let sync = take_weak!(self.sync); - if sync.status().state != SyncState::Idle && !client.queue_info().total_queue_size() > MAX_QUEUE_SIZE_TO_MINE_ON { + if sync.status().state != SyncState::Idle || !client.queue_info().total_queue_size() > MAX_QUEUE_SIZE_TO_MINE_ON { trace!(target: "miner", "Syncing. Cannot give any work."); return to_value(&(String::new(), String::new(), String::new())); } From 83f812b1760c461354389b00dd7b10c58654170d Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Thu, 24 Mar 2016 14:24:58 +0000 Subject: [PATCH 3/5] Fix logic. agaib. --- rpc/src/v1/impls/eth.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rpc/src/v1/impls/eth.rs b/rpc/src/v1/impls/eth.rs index 6695aa6b8..6a70aad2f 100644 --- a/rpc/src/v1/impls/eth.rs +++ b/rpc/src/v1/impls/eth.rs @@ -403,7 +403,7 @@ impl Eth for EthClient // check if we're still syncing and return empty strings in that case { let sync = take_weak!(self.sync); - if sync.status().state != SyncState::Idle || !client.queue_info().total_queue_size() > MAX_QUEUE_SIZE_TO_MINE_ON { + if sync.status().state != SyncState::Idle || client.queue_info().total_queue_size() > MAX_QUEUE_SIZE_TO_MINE_ON { trace!(target: "miner", "Syncing. Cannot give any work."); return to_value(&(String::new(), String::new(), String::new())); } From 68e4156143c1c0d8402483487ec52d762948d713 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Thu, 24 Mar 2016 14:29:54 +0000 Subject: [PATCH 4/5] Don't care if engaged in sync since it's typically doing so. --- rpc/src/v1/impls/eth.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rpc/src/v1/impls/eth.rs b/rpc/src/v1/impls/eth.rs index 6a70aad2f..2f8575986 100644 --- a/rpc/src/v1/impls/eth.rs +++ b/rpc/src/v1/impls/eth.rs @@ -403,7 +403,7 @@ impl Eth for EthClient // check if we're still syncing and return empty strings in that case { let sync = take_weak!(self.sync); - if sync.status().state != SyncState::Idle || client.queue_info().total_queue_size() > MAX_QUEUE_SIZE_TO_MINE_ON { + if /*sync.status().state != SyncState::Idle ||*/ client.queue_info().total_queue_size() > MAX_QUEUE_SIZE_TO_MINE_ON { trace!(target: "miner", "Syncing. Cannot give any work."); return to_value(&(String::new(), String::new(), String::new())); } From 4840371635bb72f226bf86e49f08b75101299137 Mon Sep 17 00:00:00 2001 From: arkpar Date: Thu, 24 Mar 2016 17:07:54 +0100 Subject: [PATCH 5/5] Fixed test --- ethcore/src/client/test_client.rs | 11 ++++++++++- rpc/src/v1/impls/eth.rs | 3 ++- rpc/src/v1/tests/eth.rs | 3 ++- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/ethcore/src/client/test_client.rs b/ethcore/src/client/test_client.rs index b2230af7b..893cdae03 100644 --- a/ethcore/src/client/test_client.rs +++ b/ethcore/src/client/test_client.rs @@ -16,6 +16,7 @@ //! Test client. +use std::sync::atomic::{AtomicUsize, Ordering as AtomicOrder}; use util::*; use transaction::{Transaction, LocalizedTransaction, SignedTransaction, Action}; use blockchain::TreeRoute; @@ -54,6 +55,8 @@ pub struct TestBlockChainClient { pub execution_result: RwLock>, /// Transaction receipts. pub receipts: RwLock>, + /// Block queue size. + pub queue_size: AtomicUsize, } #[derive(Clone)] @@ -90,6 +93,7 @@ impl TestBlockChainClient { code: RwLock::new(HashMap::new()), execution_result: RwLock::new(None), receipts: RwLock::new(HashMap::new()), + queue_size: AtomicUsize::new(0), }; client.add_blocks(1, EachBlockWith::Nothing); // add genesis block client.genesis_hash = client.last_hash.read().unwrap().clone(); @@ -121,6 +125,11 @@ impl TestBlockChainClient { self.storage.write().unwrap().insert((address, position), value); } + /// Set block queue size for testing + pub fn set_queue_size(&self, size: usize) { + self.queue_size.store(size, AtomicOrder::Relaxed); + } + /// Add blocks to test client. pub fn add_blocks(&self, count: usize, with: EachBlockWith) { let len = self.numbers.read().unwrap().len(); @@ -383,7 +392,7 @@ impl BlockChainClient for TestBlockChainClient { fn queue_info(&self) -> BlockQueueInfo { BlockQueueInfo { - verified_queue_size: 0, + verified_queue_size: self.queue_size.load(AtomicOrder::Relaxed), unverified_queue_size: 0, verifying_queue_size: 0, max_queue_size: 0, diff --git a/rpc/src/v1/impls/eth.rs b/rpc/src/v1/impls/eth.rs index 2f8575986..99f6eda3e 100644 --- a/rpc/src/v1/impls/eth.rs +++ b/rpc/src/v1/impls/eth.rs @@ -402,7 +402,8 @@ impl Eth for EthClient let client = take_weak!(self.client); // check if we're still syncing and return empty strings in that case { - let sync = take_weak!(self.sync); + //TODO: check if initial sync is complete here + //let sync = take_weak!(self.sync); if /*sync.status().state != SyncState::Idle ||*/ client.queue_info().total_queue_size() > MAX_QUEUE_SIZE_TO_MINE_ON { trace!(target: "miner", "Syncing. Cannot give any work."); return to_value(&(String::new(), String::new(), String::new())); diff --git a/rpc/src/v1/tests/eth.rs b/rpc/src/v1/tests/eth.rs index 41b77388b..9df6b82a1 100644 --- a/rpc/src/v1/tests/eth.rs +++ b/rpc/src/v1/tests/eth.rs @@ -474,7 +474,8 @@ fn rpc_eth_compile_serpent() { #[test] fn returns_no_work_if_cant_mine() { - let eth_tester = EthTester::default(); + let mut eth_tester = EthTester::default(); + eth_tester.client.set_queue_size(10); let request = r#"{"jsonrpc": "2.0", "method": "eth_getWork", "params": [], "id": 1}"#; let response = r#"{"jsonrpc":"2.0","result":["","",""],"id":1}"#;