diff --git a/sn_auditor/src/dag_db.rs b/sn_auditor/src/dag_db.rs index 1fd4ad0381..8bfedce059 100644 --- a/sn_auditor/src/dag_db.rs +++ b/sn_auditor/src/dag_db.rs @@ -8,7 +8,7 @@ use bls::SecretKey; use color_eyre::eyre::{eyre, Result}; -#[cfg(feature = "svg")] +#[cfg(feature = "svg-dag")] use graphviz_rust::{cmd::Format, exec, parse, printer::PrinterContext}; use serde::{Deserialize, Serialize}; use sn_client::networking::NetworkError; @@ -149,7 +149,7 @@ impl SpendDagDb { } /// Dump current DAG as svg to disk - #[cfg(feature = "svg")] + #[cfg(feature = "svg-dag")] pub fn dump_dag_svg(&self) -> Result<()> { info!("Dumping DAG to svg..."); std::fs::create_dir_all(&self.path)?; @@ -191,7 +191,7 @@ impl SpendDagDb { *w_handle = dag; std::mem::drop(w_handle); - #[cfg(feature = "svg")] + #[cfg(feature = "svg-dag")] { // update and save svg to file in a background thread so we don't block // @@ -337,7 +337,7 @@ pub async fn new_dag_with_genesis_only(client: &Client) -> Result { Ok(dag) } -#[cfg(feature = "svg")] +#[cfg(feature = "svg-dag")] fn dag_to_svg(dag: &SpendDag) -> Result> { let dot = dag.dump_dot_format(); let graph = parse(&dot).map_err(|err| eyre!("Failed to parse dag from dot: {err}"))?; @@ -357,7 +357,7 @@ fn dag_to_svg(dag: &SpendDag) -> Result> { // - marks poisoned spends as red // - marks UTXOs and unknown ancestors as yellow // - just pray it works on windows -#[cfg(feature = "svg")] +#[cfg(feature = "svg-dag")] fn quick_edit_svg(svg: Vec, dag: &SpendDag) -> Result> { let mut str = String::from_utf8(svg).map_err(|err| eyre!("Failed svg conversion: {err}"))?; diff --git a/sn_auditor/src/main.rs b/sn_auditor/src/main.rs index f486915abd..6469e4c1b5 100644 --- a/sn_auditor/src/main.rs +++ b/sn_auditor/src/main.rs @@ -106,7 +106,7 @@ async fn main() -> Result<()> { if let Some(dag_to_view) = opt.offline_viewer { let dag = SpendDagDb::offline(dag_to_view)?; - #[cfg(feature = "svg")] + #[cfg(feature = "svg-dag")] { dag.dump_dag_svg()?; } @@ -213,7 +213,7 @@ async fn initialize_background_spend_dag_collection( } // initialize svg - #[cfg(feature = "svg")] + #[cfg(feature = "svg-dag")] dag.dump_dag_svg()?; // initialize beta rewards program tracking diff --git a/sn_cli/src/bin/subcommands/wallet/audit.rs b/sn_cli/src/bin/subcommands/wallet/audit.rs index 74bb373f1b..c893f1eeaf 100644 --- a/sn_cli/src/bin/subcommands/wallet/audit.rs +++ b/sn_cli/src/bin/subcommands/wallet/audit.rs @@ -61,32 +61,35 @@ async fn step_by_step_spend_dag_gathering(client: &Client, mut dag: SpendDag) -> Ok(dag) } +/// Gather the Spend DAG from the Network and store it on disk +/// If a DAG is found on disk, it will continue from it +/// If fast_mode is true, gathers in a silent and fast way +/// else enjoy a step by step slow narrated gathering async fn gather_spend_dag(client: &Client, root_dir: &Path, fast_mode: bool) -> Result { let dag_path = root_dir.join(SPEND_DAG_FILENAME); - let mut inital_dag = match SpendDag::load_from_file(&dag_path) { - Ok(dag) => { + let inital_dag = match SpendDag::load_from_file(&dag_path) { + Ok(mut dag) => { println!("Found a local spend dag on disk, continuing from it..."); + if fast_mode { + client + .spend_dag_continue_from_utxos(&mut dag, None, false) + .await?; + } dag } Err(err) => { println!("Starting from Genesis as found no local spend dag on disk..."); info!("Starting from Genesis as failed to load spend dag from disk: {err}"); let genesis_addr = SpendAddress::from_unique_pubkey(&GENESIS_SPEND_UNIQUE_KEY); + let stop_after = if fast_mode { None } else { Some(1) }; client - .spend_dag_build_from(genesis_addr, Some(1), true) + .spend_dag_build_from(genesis_addr, stop_after, true) .await? } }; let dag = match fast_mode { - // fast but silent DAG collection - true => { - client - .spend_dag_continue_from_utxos(&mut inital_dag, None, false) - .await?; - inital_dag - } - // slow but step by step narrated DAG collection + true => inital_dag, false => step_by_step_spend_dag_gathering(client, inital_dag).await?, }; @@ -103,7 +106,7 @@ pub async fn audit( root_dir: &Path, foundation_sk: Option, ) -> Result<()> { - let fast_mode = to_dot || royalties; + let fast_mode = to_dot || royalties || foundation_sk.is_some(); let dag = gather_spend_dag(client, root_dir, fast_mode).await?; if to_dot { diff --git a/sn_cli/src/bin/subcommands/wallet/hot_wallet.rs b/sn_cli/src/bin/subcommands/wallet/hot_wallet.rs index 3322a42abe..f84010d25a 100644 --- a/sn_cli/src/bin/subcommands/wallet/hot_wallet.rs +++ b/sn_cli/src/bin/subcommands/wallet/hot_wallet.rs @@ -113,6 +113,9 @@ pub enum WalletCmds { /// Audit the Currency /// Note that this might take a very long time /// Analogous to verifying the entire blockchain in Bitcoin + /// + /// When run without any flags, runs in verbose mode, + /// a slower but more informative mode where DAG collection progress is diplayed Audit { /// EXPERIMENTAL Dump Audit DAG in dot format on stdout #[clap(long, default_value = "false")] @@ -121,6 +124,7 @@ pub enum WalletCmds { #[clap(long, default_value = "false")] royalties: bool, /// Hex string of the Foundation SK. + /// Providing this key allow displaying rewards statistics gathered from the DAG. #[clap(long, name = "sk_str")] sk_str: Option, },