feat(engine): hooks (#4582)

This commit is contained in:
Alexey Shekhirin
2023-09-18 18:52:58 +01:00
committed by GitHub
parent 78edae4d4f
commit 11f5f3f8d7
9 changed files with 423 additions and 177 deletions

View File

@ -25,7 +25,10 @@ use eyre::Context;
use fdlimit::raise_fd_limit;
use futures::{future::Either, pin_mut, stream, stream_select, StreamExt};
use reth_auto_seal_consensus::{AutoSealBuilder, AutoSealConsensus, MiningMode};
use reth_beacon_consensus::{BeaconConsensus, BeaconConsensusEngine, MIN_BLOCKS_FOR_PIPELINE_RUN};
use reth_beacon_consensus::{
hooks::{EngineHooks, PruneHook},
BeaconConsensus, BeaconConsensusEngine, MIN_BLOCKS_FOR_PIPELINE_RUN,
};
use reth_blockchain_tree::{
config::BlockchainTreeConfig, externals::TreeExternals, BlockchainTree, ShareableBlockchainTree,
};
@ -446,16 +449,19 @@ impl<Ext: RethCliExt> NodeCommand<Ext> {
None
};
let pruner = prune_config.map(|prune_config| {
let mut hooks = EngineHooks::new();
if let Some(prune_config) = prune_config {
info!(target: "reth::cli", ?prune_config, "Pruner initialized");
reth_prune::Pruner::new(
let pruner = reth_prune::Pruner::new(
db.clone(),
self.chain.clone(),
prune_config.block_interval,
prune_config.parts,
self.chain.prune_batch_sizes,
)
});
);
hooks.add(PruneHook::new(pruner, Box::new(ctx.task_executor.clone())));
}
// Configure the consensus engine
let (beacon_consensus_engine, beacon_engine_handle) = BeaconConsensusEngine::with_channel(
@ -471,7 +477,7 @@ impl<Ext: RethCliExt> NodeCommand<Ext> {
MIN_BLOCKS_FOR_PIPELINE_RUN,
consensus_engine_tx,
consensus_engine_rx,
pruner,
hooks,
)?;
info!(target: "reth::cli", "Consensus engine initialized");