Skip to content

Commit ceb3307

Browse files
kariyclaude
andcommitted
refactor: align pruning mode naming with Erigon conventions
This commit updates the pruning mode naming to match Erigon Ethereum client conventions, making the API more familiar to users who have experience with Erigon. ## Changes ### Core PruningMode Enum (crates/sync/stage/src/lib.rs) Renamed modes to match Erigon: - `Full` → `Archive` (keep all historical state) - `HistoricalBlocks(N)` → `Full(N)` (keep last N blocks) - `LatestOnly` → `Minimal` (keep only latest state) Updated documentation to explicitly reference Erigon equivalents and explain the mapping between the two systems. ### CLI Options (crates/cli/src/options.rs) Updated argument names and documentation: - `--pruning.mode` → `--prune.mode` (matches Erigon exactly) - Mode values: `archive`, `full:N`, `minimal` - Updated parser to handle new format ### Pipeline (crates/sync/pipeline/src/lib.rs) - Updated default mode from `Full` to `Archive` - Updated `is_enabled()` to check for `Archive` mode ### Tests Updated all test functions to use new naming conventions while maintaining the same test logic. ## Erigon Mapping The naming now directly corresponds to Erigon's modes: - `--prune.mode=archive` - Keep complete historical state - `--prune.mode=full:1000` - Keep last 1000 blocks - `--prune.mode=minimal` - Keep only latest state ## Usage Examples Archive mode (no pruning): ``` katana node full --prune.mode archive ``` Full mode with 1000 block history, prune every 100 blocks: ``` katana node full --prune.mode full:1000 --prune.interval 100 ``` Minimal mode for validators, prune every 50 blocks: ``` katana node full --prune.mode minimal --prune.interval 50 ``` 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 8f90c25 commit ceb3307

File tree

4 files changed

+46
-38
lines changed

4 files changed

+46
-38
lines changed

