From 958eade408453403d6dc8b28258a91998e807fe9 Mon Sep 17 00:00:00 2001 From: Josh Wilson Date: Sun, 19 May 2024 11:34:33 +0900 Subject: [PATCH] feat(audit): make svg processing a non-deafult feat --- sn_auditor/Cargo.toml | 24 ++++++++++++++++++------ sn_auditor/src/dag_db.rs | 22 +++++++++++++++------- sn_auditor/src/main.rs | 6 +++++- 3 files changed, 38 insertions(+), 14 deletions(-) diff --git a/sn_auditor/Cargo.toml b/sn_auditor/Cargo.toml index e014b64533..92c0e3bc3b 100644 --- a/sn_auditor/Cargo.toml +++ b/sn_auditor/Cargo.toml @@ -11,22 +11,34 @@ readme = "README.md" [features] default = [] -local-discovery=["sn_client/local-discovery", "sn_peers_acquisition/local-discovery"] +local-discovery = [ + "sn_client/local-discovery", + "sn_peers_acquisition/local-discovery", +] network-contacts = ["sn_peers_acquisition/network-contacts"] open-metrics = ["sn_client/open-metrics"] websockets = ["sn_client/websockets"] +svg-dag = ["graphviz-rust"] [dependencies] bls = { package = "blsttc", version = "8.0.1" } clap = { version = "4.2.1", features = ["derive"] } color-eyre = "~0.6" dirs-next = "~2.0.0" -graphviz-rust = "0.9.0" -serde = { version = "1.0.133", features = [ "derive", "rc" ]} +graphviz-rust = { version = "0.9.0", optional = true } +serde = { version = "1.0.133", features = ["derive", "rc"] } serde_json = "1.0.108" sn_client = { path = "../sn_client", version = "0.106.2" } sn_logging = { path = "../sn_logging", version = "0.2.26" } -sn_peers_acquisition= { path="../sn_peers_acquisition", version = "0.2.12" } -tiny_http = { version="0.12", features = ["ssl-rustls"] } +sn_peers_acquisition = { path = "../sn_peers_acquisition", version = "0.2.12" } +tiny_http = { version = "0.12", features = ["ssl-rustls"] } tracing = { version = "~0.1.26" } -tokio = { version = "1.32.0", features = ["io-util", "macros", "parking_lot", "rt", "sync", "time", "fs"] } +tokio = { version = "1.32.0", features = [ + "io-util", + "macros", + "parking_lot", + "rt", + "sync", + "time", + "fs", +] } diff --git a/sn_auditor/src/dag_db.rs b/sn_auditor/src/dag_db.rs index 62b56edfc3..24eb3cb037 100644 --- a/sn_auditor/src/dag_db.rs +++ b/sn_auditor/src/dag_db.rs @@ -8,6 +8,7 @@ use bls::SecretKey; use color_eyre::eyre::{eyre, Result}; +#[cfg(feature = "svg")] use graphviz_rust::{cmd::Format, exec, parse, printer::PrinterContext}; use serde::{Deserialize, Serialize}; use sn_client::networking::NetworkError; @@ -146,6 +147,7 @@ impl SpendDagDb { } /// Dump current DAG as svg to disk + #[cfg(feature = "svg")] pub fn dump_dag_svg(&self) -> Result<()> { info!("Dumping DAG to svg..."); std::fs::create_dir_all(&self.path)?; @@ -187,13 +189,17 @@ impl SpendDagDb { *w_handle = dag; std::mem::drop(w_handle); - // update and save svg to file in a background thread so we don't block - let self_clone = self.clone(); - tokio::spawn(async move { - if let Err(e) = self_clone.dump_dag_svg() { - error!("Failed to dump DAG svg: {e}"); - } - }); + #[cfg(feature = "svg")] + { + // update and save svg to file in a background thread so we don't block + // + let self_clone = self.clone(); + tokio::spawn(async move { + if let Err(e) = self_clone.dump_dag_svg() { + error!("Failed to dump DAG svg: {e}"); + } + }); + } // gather forwarded payments in a background thread so we don't block let mut self_clone = self.clone(); @@ -321,6 +327,7 @@ pub async fn new_dag_with_genesis_only(client: &Client) -> Result { Ok(dag) } +#[cfg(feature = "svg")] 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}"))?; @@ -340,6 +347,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")] 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 c205ef966c..9c19520ab4 100644 --- a/sn_auditor/src/main.rs +++ b/sn_auditor/src/main.rs @@ -104,7 +104,10 @@ async fn main() -> Result<()> { if let Some(dag_to_view) = opt.offline_viewer { let dag = SpendDagDb::offline(dag_to_view, sk)?; - dag.dump_dag_svg()?; + #[cfg(feature = "svg")] + { + dag.dump_dag_svg()?; + } start_server(dag).await?; return Ok(()); } @@ -208,6 +211,7 @@ async fn initialize_background_spend_dag_collection( } // initialize svg + #[cfg(feature = "svg")] dag.dump_dag_svg()?; // initialize beta rewards program tracking