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
+5 -1
View File
@@ -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=") {
@@ -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)
}
@@ -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;
}