From 14cf6b0118bc722402858333d194cf7b4b699d62 Mon Sep 17 00:00:00 2001 From: Paul Hauner Date: Fri, 6 Sep 2019 10:17:23 +1000 Subject: [PATCH] Add option to validator service to fix bug With the previous setup it would never produce on the 0 slot. --- validator_client/src/service.rs | 44 +++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 18 deletions(-) diff --git a/validator_client/src/service.rs b/validator_client/src/service.rs index 8cdba537a..5169f67f8 100644 --- a/validator_client/src/service.rs +++ b/validator_client/src/service.rs @@ -46,8 +46,8 @@ pub struct Service, slots_per_epoch: u64, /// The chain specification for this clients instance. spec: Arc, @@ -168,8 +168,6 @@ impl Service Service Service error_chain::Result<()> { - let current_slot = self + let wall_clock_slot = self .slot_clock .now() .ok_or_else::(|| { "Genesis is not in the past. Exiting.".into() })?; - let current_epoch = current_slot.epoch(self.slots_per_epoch); + let wall_clock_epoch = wall_clock_slot.epoch(self.slots_per_epoch); // this is a non-fatal error. If the slot clock repeats, the node could // have been slow to process the previous slot and is now duplicating tasks. // We ignore duplicated but raise a critical error. - if current_slot <= self.current_slot { - crit!( - self.log, - "The validator tried to duplicate a slot. Likely missed the previous slot" - ); - return Err("Duplicate slot".into()); + if let Some(current_slot) = self.current_slot { + if wall_clock_slot <= current_slot { + crit!( + self.log, + "The validator tried to duplicate a slot. Likely missed the previous slot" + ); + return Err("Duplicate slot".into()); + } } - self.current_slot = current_slot; - info!(self.log, "Processing"; "slot" => current_slot.as_u64(), "epoch" => current_epoch.as_u64()); + self.current_slot = Some(wall_clock_slot); + info!(self.log, "Processing"; "slot" => wall_clock_slot.as_u64(), "epoch" => wall_clock_epoch.as_u64()); Ok(()) } @@ -324,7 +324,10 @@ impl Service Service