Skip to content

Commit 1737b8d

Browse files
authored
fix: receipts logs arg parsing (#16240)
1 parent 6195c70 commit 1737b8d

File tree

4 files changed

+45
-34
lines changed

4 files changed

+45
-34
lines changed

book/cli/reth/node.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -697,6 +697,9 @@ Pruning:
697697
--prune.receipts.before <BLOCK_NUMBER>
698698
Prune receipts before the specified block number. The specified block number is not pruned
699699
700+
--prune.receiptslogfilter <FILTER_CONFIG>
701+
Configure receipts log filter. Format: <`address`>:<`prune_mode`>[,<`address`>:<`prune_mode`>...] Where <`prune_mode`> can be 'full', 'distance:<`blocks`>', or 'before:<`block_number`>'
702+
700703
--prune.accounthistory.full
701704
Prunes all account history
702705
@@ -715,9 +718,6 @@ Pruning:
715718
--prune.storagehistory.before <BLOCK_NUMBER>
716719
Prune storage history before the specified block number. The specified block number is not pruned
717720
718-
--prune.receiptslogfilter <FILTER_CONFIG>
719-
Configure receipts log filter. Format: <`address`>:<`prune_mode`>[,<`address`>:<`prune_mode`>...] Where <`prune_mode`> can be 'full', 'distance:<`blocks`>', or 'before:<`block_number`>'
720-
721721
Engine:
722722
--engine.persistence-threshold <PERSISTENCE_THRESHOLD>
723723
Configure persistence threshold for engine experimental

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,7 @@ impl<R, ChainSpec: EthChainSpec> LaunchContextWith<Attached<WithConfigs<ChainSpe
332332
}
333333

