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

@@ -12,7 +12,7 @@ use reth_primitives::{
use reth_provider::{
providers::SnapshotProvider, DatabaseProviderRO, HeaderProvider, ProviderError, ProviderFactory,
};
use reth_snapshot::segments::{Headers, Segment};
use reth_snapshot::{segments, segments::Segment};
use std::{path::Path, sync::Arc};
impl Command {
@@ -23,15 +23,22 @@ impl Command {
inclusion_filter: InclusionFilter,
phf: PerfectHashingFunction,
) -> eyre::Result<()> {
let segment = Headers::new(
compression,
if self.with_filters {
Filters::WithFilters(inclusion_filter, phf)
} else {
Filters::WithoutFilters
},
);
segment.snapshot::<DB>(provider, self.from..=(self.from + self.block_interval - 1))?;
let range = self.block_range();
let filters = if self.with_filters {
Filters::WithFilters(inclusion_filter, phf)
} else {
Filters::WithoutFilters
};
let segment = segments::Headers::new(compression, filters);
segment.snapshot::<DB>(provider, range.clone())?;
// Default name doesn't have any configuration
reth_primitives::fs::rename(
SnapshotSegment::Headers.filename(&range),
SnapshotSegment::Headers.filename_with_configuration(filters, compression, &range),
)?;
Ok(())
}
@@ -51,12 +58,13 @@ impl Command {
Filters::WithoutFilters
};
let range = self.from..=(self.from + self.block_interval - 1);
let range = self.block_range();
let mut row_indexes = range.clone().collect::<Vec<_>>();
let mut rng = rand::thread_rng();
let path =
SnapshotSegment::Headers.filename_with_configuration(filters, compression, &range);
let path = SnapshotSegment::Headers
.filename_with_configuration(filters, compression, &range)
.into();
let provider = SnapshotProvider::default();
let jar_provider =
provider.get_segment_provider(SnapshotSegment::Headers, self.from, Some(path))?;

View File

@@ -7,7 +7,7 @@ use reth_primitives::{
BlockNumber, ChainSpec, SnapshotSegment,
};
use reth_provider::ProviderFactory;
use std::{path::Path, sync::Arc};
use std::{ops::RangeInclusive, path::Path, sync::Arc};
mod bench;
mod headers;
@@ -130,4 +130,9 @@ impl Command {
Ok(())
}
/// Gives out the inclusive block range for the snapshot requested by the user.
fn block_range(&self) -> RangeInclusive<BlockNumber> {
self.from..=(self.from + self.block_interval - 1)
}
}

View File

@@ -24,15 +24,22 @@ impl Command {
inclusion_filter: InclusionFilter,
phf: PerfectHashingFunction,
) -> eyre::Result<()> {
let segment = segments::Receipts::new(
compression,
if self.with_filters {
Filters::WithFilters(inclusion_filter, phf)
} else {
Filters::WithoutFilters
},
);
segment.snapshot::<DB>(provider, self.from..=(self.from + self.block_interval - 1))?;
let range = self.block_range();
let filters = if self.with_filters {
Filters::WithFilters(inclusion_filter, phf)
} else {
Filters::WithoutFilters
};
let segment = segments::Receipts::new(compression, filters);
segment.snapshot::<DB>(provider, range.clone())?;
// Default name doesn't have any configuration
reth_primitives::fs::rename(
SnapshotSegment::Receipts.filename(&range),
SnapshotSegment::Receipts.filename_with_configuration(filters, compression, &range),
)?;
Ok(())
}
@@ -62,11 +69,10 @@ impl Command {
let mut row_indexes = tx_range.clone().collect::<Vec<_>>();
let path = SnapshotSegment::Receipts.filename_with_configuration(
filters,
compression,
&block_range,
);
let path = SnapshotSegment::Receipts
.filename_with_configuration(filters, compression, &block_range)
.into();
let provider = SnapshotProvider::default();
let jar_provider =
provider.get_segment_provider(SnapshotSegment::Receipts, self.from, Some(path))?;

View File

@@ -24,15 +24,22 @@ impl Command {
inclusion_filter: InclusionFilter,
phf: PerfectHashingFunction,
) -> eyre::Result<()> {
let segment = segments::Transactions::new(
compression,
if self.with_filters {
Filters::WithFilters(inclusion_filter, phf)
} else {
Filters::WithoutFilters
},
);
segment.snapshot::<DB>(provider, self.from..=(self.from + self.block_interval - 1))?;
let range = self.block_range();
let filters = if self.with_filters {
Filters::WithFilters(inclusion_filter, phf)
} else {
Filters::WithoutFilters
};
let segment = segments::Transactions::new(compression, filters);
segment.snapshot::<DB>(provider, range.clone())?;
// Default name doesn't have any configuration
reth_primitives::fs::rename(
SnapshotSegment::Transactions.filename(&range),
SnapshotSegment::Transactions.filename_with_configuration(filters, compression, &range),
)?;
Ok(())
}
@@ -62,11 +69,9 @@ impl Command {
let mut row_indexes = tx_range.clone().collect::<Vec<_>>();
let path = SnapshotSegment::Transactions.filename_with_configuration(
filters,
compression,
&block_range,
);
let path = SnapshotSegment::Transactions
.filename_with_configuration(filters, compression, &block_range)
.into();
let provider = SnapshotProvider::default();
let jar_provider =
provider.get_segment_provider(SnapshotSegment::Transactions, self.from, Some(path))?;

View File

@@ -301,13 +301,14 @@ impl<Ext: RethCliExt> NodeCommand<Ext> {
// configure snapshotter
let snapshotter = reth_snapshot::Snapshotter::new(
db.clone(),
data_dir.snapshots_path(),
self.chain.clone(),
self.chain.snapshot_block_interval,
);
)?;
// setup the blockchain provider
let factory = ProviderFactory::new(Arc::clone(&db), Arc::clone(&self.chain))
.with_snapshots(snapshotter.highest_snapshot_receiver());
.with_snapshots(data_dir.snapshots_path(), 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))