crates/cli/src/full.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,9 @@ impl FullNodeArgs {
114114
use crate::options::PruningMode as CliPruningMode;
115115

116116
let mode = match self.pruning.mode.as_ref()? {
117-
CliPruningMode::Full => katana_stage::PruningMode::Full,
118-
CliPruningMode::Latest => katana_stage::PruningMode::LatestOnly,
119-
CliPruningMode::Archive(n) => katana_stage::PruningMode::HistoricalBlocks(*n),
117+
CliPruningMode::Archive => katana_stage::PruningMode::Archive,
118+
CliPruningMode::Minimal => katana_stage::PruningMode::Minimal,
119+
CliPruningMode::Full(n) => katana_stage::PruningMode::Full(*n),
120120
};
121121

122122
Some(full::PruningConfig { mode, interval: self.pruning.interval })

crates/cli/src/options.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -723,13 +723,13 @@ impl TracerOptions {
723723
#[derive(Debug, Args, Clone, Serialize, Deserialize, PartialEq)]
724724
#[command(next_help_heading = "Pruning options")]
725725
pub struct PruningOptions {
726-
/// State pruning mode.
726+
/// State pruning mode (follows Erigon conventions).
727727
///
728728
/// Determines how much historical state to retain:
729-
/// - 'full': Keep all historical state (no pruning, default)
730-
/// - 'archive:N': Keep last N blocks of historical state
731-
/// - 'latest': Keep only the latest state
732-
#[arg(long = "pruning.mode", value_name = "MODE")]
729+
/// - 'archive': Keep all historical state (no pruning, default)
730+
/// - 'full:N': Keep last N blocks of historical state
731+
/// - 'minimal': Keep only the latest state
732+
#[arg(long = "prune.mode", value_name = "MODE")]
733733
#[arg(value_parser = parse_pruning_mode)]
734734
#[serde(default)]
735735
pub mode: Option<PruningMode>,
@@ -738,7 +738,7 @@ pub struct PruningOptions {
738738
///
739739
/// Pruning will be triggered after every N blocks are synced.
740740
/// If not specified, pruning is disabled even if a pruning mode is set.
741-
#[arg(long = "pruning.interval", value_name = "BLOCKS")]
741+
#[arg(long = "prune.interval", value_name = "BLOCKS")]
742742
#[serde(default)]
743743
pub interval: Option<u64>,
744744
}
@@ -752,26 +752,26 @@ impl Default for PruningOptions {
752752
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
753753
#[serde(rename_all = "lowercase")]
754754
pub enum PruningMode {
755-
Full,
756-
Archive(u64),
757-
Latest,
755+
Archive,
756+
Full(u64),
757+
Minimal,
758758
}
759759

760760
fn parse_pruning_mode(s: &str) -> Result<PruningMode, String> {
761761
match s.to_lowercase().as_str() {
762-
"full" => Ok(PruningMode::Full),
763-
"latest" => Ok(PruningMode::Latest),
764-
s if s.starts_with("archive:") => {
762+
"archive" => Ok(PruningMode::Archive),
763+
"minimal" => Ok(PruningMode::Minimal),
764+
s if s.starts_with("full:") => {
765765
let n = s
766-
.strip_prefix("archive:")
766+
.strip_prefix("full:")
767767
.and_then(|n| n.parse::<u64>().ok())
768768
.ok_or_else(|| {
769-
format!("Invalid archive format. Use 'archive:N' where N is a number")
769+
format!("Invalid full format. Use 'full:N' where N is the number of blocks to keep")
770770
})?;
771-
Ok(PruningMode::Archive(n))
771+
Ok(PruningMode::Full(n))
772772
}
773773
_ => Err(format!(
774-
"Invalid pruning mode '{}'. Valid modes are: 'full', 'latest', 'archive:N'",
774+
"Invalid pruning mode '{}'. Valid modes are: 'archive', 'minimal', 'full:N'",
775775
s
776776
)),
777777
}

crates/sync/pipeline/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ pub struct PruningConfig {
217217

218218
impl Default for PruningConfig {
219219
fn default() -> Self {
220-
Self { mode: PruningMode::Full, interval: None }
220+
Self { mode: PruningMode::Archive, interval: None }
221221
}
222222
}
223223

@@ -229,7 +229,7 @@ impl PruningConfig {
229229

230230
/// Returns whether pruning is enabled.
231231
pub fn is_enabled(&self) -> bool {
232-
!matches!(self.mode, PruningMode::Full) && self.interval.is_some()
232+
!matches!(self.mode, PruningMode::Archive) && self.interval.is_some()
233233
}
234234
}
235235

crates/sync/stage/src/lib.rs

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -66,19 +66,27 @@ pub struct StageExecutionOutput {
6666
}
6767

6868
/// Pruning mode configuration that determines how much historical state to retain.
69+
///
70+
/// Naming follows the Erigon Ethereum client conventions:
71+
/// - `Archive`: Keep complete historical state (like Erigon's archive mode)
72+
/// - `Full`: Keep last N blocks of state (like Erigon's full mode with configurable distance)
73+
/// - `Minimal`: Keep only latest state (like Erigon's minimal mode for validators)
6974
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
7075
pub enum PruningMode {
7176
/// Keep all historical state since genesis (no pruning).
72-
Full,
77+
/// Equivalent to Erigon's `--prune.mode=archive`.
78+
Archive,
7379
/// Keep only the last N blocks of historical state.
74-
HistoricalBlocks(u64),
80+
/// Similar to Erigon's `--prune.mode=full` with `--prune.distance=N`.
81+
Full(u64),
7582
/// Keep only the latest state, pruning all historical data.
76-
LatestOnly,
83+
/// Equivalent to Erigon's `--prune.mode=minimal`.
84+
Minimal,
7785
}
7886

7987
impl Default for PruningMode {
8088
fn default() -> Self {
81-
Self::Full
89+
Self::Archive
8290
}
8391
}
8492

@@ -111,13 +119,13 @@ impl PruneInput {
111119

112120
/// Calculates the block number before which all state should be pruned.
113121
///
114-
/// Returns `None` if no pruning should occur (e.g., in `Full` mode).
122+
/// Returns `None` if no pruning should occur (e.g., in `Archive` mode).
115123
/// Returns `Some(block_number)` indicating that all state before this block can be pruned.
116124
pub fn prune_before(&self) -> Option<BlockNumber> {
117125
match self.mode {
118-
PruningMode::Full => None,
119-
PruningMode::LatestOnly => Some(self.tip.saturating_sub(1)),
120-
PruningMode::HistoricalBlocks(n) => {
126+
PruningMode::Archive => None,
127+
PruningMode::Minimal => Some(self.tip.saturating_sub(1)),
128+
PruningMode::Full(n) => {
121129
if self.tip > n {
122130
Some(self.tip - n)
123131
} else {
@@ -239,33 +247,33 @@ mod tests {
239247
}
240248

241249
#[test]
242-
fn prune_before_full_mode() {
243-
let input = PruneInput::new(1000, PruningMode::Full);
250+
fn prune_before_archive_mode() {
251+
let input = PruneInput::new(1000, PruningMode::Archive);
244252
assert_eq!(input.prune_before(), None);
245253
}
246254

247255
#[test]
248-
fn prune_before_latest_only() {
249-
let input = PruneInput::new(1000, PruningMode::LatestOnly);
256+
fn prune_before_minimal_mode() {
257+
let input = PruneInput::new(1000, PruningMode::Minimal);
250258
assert_eq!(input.prune_before(), Some(999));
251259

252260
// Edge case: tip at block 0
253-
let input = PruneInput::new(0, PruningMode::LatestOnly);
261+
let input = PruneInput::new(0, PruningMode::Minimal);
254262
assert_eq!(input.prune_before(), Some(0));
255263
}
256264

257265
#[test]
258-
fn prune_before_historical_blocks() {
266+
fn prune_before_full_mode() {
259267
// Keep last 100 blocks, tip at 1000
260-
let input = PruneInput::new(1000, PruningMode::HistoricalBlocks(100));
268+
let input = PruneInput::new(1000, PruningMode::Full(100));
261269
assert_eq!(input.prune_before(), Some(900));
262270

263271
// Keep last 100 blocks, tip at 50 (not enough blocks yet)
264-
let input = PruneInput::new(50, PruningMode::HistoricalBlocks(100));
272+
let input = PruneInput::new(50, PruningMode::Full(100));
265273
assert_eq!(input.prune_before(), None);
266274

267275
// Keep last 100 blocks, tip at exactly 100
268-
let input = PruneInput::new(100, PruningMode::HistoricalBlocks(100));
276+
let input = PruneInput::new(100, PruningMode::Full(100));
269277
assert_eq!(input.prune_before(), Some(0));
270278
}
271279
}

0 commit comments

Comments
 (0)