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

Rename --pruning and --keep-blocks to be more similar to one another #11934

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions bin/node/cli/benches/block_production.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use sc_consensus::{
};
use sc_service::{
config::{
DatabaseSource, KeepBlocks, KeystoreConfig, NetworkConfiguration, OffchainWorkerConfig,
BlocksPruning, DatabaseSource, KeystoreConfig, NetworkConfiguration, OffchainWorkerConfig,
PruningMode, WasmExecutionMethod, WasmtimeInstantiationStrategy,
},
BasePath, Configuration, Role,
Expand Down Expand Up @@ -75,7 +75,7 @@ fn new_node(tokio_handle: Handle) -> node_cli::service::NewFullBase {
state_cache_size: 67108864,
state_cache_child_ratio: None,
state_pruning: Some(PruningMode::ArchiveAll),
keep_blocks: KeepBlocks::All,
blocks_pruning: BlocksPruning::All,
chain_spec: spec,
wasm_method: WasmExecutionMethod::Compiled {
instantiation_strategy: WasmtimeInstantiationStrategy::PoolingCopyOnWrite,
Expand Down
4 changes: 2 additions & 2 deletions bin/node/cli/benches/transaction_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use node_runtime::{constants::currency::*, BalancesCall, SudoCall};
use sc_client_api::execution_extensions::ExecutionStrategies;
use sc_service::{
config::{
DatabaseSource, KeepBlocks, KeystoreConfig, NetworkConfiguration, OffchainWorkerConfig,
BlocksPruning, DatabaseSource, KeystoreConfig, NetworkConfiguration, OffchainWorkerConfig,
PruningMode, TransactionPoolOptions, WasmExecutionMethod,
},
BasePath, Configuration, Role,
Expand Down Expand Up @@ -69,7 +69,7 @@ fn new_node(tokio_handle: Handle) -> node_cli::service::NewFullBase {
state_cache_size: 67108864,
state_cache_child_ratio: None,
state_pruning: Some(PruningMode::ArchiveAll),
keep_blocks: KeepBlocks::All,
blocks_pruning: BlocksPruning::All,
chain_spec: spec,
wasm_method: WasmExecutionMethod::Interpreted,
// NOTE: we enforce the use of the native runtime to make the errors more debuggable
Expand Down
2 changes: 1 addition & 1 deletion bin/node/testing/src/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ impl BenchDb {
state_cache_child_ratio: Some((0, 100)),
state_pruning: Some(PruningMode::ArchiveAll),
source: database_type.into_settings(dir.into()),
keep_blocks: sc_client_db::KeepBlocks::All,
blocks_pruning: sc_client_db::BlocksPruning::All,
};
let task_executor = TaskExecutor::new();

Expand Down
2 changes: 1 addition & 1 deletion client/cli/src/commands/chain_info_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ impl ChainInfoCmd {
state_cache_child_ratio: config.state_cache_child_ratio.map(|v| (v, 100)),
state_pruning: config.state_pruning.clone(),
source: config.database.clone(),
keep_blocks: config.keep_blocks.clone(),
blocks_pruning: config.blocks_pruning.clone(),
};
let backend = sc_service::new_db_backend::<B>(db_config)?;
let info: ChainInfo<B> = backend.blockchain().info().into();
Expand Down
12 changes: 6 additions & 6 deletions client/cli/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use sc_service::{
NodeKeyConfig, OffchainWorkerConfig, PrometheusConfig, PruningMode, Role, RpcMethods,
TelemetryEndpoints, TransactionPoolOptions, WasmExecutionMethod,
},
ChainSpec, KeepBlocks, TracingReceiver,
BlocksPruning, ChainSpec, TracingReceiver,
};
use sc_tracing::logging::LoggerBuilder;
use std::{net::SocketAddr, path::PathBuf};
Expand Down Expand Up @@ -257,11 +257,11 @@ pub trait CliConfiguration<DCV: DefaultConfigurationValues = ()>: Sized {
/// Get the block pruning mode.
///
/// By default this is retrieved from `block_pruning` if it is available. Otherwise its
/// `KeepBlocks::All`.
fn keep_blocks(&self) -> Result<KeepBlocks> {
/// `BlocksPruning::All`.
fn blocks_pruning(&self) -> Result<BlocksPruning> {
self.pruning_params()
.map(|x| x.keep_blocks())
.unwrap_or_else(|| Ok(KeepBlocks::All))
.map(|x| x.blocks_pruning())
.unwrap_or_else(|| Ok(BlocksPruning::All))
}

/// Get the chain ID (string).
Expand Down Expand Up @@ -536,7 +536,7 @@ pub trait CliConfiguration<DCV: DefaultConfigurationValues = ()>: Sized {
state_cache_size: self.state_cache_size()?,
state_cache_child_ratio: self.state_cache_child_ratio()?,
state_pruning: self.state_pruning()?,
keep_blocks: self.keep_blocks()?,
blocks_pruning: self.blocks_pruning()?,
wasm_method: self.wasm_method()?,
wasm_runtime_overrides: self.wasm_runtime_overrides(),
execution_strategies: self.execution_strategies(is_dev, is_validator)?,
Expand Down
22 changes: 11 additions & 11 deletions client/cli/src/params/pruning_params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

use crate::error;
use clap::Args;
use sc_service::{KeepBlocks, PruningMode};
use sc_service::{BlocksPruning, PruningMode};

/// Parameters to define the pruning mode
#[derive(Debug, Clone, PartialEq, Args)]
Expand All @@ -28,37 +28,37 @@ pub struct PruningParams {
/// Default is to keep only the last 256 blocks,
/// otherwise, the state can be kept for all of the blocks (i.e 'archive'),
/// or for all of the canonical blocks (i.e 'archive-canonical').
#[clap(long, value_name = "PRUNING_MODE")]
pub pruning: Option<String>,
#[clap(alias = "pruning", long, value_name = "PRUNING_MODE")]
pub state_pruning: Option<String>,
/// Specify the number of finalized blocks to keep in the database.
///
/// Default is to keep all blocks.
///
/// NOTE: only finalized blocks are subject for removal!
#[clap(long, value_name = "COUNT")]
pub keep_blocks: Option<u32>,
#[clap(alias = "keep-blocks", long, value_name = "COUNT")]
pub blocks_pruning: Option<u32>,
}

impl PruningParams {
/// Get the pruning value from the parameters
pub fn state_pruning(&self) -> error::Result<Option<PruningMode>> {
self.pruning
self.state_pruning
.as_ref()
.map(|s| match s.as_str() {
"archive" => Ok(PruningMode::ArchiveAll),
bc => bc
.parse()
.map_err(|_| error::Error::Input("Invalid pruning mode specified".to_string()))
.map(PruningMode::keep_blocks),
.map(PruningMode::blocks_pruning),
})
.transpose()
}

/// Get the block pruning value from the parameters
pub fn keep_blocks(&self) -> error::Result<KeepBlocks> {
Ok(match self.keep_blocks {
Some(n) => KeepBlocks::Some(n),
None => KeepBlocks::All,
pub fn blocks_pruning(&self) -> error::Result<BlocksPruning> {
Ok(match self.blocks_pruning {
Some(n) => BlocksPruning::Some(n),
None => BlocksPruning::All,
})
}
}
26 changes: 13 additions & 13 deletions client/db/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,12 +300,12 @@ pub struct DatabaseSettings {
/// Block pruning mode.
///
/// NOTE: only finalized blocks are subject for removal!
pub keep_blocks: KeepBlocks,
pub blocks_pruning: BlocksPruning,
}

/// Block pruning settings.
#[derive(Debug, Clone, Copy)]
pub enum KeepBlocks {
pub enum BlocksPruning {
/// Keep full block history.
All,
/// Keep N recent finalized blocks.
Expand Down Expand Up @@ -1012,7 +1012,7 @@ pub struct Backend<Block: BlockT> {
shared_cache: SharedCache<Block>,
import_lock: Arc<RwLock<()>>,
is_archive: bool,
keep_blocks: KeepBlocks,
blocks_pruning: BlocksPruning,
io_stats: FrozenForDuration<(kvdb::IoStats, StateUsageInfo)>,
state_usage: Arc<StateUsageStats>,
genesis_state: RwLock<Option<Arc<DbGenesisStorage<Block>>>>,
Expand Down Expand Up @@ -1043,21 +1043,21 @@ impl<Block: BlockT> Backend<Block> {

/// Create new memory-backed client backend for tests.
#[cfg(any(test, feature = "test-helpers"))]
pub fn new_test(keep_blocks: u32, canonicalization_delay: u64) -> Self {
Self::new_test_with_tx_storage(keep_blocks, canonicalization_delay)
pub fn new_test(blocks_pruning: u32, canonicalization_delay: u64) -> Self {
Self::new_test_with_tx_storage(blocks_pruning, canonicalization_delay)
}

/// Create new memory-backed client backend for tests.
#[cfg(any(test, feature = "test-helpers"))]
pub fn new_test_with_tx_storage(keep_blocks: u32, canonicalization_delay: u64) -> Self {
pub fn new_test_with_tx_storage(blocks_pruning: u32, canonicalization_delay: u64) -> Self {
let db = kvdb_memorydb::create(crate::utils::NUM_COLUMNS);
let db = sp_database::as_database(db);
let db_setting = DatabaseSettings {
state_cache_size: 16777216,
state_cache_child_ratio: Some((50, 100)),
state_pruning: Some(PruningMode::keep_blocks(keep_blocks)),
state_pruning: Some(PruningMode::blocks_pruning(blocks_pruning)),
source: DatabaseSource::Custom { db, require_create_flag: true },
keep_blocks: KeepBlocks::Some(keep_blocks),
blocks_pruning: BlocksPruning::Some(blocks_pruning),
};

Self::new(db_setting, canonicalization_delay).expect("failed to create test-db")
Expand Down Expand Up @@ -1124,7 +1124,7 @@ impl<Block: BlockT> Backend<Block> {
is_archive: is_archive_pruning,
io_stats: FrozenForDuration::new(std::time::Duration::from_secs(1)),
state_usage: Arc::new(StateUsageStats::new()),
keep_blocks: config.keep_blocks,
blocks_pruning: config.blocks_pruning,
genesis_state: RwLock::new(None),
};

Expand Down Expand Up @@ -1691,9 +1691,9 @@ impl<Block: BlockT> Backend<Block> {
finalized: NumberFor<Block>,
displaced: &FinalizationDisplaced<Block::Hash, NumberFor<Block>>,
) -> ClientResult<()> {
if let KeepBlocks::Some(keep_blocks) = self.keep_blocks {
if let BlocksPruning::Some(blocks_pruning) = self.blocks_pruning {
// Always keep the last finalized block
let keep = std::cmp::max(keep_blocks, 1);
let keep = std::cmp::max(blocks_pruning, 1);
if finalized >= keep.into() {
let number = finalized.saturating_sub(keep.into());
self.prune_block(transaction, BlockId::<Block>::number(number))?;
Expand Down Expand Up @@ -2440,9 +2440,9 @@ pub(crate) mod tests {
DatabaseSettings {
state_cache_size: 16777216,
state_cache_child_ratio: Some((50, 100)),
state_pruning: Some(PruningMode::keep_blocks(1)),
state_pruning: Some(PruningMode::blocks_pruning(1)),
source: DatabaseSource::Custom { db: backing, require_create_flag: false },
keep_blocks: KeepBlocks::All,
blocks_pruning: BlocksPruning::All,
},
0,
)
Expand Down
8 changes: 4 additions & 4 deletions client/network/test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,7 @@ pub struct FullPeerConfig {
/// Pruning window size.
///
/// NOTE: only finalized blocks are subject for removal!
pub keep_blocks: Option<u32>,
pub blocks_pruning: Option<u32>,
/// Block announce validator.
pub block_announce_validator: Option<Box<dyn BlockAnnounceValidator<Block> + Send + Sync>>,
/// List of notification protocols that the network must support.
Expand Down Expand Up @@ -739,10 +739,10 @@ where

/// Add a full peer.
fn add_full_peer_with_config(&mut self, config: FullPeerConfig) {
let mut test_client_builder = match (config.keep_blocks, config.storage_chain) {
(Some(keep_blocks), true) => TestClientBuilder::with_tx_storage(keep_blocks),
let mut test_client_builder = match (config.blocks_pruning, config.storage_chain) {
(Some(blocks_pruning), true) => TestClientBuilder::with_tx_storage(blocks_pruning),
(None, true) => TestClientBuilder::with_tx_storage(u32::MAX),
(Some(keep_blocks), false) => TestClientBuilder::with_pruning_window(keep_blocks),
(Some(blocks_pruning), false) => TestClientBuilder::with_pruning_window(blocks_pruning),
(None, false) => TestClientBuilder::with_default_backend(),
};
if let Some(storage) = config.extra_storage {
Expand Down
2 changes: 1 addition & 1 deletion client/network/test/src/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@ fn syncs_header_only_forks() {
sp_tracing::try_init_simple();
let mut net = TestNet::new(0);
net.add_full_peer_with_config(Default::default());
net.add_full_peer_with_config(FullPeerConfig { keep_blocks: Some(3), ..Default::default() });
net.add_full_peer_with_config(FullPeerConfig { blocks_pruning: Some(3), ..Default::default() });
net.peer(0).push_blocks(2, false);
net.peer(1).push_blocks(2, false);

Expand Down
2 changes: 1 addition & 1 deletion client/service/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ where
state_cache_child_ratio: config.state_cache_child_ratio.map(|v| (v, 100)),
state_pruning: config.state_pruning.clone(),
source: config.database.clone(),
keep_blocks: config.keep_blocks,
blocks_pruning: config.blocks_pruning,
};

let backend = new_db_backend(db_config)?;
Expand Down
4 changes: 2 additions & 2 deletions client/service/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
//! Service configuration.

pub use sc_client_api::execution_extensions::{ExecutionStrategies, ExecutionStrategy};
pub use sc_client_db::{Database, DatabaseSource, KeepBlocks, PruningMode};
pub use sc_client_db::{BlocksPruning, Database, DatabaseSource, PruningMode};
pub use sc_executor::WasmExecutionMethod;
#[cfg(feature = "wasmtime")]
pub use sc_executor::WasmtimeInstantiationStrategy;
Expand Down Expand Up @@ -79,7 +79,7 @@ pub struct Configuration {
/// Number of blocks to keep in the db.
///
/// NOTE: only finalized blocks are subject for removal!
pub keep_blocks: KeepBlocks,
pub blocks_pruning: BlocksPruning,
/// Chain configuration.
pub chain_spec: Box<dyn ChainSpec>,
/// Wasm execution method.
Expand Down
2 changes: 1 addition & 1 deletion client/service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ pub use self::{
error::Error,
};
pub use config::{
BasePath, Configuration, DatabaseSource, KeepBlocks, PruningMode, Role, RpcMethods, TaskType,
BasePath, BlocksPruning, Configuration, DatabaseSource, PruningMode, Role, RpcMethods, TaskType,
};
pub use sc_chain_spec::{
ChainSpec, ChainType, Extension as ChainSpecExtension, GenericChainSpec, NoExtension,
Expand Down
8 changes: 4 additions & 4 deletions client/service/test/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use sc_block_builder::BlockBuilderProvider;
use sc_client_api::{
in_mem, BlockBackend, BlockchainEvents, FinalityNotifications, StorageProvider,
};
use sc_client_db::{Backend, DatabaseSettings, DatabaseSource, KeepBlocks, PruningMode};
use sc_client_db::{Backend, BlocksPruning, DatabaseSettings, DatabaseSource, PruningMode};
use sc_consensus::{
BlockCheckParams, BlockImport, BlockImportParams, ForkChoiceStrategy, ImportResult,
};
Expand Down Expand Up @@ -1200,7 +1200,7 @@ fn doesnt_import_blocks_that_revert_finality() {
state_cache_size: 1 << 20,
state_cache_child_ratio: None,
state_pruning: Some(PruningMode::ArchiveAll),
keep_blocks: KeepBlocks::All,
blocks_pruning: BlocksPruning::All,
source: DatabaseSource::RocksDb { path: tmp.path().into(), cache_size: 1024 },
},
u64::MAX,
Expand Down Expand Up @@ -1426,8 +1426,8 @@ fn returns_status_for_pruned_blocks() {
DatabaseSettings {
state_cache_size: 1 << 20,
state_cache_child_ratio: None,
state_pruning: Some(PruningMode::keep_blocks(1)),
keep_blocks: KeepBlocks::All,
state_pruning: Some(PruningMode::blocks_pruning(1)),
blocks_pruning: BlocksPruning::All,
source: DatabaseSource::RocksDb { path: tmp.path().into(), cache_size: 1024 },
},
u64::MAX,
Expand Down
6 changes: 3 additions & 3 deletions client/service/test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ use sc_network::{
use sc_service::{
client::Client,
config::{BasePath, DatabaseSource, KeystoreConfig},
ChainSpecExtension, Configuration, Error, GenericChainSpec, KeepBlocks, Role, RuntimeGenesis,
SpawnTaskHandle, TaskManager,
BlocksPruning, ChainSpecExtension, Configuration, Error, GenericChainSpec, Role,
RuntimeGenesis, SpawnTaskHandle, TaskManager,
};
use sc_transaction_pool_api::TransactionPool;
use sp_api::BlockId;
Expand Down Expand Up @@ -234,7 +234,7 @@ fn node_config<
state_cache_size: 16777216,
state_cache_child_ratio: None,
state_pruning: Default::default(),
keep_blocks: KeepBlocks::All,
blocks_pruning: BlocksPruning::All,
chain_spec: Box::new((*spec).clone()),
wasm_method: sc_service::config::WasmExecutionMethod::Interpreted,
wasm_runtime_overrides: Default::default(),
Expand Down
Loading