Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Iso/20240412 t1232 force purge chain from storage #855

Merged
merged 6 commits into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions node/src/cli.rs
Expand Up @@ -84,6 +84,10 @@ pub struct Cli {
#[arg(long)]
pub no_hardware_benchmarks: bool,

/// Purge chain from storage, for that time when purge-chain subcommand cannot be used
#[arg(long)]
pub force_purge_chain_from_storage: bool,

/// Relay chain arguments
#[arg(raw = true)]
pub relaychain_args: Vec<String>,
Expand Down
18 changes: 17 additions & 1 deletion node/src/command.rs
Expand Up @@ -31,7 +31,7 @@
};
use sc_service::config::{BasePath, PrometheusConfig};
use sp_runtime::traits::AccountIdConversion;
use std::net::SocketAddr;
use std::{fs, net::SocketAddr};
// default to Nodle parachain id
const DEFAULT_PARA_ID: u32 = 2026;

Expand Down Expand Up @@ -248,6 +248,22 @@
.map(|e| e.para_id)
.ok_or("Could not find parachain ID in chain-spec.")?;

if cli.force_purge_chain_from_storage {
let db_path =
config.database.path().and_then(|p| p.parent()).ok_or_else(|| {
sc_cli::Error::Input("Cannot purge custom database implementation".into())
})?;
match fs::remove_dir_all(&db_path) {

Check warning on line 256 in node/src/command.rs

View workflow job for this annotation

GitHub Actions / lints

the borrowed expression implements the required traits

warning: the borrowed expression implements the required traits --> node/src/command.rs:256:31 | 256 | match fs::remove_dir_all(&db_path) { | ^^^^^^^^ help: change this to: `db_path` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrows_for_generic_args = note: `#[warn(clippy::needless_borrows_for_generic_args)]` on by default
Ok(_) => {
log::warn!("🧯 Removed {:?}", &db_path);
}
Err(ref err) if err.kind() == std::io::ErrorKind::NotFound => {
log::error!("🧯 {:?} did not exist.", &db_path);
}
Err(err) => return Result::Err(err.into()),
}
};

let polkadot_cli = RelayChainCli::new(
&config,
[RelayChainCli::executable_name()]
Expand Down