334334
/// Returns the configured [`PruneConfig`]
335+
///
335336
/// Any configuration set in CLI will take precedence over those set in toml
336337
pub fn prune_config(&self) -> Option<PruneConfig> {
337338
let Some(mut node_prune_config) = self.node_config().prune_config() else {
@@ -1086,7 +1087,7 @@ mod tests {
10861087
storage_history_full: false,
10871088
storage_history_distance: None,
10881089
storage_history_before: None,
1089-
receipts_log_filter: vec![],
1090+
receipts_log_filter: None,
10901091
},
10911092
..NodeConfig::test()
10921093
};

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

Lines changed: 38 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
use crate::args::error::ReceiptsLogError;
44
use alloy_primitives::{Address, BlockNumber};
55
use clap::{builder::RangedU64ValueParser, Args};
6-
use reth_chainspec::EthChainSpec;
76
use reth_config::config::PruneConfig;
87
use reth_prune_types::{PruneMode, PruneModes, ReceiptsLogPruneConfig, MINIMUM_PRUNING_DISTANCE};
98
use std::collections::BTreeMap;
@@ -56,6 +55,12 @@ pub struct PruningArgs {
5655
/// Prune receipts before the specified block number. The specified block number is not pruned.
5756
#[arg(long = "prune.receipts.before", value_name = "BLOCK_NUMBER", conflicts_with_all = &["receipts_full", "receipts_distance"])]
5857
pub receipts_before: Option<BlockNumber>,
58+
// Receipts Log Filter
59+
/// Configure receipts log filter. Format:
60+
/// <`address`>:<`prune_mode`>[,<`address`>:<`prune_mode`>...] Where <`prune_mode`> can be
61+
/// 'full', 'distance:<`blocks`>', or 'before:<`block_number`>'
62+
#[arg(long = "prune.receiptslogfilter", value_name = "FILTER_CONFIG", conflicts_with_all = &["receipts_full", "receipts_distance", "receipts_before"], value_parser = parse_receipts_log_filter)]
63+
pub receipts_log_filter: Option<ReceiptsLogPruneConfig>,
5964

6065
// Account History
6166
/// Prunes all account history.
@@ -81,18 +86,11 @@ pub struct PruningArgs {
8186
/// pruned.
8287
#[arg(long = "prune.storagehistory.before", value_name = "BLOCK_NUMBER", conflicts_with_all = &["storage_history_full", "storage_history_distance"])]
8388
pub storage_history_before: Option<BlockNumber>,
84-
85-
// Receipts Log Filter
86-
/// Configure receipts log filter. Format:
87-
/// <`address`>:<`prune_mode`>[,<`address`>:<`prune_mode`>...] Where <`prune_mode`> can be
88-
/// 'full', 'distance:<`blocks`>', or 'before:<`block_number`>'
89-
#[arg(long = "prune.receiptslogfilter", value_name = "FILTER_CONFIG", value_delimiter = ',', value_parser = parse_receipts_log_filter)]
90-
pub receipts_log_filter: Vec<String>,
9189
}
9290

9391
impl PruningArgs {
9492
/// Returns pruning configuration.
95-
pub fn prune_config(&self, chain_spec: &impl EthChainSpec) -> Option<PruneConfig> {
93+
pub fn prune_config(&self) -> Option<PruneConfig> {
9694
// Initialise with a default prune configuration.
9795
let mut config = PruneConfig::default();
9896

@@ -103,21 +101,10 @@ impl PruningArgs {
103101
segments: PruneModes {
104102
sender_recovery: Some(PruneMode::Full),
105103
transaction_lookup: None,
106-
// prune all receipts if chain doesn't have deposit contract specified in chain
107-
// spec
108-
receipts: chain_spec
109-
.deposit_contract()
110-
.map(|contract| PruneMode::Before(contract.block))
111-
.or(Some(PruneMode::Distance(MINIMUM_PRUNING_DISTANCE))),
104+
receipts: Some(PruneMode::Distance(MINIMUM_PRUNING_DISTANCE)),
112105
account_history: Some(PruneMode::Distance(MINIMUM_PRUNING_DISTANCE)),
113106
storage_history: Some(PruneMode::Distance(MINIMUM_PRUNING_DISTANCE)),
114-
receipts_log_filter: ReceiptsLogPruneConfig(
115-
chain_spec
116-
.deposit_contract()
117-
.map(|contract| (contract.address, PruneMode::Before(contract.block)))
118-
.into_iter()
119-
.collect(),
120-
),
107+
receipts_log_filter: Default::default(),
121108
},
122109
}
123110
}
@@ -141,9 +128,18 @@ impl PruningArgs {
141128
if let Some(mode) = self.storage_history_prune_mode() {
142129
config.segments.storage_history = Some(mode);
143130
}
131+
if let Some(receipt_logs) =
132+
self.receipts_log_filter.as_ref().filter(|c| !c.is_empty()).cloned()
133+
{
134+
config.segments.receipts_log_filter = receipt_logs;
135+
// need to remove the receipts segment filter entirely because that takes precendence
136+
// over the logs filter
137+
config.segments.receipts.take();
138+
}
144139

145140
Some(config)
146141
}
142+
147143
const fn sender_recovery_prune_mode(&self) -> Option<PruneMode> {
148144
if self.sender_recovery_full {
149145
Some(PruneMode::Full)
@@ -205,6 +201,7 @@ impl PruningArgs {
205201
}
206202
}
207203

204+
/// Parses `,` separated pruning info into [`ReceiptsLogPruneConfig`].
208205
pub(crate) fn parse_receipts_log_filter(
209206
value: &str,
210207
) -> Result<ReceiptsLogPruneConfig, ReceiptsLogError> {
@@ -236,9 +233,8 @@ pub(crate) fn parse_receipts_log_filter(
236233
if parts.len() < 3 {
237234
return Err(ReceiptsLogError::InvalidFilterFormat(filter.to_string()));
238235
}
239-
let block_number = parts[2]
240-
.parse::<BlockNumber>()
241-
.map_err(ReceiptsLogError::InvalidBlockNumber)?;
236+
let block_number =
237+
parts[2].parse::<u64>().map_err(ReceiptsLogError::InvalidBlockNumber)?;
242238
PruneMode::Before(block_number)
243239
}
244240
_ => return Err(ReceiptsLogError::InvalidPruneMode(parts[1].to_string())),
@@ -251,6 +247,7 @@ pub(crate) fn parse_receipts_log_filter(
251247
#[cfg(test)]
252248
mod tests {
253249
use super::*;
250+
use alloy_primitives::address;
254251
use clap::Parser;
255252

256253
/// A helper type to parse Args more easily
@@ -262,6 +259,22 @@ mod tests {
262259

263260
#[test]
264261
fn pruning_args_sanity_check() {
262+
let args = CommandParser::<PruningArgs>::parse_from([
263+
"reth",
264+
"--prune.receiptslogfilter",
265+
"0x0000000000000000000000000000000000000003:before:5000000",
266+
])
267+
.args;
268+
let mut config = ReceiptsLogPruneConfig::default();
269+
config.0.insert(
270+
address!("0x0000000000000000000000000000000000000003"),
271+
PruneMode::Before(5000000),
272+
);
273+
assert_eq!(args.receipts_log_filter, Some(config));
274+
}
275+
276+
#[test]
277+
fn parse_receiptslogfilter() {
265278
let default_args = PruningArgs::default();
266279
let args = CommandParser::<PruningArgs>::parse_from(["reth"]).args;
267280
assert_eq!(args, default_args);

crates/node/core/src/node_config.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -283,11 +283,8 @@ impl<ChainSpec> NodeConfig<ChainSpec> {
283283
}
284284

285285
/// Returns pruning configuration.
286-
pub fn prune_config(&self) -> Option<PruneConfig>
287-
where
288-
ChainSpec: EthChainSpec,
289-
{
290-
self.pruning.prune_config(&self.chain)
286+
pub fn prune_config(&self) -> Option<PruneConfig> {
287+
self.pruning.prune_config()
291288
}
292289

293290
/// Returns the max block that the node should run to, looking it up from the network if

0 commit comments

Comments
 (0)