fix(bin): skip first ConsensusLayerHealthEvents tick (#3012)

This commit is contained in:
Alexey Shekhirin
2023-06-06 14:31:57 +04:00
committed by GitHub
parent a2004f06ae
commit 201366d8f7

View File

@ -7,7 +7,7 @@ use std::{
task::{ready, Context, Poll},
time::Duration,
};
use tokio::time::Interval;
use tokio::time::{Instant, Interval};
/// Interval of checking Consensus Layer client health.
const CHECK_INTERVAL: Duration = Duration::from_secs(300);
@ -27,7 +27,9 @@ pub struct ConsensusLayerHealthEvents {
impl ConsensusLayerHealthEvents {
/// Creates a new [ConsensusLayerHealthEvents] with the given canonical chain tracker.
pub fn new(canon_chain: Box<dyn CanonChainTracker>) -> Self {
Self { interval: tokio::time::interval(CHECK_INTERVAL), canon_chain }
// Skip the first tick to prevent the false `ConsensusLayerHealthEvent::NeverSeen` event.
let interval = tokio::time::interval_at(Instant::now() + CHECK_INTERVAL, CHECK_INTERVAL);
Self { interval, canon_chain }
}
}