Skip to content

Commit

Permalink
fix(engine, pruner): prune poll logic, history indices (#4043)
Browse files Browse the repository at this point in the history
  • Loading branch information
shekhirin authored Aug 3, 2023
1 parent 8d0aa64 commit f917d49
Show file tree
Hide file tree
Showing 4 changed files with 161 additions and 150 deletions.
16 changes: 16 additions & 0 deletions crates/consensus/beacon/src/engine/forkchoice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,18 @@ impl ForkchoiceStateTracker {
self.latest_status().map(|s| s.is_valid()).unwrap_or(false)
}

/// Returns whether the latest received FCU is syncing: [ForkchoiceStatus::Syncing]
#[allow(unused)]
pub(crate) fn is_latest_syncing(&self) -> bool {
self.latest_status().map(|s| s.is_syncing()).unwrap_or(false)
}

/// Returns whether the latest received FCU is syncing: [ForkchoiceStatus::Invalid]
#[allow(unused)]
pub(crate) fn is_latest_invalid(&self) -> bool {
self.latest_status().map(|s| s.is_invalid()).unwrap_or(false)
}

/// Returns the last valid head hash.
#[allow(unused)]
pub(crate) fn last_valid_head(&self) -> Option<H256> {
Expand Down Expand Up @@ -98,6 +110,10 @@ impl ForkchoiceStatus {
matches!(self, ForkchoiceStatus::Valid)
}

pub(crate) fn is_invalid(&self) -> bool {
matches!(self, ForkchoiceStatus::Invalid)
}

pub(crate) fn is_syncing(&self) -> bool {
matches!(self, ForkchoiceStatus::Syncing)
}
Expand Down
11 changes: 6 additions & 5 deletions crates/consensus/beacon/src/engine/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1715,12 +1715,13 @@ where

// Poll prune controller if all conditions are met:
// 1. Pipeline is idle
// 2. Pruning is running and we need to prioritize checking its events OR no engine and
// sync messages are pending and we may start pruning
// 3. Latest FCU status is VALID
// 2. Either of two:
// 1. Pruning is running and we need to prioritize checking its events
// 2. Both engine and sync messages are pending AND latest FCU status is not INVALID,
// so we may start pruning
if this.sync.is_pipeline_idle() &&
(this.is_prune_active() || is_pending) &&
this.forkchoice_state_tracker.is_latest_valid()
(this.is_prune_active() ||
is_pending && !this.forkchoice_state_tracker.is_latest_invalid())
{
if let Some(ref mut prune) = this.prune {
match prune.poll(cx, this.blockchain.canonical_tip().number) {
Expand Down
Loading

0 comments on commit f917d49

Please sign in to comment.