Skip to content

Commit d422073

Browse files
committed
add reth-prune-static-files
1 parent 47dc432 commit d422073

File tree

16 files changed

+226
-66
lines changed

16 files changed

+226
-66
lines changed

.github/assets/check_wasm.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ exclude_crates=(
6868
reth-payload-builder # reth-metrics
6969
reth-provider # tokio
7070
reth-prune # tokio
71+
reth-prune-static-files # reth-provider
7172
reth-stages-api # reth-provider, reth-prune
7273
reth-static-file # tokio
7374
reth-transaction-pool # c-kzg

Cargo.lock

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ members = [
9494
"crates/primitives-traits/",
9595
"crates/primitives/",
9696
"crates/prune/prune",
97+
"crates/prune/static-files",
9798
"crates/prune/types",
9899
"crates/ress/protocol",
99100
"crates/ress/provider",
@@ -429,6 +430,7 @@ reth-primitives = { path = "crates/primitives", default-features = false }
429430
reth-primitives-traits = { path = "crates/primitives-traits", default-features = false }
430431
reth-provider = { path = "crates/storage/provider" }
431432
reth-prune = { path = "crates/prune/prune" }
433+
reth-prune-static-files = { path = "crates/prune/static-files" }
432434
reth-prune-types = { path = "crates/prune/types", default-features = false }
433435
reth-revm = { path = "crates/revm", default-features = false }
434436
reth-rpc = { path = "crates/rpc/rpc" }

crates/node/builder/src/launch/common.rs

Lines changed: 3 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,11 @@ use crate::{
3434
hooks::OnComponentInitializedHook,
3535
BuilderContext, ExExLauncher, NodeAdapter, PrimitivesTy,
3636
};
37-
use alloy_consensus::BlockHeader as _;
3837
use alloy_eips::eip2124::Head;
3938
use alloy_primitives::{BlockNumber, B256};
4039
use eyre::Context;
4140
use rayon::ThreadPoolBuilder;
42-
use reth_chainspec::{Chain, EthChainSpec, EthereumHardfork, EthereumHardforks};
41+
use reth_chainspec::{Chain, EthChainSpec, EthereumHardforks};
4342
use reth_config::{config::EtlConfig, PruneConfig};
4443
use reth_consensus::noop::NoopConsensus;
4544
use reth_db_api::{database::Database, database_metrics::DatabaseMetrics};
@@ -67,8 +66,8 @@ use reth_node_metrics::{
6766
};
6867
use reth_provider::{
6968
providers::{NodeTypesForProvider, ProviderNodeTypes, StaticFileProvider},
70-
BlockHashReader, BlockNumReader, BlockReaderIdExt, ProviderError, ProviderFactory,
71-
ProviderResult, StageCheckpointReader, StaticFileProviderFactory,
69+
BlockHashReader, BlockNumReader, ProviderError, ProviderFactory, ProviderResult,
70+
StageCheckpointReader, StaticFileProviderFactory,
7271
};
7372
use reth_prune::{PruneModes, PrunerBuilder};
7473
use reth_rpc_builder::config::RethRpcServerConfig;
@@ -945,40 +944,6 @@ where
945944
Ok(None)
946945
}
947946

948-
/// Expire the pre-merge transactions if the node is configured to do so and the chain has a
949-
/// merge block.
950-
///
951-
/// If the node is configured to prune pre-merge transactions and it has synced past the merge
952-
/// block, it will delete the pre-merge transaction static files if they still exist.
953-
pub fn expire_pre_merge_transactions(&self) -> eyre::Result<()>
954-
where
955-
T: FullNodeTypes<Provider: StaticFileProviderFactory>,
956-
{
957-
if self.node_config().pruning.bodies_pre_merge &&
958-
let Some(merge_block) = self
959-
.chain_spec()
960-
.ethereum_fork_activation(EthereumHardfork::Paris)
961-
.block_number()
962-
{
963-
// Ensure we only expire transactions after we synced past the merge block.
964-
let Some(latest) = self.blockchain_db().latest_header()? else { return Ok(()) };
965-
if latest.number() > merge_block {
966-
let provider = self.blockchain_db().static_file_provider();
967-
if provider
968-
.get_lowest_transaction_static_file_block()
969-
.is_some_and(|lowest| lowest < merge_block)
970-
{
971-
info!(target: "reth::cli", merge_block, "Expiring pre-merge transactions");
972-
provider.delete_transactions_below(merge_block)?;
973-
} else {
974-
debug!(target: "reth::cli", merge_block, "No pre-merge transactions to expire");
975-
}
976-
}
977-
}
978-
979-
Ok(())
980-
}
981-
982947
/// Returns the metrics sender.
983948
pub fn sync_metrics_tx(&self) -> UnboundedSender<MetricEvent> {
984949
self.right().db_provider_container.metrics_sender.clone()

crates/node/builder/src/launch/engine.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,6 @@ impl EngineNodeLauncher {
117117
})?
118118
.with_components(components_builder, on_component_initialized).await?;
119119

120-
// Try to expire pre-merge transaction history if configured
121-
ctx.expire_pre_merge_transactions()?;
122-
123120
// spawn exexs if any
124121
let maybe_exex_manager_handle = ctx.launch_exex(installed_exex).await?;
125122

crates/node/core/src/args/pruning.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,10 @@ impl PruningArgs {
126126
receipts: Some(PruneMode::Distance(MINIMUM_PRUNING_DISTANCE)),
127127
account_history: Some(PruneMode::Distance(MINIMUM_PRUNING_DISTANCE)),
128128
storage_history: Some(PruneMode::Distance(MINIMUM_PRUNING_DISTANCE)),
129-
// TODO: set default to pre-merge block if available
130-
bodies_history: None,
129+
bodies_history: chain_spec
130+
.ethereum_fork_activation(EthereumHardfork::Paris)
131+
.block_number()
132+
.map(PruneMode::Before),
131133
merkle_changesets: PruneMode::Distance(MINIMUM_PRUNING_DISTANCE),
132134
#[expect(deprecated)]
133135
receipts_log_filter: (),

crates/prune/prune/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ reth-errors.workspace = true
1919
reth-provider.workspace = true
2020
reth-tokio-util.workspace = true
2121
reth-config.workspace = true
22+
reth-prune-static-files.workspace = true
2223
reth-prune-types.workspace = true
2324
reth-primitives-traits.workspace = true
2425
reth-static-file-types.workspace = true

crates/prune/prune/src/segments/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ pub use static_file::{
1515
use std::{fmt::Debug, ops::RangeInclusive};
1616
use tracing::error;
1717
pub use user::{
18-
AccountHistory, MerkleChangeSets, Receipts as UserReceipts, SenderRecovery, StorageHistory,
19-
TransactionLookup,
18+
AccountHistory, BodiesAdapter, MerkleChangeSets, Receipts as UserReceipts, SenderRecovery,
19+
StorageHistory, TransactionLookup,
2020
};
2121

2222
/// A segment represents a pruning of some portion of the data.

crates/prune/prune/src/segments/set.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::segments::{
2-
AccountHistory, MerkleChangeSets, Segment, SenderRecovery, StorageHistory, TransactionLookup,
3-
UserReceipts,
2+
AccountHistory, BodiesAdapter, MerkleChangeSets, Segment, SenderRecovery, StorageHistory,
3+
TransactionLookup, UserReceipts,
44
};
55
use alloy_eips::eip2718::Encodable2718;
66
use reth_db_api::{table::Value, transaction::DbTxMut};
@@ -68,7 +68,7 @@ where
6868
receipts,
6969
account_history,
7070
storage_history,
71-
bodies_history: _,
71+
bodies_history,
7272
merkle_changesets,
7373
receipts_log_filter: (),
7474
} = prune_modes;
@@ -92,6 +92,8 @@ where
9292
.segment_opt(transaction_lookup.map(TransactionLookup::new))
9393
// Sender recovery
9494
.segment_opt(sender_recovery.map(SenderRecovery::new))
95+
// Bodies
96+
.segment_opt(bodies_history.map(BodiesAdapter::new))
9597
}
9698
}
9799

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
use crate::{
2+
segments::{PruneInput, Segment},
3+
PrunerError,
4+
};
5+
use reth_provider::{BlockReader, StaticFileProviderFactory};
6+
use reth_prune_static_files::Bodies;
7+
use reth_prune_types::{PruneMode, PrunePurpose, PruneSegment, SegmentOutput};
8+
9+
/// Segment adapter for pruning transactions in static files.
10+
///
11+
/// This wraps the implementation from `reth_prune_static_files` and implements
12+
/// the `Segment` trait required by the pruner.
13+
#[derive(Debug)]
14+
pub struct BodiesAdapter {
15+
inner: Bodies,
16+
}
17+
18+
impl BodiesAdapter {
19+
/// Creates a new [`BodiesAdapter`] segment with the given prune mode.
20+
pub const fn new(mode: PruneMode) -> Self {
21+
Self { inner: Bodies::new(mode) }
22+
}
23+
}
24+
25+
impl<Provider> Segment<Provider> for BodiesAdapter
26+
where
27+
Provider: StaticFileProviderFactory + BlockReader,
28+
{
29+
fn segment(&self) -> PruneSegment {
30+
self.inner.segment()
31+
}
32+
33+
fn mode(&self) -> Option<PruneMode> {
34+
self.inner.mode()
35+
}
36+
37+
fn purpose(&self) -> PrunePurpose {
38+
self.inner.purpose()
39+
}
40+
41+
fn prune(&self, provider: &Provider, input: PruneInput) -> Result<SegmentOutput, PrunerError> {
42+
Ok(self.inner.prune(provider, input.to_block)?)
43+
}
44+
}

0 commit comments

Comments
 (0)