From 3ad18b4367047b4fab37b3946004c06086c8b080 Mon Sep 17 00:00:00 2001 From: Age Manning Date: Mon, 25 Mar 2019 17:47:23 +1100 Subject: [PATCH] Adds manager duties to validator runtime --- validator_client/src/main.rs | 2 +- validator_client/src/service.rs | 30 ++++++++++++++++++++++++++++-- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/validator_client/src/main.rs b/validator_client/src/main.rs index 1c59513a7..84d0cbff7 100644 --- a/validator_client/src/main.rs +++ b/validator_client/src/main.rs @@ -54,6 +54,6 @@ fn main() { // start the validator service. match ValidatorService::start(config, log.clone()) { Ok(_) => info!(log, "Validator client shutdown successfully."), - Err(e) => error!(log, "Validator exited due to {:?}", e), + Err(e) => error!(log, "Validator exited due to: {}", e.to_string()), } } diff --git a/validator_client/src/service.rs b/validator_client/src/service.rs index 9eeb308db..720388a61 100644 --- a/validator_client/src/service.rs +++ b/validator_client/src/service.rs @@ -2,6 +2,7 @@ use crate::attester_service::{AttestationGrpcClient, AttesterService}; use crate::block_producer_service::{BeaconBlockGrpcClient, BlockProducerService}; use crate::config::Config as ValidatorConfig; +use crate::duties::PollOutcome; use crate::duties::{DutiesManager, DutiesManagerService, EpochDutiesMap}; use crate::error as error_chain; use crate::error::ErrorKind; @@ -84,7 +85,8 @@ impl Service { if SystemTime::now() .duration_since(SystemTime::UNIX_EPOCH) .unwrap() - > Duration::from_secs(info.genesis_time) + .as_secs() + < info.genesis_time { warn!( log, @@ -239,8 +241,32 @@ impl Service { Ok(slot) => slot.expect("Genesis is in the future"), }; + debug_assert!( + current_slot > service.current_slot, + "The Timer should poll a new slot" + ); + debug!(service.log, "Processing slot: {}", current_slot.as_u64()); - manager.poll(); + + // check for new duties + match manager.poll() { + Err(error) => { + error!(service.log, "Epoch duties poll error"; "error" => format!("{:?}", error)) + } + Ok(PollOutcome::NoChange(epoch)) => { + debug!(service.log, "No change in duties"; "epoch" => epoch) + } + Ok(PollOutcome::DutiesChanged(epoch, duties)) => { + info!(service.log, "Duties changed (potential re-org)"; "epoch" => epoch, "duties" => format!("{:?}", duties)) + } + Ok(PollOutcome::NewDuties(epoch, duties)) => { + info!(service.log, "New duties obtained"; "epoch" => epoch, "duties" => format!("{:?}", duties)) + } + Ok(PollOutcome::UnknownValidatorOrEpoch(epoch)) => { + error!(service.log, "Epoch or validator unknown"; "epoch" => epoch) + } + }; + Ok(()) })) .map_err(|e| format!("Service thread failed: {:?}", e))?;