Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

Commit 9a0644c

Browse files
lexnvbkchr
andauthored
cli: Improve pruning documentation (#12819)
* cli: Improve pruning documentation Signed-off-by: Alexandru Vasile <[email protected]> * cli: Keep `finalized` notation and remove `canonical` one * cli: Fix cargo doc * cli: `PruningModeClap` IR enum Signed-off-by: Alexandru Vasile <[email protected]> * cli: Convert PruningModeClap into pruning modes Signed-off-by: Alexandru Vasile <[email protected]> * cli: Use `PruningModeClap` Signed-off-by: Alexandru Vasile <[email protected]> * cli: Rename to `DatabasePruningMode` Signed-off-by: Alexandru Vasile <[email protected]> * cli: Implement `FromStr` instead of `clap::ValueEnum` Signed-off-by: Alexandru Vasile <[email protected]> * Update client/cli/src/params/pruning_params.rs Co-authored-by: Bastian Köcher <[email protected]> * Fix clippy Signed-off-by: Alexandru Vasile <[email protected]> * cli: Add option documentation back Signed-off-by: Alexandru Vasile <[email protected]> * Apply suggestions from code review Signed-off-by: Alexandru Vasile <[email protected]> Co-authored-by: Bastian Köcher <[email protected]>
1 parent 02a9dea commit 9a0644c

File tree

1 file changed

+75
-39
lines changed

1 file changed

+75
-39
lines changed

client/cli/src/params/pruning_params.rs

+75-39
Original file line numberDiff line numberDiff line change
@@ -23,57 +23,93 @@ use sc_service::{BlocksPruning, PruningMode};
2323
/// Parameters to define the pruning mode
2424
#[derive(Debug, Clone, PartialEq, Args)]
2525
pub struct PruningParams {
26-
/// Specify the state pruning mode, a number of blocks to keep or 'archive'.
26+
/// Specify the state pruning mode.
2727
///
28-
/// Default is to keep only the last 256 blocks,
29-
/// otherwise, the state can be kept for all of the blocks (i.e 'archive'),
30-
/// or for all of the canonical blocks (i.e 'archive-canonical').
31-
#[arg(alias = "pruning", long, value_name = "PRUNING_MODE")]
32-
pub state_pruning: Option<String>,
33-
/// Specify the blocks pruning mode, a number of blocks to keep or 'archive'.
28+
/// This mode specifies when the block's state (ie, storage)
29+
/// should be pruned (ie, removed) from the database.
3430
///
35-
/// Default is to keep all finalized blocks.
36-
/// otherwise, all blocks can be kept (i.e 'archive'),
37-
/// or for all canonical blocks (i.e 'archive-canonical'),
38-
/// or for the last N blocks (i.e a number).
31+
/// Possible values:
32+
/// 'archive' Keep the state of all blocks.
33+
/// 'archive-canonical' Keep only the state of finalized blocks.
34+
/// number Keep the state of the last number of finalized blocks.
35+
#[arg(alias = "pruning", long, value_name = "PRUNING_MODE", default_value = "256")]
36+
pub state_pruning: DatabasePruningMode,
37+
/// Specify the blocks pruning mode.
3938
///
40-
/// NOTE: only finalized blocks are subject for removal!
41-
#[arg(alias = "keep-blocks", long, value_name = "COUNT")]
42-
pub blocks_pruning: Option<String>,
39+
/// This mode specifies when the block's body (including justifications)
40+
/// should be pruned (ie, removed) from the database.
41+
///
42+
/// Possible values:
43+
/// 'archive' Keep all blocks.
44+
/// 'archive-canonical' Keep only finalized blocks.
45+
/// number Keep the last `number` of finalized blocks.
46+
#[arg(
47+
alias = "keep-blocks",
48+
long,
49+
value_name = "PRUNING_MODE",
50+
default_value = "archive-canonical"
51+
)]
52+
pub blocks_pruning: DatabasePruningMode,
4353
}
4454

4555
impl PruningParams {
4656
/// Get the pruning value from the parameters
4757
pub fn state_pruning(&self) -> error::Result<Option<PruningMode>> {
48-
self.state_pruning
49-
.as_ref()
50-
.map(|s| match s.as_str() {
51-
"archive" => Ok(PruningMode::ArchiveAll),
52-
"archive-canonical" => Ok(PruningMode::ArchiveCanonical),
53-
bc => bc
54-
.parse()
55-
.map_err(|_| {
56-
error::Error::Input("Invalid state pruning mode specified".to_string())
57-
})
58-
.map(PruningMode::blocks_pruning),
59-
})
60-
.transpose()
58+
Ok(Some(self.state_pruning.into()))
6159
}
6260

6361
/// Get the block pruning value from the parameters
6462
pub fn blocks_pruning(&self) -> error::Result<BlocksPruning> {
65-
match self.blocks_pruning.as_ref() {
66-
Some(bp) => match bp.as_str() {
67-
"archive" => Ok(BlocksPruning::KeepAll),
68-
"archive-canonical" => Ok(BlocksPruning::KeepFinalized),
69-
bc => bc
70-
.parse()
71-
.map_err(|_| {
72-
error::Error::Input("Invalid blocks pruning mode specified".to_string())
73-
})
74-
.map(BlocksPruning::Some),
75-
},
76-
None => Ok(BlocksPruning::KeepFinalized),
63+
Ok(self.blocks_pruning.into())
64+
}
65+
}
66+
67+
/// Specifies the pruning mode of the database.
68+
///
69+
/// This specifies when the block's data (either state via `--state-pruning`
70+
/// or body via `--blocks-pruning`) should be pruned (ie, removed) from
71+
/// the database.
72+
#[derive(Debug, Clone, Copy, PartialEq)]
73+
pub enum DatabasePruningMode {
74+
/// Keep the data of all blocks.
75+
Archive,
76+
/// Keep only the data of finalized blocks.
77+
ArchiveCanonical,
78+
/// Keep the data of the last number of finalized blocks.
79+
Custom(u32),
80+
}
81+
82+
impl std::str::FromStr for DatabasePruningMode {
83+
type Err = String;
84+
85+
fn from_str(input: &str) -> Result<Self, Self::Err> {
86+
match input {
87+
"archive" => Ok(Self::Archive),
88+
"archive-canonical" => Ok(Self::ArchiveCanonical),
89+
bc => bc
90+
.parse()
91+
.map_err(|_| "Invalid pruning mode specified".to_string())
92+
.map(Self::Custom),
93+
}
94+
}
95+
}
96+
97+
impl Into<PruningMode> for DatabasePruningMode {
98+
fn into(self) -> PruningMode {
99+
match self {
100+
DatabasePruningMode::Archive => PruningMode::ArchiveAll,
101+
DatabasePruningMode::ArchiveCanonical => PruningMode::ArchiveCanonical,
102+
DatabasePruningMode::Custom(n) => PruningMode::blocks_pruning(n),
103+
}
104+
}
105+
}
106+
107+
impl Into<BlocksPruning> for DatabasePruningMode {
108+
fn into(self) -> BlocksPruning {
109+
match self {
110+
DatabasePruningMode::Archive => BlocksPruning::KeepAll,
111+
DatabasePruningMode::ArchiveCanonical => BlocksPruning::KeepFinalized,
112+
DatabasePruningMode::Custom(n) => BlocksPruning::Some(n),
77113
}
78114
}
79115
}

0 commit comments

Comments
 (0)