Add option to validator service to fix bug
With the previous setup it would never produce on the 0 slot.
This commit is contained in:
parent
8b69a48fc5
commit
14cf6b0118
@ -46,8 +46,8 @@ pub struct Service<B: BeaconNodeDuties + 'static, S: Signer + 'static, E: EthSpe
|
|||||||
fork: Fork,
|
fork: Fork,
|
||||||
/// The slot clock for this service.
|
/// The slot clock for this service.
|
||||||
slot_clock: SystemTimeSlotClock,
|
slot_clock: SystemTimeSlotClock,
|
||||||
/// The current slot we are processing.
|
/// The slot that is currently, or was previously processed by the service.
|
||||||
current_slot: Slot,
|
current_slot: Option<Slot>,
|
||||||
slots_per_epoch: u64,
|
slots_per_epoch: u64,
|
||||||
/// The chain specification for this clients instance.
|
/// The chain specification for this clients instance.
|
||||||
spec: Arc<ChainSpec>,
|
spec: Arc<ChainSpec>,
|
||||||
@ -168,8 +168,6 @@ impl<B: BeaconNodeDuties + 'static, S: Signer + 'static, E: EthSpec> Service<B,
|
|||||||
format!("Unable to start slot clock: {}.", e).into()
|
format!("Unable to start slot clock: {}.", e).into()
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
let current_slot = slot_clock.now().unwrap_or_else(|| Slot::new(0));
|
|
||||||
|
|
||||||
/* Generate the duties manager */
|
/* Generate the duties manager */
|
||||||
|
|
||||||
// Load generated keypairs
|
// Load generated keypairs
|
||||||
@ -200,7 +198,7 @@ impl<B: BeaconNodeDuties + 'static, S: Signer + 'static, E: EthSpec> Service<B,
|
|||||||
Ok(Service {
|
Ok(Service {
|
||||||
fork,
|
fork,
|
||||||
slot_clock,
|
slot_clock,
|
||||||
current_slot,
|
current_slot: None,
|
||||||
slots_per_epoch,
|
slots_per_epoch,
|
||||||
spec,
|
spec,
|
||||||
duties_manager,
|
duties_manager,
|
||||||
@ -296,27 +294,29 @@ impl<B: BeaconNodeDuties + 'static, S: Signer + 'static, E: EthSpec> Service<B,
|
|||||||
|
|
||||||
/// Updates the known current slot and epoch.
|
/// Updates the known current slot and epoch.
|
||||||
fn update_current_slot(&mut self) -> error_chain::Result<()> {
|
fn update_current_slot(&mut self) -> error_chain::Result<()> {
|
||||||
let current_slot = self
|
let wall_clock_slot = self
|
||||||
.slot_clock
|
.slot_clock
|
||||||
.now()
|
.now()
|
||||||
.ok_or_else::<error_chain::Error, _>(|| {
|
.ok_or_else::<error_chain::Error, _>(|| {
|
||||||
"Genesis is not in the past. Exiting.".into()
|
"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
|
// 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.
|
// have been slow to process the previous slot and is now duplicating tasks.
|
||||||
// We ignore duplicated but raise a critical error.
|
// We ignore duplicated but raise a critical error.
|
||||||
if current_slot <= self.current_slot {
|
if let Some(current_slot) = self.current_slot {
|
||||||
crit!(
|
if wall_clock_slot <= current_slot {
|
||||||
self.log,
|
crit!(
|
||||||
"The validator tried to duplicate a slot. Likely missed the previous slot"
|
self.log,
|
||||||
);
|
"The validator tried to duplicate a slot. Likely missed the previous slot"
|
||||||
return Err("Duplicate slot".into());
|
);
|
||||||
|
return Err("Duplicate slot".into());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
self.current_slot = current_slot;
|
self.current_slot = Some(wall_clock_slot);
|
||||||
info!(self.log, "Processing"; "slot" => current_slot.as_u64(), "epoch" => current_epoch.as_u64());
|
info!(self.log, "Processing"; "slot" => wall_clock_slot.as_u64(), "epoch" => wall_clock_epoch.as_u64());
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -324,7 +324,10 @@ impl<B: BeaconNodeDuties + 'static, S: Signer + 'static, E: EthSpec> Service<B,
|
|||||||
fn check_for_duties(&mut self) {
|
fn check_for_duties(&mut self) {
|
||||||
let cloned_manager = self.duties_manager.clone();
|
let cloned_manager = self.duties_manager.clone();
|
||||||
let cloned_log = self.log.clone();
|
let cloned_log = self.log.clone();
|
||||||
let current_epoch = self.current_slot.epoch(self.slots_per_epoch);
|
let current_epoch = self
|
||||||
|
.current_slot
|
||||||
|
.expect("The current slot must be updated before checking for duties")
|
||||||
|
.epoch(self.slots_per_epoch);
|
||||||
// spawn a new thread separate to the runtime
|
// spawn a new thread separate to the runtime
|
||||||
// TODO: Handle thread termination/timeout
|
// TODO: Handle thread termination/timeout
|
||||||
// TODO: Add duties thread back in, with channel to process duties in duty change.
|
// TODO: Add duties thread back in, with channel to process duties in duty change.
|
||||||
@ -338,14 +341,19 @@ impl<B: BeaconNodeDuties + 'static, S: Signer + 'static, E: EthSpec> Service<B,
|
|||||||
|
|
||||||
/// If there are any duties to process, spawn a separate thread and perform required actions.
|
/// If there are any duties to process, spawn a separate thread and perform required actions.
|
||||||
fn process_duties(&mut self) {
|
fn process_duties(&mut self) {
|
||||||
if let Some(work) = self.duties_manager.get_current_work(self.current_slot) {
|
if let Some(work) = self.duties_manager.get_current_work(
|
||||||
|
self.current_slot
|
||||||
|
.expect("The current slot must be updated before processing duties"),
|
||||||
|
) {
|
||||||
for (signer_index, work_type) in work {
|
for (signer_index, work_type) in work {
|
||||||
if work_type.produce_block {
|
if work_type.produce_block {
|
||||||
// we need to produce a block
|
// we need to produce a block
|
||||||
// spawns a thread to produce a beacon block
|
// spawns a thread to produce a beacon block
|
||||||
let signers = self.duties_manager.signers.clone(); // this is an arc
|
let signers = self.duties_manager.signers.clone(); // this is an arc
|
||||||
let fork = self.fork.clone();
|
let fork = self.fork.clone();
|
||||||
let slot = self.current_slot;
|
let slot = self
|
||||||
|
.current_slot
|
||||||
|
.expect("The current slot must be updated before processing duties");
|
||||||
let spec = self.spec.clone();
|
let spec = self.spec.clone();
|
||||||
let beacon_node = self.beacon_block_client.clone();
|
let beacon_node = self.beacon_block_client.clone();
|
||||||
let log = self.log.clone();
|
let log = self.log.clone();
|
||||||
|
Loading…
Reference in New Issue
Block a user