Skip to content

Commit

Permalink
simplify deps
Browse files Browse the repository at this point in the history
  • Loading branch information
shekhirin committed Sep 13, 2023
1 parent 477e9e3 commit 73ee4ae
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 16 deletions.
16 changes: 6 additions & 10 deletions crates/consensus/beacon/src/engine/hooks/controller.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::hooks::{Hook, HookAction, HookArguments, HookError, Hooks};
use crate::hooks::{Hook, HookAction, HookArguments, HookDependencies, HookError, Hooks};
use std::task::{Context, Poll};
use tracing::debug;

Expand Down Expand Up @@ -53,7 +53,7 @@ impl HooksController {
&mut self,
cx: &mut Context<'_>,
args: HookArguments,
is_pipeline_active: bool,
active_dependencies: HookDependencies,
) -> Result<Poll<HookAction>, HookError> {
let hook_idx = self.hook_idx % self.hooks.len();
self.hook_idx = hook_idx + 1;
Expand All @@ -62,14 +62,10 @@ impl HooksController {
let Some(mut hook) = self.hooks[hook_idx].take() else { return Ok(Poll::Pending) };

// Hook with DB write dependency is not allowed to run due to already
// running hook with DB write dependency.
let db_write = hook.dependencies().db_write && self.running_hook_with_db_write.is_some();
// Hook with idle pipeline dependency is not allowed to run due to pipeline
// being active.
let pipeline_idle = hook.dependencies().pipeline_idle && is_pipeline_active;

let skip_hook = db_write || pipeline_idle;
if skip_hook {
// running hook with DB write dependency or active DB write according to passed dependencies
if hook.dependencies().db_write &&
(self.running_hook_with_db_write.is_some() || active_dependencies.db_write)
{
return Ok(Poll::Pending)
}

Expand Down
1 change: 0 additions & 1 deletion crates/consensus/beacon/src/engine/hooks/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,5 +88,4 @@ pub enum HookError {

pub struct HookDependencies {
pub db_write: bool,
pub pipeline_idle: bool,
}
6 changes: 3 additions & 3 deletions crates/consensus/beacon/src/engine/hooks/prune.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! Prune management for the engine implementation.
//! Prune hook for the engine implementation.
use crate::engine::hooks::{
Hook, HookAction, HookArguments, HookDependencies, HookError, HookEvent,
Expand All @@ -8,7 +8,7 @@ use metrics::Counter;
use reth_db::database::Database;
use reth_interfaces::sync::SyncState;
use reth_primitives::BlockNumber;
use reth_prune::{Pruner, PrunerError, PrunerResult, PrunerWithResult};
use reth_prune::{Pruner, PrunerError, PrunerWithResult};
use reth_tasks::TaskSpawner;
use std::task::{ready, Context, Poll};
use tokio::sync::oneshot;
Expand Down Expand Up @@ -144,7 +144,7 @@ impl<DB: Database + 'static> Hook for EnginePruneController<DB> {
}

fn dependencies(&self) -> HookDependencies {
HookDependencies { db_write: true, pipeline_idle: true }
HookDependencies { db_write: true }
}
}

Expand Down
4 changes: 2 additions & 2 deletions crates/consensus/beacon/src/engine/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ mod handle;
pub use handle::BeaconConsensusEngineHandle;

mod forkchoice;
use crate::hooks::Hooks;
use crate::hooks::{HookDependencies, Hooks};
pub use forkchoice::ForkchoiceStatus;

mod metrics;
Expand Down Expand Up @@ -1803,7 +1803,7 @@ where
.poll_next_hook(
cx,
HookArguments { tip_block_number: this.blockchain.canonical_tip().number },
this.sync.is_pipeline_active(),
HookDependencies { db_write: this.sync.is_pipeline_active() },
)?
.map(|action| this.on_hook_action(action))
{
Expand Down

0 comments on commit 73ee4ae

Please sign in to comment.