From 7610d308e83056dce4e1d0961c1d8562d0f26637 Mon Sep 17 00:00:00 2001 From: debris Date: Tue, 14 Jun 2016 15:17:17 +0200 Subject: [PATCH 1/3] fixed #1255 --- rpc/src/v1/impls/eth.rs | 11 ++++++++++- rpc/src/v1/tests/mocked/eth.rs | 2 +- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/rpc/src/v1/impls/eth.rs b/rpc/src/v1/impls/eth.rs index b0d6abcf0..ac123c565 100644 --- a/rpc/src/v1/impls/eth.rs +++ b/rpc/src/v1/impls/eth.rs @@ -212,6 +212,7 @@ fn from_params_default_third(params: Params) -> Result<(F1, F2, BlockNum // must be in range [-32099, -32000] const UNSUPPORTED_REQUEST_CODE: i64 = -32000; +const NO_WORK_CODE: i64 = -32001; fn make_unsupported_err() -> Error { Error { @@ -221,6 +222,14 @@ fn make_unsupported_err() -> Error { } } +fn no_work_err() -> Error { + Error { + code: ErrorCode::ServerError(NO_WORK_CODE), + message: "Mining not ready.".into(), + data: None + } +} + impl Eth for EthClient where C: MiningBlockChainClient + 'static, S: SyncProvider + 'static, @@ -460,7 +469,7 @@ impl Eth for EthClient where //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())); + return Err(no_work_err()); } } diff --git a/rpc/src/v1/tests/mocked/eth.rs b/rpc/src/v1/tests/mocked/eth.rs index 34708e232..801a74f1d 100644 --- a/rpc/src/v1/tests/mocked/eth.rs +++ b/rpc/src/v1/tests/mocked/eth.rs @@ -732,7 +732,7 @@ fn returns_no_work_if_cant_mine() { 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}"#; + let response = r#"{"jsonrpc":"2.0","error":{"code":-32001,"message":"Mining not ready.","data":null},"id":1}"#; assert_eq!(eth_tester.io.handle_request(request), Some(response.to_owned())); } From dac387fac10c6c38035171ef0e30910e7fb115fb Mon Sep 17 00:00:00 2001 From: debris Date: Wed, 15 Jun 2016 01:12:46 +0200 Subject: [PATCH 2/3] changed rpc error message to Still Syncing, when mining is not ready --- 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 ac123c565..2d337e73c 100644 --- a/rpc/src/v1/impls/eth.rs +++ b/rpc/src/v1/impls/eth.rs @@ -225,7 +225,7 @@ fn make_unsupported_err() -> Error { fn no_work_err() -> Error { Error { code: ErrorCode::ServerError(NO_WORK_CODE), - message: "Mining not ready.".into(), + message: "Still syncing.".into(), data: None } } From be6c572449e67a1b49abc78735d215d6015fee0a Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Wed, 15 Jun 2016 01:26:58 +0200 Subject: [PATCH 3/3] Update eth.rs --- rpc/src/v1/tests/mocked/eth.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rpc/src/v1/tests/mocked/eth.rs b/rpc/src/v1/tests/mocked/eth.rs index 801a74f1d..45f8bd366 100644 --- a/rpc/src/v1/tests/mocked/eth.rs +++ b/rpc/src/v1/tests/mocked/eth.rs @@ -732,7 +732,7 @@ fn returns_no_work_if_cant_mine() { 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","error":{"code":-32001,"message":"Mining not ready.","data":null},"id":1}"#; + let response = r#"{"jsonrpc":"2.0","error":{"code":-32001,"message":"Still syncing.","data":null},"id":1}"#; assert_eq!(eth_tester.io.handle_request(request), Some(response.to_owned())); }