From c57e3cefe4a820dab9a15b13298972b0a9cd3f62 Mon Sep 17 00:00:00 2001 From: keorn Date: Wed, 21 Sep 2016 10:29:44 +0200 Subject: [PATCH] sync check method --- ethcore/src/engines/authority_round.rs | 2 +- sync/src/tests/{consensus.rs => auth_round.rs} | 13 ++++++++++--- sync/src/tests/mocknet.rs | 14 +++++++++++++- sync/src/tests/mod.rs | 2 +- 4 files changed, 25 insertions(+), 6 deletions(-) rename sync/src/tests/{consensus.rs => auth_round.rs} (82%) diff --git a/ethcore/src/engines/authority_round.rs b/ethcore/src/engines/authority_round.rs index 79acbe0c9..c2fa89e90 100644 --- a/ethcore/src/engines/authority_round.rs +++ b/ethcore/src/engines/authority_round.rs @@ -112,8 +112,8 @@ impl IoHandler for TransitionHandler { fn timeout(&self, io: &IoContext, timer: TimerToken) { if timer == ENGINE_TIMEOUT_TOKEN { - debug!(target: "authorityround", "timeout"); if let Some(engine) = self.engine.upgrade() { + debug!(target: "authorityround", "Timeout step: {}", engine.step.load(AtomicOrdering::Relaxed)); engine.step.fetch_add(1, AtomicOrdering::SeqCst); io.register_timer_once(ENGINE_TIMEOUT_TOKEN, engine.our_params.step_duration).expect("Failed to restart consensus step timer.") } diff --git a/sync/src/tests/consensus.rs b/sync/src/tests/auth_round.rs similarity index 82% rename from sync/src/tests/consensus.rs rename to sync/src/tests/auth_round.rs index 55b0bb0f7..4f8a8cbc4 100644 --- a/sync/src/tests/consensus.rs +++ b/sync/src/tests/auth_round.rs @@ -21,15 +21,20 @@ use std::thread::sleep; use std::time::Duration; use ethcore::client::BlockChainClient; +fn authorities() -> Vec { vec!["1".sha3(), "2".sha3()] } + #[test] -fn two_peer_tx_seal() { +fn three_peer_tx_seal() { ::env_logger::init().ok(); - let mut net = MockNet::new_with_spec(2, vec!["1".sha3()], &Spec::new_test_round); + let mut net = MockNet::new_with_spec(2, authorities(), &Spec::new_test_round); net.peer(1).issue_rand_tx(); sleep(Duration::from_secs(1)); net.sync(); + sleep(Duration::from_secs(1)); + net.sync(); println!("{:?}", net.peer(0).client.chain_info()); println!("{:?}", net.peer(1).client.chain_info()); + net.is_synced(1); } #[test] @@ -43,15 +48,17 @@ fn issue_many() { net.sync(); println!("{:?}", net.peer(0).client.chain_info()); println!("{:?}", net.peer(1).client.chain_info()); + net.is_synced(10); } #[test] fn rand_simulation() { ::env_logger::init().ok(); - let mut net = MockNet::new_with_spec(2, vec!["1".sha3()], &Spec::new_test_round); + let mut net = MockNet::new_with_spec(3, authorities(), &Spec::new_test_round); net.rand_simulation(10); println!("{:?}", net.peer(0).client.chain_info()); println!("{:?}", net.peer(1).client.chain_info()); + net.is_synced(10); } diff --git a/sync/src/tests/mocknet.rs b/sync/src/tests/mocknet.rs index 088d55fbe..2ed204243 100644 --- a/sync/src/tests/mocknet.rs +++ b/sync/src/tests/mocknet.rs @@ -29,6 +29,7 @@ use ::SyncConfig; use devtools::RandomTempPath; use ethcore::miner::Miner; use ethcore::service::ClientService; +use ethcore::header::BlockNumber; use std::time::Duration; use std::thread::sleep; use rand::{thread_rng, Rng}; @@ -271,6 +272,7 @@ impl MockNet { let mut io = TestIo::new(peer0.client.clone(), &peer0.snapshot_service, &mut *q0, None); p.sync.write().maintain_sync(&mut io); p.sync.write().propagate_new_transactions(&mut io); + sleep(Duration::from_millis(10)); } } @@ -317,8 +319,18 @@ impl MockNet { pub fn rand_simulation(&mut self, steps: usize) { for _ in 0..steps { self.rand_peer().issue_rand_tx(); - sleep(Duration::from_millis(100)); + sleep(Duration::from_millis(500)); self.sync(); } } + + pub fn is_synced(&self, block: BlockNumber) { + println!("Is block {:?}", &block); + let hash = self.peer(0).client.chain_info().best_block_hash; + for p in &self.peers { + let ci = p.client.chain_info(); + assert_eq!(ci.best_block_number, block); + assert_eq!(ci.best_block_hash, hash); + } + } } diff --git a/sync/src/tests/mod.rs b/sync/src/tests/mod.rs index e64792d33..394e2bf20 100644 --- a/sync/src/tests/mod.rs +++ b/sync/src/tests/mod.rs @@ -19,4 +19,4 @@ pub mod snapshot; pub mod mocknet; mod chain; mod rpc; -mod consensus; +mod auth_round;