Skip to content

Commit d1a52cc

Browse files
committed
on new nodes always write receipts to static files
1 parent 012a482 commit d1a52cc

File tree

4 files changed

+34
-15
lines changed

4 files changed

+34
-15
lines changed

crates/stages/stages/src/stages/execution.rs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use reth_provider::{
1313
providers::{StaticFileProvider, StaticFileWriter},
1414
BlockHashReader, BlockReader, DBProvider, ExecutionOutcome, HeaderProvider,
1515
LatestStateProviderRef, OriginalValuesKnown, ProviderError, StateWriter,
16-
StaticFileProviderFactory, StatsReader, TransactionVariant,
16+
StaticFileProviderFactory, StatsReader, StorageSettingsCache, TransactionVariant,
1717
};
1818
use reth_revm::database::StateProviderDatabase;
1919
use reth_stages_api::{
@@ -185,11 +185,17 @@ where
185185
unwind_to: Option<u64>,
186186
) -> Result<(), StageError>
187187
where
188-
Provider: StaticFileProviderFactory + DBProvider + BlockReader + HeaderProvider,
188+
Provider: StaticFileProviderFactory
189+
+ DBProvider
190+
+ BlockReader
191+
+ HeaderProvider
192+
+ StorageSettingsCache,
189193
{
190-
// If there's any receipts pruning configured, receipts are written directly to database and
191-
// inconsistencies are expected.
192-
if provider.prune_modes_ref().has_receipts_pruning() {
194+
// On old nodes, if there's any receipts pruning configured, receipts are written directly
195+
// to database and inconsistencies are expected.
196+
if provider.prune_modes_ref().has_receipts_pruning() &&
197+
!provider.cached_storage_settings().receipts_on_static_files
198+
{
193199
return Ok(())
194200
}
195201

@@ -259,7 +265,8 @@ where
259265
Primitives: NodePrimitives<BlockHeader: reth_db_api::table::Value>,
260266
> + StatsReader
261267
+ BlockHashReader
262-
+ StateWriter<Receipt = <E::Primitives as NodePrimitives>::Receipt>,
268+
+ StateWriter<Receipt = <E::Primitives as NodePrimitives>::Receipt>
269+
+ StorageSettingsCache,
263270
{
264271
/// Return the id of the stage
265272
fn id(&self) -> StageId {

crates/storage/db-common/src/init.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ where
164164
static_file_provider.latest_writer(StaticFileSegment::Transactions)?.increment_block(0)?;
165165

166166
// Behaviour reserved only for new nodes should be set here.
167-
let storage_settings = StorageSettings::new();
167+
let storage_settings = StorageSettings::new().with_receipts_on_static_files();
168168
provider_rw.write_storage_settings(storage_settings)?;
169169

170170
// `commit_unwind`` will first commit the DB and then the static file provider, which is

crates/storage/provider/src/providers/database/provider.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,9 @@ use reth_prune_types::{
5858
use reth_stages_types::{StageCheckpoint, StageId};
5959
use reth_static_file_types::StaticFileSegment;
6060
use reth_storage_api::{
61-
BlockBodyIndicesProvider, BlockBodyReader, MetadataProvider, MetadataWriter, NodePrimitivesProvider, StateProvider, StorageChangeSetReader, StorageSettingsCache, TryIntoHistoricalStateProvider
61+
BlockBodyIndicesProvider, BlockBodyReader, MetadataProvider, MetadataWriter,
62+
NodePrimitivesProvider, StateProvider, StorageChangeSetReader, StorageSettingsCache,
63+
TryIntoHistoricalStateProvider,
6264
};
6365
use reth_storage_errors::provider::ProviderResult;
6466
use reth_trie::{
@@ -367,7 +369,9 @@ impl<TX: DbTx + DbTxMut + 'static, N: NodeTypesForProvider> DatabaseProvider<TX,
367369
// iterate over block body and remove receipts
368370
self.remove::<tables::Receipts<ReceiptTy<N>>>(from_tx..)?;
369371

370-
if !self.prune_modes.has_receipts_pruning() {
372+
if !self.prune_modes.has_receipts_pruning() ||
373+
self.cached_storage_settings().receipts_on_static_files
374+
{
371375
let static_file_receipt_num =
372376
self.static_file_provider.get_highest_static_file_tx(StaticFileSegment::Receipts);
373377

@@ -1609,7 +1613,8 @@ impl<TX: DbTxMut + DbTx + 'static, N: NodeTypesForProvider> StateWriter
16091613
));
16101614
}
16111615

1612-
let has_receipts_pruning = self.prune_modes.has_receipts_pruning();
1616+
let write_to_db = self.prune_modes.has_receipts_pruning() &&
1617+
!self.cached_storage_settings().receipts_on_static_files;
16131618

16141619
// Prepare receipts cursor if we are going to write receipts to the database
16151620
//
@@ -1620,7 +1625,7 @@ impl<TX: DbTxMut + DbTx + 'static, N: NodeTypesForProvider> StateWriter
16201625
// Prepare receipts static writer if we are going to write receipts to static files
16211626
//
16221627
// We are writing to static files if requested and if there's no receipt pruning configured
1623-
let mut receipts_static_writer = has_receipts_pruning
1628+
let mut receipts_static_writer = write_to_db
16241629
.not()
16251630
.then(|| self.static_file_provider.get_writer(first_block, StaticFileSegment::Receipts))
16261631
.transpose()?;

crates/storage/provider/src/providers/static_file/manager.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ use reth_static_file_types::{
4040
find_fixed_range, HighestStaticFiles, SegmentHeader, SegmentRangeInclusive, StaticFileSegment,
4141
DEFAULT_BLOCKS_PER_STATIC_FILE,
4242
};
43-
use reth_storage_api::{BlockBodyIndicesProvider, DBProvider};
43+
use reth_storage_api::{BlockBodyIndicesProvider, DBProvider, StorageSettingsCache};
4444
use reth_storage_errors::provider::{ProviderError, ProviderResult};
4545
use std::{
4646
collections::{hash_map::Entry, BTreeMap, HashMap},
@@ -762,7 +762,11 @@ impl<N: NodePrimitives> StaticFileProvider<N> {
762762
has_receipt_pruning: bool,
763763
) -> ProviderResult<Option<PipelineTarget>>
764764
where
765-
Provider: DBProvider + BlockReader + StageCheckpointReader + ChainSpecProvider,
765+
Provider: DBProvider
766+
+ BlockReader
767+
+ StageCheckpointReader
768+
+ ChainSpecProvider
769+
+ StorageSettingsCache,
766770
N: NodePrimitives<Receipt: Value, BlockHeader: Value, SignedTx: Value>,
767771
{
768772
// OVM historical import is broken and does not work with this check. It's importing
@@ -797,8 +801,11 @@ impl<N: NodePrimitives> StaticFileProvider<N> {
797801
};
798802

799803
for segment in StaticFileSegment::iter() {
800-
if has_receipt_pruning && segment.is_receipts() {
801-
// Pruned nodes (including full node) do not store receipts as static files.
804+
if segment.is_receipts() &&
805+
has_receipt_pruning &&
806+
!provider.cached_storage_settings().receipts_on_static_files
807+
{
808+
// Old pruned nodes (including full node) do not store receipts as static files.
802809
continue
803810
}
804811

0 commit comments

Comments
 (0)