From 26155f51d5866864ac1de6206b62043307a5a7af Mon Sep 17 00:00:00 2001 From: keorn Date: Wed, 2 Nov 2016 12:13:47 +0000 Subject: [PATCH] proper calculation of remaining step time --- ethcore/src/engines/authority_round.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ethcore/src/engines/authority_round.rs b/ethcore/src/engines/authority_round.rs index 0b16193a8..abc324e68 100644 --- a/ethcore/src/engines/authority_round.rs +++ b/ethcore/src/engines/authority_round.rs @@ -103,8 +103,8 @@ impl AuthorityRound { self.step.load(AtomicOrdering::SeqCst) } - fn remaining_step_millis(&self) -> u64 { - unix_now().as_millis() % self.our_params.step_duration.as_millis() + fn remaining_step_duration(&self) -> Duration { + self.our_params.step_duration * (self.step() as u32 + 1) - unix_now() } fn step_proposer(&self, step: usize) -> &Address { @@ -133,7 +133,7 @@ const ENGINE_TIMEOUT_TOKEN: TimerToken = 23; impl IoHandler for TransitionHandler { fn initialize(&self, io: &IoContext) { if let Some(engine) = self.engine.upgrade() { - io.register_timer_once(ENGINE_TIMEOUT_TOKEN, engine.remaining_step_millis()).expect("Error registering engine timeout"); + io.register_timer_once(ENGINE_TIMEOUT_TOKEN, engine.remaining_step_duration().as_millis()).expect("Error registering engine timeout"); } } @@ -147,7 +147,7 @@ impl IoHandler for TransitionHandler { Err(err) => trace!(target: "poa", "timeout: Could not send a sealing message {} for step {}.", err, engine.step.load(AtomicOrdering::Relaxed)), } } - io.register_timer_once(ENGINE_TIMEOUT_TOKEN, engine.remaining_step_millis()).expect("Failed to restart consensus step timer.") + io.register_timer_once(ENGINE_TIMEOUT_TOKEN, engine.remaining_step_duration().as_millis()).expect("Failed to restart consensus step timer.") } } }