mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
fix: update block interval properly (#11546)
This commit is contained in:
@ -14,6 +14,9 @@ use std::{
|
||||
|
||||
const EXTENSION: &str = "toml";
|
||||
|
||||
/// The default prune block interval
|
||||
pub const DEFAULT_BLOCK_INTERVAL: usize = 5;
|
||||
|
||||
/// Configuration for the reth node.
|
||||
#[derive(Debug, Clone, Default, Deserialize, PartialEq, Eq, Serialize)]
|
||||
#[serde(default)]
|
||||
@ -383,7 +386,7 @@ pub struct PruneConfig {
|
||||
|
||||
impl Default for PruneConfig {
|
||||
fn default() -> Self {
|
||||
Self { block_interval: 5, segments: PruneModes::none() }
|
||||
Self { block_interval: DEFAULT_BLOCK_INTERVAL, segments: PruneModes::none() }
|
||||
}
|
||||
}
|
||||
|
||||
@ -397,27 +400,33 @@ impl PruneConfig {
|
||||
/// if the corresponding value in this config is not set.
|
||||
pub fn merge(&mut self, other: Option<Self>) {
|
||||
let Some(other) = other else { return };
|
||||
let Self {
|
||||
block_interval,
|
||||
segments:
|
||||
PruneModes {
|
||||
sender_recovery,
|
||||
transaction_lookup,
|
||||
receipts,
|
||||
account_history,
|
||||
storage_history,
|
||||
receipts_log_filter,
|
||||
},
|
||||
} = other;
|
||||
|
||||
// Merge block_interval
|
||||
if self.block_interval == 0 {
|
||||
self.block_interval = other.block_interval;
|
||||
// Merge block_interval, only update if it's the default interval
|
||||
if self.block_interval == DEFAULT_BLOCK_INTERVAL {
|
||||
self.block_interval = block_interval;
|
||||
}
|
||||
|
||||
// Merge the various segment prune modes
|
||||
self.segments.sender_recovery =
|
||||
self.segments.sender_recovery.or(other.segments.sender_recovery);
|
||||
self.segments.transaction_lookup =
|
||||
self.segments.transaction_lookup.or(other.segments.transaction_lookup);
|
||||
self.segments.receipts = self.segments.receipts.or(other.segments.receipts);
|
||||
self.segments.account_history =
|
||||
self.segments.account_history.or(other.segments.account_history);
|
||||
self.segments.storage_history =
|
||||
self.segments.storage_history.or(other.segments.storage_history);
|
||||
self.segments.sender_recovery = self.segments.sender_recovery.or(sender_recovery);
|
||||
self.segments.transaction_lookup = self.segments.transaction_lookup.or(transaction_lookup);
|
||||
self.segments.receipts = self.segments.receipts.or(receipts);
|
||||
self.segments.account_history = self.segments.account_history.or(account_history);
|
||||
self.segments.storage_history = self.segments.storage_history.or(storage_history);
|
||||
|
||||
if self.segments.receipts_log_filter.0.is_empty() &&
|
||||
!other.segments.receipts_log_filter.0.is_empty()
|
||||
{
|
||||
self.segments.receipts_log_filter = other.segments.receipts_log_filter;
|
||||
if self.segments.receipts_log_filter.0.is_empty() && !receipts_log_filter.0.is_empty() {
|
||||
self.segments.receipts_log_filter = receipts_log_filter;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -961,7 +970,7 @@ receipts = 'full'
|
||||
|
||||
// Check that the configuration has been merged. Any configuration present in config1
|
||||
// should not be overwritten by config2
|
||||
assert_eq!(config1.block_interval, 5);
|
||||
assert_eq!(config1.block_interval, 10);
|
||||
assert_eq!(config1.segments.sender_recovery, Some(PruneMode::Full));
|
||||
assert_eq!(config1.segments.transaction_lookup, Some(PruneMode::Full));
|
||||
assert_eq!(config1.segments.receipts, Some(PruneMode::Distance(1000)));
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
|
||||
use crate::args::error::ReceiptsLogError;
|
||||
use alloy_primitives::{Address, BlockNumber};
|
||||
use clap::Args;
|
||||
use clap::{builder::RangedU64ValueParser, Args};
|
||||
use reth_chainspec::EthChainSpec;
|
||||
use reth_config::config::PruneConfig;
|
||||
use reth_prune_types::{PruneMode, PruneModes, ReceiptsLogPruneConfig, MINIMUM_PRUNING_DISTANCE};
|
||||
@ -17,7 +17,7 @@ pub struct PruningArgs {
|
||||
pub full: bool,
|
||||
|
||||
/// Minimum pruning interval measured in blocks.
|
||||
#[arg(long, default_value = None)]
|
||||
#[arg(long, value_parser = RangedU64ValueParser::<u64>::new().range(1..),)]
|
||||
pub block_interval: Option<u64>,
|
||||
|
||||
// Sender Recovery
|
||||
@ -99,7 +99,7 @@ impl PruningArgs {
|
||||
// If --full is set, use full node defaults.
|
||||
if self.full {
|
||||
config = PruneConfig {
|
||||
block_interval: 5,
|
||||
block_interval: config.block_interval,
|
||||
segments: PruneModes {
|
||||
sender_recovery: Some(PruneMode::Full),
|
||||
transaction_lookup: None,
|
||||
@ -123,6 +123,9 @@ impl PruningArgs {
|
||||
}
|
||||
|
||||
// Override with any explicitly set prune.* flags.
|
||||
if let Some(block_interval) = self.block_interval {
|
||||
config.block_interval = block_interval as usize;
|
||||
}
|
||||
if let Some(mode) = self.sender_recovery_prune_mode() {
|
||||
config.segments.sender_recovery = Some(mode);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user