diff --git a/nym-node/src/cli/commands/debug/mod.rs b/nym-node/src/cli/commands/debug/mod.rs new file mode 100644 index 0000000000..9fc1175a80 --- /dev/null +++ b/nym-node/src/cli/commands/debug/mod.rs @@ -0,0 +1,4 @@ +// Copyright 2025 - Nym Technologies SA +// SPDX-License-Identifier: GPL-3.0-only + +pub(crate) mod reset_providers_dbs; diff --git a/nym-node/src/cli/commands/debug/reset_providers_dbs.rs b/nym-node/src/cli/commands/debug/reset_providers_dbs.rs new file mode 100644 index 0000000000..39130686ae --- /dev/null +++ b/nym-node/src/cli/commands/debug/reset_providers_dbs.rs @@ -0,0 +1,36 @@ +// Copyright 2025 - Nym Technologies SA +// SPDX-License-Identifier: GPL-3.0-only + +use crate::cli::helpers::ConfigArgs; +use crate::config::upgrade_helpers::try_load_current_config; +use crate::node::helpers::load_ed25519_identity_public_key; +use crate::node::ServiceProvidersData; +use nym_network_requester::{CustomGatewayDetails, GatewayDetails, GatewayRegistration}; +use std::fs; + +#[derive(Debug, clap::Args)] +pub struct Args { + #[clap(flatten)] + pub(crate) config: ConfigArgs, +} + +pub async fn execute(args: Args) -> anyhow::Result<()> { + let config = try_load_current_config(args.config.config_path()).await?; + + let public_key = load_ed25519_identity_public_key( + &config.storage_paths.keys.public_ed25519_identity_key_file, + )?; + + let storage_paths = &config.service_providers.storage_paths; + for db_path in [ + &storage_paths.authenticator.gateway_registrations, + &storage_paths.ip_packet_router.gateway_registrations, + &storage_paths.network_requester.gateway_registrations, + ] { + fs::remove_file(db_path)?; + let gateway_details: GatewayRegistration = + GatewayDetails::Custom(CustomGatewayDetails::new(public_key)).into(); + ServiceProvidersData::initialise_client_gateway_storage(db_path, &gateway_details).await?; + } + Ok(()) +} diff --git a/nym-node/src/cli/commands/mod.rs b/nym-node/src/cli/commands/mod.rs index 345a2143e7..6bab14a818 100644 --- a/nym-node/src/cli/commands/mod.rs +++ b/nym-node/src/cli/commands/mod.rs @@ -3,6 +3,7 @@ pub(crate) mod bonding_information; pub(super) mod build_info; +pub(super) mod debug; pub(super) mod migrate; pub(crate) mod node_details; pub(crate) mod reset_sphinx_keys; diff --git a/nym-node/src/cli/mod.rs b/nym-node/src/cli/mod.rs index 37e79bcd8f..8620cc1dd1 100644 --- a/nym-node/src/cli/mod.rs +++ b/nym-node/src/cli/mod.rs @@ -2,12 +2,12 @@ // SPDX-License-Identifier: GPL-3.0-only use crate::cli::commands::{ - bonding_information, build_info, migrate, node_details, reset_sphinx_keys, run, sign, + bonding_information, build_info, debug, migrate, node_details, reset_sphinx_keys, run, sign, test_throughput, }; use crate::env::vars::{NYMNODE_CONFIG_ENV_FILE_ARG, NYMNODE_NO_BANNER_ARG}; use crate::logging::setup_tracing_logger; -use clap::{Parser, Subcommand}; +use clap::{Args, Parser, Subcommand}; use nym_bin_common::bin_info; use std::future::Future; use std::sync::OnceLock; @@ -72,6 +72,11 @@ impl Cli { Commands::UnsafeResetSphinxKeys(args) => { { Self::execute_async(reset_sphinx_keys::execute(args))? }? } + Commands::Debug(debug) => match debug.command { + DebugCommands::ResetProvidersGatewayDbs(args) => { + { Self::execute_async(debug::reset_providers_dbs::execute(args))? }? + } + }, } Ok(()) } @@ -100,12 +105,28 @@ pub(crate) enum Commands { /// UNSAFE: reset existing sphinx keys and attempt to generate fresh one for the current network state UnsafeResetSphinxKeys(reset_sphinx_keys::Args), + /// Commands exposed for debug purposes, usually not meant to be used by operators + #[clap(hide = true)] + Debug(Debug), + /// Attempt to approximate the maximum mixnet throughput if nym-node /// was running on this machine in mixnet mode #[clap(hide = true)] TestThroughput(test_throughput::Args), } +#[derive(Debug, Args)] +pub(crate) struct Debug { + #[clap(subcommand)] + pub(crate) command: DebugCommands, +} + +#[derive(Subcommand, Debug)] +pub(crate) enum DebugCommands { + /// Reset the internal GatewaysDetailsStores of all service providers in case they got corrupted + ResetProvidersGatewayDbs(debug::reset_providers_dbs::Args), +} + #[cfg(test)] mod tests { use super::*; diff --git a/nym-node/src/node/mod.rs b/nym-node/src/node/mod.rs index c240686b8a..6ec9105482 100644 --- a/nym-node/src/node/mod.rs +++ b/nym-node/src/node/mod.rs @@ -164,7 +164,7 @@ impl ServiceProvidersData { Ok(()) } - async fn initialise_client_gateway_storage( + pub(crate) async fn initialise_client_gateway_storage( storage_path: &Path, registration: &GatewayRegistration, ) -> Result<(), ServiceProvidersError> {