Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

stop eth_syncing from returning true forever #1181

Merged
merged 1 commit into from
May 31, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions rpc/src/v1/impls/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,12 +244,14 @@ impl<C, S, A, M, EM> Eth for EthClient<C, S, A, M, EM> 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,
}
Expand Down
11 changes: 11 additions & 0 deletions rpc/src/v1/tests/mocked/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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]
Expand Down