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

Commit

Permalink
client/cli: Add delayed pruning mode and make it default
Browse files Browse the repository at this point in the history
Signed-off-by: Alexandru Vasile <[email protected]>
  • Loading branch information
lexnv committed Oct 14, 2022
1 parent d18d071 commit a5fb1cc
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
14 changes: 13 additions & 1 deletion client/cli/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,18 @@ pub(crate) const NODE_NAME_MAX_LENGTH: usize = 64;
/// Default sub directory to store network config.
pub(crate) const DEFAULT_NETWORK_CONFIG_PATH: &str = "network";

/// Delay the pruning of blocks by a given number of finalizations.
///
/// This value should be set to a sensible amount to accommodate the RPC
/// Spec V2 requirements of block pinning.
///
/// The user derives no benefits from controlling this, as the RPC API
/// should be uniform across the nodes.
///
/// This ensures that users have roughly 32 * 6 seconds (block finalization)
/// ~ 3 minutes to fetch the details of blocks.
pub(crate) const DELAYED_PRUNING: u32 = 32;

/// The recommended open file descriptor limit to be configured for the process.
const RECOMMENDED_OPEN_FILE_DESCRIPTOR_LIMIT: u64 = 10_000;

Expand Down Expand Up @@ -255,7 +267,7 @@ pub trait CliConfiguration<DCV: DefaultConfigurationValues = ()>: Sized {
fn blocks_pruning(&self) -> Result<BlocksPruning> {
self.pruning_params()
.map(|x| x.blocks_pruning())
.unwrap_or_else(|| Ok(BlocksPruning::KeepFinalized))
.unwrap_or_else(|| Ok(BlocksPruning::Delayed(DELAYED_PRUNING)))
}

/// Get the chain ID (string).
Expand Down
15 changes: 10 additions & 5 deletions client/cli/src/params/pruning_params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,16 @@ pub struct PruningParams {
/// or for all of the canonical blocks (i.e 'archive-canonical').
#[clap(alias = "pruning", long, value_name = "PRUNING_MODE")]
pub state_pruning: Option<String>,
/// Specify the blocks pruning mode, a number of blocks to keep or 'archive'.
/// Specify the blocks pruning mode.
///
/// Default is to keep all finalized blocks.
/// otherwise, all blocks can be kept (i.e 'archive'),
/// or for all canonical blocks (i.e 'archive-canonical'),
/// or for the last N blocks (i.e a number).
/// The options are as follows:
/// 'delayed' Pruning of blocks is delayed for a sensible amount of time to
/// satisfy the RPC Spec V2.
/// 'archive' Keep all blocks.
/// 'archive-canonical' Keep all finalized (canonical) blocks.
/// [number] Keep the last N finalized (canonical) blocks.
///
/// Default is the 'delayed' option.
///
/// NOTE: only finalized blocks are subject for removal!
#[clap(alias = "keep-blocks", long, value_name = "COUNT")]
Expand Down Expand Up @@ -66,6 +70,7 @@ impl PruningParams {
Some(bp) => match bp.as_str() {
"archive" => Ok(BlocksPruning::KeepAll),
"archive-canonical" => Ok(BlocksPruning::KeepFinalized),
"delayed" => Ok(BlocksPruning::Delayed(crate::DELAYED_PRUNING)),
bc => bc
.parse()
.map_err(|_| {
Expand Down

0 comments on commit a5fb1cc

Please sign in to comment.