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

opti: improve DAG verification redundancy #1713

Merged
merged 1 commit into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion sn_cli/src/bin/subcommands/wallet/audit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ async fn gather_spend_dag(client: &Client, root_dir: &Path) -> Result<SpendDag>
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?
}
};

Expand Down
33 changes: 18 additions & 15 deletions sn_client/src/audit/spend_dag_building.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u32>,
verify: bool,
) -> WalletResult<SpendDag> {
info!("Building spend DAG from {spend_addr:?}");
let mut dag = SpendDag::new(spend_addr);
Expand Down Expand Up @@ -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)
}

Expand Down Expand Up @@ -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);

Expand All @@ -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(())
}
Expand Down
Loading