sync check method

This commit is contained in:
keorn 2016-09-21 10:29:44 +02:00
parent 9d23915caf
commit c57e3cefe4
4 changed files with 25 additions and 6 deletions

View File

@ -112,8 +112,8 @@ impl IoHandler<BlockArrived> for TransitionHandler {
fn timeout(&self, io: &IoContext<BlockArrived>, 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.")
}

View File

@ -21,15 +21,20 @@ use std::thread::sleep;
use std::time::Duration;
use ethcore::client::BlockChainClient;
fn authorities() -> Vec<H256> { 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);
}

View File

@ -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);
}
}
}

View File

@ -19,4 +19,4 @@ pub mod snapshot;
pub mod mocknet;
mod chain;
mod rpc;
mod consensus;
mod auth_round;