feat: refactor generation of snapshots from the cli (#5464)

This commit is contained in:
joshieDo
2023-11-24 18:02:14 +00:00
committed by GitHub
parent 269073b2d4
commit af88851723
15 changed files with 225 additions and 158 deletions

View File

@ -31,7 +31,7 @@ impl Default for Headers {
}
impl Segment for Headers {
fn segment() -> SnapshotSegment {
fn segment(&self) -> SnapshotSegment {
SnapshotSegment::Headers
}
@ -45,7 +45,7 @@ impl Segment for Headers {
let mut jar = prepare_jar::<DB, 3>(
provider,
directory,
Self::segment(),
self.segment(),
self.config,
range.clone(),
range_len,

View File

@ -37,7 +37,7 @@ pub trait Segment: Default {
) -> ProviderResult<()>;
/// Returns this struct's [`SnapshotSegment`].
fn segment() -> SnapshotSegment;
fn segment(&self) -> SnapshotSegment;
/// Generates the dataset to train a zstd dictionary with the most recent rows (at most 1000).
fn dataset_for_compression<DB: Database, T: Table<Key = u64>>(

View File

@ -28,7 +28,7 @@ impl Default for Receipts {
}
impl Segment for Receipts {
fn segment() -> SnapshotSegment {
fn segment(&self) -> SnapshotSegment {
SnapshotSegment::Receipts
}
@ -44,7 +44,7 @@ impl Segment for Receipts {
let mut jar = prepare_jar::<DB, 1>(
provider,
directory,
Self::segment(),
self.segment(),
self.config,
block_range,
tx_range_len,

View File

@ -28,7 +28,7 @@ impl Default for Transactions {
}
impl Segment for Transactions {
fn segment() -> SnapshotSegment {
fn segment(&self) -> SnapshotSegment {
SnapshotSegment::Transactions
}
@ -44,7 +44,7 @@ impl Segment for Transactions {
let mut jar = prepare_jar::<DB, 1>(
provider,
directory,
Self::segment(),
self.segment(),
self.config,
block_range,
tx_range_len,

View File

@ -210,9 +210,10 @@ impl<DB: Database> Snapshotter<DB> {
let temp = self.snapshots_path.join(TEMPORARY_SUBDIRECTORY);
let provider = self.provider_factory.provider()?;
let tx_range = provider.transaction_range_by_block_range(block_range.clone())?;
let filename = S::segment().filename(&block_range, &tx_range);
let segment = S::default();
let filename = segment.segment().filename(&block_range, &tx_range);
S::default().snapshot::<DB>(&provider, temp.clone(), block_range)?;
segment.snapshot::<DB>(&provider, temp.clone(), block_range)?;
reth_primitives::fs::rename(temp.join(&filename), self.snapshots_path.join(filename))?;
}