feat: share SnapshotProvider through ProviderFactory (#5249)

Co-authored-by: Alexey Shekhirin <a.shekhirin@gmail.com>
This commit is contained in:
joshieDo
2023-11-14 17:50:12 +00:00
committed by GitHub
parent 8ecd90b884
commit d21e346c04
8 changed files with 146 additions and 56 deletions

View File

@ -266,6 +266,11 @@ impl<D> ChainPath<D> {
self.0.join("db").into()
}
/// Returns the path to the snapshots directory for this chain.
pub fn snapshots_path(&self) -> PathBuf {
self.0.join("snapshots").into()
}
/// Returns the path to the reth p2p secret key for this chain.
///
/// `<DIR>/<CHAIN_ID>/discovery-secret`

View File

@ -298,8 +298,16 @@ impl<Ext: RethCliExt> NodeCommand<Ext> {
// fetch the head block from the database
let head = self.lookup_head(Arc::clone(&db)).wrap_err("the head block is missing")?;
// configure snapshotter
let snapshotter = reth_snapshot::Snapshotter::new(
db.clone(),
self.chain.clone(),
self.chain.snapshot_block_interval,
);
// setup the blockchain provider
let factory = ProviderFactory::new(Arc::clone(&db), Arc::clone(&self.chain));
let factory = ProviderFactory::new(Arc::clone(&db), Arc::clone(&self.chain))
.with_snapshots(snapshotter.highest_snapshot_receiver());
let blockchain_db = BlockchainProvider::new(factory, blockchain_tree.clone())?;
let blob_store = InMemoryBlobStore::default();
let validator = TransactionValidationTaskExecutor::eth_builder(Arc::clone(&self.chain))
@ -454,12 +462,14 @@ impl<Ext: RethCliExt> NodeCommand<Ext> {
None
};
let (highest_snapshots_tx, highest_snapshots_rx) = watch::channel(None);
let mut hooks = EngineHooks::new();
let pruner_events = if let Some(prune_config) = prune_config {
let mut pruner = self.build_pruner(&prune_config, db.clone(), highest_snapshots_rx);
let mut pruner = self.build_pruner(
&prune_config,
db.clone(),
snapshotter.highest_snapshot_receiver(),
);
let events = pruner.events();
hooks.add(PruneHook::new(pruner, Box::new(ctx.task_executor.clone())));
@ -470,13 +480,6 @@ impl<Ext: RethCliExt> NodeCommand<Ext> {
Either::Right(stream::empty())
};
let _snapshotter = reth_snapshot::Snapshotter::new(
db,
self.chain.clone(),
self.chain.snapshot_block_interval,
highest_snapshots_tx,
);
// Configure the consensus engine
let (beacon_consensus_engine, beacon_engine_handle) = BeaconConsensusEngine::with_channel(
client,