diff --git a/sn_cli/src/bin/subcommands/wallet/audit.rs b/sn_cli/src/bin/subcommands/wallet/audit.rs index 2b275c1f0a..7c98940aeb 100644 --- a/sn_cli/src/bin/subcommands/wallet/audit.rs +++ b/sn_cli/src/bin/subcommands/wallet/audit.rs @@ -28,7 +28,9 @@ async fn gather_spend_dag(client: &Client, root_dir: &Path) -> Result 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_CASHNOTE.unique_pubkey()); - client.spend_dag_build_from(genesis_addr, None).await? + client + .spend_dag_build_from(genesis_addr, None, true) + .await? } }; diff --git a/sn_client/src/audit/spend_dag_building.rs b/sn_client/src/audit/spend_dag_building.rs index 9186fa0bc2..08188f9298 100644 --- a/sn_client/src/audit/spend_dag_building.rs +++ b/sn_client/src/audit/spend_dag_building.rs @@ -16,11 +16,12 @@ use std::collections::BTreeSet; impl Client { /// Builds a SpendDag from a given SpendAddress recursively following descendants all the way to UTxOs /// Started from Genesis this gives the entire SpendDag of the Network at a certain point in time - /// Once the DAG collected, verifies and records errors in the DAG + /// Once the DAG collected, optionally verifies and records errors in the DAG pub async fn spend_dag_build_from( &self, spend_addr: SpendAddress, max_depth: Option, + verify: bool, ) -> WalletResult { info!("Building spend DAG from {spend_addr:?}"); let mut dag = SpendDag::new(spend_addr); @@ -120,17 +121,19 @@ impl Client { info!("Finished building SpendDAG from {spend_addr:?} in {elapsed:?}"); // verify the DAG - info!("Now verifying SpendDAG from {spend_addr:?} and recording errors..."); - let start = std::time::Instant::now(); - if let Err(e) = dag.record_faults(&dag.source()) { - let s = format!( - "Collected DAG starting at {spend_addr:?} is invalid, this is probably a bug: {e}" - ); - error!("{s}"); - return Err(WalletError::Dag(s)); + if verify { + info!("Now verifying SpendDAG from {spend_addr:?} and recording errors..."); + let start = std::time::Instant::now(); + if let Err(e) = dag.record_faults(&dag.source()) { + let s = format!( + "Collected DAG starting at {spend_addr:?} is invalid, this is probably a bug: {e}" + ); + error!("{s}"); + return Err(WalletError::Dag(s)); + } + let elapsed = start.elapsed(); + info!("Finished verifying SpendDAG from {spend_addr:?} in {elapsed:?}"); } - let elapsed = start.elapsed(); - info!("Finished verifying SpendDAG from {spend_addr:?} in {elapsed:?}"); Ok(dag) } @@ -271,7 +274,10 @@ impl Client { let mut stream = futures::stream::iter(utxos.into_iter()) .map(|utxo| async move { debug!("Queuing task to gather DAG from utxo: {:?}", utxo); - (self.spend_dag_build_from(utxo, max_depth).await, utxo) + ( + self.spend_dag_build_from(utxo, max_depth, false).await, + utxo, + ) }) .buffer_unordered(crate::MAX_CONCURRENT_TASKS); @@ -287,9 +293,6 @@ impl Client { }; } - dag.record_faults(&dag.source()) - .map_err(|e| WalletError::Dag(e.to_string()))?; - info!("Done gathering spend DAG from utxos"); Ok(()) }