Merge branch 'master' into lightsync
This commit is contained in:
@@ -25,7 +25,7 @@ time = "0.1.34"
|
||||
rand = "0.3.13"
|
||||
heapsize = "0.3"
|
||||
ethcore-ipc = { path = "../ipc/rpc" }
|
||||
semver = "0.2"
|
||||
semver = "0.5"
|
||||
ethcore-ipc-nano = { path = "../ipc/nano" }
|
||||
ethcore-devtools = { path = "../devtools" }
|
||||
ethkey = { path = "../ethkey" }
|
||||
|
||||
@@ -94,7 +94,7 @@ use rlp::*;
|
||||
use network::*;
|
||||
use ethcore::views::{HeaderView};
|
||||
use ethcore::header::{BlockNumber, Header as BlockHeader};
|
||||
use ethcore::client::{BlockChainClient, BlockStatus, BlockId, BlockChainInfo, BlockImportError};
|
||||
use ethcore::client::{BlockChainClient, BlockStatus, BlockId, BlockChainInfo, BlockImportError, BlockQueueInfo};
|
||||
use ethcore::error::*;
|
||||
use ethcore::snapshot::{ManifestData, RestorationStatus};
|
||||
use sync_io::SyncIo;
|
||||
@@ -235,6 +235,13 @@ impl SyncStatus {
|
||||
min_peers
|
||||
}
|
||||
}
|
||||
|
||||
/// Is it doing a major sync?
|
||||
pub fn is_syncing(&self, queue_info: BlockQueueInfo) -> bool {
|
||||
let is_syncing_state = match self.state { SyncState::Idle | SyncState::NewBlocks => false, _ => true };
|
||||
let is_verifying = queue_info.unverified_queue_size + queue_info.verified_queue_size > 3;
|
||||
is_verifying || is_syncing_state
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Eq, Debug, Clone)]
|
||||
@@ -2112,6 +2119,48 @@ mod tests {
|
||||
rlp.out()
|
||||
}
|
||||
|
||||
fn queue_info(unverified: usize, verified: usize) -> BlockQueueInfo {
|
||||
BlockQueueInfo {
|
||||
unverified_queue_size: unverified,
|
||||
verified_queue_size: verified,
|
||||
verifying_queue_size: 0,
|
||||
max_queue_size: 1000,
|
||||
max_mem_use: 1000,
|
||||
mem_used: 500
|
||||
}
|
||||
}
|
||||
|
||||
fn sync_status(state: SyncState) -> SyncStatus {
|
||||
SyncStatus {
|
||||
state: state,
|
||||
protocol_version: 0,
|
||||
network_id: 0,
|
||||
start_block_number: 0,
|
||||
last_imported_block_number: None,
|
||||
highest_block_number: None,
|
||||
blocks_total: 0,
|
||||
blocks_received: 0,
|
||||
num_peers: 0,
|
||||
num_active_peers: 0,
|
||||
mem_used: 0,
|
||||
num_snapshot_chunks: 0,
|
||||
snapshot_chunks_done: 0,
|
||||
last_imported_old_block_number: None,
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn is_still_verifying() {
|
||||
assert!(!sync_status(SyncState::Idle).is_syncing(queue_info(2, 1)));
|
||||
assert!(sync_status(SyncState::Idle).is_syncing(queue_info(2, 2)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn is_synced_state() {
|
||||
assert!(sync_status(SyncState::Blocks).is_syncing(queue_info(0, 0)));
|
||||
assert!(!sync_status(SyncState::Idle).is_syncing(queue_info(0, 0)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn return_receipts_empty() {
|
||||
let mut client = TestBlockChainClient::new();
|
||||
|
||||
@@ -82,12 +82,14 @@ fn authority_round() {
|
||||
net.sync();
|
||||
// Trigger block proposal
|
||||
net.peer(0).chain.miner().import_own_transaction(&*net.peer(0).chain, new_tx(s0.secret(), 0.into())).unwrap();
|
||||
net.peer(1).chain.miner().import_own_transaction(&*net.peer(1).chain, new_tx(s1.secret(), 0.into())).unwrap();
|
||||
// Sync a block
|
||||
net.sync();
|
||||
assert_eq!(net.peer(0).chain.chain_info().best_block_number, 1);
|
||||
assert_eq!(net.peer(1).chain.chain_info().best_block_number, 1);
|
||||
|
||||
net.peer(1).chain.miner().import_own_transaction(&*net.peer(1).chain, new_tx(s1.secret(), 0.into())).unwrap();
|
||||
net.peer(0).chain.miner().import_own_transaction(&*net.peer(0).chain, new_tx(s0.secret(), 1.into())).unwrap();
|
||||
net.peer(1).chain.miner().import_own_transaction(&*net.peer(1).chain, new_tx(s1.secret(), 1.into())).unwrap();
|
||||
// Move to next proposer step
|
||||
net.peer(0).chain.engine().step();
|
||||
net.peer(1).chain.engine().step();
|
||||
@@ -96,14 +98,17 @@ fn authority_round() {
|
||||
assert_eq!(net.peer(1).chain.chain_info().best_block_number, 2);
|
||||
|
||||
// Fork the network
|
||||
net.peer(0).chain.miner().import_own_transaction(&*net.peer(0).chain, new_tx(s0.secret(), 1.into())).unwrap();
|
||||
net.peer(0).chain.miner().import_own_transaction(&*net.peer(0).chain, new_tx(s0.secret(), 2.into())).unwrap();
|
||||
net.peer(1).chain.miner().import_own_transaction(&*net.peer(1).chain, new_tx(s1.secret(), 2.into())).unwrap();
|
||||
net.peer(0).chain.engine().step();
|
||||
net.peer(1).chain.engine().step();
|
||||
assert_eq!(net.peer(0).chain.chain_info().best_block_number, 3);
|
||||
net.peer(1).chain.miner().import_own_transaction(&*net.peer(1).chain, new_tx(s1.secret(), 1.into())).unwrap();
|
||||
net.peer(0).chain.engine().step();
|
||||
net.peer(1).chain.engine().step();
|
||||
assert_eq!(net.peer(1).chain.chain_info().best_block_number, 3);
|
||||
let ci0 = net.peer(0).chain.chain_info();
|
||||
let ci1 = net.peer(1).chain.chain_info();
|
||||
assert_eq!(ci0.best_block_number, 3);
|
||||
assert_eq!(ci1.best_block_number, 3);
|
||||
assert!(ci0.best_block_hash != ci1.best_block_hash);
|
||||
// Reorg to the correct one.
|
||||
net.sync();
|
||||
let ci0 = net.peer(0).chain.chain_info();
|
||||
|
||||
Reference in New Issue
Block a user