mirror of
https://github.com/sigp/lighthouse.git
synced 2026-05-07 08:52:54 +00:00
Add logging on shutdown
This commit is contained in:
@@ -251,8 +251,13 @@ where
|
|||||||
.ok_or_else(|| "node timer requires a chain spec".to_string())?
|
.ok_or_else(|| "node timer requires a chain spec".to_string())?
|
||||||
.milliseconds_per_slot;
|
.milliseconds_per_slot;
|
||||||
|
|
||||||
let timer_exit = timer::spawn(&context.runtime_handle, beacon_chain, milliseconds_per_slot)
|
let timer_exit = timer::spawn(
|
||||||
.map_err(|e| format!("Unable to start node timer: {}", e))?;
|
&context.runtime_handle,
|
||||||
|
beacon_chain,
|
||||||
|
milliseconds_per_slot,
|
||||||
|
context.log.clone(),
|
||||||
|
)
|
||||||
|
.map_err(|e| format!("Unable to start node timer: {}", e))?;
|
||||||
|
|
||||||
self.exit_channels.push(timer_exit);
|
self.exit_channels.push(timer_exit);
|
||||||
|
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ pub fn spawn_notifier<T: BeaconChainTypes>(
|
|||||||
milliseconds_per_slot: u64,
|
milliseconds_per_slot: u64,
|
||||||
log: slog::Logger,
|
log: slog::Logger,
|
||||||
) -> Result<tokio::sync::oneshot::Sender<()>, String> {
|
) -> Result<tokio::sync::oneshot::Sender<()>, String> {
|
||||||
|
let log_1 = log.clone();
|
||||||
let slot_duration = Duration::from_millis(milliseconds_per_slot);
|
let slot_duration = Duration::from_millis(milliseconds_per_slot);
|
||||||
let duration_to_next_slot = beacon_chain
|
let duration_to_next_slot = beacon_chain
|
||||||
.slot_clock
|
.slot_clock
|
||||||
@@ -149,8 +150,16 @@ pub fn spawn_notifier<T: BeaconChainTypes>(
|
|||||||
|
|
||||||
let (exit_signal, exit) = tokio::sync::oneshot::channel();
|
let (exit_signal, exit) = tokio::sync::oneshot::channel();
|
||||||
|
|
||||||
|
let exit_future = async move {
|
||||||
|
let _ = exit.await.ok();
|
||||||
|
info!(log_1, "Notifier service shutdown");
|
||||||
|
};
|
||||||
|
|
||||||
// run the notifier on the current executor
|
// run the notifier on the current executor
|
||||||
handle.spawn(futures::future::select(Box::pin(interval_future), exit));
|
handle.spawn(futures::future::select(
|
||||||
|
Box::pin(interval_future),
|
||||||
|
Box::pin(exit_future),
|
||||||
|
));
|
||||||
|
|
||||||
Ok(exit_signal)
|
Ok(exit_signal)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -289,6 +289,7 @@ impl Service {
|
|||||||
exit: tokio::sync::oneshot::Receiver<()>,
|
exit: tokio::sync::oneshot::Receiver<()>,
|
||||||
) {
|
) {
|
||||||
let update_interval = Duration::from_millis(service.config().auto_update_interval_millis);
|
let update_interval = Duration::from_millis(service.config().auto_update_interval_millis);
|
||||||
|
let log = service.log.clone();
|
||||||
|
|
||||||
let mut interval = interval_at(Instant::now(), update_interval);
|
let mut interval = interval_at(Instant::now(), update_interval);
|
||||||
|
|
||||||
@@ -300,7 +301,12 @@ impl Service {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let future = futures::future::select(Box::pin(update_future), exit);
|
let exit_future = async move {
|
||||||
|
let _ = exit.await.ok();
|
||||||
|
info!(log, "Eth1 service shutdown");
|
||||||
|
};
|
||||||
|
|
||||||
|
let future = futures::future::select(Box::pin(update_future), Box::pin(exit_future));
|
||||||
|
|
||||||
handle.spawn(future);
|
handle.spawn(future);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,8 +3,8 @@
|
|||||||
//! This service allows task execution on the beacon node for various functionality.
|
//! This service allows task execution on the beacon node for various functionality.
|
||||||
|
|
||||||
use beacon_chain::{BeaconChain, BeaconChainTypes};
|
use beacon_chain::{BeaconChain, BeaconChainTypes};
|
||||||
use futures::future;
|
|
||||||
use futures::stream::StreamExt;
|
use futures::stream::StreamExt;
|
||||||
|
use slog::info;
|
||||||
use slot_clock::SlotClock;
|
use slot_clock::SlotClock;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
@@ -16,6 +16,7 @@ pub fn spawn<T: BeaconChainTypes>(
|
|||||||
handle: &Handle,
|
handle: &Handle,
|
||||||
beacon_chain: Arc<BeaconChain<T>>,
|
beacon_chain: Arc<BeaconChain<T>>,
|
||||||
milliseconds_per_slot: u64,
|
milliseconds_per_slot: u64,
|
||||||
|
log: slog::Logger,
|
||||||
) -> Result<tokio::sync::oneshot::Sender<()>, &'static str> {
|
) -> Result<tokio::sync::oneshot::Sender<()>, &'static str> {
|
||||||
let (exit_signal, exit) = tokio::sync::oneshot::channel();
|
let (exit_signal, exit) = tokio::sync::oneshot::channel();
|
||||||
|
|
||||||
@@ -26,14 +27,22 @@ pub fn spawn<T: BeaconChainTypes>(
|
|||||||
.ok_or_else(|| "slot_notifier unable to determine time to next slot")?;
|
.ok_or_else(|| "slot_notifier unable to determine time to next slot")?;
|
||||||
|
|
||||||
// Warning: `interval_at` panics if `milliseconds_per_slot` = 0.
|
// Warning: `interval_at` panics if `milliseconds_per_slot` = 0.
|
||||||
let timer_future = interval_at(start_instant, Duration::from_millis(milliseconds_per_slot))
|
let mut interval = interval_at(start_instant, Duration::from_millis(milliseconds_per_slot));
|
||||||
.for_each(move |_| {
|
let timer_future = async move {
|
||||||
|
while interval.next().await.is_some() {
|
||||||
beacon_chain.per_slot_task();
|
beacon_chain.per_slot_task();
|
||||||
future::ready(())
|
}
|
||||||
});
|
};
|
||||||
|
|
||||||
let future = futures::future::select(timer_future, exit);
|
let log_1 = log.clone();
|
||||||
|
let exit_future = async move {
|
||||||
|
let _ = exit.await.ok();
|
||||||
|
info!(log_1, "Timer service shutdown");
|
||||||
|
};
|
||||||
|
|
||||||
|
let future = futures::future::select(Box::pin(timer_future), Box::pin(exit_future));
|
||||||
handle.spawn(future);
|
handle.spawn(future);
|
||||||
|
info!(log, "Timer service started");
|
||||||
|
|
||||||
Ok(exit_signal)
|
Ok(exit_signal)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user