Skip to content

Commit 06ce993

Browse files
author
Povilas Liubauskas
committed
Skip computing participation metrics if there is too many empty slots after head
1 parent a309b96 commit 06ce993

File tree

2 files changed

+15
-17
lines changed

2 files changed

+15
-17
lines changed

fork_choice_control/src/controller.rs

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,10 @@ where
484484
&self.state_cache
485485
}
486486

487+
pub fn store_config(&self) -> StoreConfig {
488+
self.store_snapshot().store_config()
489+
}
490+
487491
pub(crate) fn store_snapshot(&self) -> Guard<Arc<Store<P>>> {
488492
self.store_snapshot.load()
489493
}
@@ -509,18 +513,6 @@ where
509513
}
510514
}
511515

512-
#[cfg(test)]
513-
impl<P, E, W> Controller<P, E, W>
514-
where
515-
P: Preset,
516-
E: ExecutionEngine<P> + Clone + Send + Sync + 'static,
517-
W: Wait,
518-
{
519-
pub fn store_config(&self) -> StoreConfig {
520-
self.store_snapshot().store_config()
521-
}
522-
}
523-
524516
/// A wrapper over [`JoinHandle`] that can be used to wait for the mutator thread to finish.
525517
///
526518
/// We previously used [`std::process::exit`] to terminate the process when the mutator thread

metrics/src/server.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -190,11 +190,17 @@ pub async fn prometheus_metrics<P: Preset, W: Wait>(
190190
.unwrap_or_default(),
191191
);
192192

193-
let epoch = misc::compute_epoch_at_slot::<P>(controller.head().value.slot());
194-
// Take state at last slot in epoch
195-
let slot = misc::compute_start_slot_at_epoch::<P>(epoch).saturating_sub(1);
196-
if let Some(state) = controller.state_at_slot(slot)? {
197-
scrape_epoch_statistics(&state.value, &metrics)?;
193+
let head_slot = controller.head().value.slot();
194+
let store_slot = controller.slot();
195+
let max_empty_slots = controller.store_config().max_empty_slots;
196+
197+
if head_slot + max_empty_slots >= store_slot {
198+
let epoch = misc::compute_epoch_at_slot::<P>(head_slot);
199+
// Take state at last slot in epoch
200+
let slot = misc::compute_start_slot_at_epoch::<P>(epoch).saturating_sub(1);
201+
if let Some(state) = controller.state_at_slot(slot)? {
202+
scrape_epoch_statistics(&state.value, &metrics)?;
203+
}
198204
}
199205

200206
TextEncoder::new()

0 commit comments

Comments
 (0)