stop eth_syncing from returning true forever (#1181)

This commit is contained in:
Robert Habermeier 2016-05-31 10:31:36 +02:00 committed by Gav Wood
parent 6d25e7f8b4
commit b036f1de98
2 changed files with 15 additions and 2 deletions

View File

@ -244,12 +244,14 @@ impl<C, S, A, M, EM> Eth for EthClient<C, S, A, M, EM> where
let res = match status.state { let res = match status.state {
SyncState::Idle => SyncStatus::None, SyncState::Idle => SyncStatus::None,
SyncState::Waiting | SyncState::Blocks | SyncState::NewBlocks | SyncState::ChainHead => { 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 { let info = SyncInfo {
starting_block: U256::from(status.start_block_number), 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)) 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), true => SyncStatus::Info(info),
false => SyncStatus::None, false => SyncStatus::None,
} }

View File

@ -107,6 +107,7 @@ fn rpc_eth_syncing() {
status.state = SyncState::Blocks; status.state = SyncState::Blocks;
status.highest_block_number = Some(2500); status.highest_block_number = Some(2500);
// "sync" to 1000 blocks.
// causes TestBlockChainClient to return 1000 for its best block number. // causes TestBlockChainClient to return 1000 for its best block number.
let mut blocks = tester.client.blocks.write().unwrap(); let mut blocks = tester.client.blocks.write().unwrap();
for i in 0..1000 { 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}"#; 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())); 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] #[test]