feat: add directory paths to Snapshotter and SnapshotProvider (#5283)

Co-authored-by: Alexey Shekhirin <a.shekhirin@gmail.com>
Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
This commit is contained in:
joshieDo
2023-11-14 20:54:13 +00:00
committed by GitHub
parent fd392ba0b9
commit 7b781eb602
16 changed files with 247 additions and 101 deletions

View File

@ -21,6 +21,7 @@ use reth_primitives::{
use revm::primitives::{BlockEnv, CfgEnv};
use std::{
ops::{RangeBounds, RangeInclusive},
path::PathBuf,
sync::Arc,
};
use tokio::sync::watch;
@ -82,10 +83,12 @@ impl<DB> ProviderFactory<DB> {
/// database provider comes with a shared snapshot provider
pub fn with_snapshots(
mut self,
snapshots_path: PathBuf,
highest_snapshot_tracker: watch::Receiver<Option<HighestSnapshots>>,
) -> Self {
self.snapshot_provider = Some(Arc::new(
SnapshotProvider::default().with_highest_tracker(Some(highest_snapshot_tracker)),
SnapshotProvider::new(snapshots_path)
.with_highest_tracker(Some(highest_snapshot_tracker)),
));
self
}

View File

@ -20,9 +20,16 @@ pub struct SnapshotProvider {
map: DashMap<(BlockNumber, SnapshotSegment), LoadedJar>,
/// Tracks the highest snapshot of every segment.
highest_tracker: Option<watch::Receiver<Option<HighestSnapshots>>>,
/// Directory where snapshots are located
path: PathBuf,
}
impl SnapshotProvider {
/// Creates a new [`SnapshotProvider`].
pub fn new(path: PathBuf) -> Self {
Self { map: Default::default(), highest_tracker: None, path }
}
/// Adds a highest snapshot tracker to the provider
pub fn with_highest_tracker(
mut self,
@ -50,9 +57,9 @@ impl SnapshotProvider {
if let Some(path) = &path {
self.map.insert(key, LoadedJar::new(NippyJar::load(path)?)?);
} else {
path = Some(segment.filename(
path = Some(self.path.join(segment.filename(
&((snapshot * BLOCKS_PER_SNAPSHOT)..=((snapshot + 1) * BLOCKS_PER_SNAPSHOT - 1)),
));
)));
}
self.get_segment_provider(segment, block, path)