Make CLI state pruning optional again (#13017)

* Make CLI state pruning optional again

The state pruning setting is stored in the database when it is created. In later runs it is fine to
drop the `--state-pruning` CLI argument as the setting is stored in the database. The state db will
only return an error if the stored state pruning doesn't match the state pruning given via CLI.

Recently we improved the state pruning CLI handling and accidentally made the state pruning value
always present (as we set some default value for the clap). If we could find out if a user has
passed a value or the default value was taken, we could keep the default value in the CLI interface,
but clap isn't supporting this right now. So, we need to go back and make `state_pruning` an
optional with the default written into the docs.

It also adds a test to ensure that we don't break this behavior again.

* More docs
This commit is contained in:
Bastian Köcher
2022-12-26 17:37:09 +01:00
committed by GitHub
parent 9726a10dbb
commit 9f5ed21fe9
3 changed files with 75 additions and 10 deletions
@@ -28,21 +28,44 @@ pub struct PruningParams {
/// This mode specifies when the block's state (ie, storage)
/// should be pruned (ie, removed) from the database.
///
/// This setting can only be set on the first creation of the database. Every subsequent run
/// will load the pruning mode from the database and will error if the stored mode doesn't
/// match this CLI value. It is fine to drop this CLI flag for subsequent runs.
///
/// Possible values:
/// 'archive' Keep the state of all blocks.
/// 'archive-canonical' Keep only the state of finalized blocks.
/// number Keep the state of the last number of finalized blocks.
#[arg(alias = "pruning", long, value_name = "PRUNING_MODE", default_value = "256")]
pub state_pruning: DatabasePruningMode,
///
/// - archive:
///
/// Keep the state of all blocks.
///
/// - 'archive-canonical'
///
/// Keep only the state of finalized blocks.
///
/// - number
///
/// Keep the state of the last number of finalized blocks.
///
/// [default: 256]
#[arg(alias = "pruning", long, value_name = "PRUNING_MODE")]
pub state_pruning: Option<DatabasePruningMode>,
/// Specify the blocks pruning mode.
///
/// This mode specifies when the block's body (including justifications)
/// should be pruned (ie, removed) from the database.
///
/// Possible values:
/// 'archive' Keep all blocks.
/// 'archive-canonical' Keep only finalized blocks.
/// number Keep the last `number` of finalized blocks.
/// - 'archive'
///
/// Keep all blocks.
///
/// - 'archive-canonical'
///
/// Keep only finalized blocks.
///
/// - number
///
/// Keep the last `number` of finalized blocks.
#[arg(
alias = "keep-blocks",
long,
@@ -55,7 +78,7 @@ pub struct PruningParams {
impl PruningParams {
/// Get the pruning value from the parameters
pub fn state_pruning(&self) -> error::Result<Option<PruningMode>> {
Ok(Some(self.state_pruning.into()))
Ok(self.state_pruning.map(|v| v.into()))
}
/// Get the block pruning value from the parameters