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

Make CLI state pruning optional again #13017

Merged
merged 2 commits into from
Dec 26, 2022
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
6 changes: 5 additions & 1 deletion bin/node/cli/tests/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ pub fn find_ws_url_from_output(read: impl Read + Send) -> (String, String) {
let line =
line.expect("failed to obtain next line from stdout for WS address discovery");
data.push_str(&line);
data.push_str("\n");

// does the line contain our port (we expect this specific output from substrate).
let sock_addr = match line.split_once("Running JSON-RPC WS server: addr=") {
Expand All @@ -170,7 +171,10 @@ pub fn find_ws_url_from_output(read: impl Read + Send) -> (String, String) {

Some(format!("ws://{}", sock_addr))
})
.expect("We should get a WebSocket address");
.unwrap_or_else(|| {
eprintln!("Observed node output:\n{}", data);
panic!("We should get a WebSocket address")
});

(ws_url, data)
}
38 changes: 38 additions & 0 deletions bin/node/cli/tests/remember_state_pruning_works.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// This file is part of Substrate.

// Copyright (C) 2022 Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0

// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

use tempfile::tempdir;

pub mod common;

#[tokio::test]
#[cfg(unix)]
async fn remember_state_pruning_works() {
let base_path = tempdir().expect("could not create a temp dir");

// First run with `--state-pruning=archive`.
common::run_node_for_a_while(
base_path.path(),
&["--dev", "--state-pruning=archive", "--no-hardware-benchmarks"],
)
.await;

// Then run again without specifying the state pruning.
// This should load state pruning settings from the db.
common::run_node_for_a_while(base_path.path(), &["--dev", "--no-hardware-benchmarks"]).await;
}
41 changes: 32 additions & 9 deletions client/cli/src/params/pruning_params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down