Skip to content

Commit

Permalink
Skip computing participation metrics if there is too many empty slots…
Browse files Browse the repository at this point in the history
… after head
  • Loading branch information
Povilas Liubauskas committed May 24, 2024
1 parent a309b96 commit 06ce993
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 17 deletions.
16 changes: 4 additions & 12 deletions fork_choice_control/src/controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,10 @@ where
&self.state_cache
}

pub fn store_config(&self) -> StoreConfig {
self.store_snapshot().store_config()
}

pub(crate) fn store_snapshot(&self) -> Guard<Arc<Store<P>>> {
self.store_snapshot.load()
}
Expand All @@ -509,18 +513,6 @@ where
}
}

#[cfg(test)]
impl<P, E, W> Controller<P, E, W>
where
P: Preset,
E: ExecutionEngine<P> + Clone + Send + Sync + 'static,
W: Wait,
{
pub fn store_config(&self) -> StoreConfig {
self.store_snapshot().store_config()
}
}

/// A wrapper over [`JoinHandle`] that can be used to wait for the mutator thread to finish.
///
/// We previously used [`std::process::exit`] to terminate the process when the mutator thread
Expand Down
16 changes: 11 additions & 5 deletions metrics/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,11 +190,17 @@ pub async fn prometheus_metrics<P: Preset, W: Wait>(
.unwrap_or_default(),
);

let epoch = misc::compute_epoch_at_slot::<P>(controller.head().value.slot());
// Take state at last slot in epoch
let slot = misc::compute_start_slot_at_epoch::<P>(epoch).saturating_sub(1);
if let Some(state) = controller.state_at_slot(slot)? {
scrape_epoch_statistics(&state.value, &metrics)?;
let head_slot = controller.head().value.slot();
let store_slot = controller.slot();
let max_empty_slots = controller.store_config().max_empty_slots;

if head_slot + max_empty_slots >= store_slot {
let epoch = misc::compute_epoch_at_slot::<P>(head_slot);
// Take state at last slot in epoch
let slot = misc::compute_start_slot_at_epoch::<P>(epoch).saturating_sub(1);
if let Some(state) = controller.state_at_slot(slot)? {
scrape_epoch_statistics(&state.value, &metrics)?;
}
}

TextEncoder::new()
Expand Down

0 comments on commit 06ce993

Please sign in to comment.