From b036f1de98bd82648033d4fc8be5f56aadd95054 Mon Sep 17 00:00:00 2001 From: Robert Habermeier Date: Tue, 31 May 2016 10:31:36 +0200 Subject: [PATCH] stop eth_syncing from returning true forever (#1181) --- rpc/src/v1/impls/eth.rs | 6 ++++-- rpc/src/v1/tests/mocked/eth.rs | 11 +++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/rpc/src/v1/impls/eth.rs b/rpc/src/v1/impls/eth.rs index 100770ae1..a57fc333c 100644 --- a/rpc/src/v1/impls/eth.rs +++ b/rpc/src/v1/impls/eth.rs @@ -244,12 +244,14 @@ impl Eth for EthClient where let res = match status.state { SyncState::Idle => SyncStatus::None, SyncState::Waiting | SyncState::Blocks | SyncState::NewBlocks | SyncState::ChainHead => { + let current_block = U256::from(take_weak!(self.client).chain_info().best_block_number); + let info = SyncInfo { starting_block: U256::from(status.start_block_number), - current_block: U256::from(take_weak!(self.client).chain_info().best_block_number), + current_block: current_block, highest_block: U256::from(status.highest_block_number.unwrap_or(status.start_block_number)) }; - match info.highest_block > info.starting_block + U256::from(6) { + match info.highest_block > info.current_block + U256::from(6) { true => SyncStatus::Info(info), false => SyncStatus::None, } diff --git a/rpc/src/v1/tests/mocked/eth.rs b/rpc/src/v1/tests/mocked/eth.rs index aa0955751..c51d6d7da 100644 --- a/rpc/src/v1/tests/mocked/eth.rs +++ b/rpc/src/v1/tests/mocked/eth.rs @@ -107,6 +107,7 @@ fn rpc_eth_syncing() { status.state = SyncState::Blocks; status.highest_block_number = Some(2500); + // "sync" to 1000 blocks. // causes TestBlockChainClient to return 1000 for its best block number. let mut blocks = tester.client.blocks.write().unwrap(); for i in 0..1000 { @@ -116,6 +117,16 @@ fn rpc_eth_syncing() { let true_res = r#"{"jsonrpc":"2.0","result":{"currentBlock":"0x03e8","highestBlock":"0x09c4","startingBlock":"0x00"},"id":1}"#; assert_eq!(tester.io.handle_request(request), Some(true_res.to_owned())); + + { + // finish "syncing" + let mut blocks = tester.client.blocks.write().unwrap(); + for i in 0..1500 { + blocks.insert(H256::from(i + 1000), Vec::new()); + } + } + + assert_eq!(tester.io.handle_request(request), Some(false_res.to_owned())); } #[test]