mirror of
https://gitlab.com/pulsechaincom/lighthouse-pulse.git
synced 2025-01-17 09:18:46 +00:00
41 lines
1.6 KiB
Rust
41 lines
1.6 KiB
Rust
|
use super::traits::BeaconNode;
|
||
|
use super::{DutiesManager, PollOutcome};
|
||
|
use slog::{debug, error, info, Logger};
|
||
|
use slot_clock::SlotClock;
|
||
|
use std::time::Duration;
|
||
|
|
||
|
pub struct DutiesManagerService<T: SlotClock, U: BeaconNode> {
|
||
|
pub manager: DutiesManager<T, U>,
|
||
|
pub poll_interval_millis: u64,
|
||
|
pub log: Logger,
|
||
|
}
|
||
|
|
||
|
impl<T: SlotClock, U: BeaconNode> DutiesManagerService<T, U> {
|
||
|
/// Run a loop which polls the manager each `poll_interval_millis` milliseconds.
|
||
|
///
|
||
|
/// Logs the results of the polls.
|
||
|
pub fn run(&mut self) {
|
||
|
loop {
|
||
|
match self.manager.poll() {
|
||
|
Err(error) => {
|
||
|
error!(self.log, "Epoch duties poll error"; "error" => format!("{:?}", error))
|
||
|
}
|
||
|
Ok(PollOutcome::NoChange(epoch)) => {
|
||
|
debug!(self.log, "No change in duties"; "epoch" => epoch)
|
||
|
}
|
||
|
Ok(PollOutcome::DutiesChanged(epoch, duties)) => {
|
||
|
info!(self.log, "Duties changed (potential re-org)"; "epoch" => epoch, "duties" => format!("{:?}", duties))
|
||
|
}
|
||
|
Ok(PollOutcome::NewDuties(epoch, duties)) => {
|
||
|
info!(self.log, "New duties obtained"; "epoch" => epoch, "duties" => format!("{:?}", duties))
|
||
|
}
|
||
|
Ok(PollOutcome::UnknownValidatorOrEpoch(epoch)) => {
|
||
|
error!(self.log, "Epoch or validator unknown"; "epoch" => epoch)
|
||
|
}
|
||
|
};
|
||
|
|
||
|
std::thread::sleep(Duration::from_millis(self.poll_interval_millis));
|
||
|
}
|
||
|
}
|
||
|
}
|