Skip to content

Commit

Permalink
feat(audit): make svg processing a non-deafult feat
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuef committed May 19, 2024
1 parent d06fead commit 958eade
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 14 deletions.
24 changes: 18 additions & 6 deletions sn_auditor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
] }
22 changes: 15 additions & 7 deletions sn_auditor/src/dag_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)?;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -321,6 +327,7 @@ pub async fn new_dag_with_genesis_only(client: &Client) -> Result<SpendDag> {
Ok(dag)
}

#[cfg(feature = "svg")]
fn dag_to_svg(dag: &SpendDag) -> Result<Vec<u8>> {
let dot = dag.dump_dot_format();
let graph = parse(&dot).map_err(|err| eyre!("Failed to parse dag from dot: {err}"))?;
Expand All @@ -340,6 +347,7 @@ fn dag_to_svg(dag: &SpendDag) -> Result<Vec<u8>> {
// - 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<u8>, dag: &SpendDag) -> Result<Vec<u8>> {
let mut str = String::from_utf8(svg).map_err(|err| eyre!("Failed svg conversion: {err}"))?;

Expand Down
6 changes: 5 additions & 1 deletion sn_auditor/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(());
}
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 958eade

Please sign in to comment.