diff --git a/Cargo.lock b/Cargo.lock index 4bdc0944a6..90c2bd227a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6989,6 +6989,7 @@ dependencies = [ "color-eyre", "dirs-next", "graphviz-rust", + "lazy_static", "serde", "serde_json", "sn_client", diff --git a/sn_auditor/Cargo.toml b/sn_auditor/Cargo.toml index 4cce23c440..afde173fe0 100644 --- a/sn_auditor/Cargo.toml +++ b/sn_auditor/Cargo.toml @@ -27,6 +27,7 @@ clap = { version = "4.2.1", features = ["derive"] } color-eyre = "~0.6" dirs-next = "~2.0.0" graphviz-rust = { version = "0.9.0", optional = true } +lazy_static = "1.4.0" serde = { version = "1.0.133", features = ["derive", "rc"] } serde_json = "1.0.108" sn_client = { path = "../sn_client", version = "0.107.3" } diff --git a/sn_auditor/README.md b/sn_auditor/README.md index bb4b45abbf..e8291f9f3d 100644 --- a/sn_auditor/README.md +++ b/sn_auditor/README.md @@ -38,6 +38,13 @@ It can be run with the following flags: discord usernames of the beta participants ``` +The following env var: + +``` +# time in seconds UTXOs are refetched in DAG crawl +UTXO_REATTEMPT_INTERVAL=3600 +``` + ## Endpoints The webserver listens on port `4242` and has the following endpoints: diff --git a/sn_auditor/src/dag_db.rs b/sn_auditor/src/dag_db.rs index 2e965ec91d..12db768623 100644 --- a/sn_auditor/src/dag_db.rs +++ b/sn_auditor/src/dag_db.rs @@ -12,6 +12,7 @@ use color_eyre::eyre::Context; use color_eyre::eyre::{bail, eyre, Result}; #[cfg(feature = "svg-dag")] use graphviz_rust::{cmd::Format, exec, parse, printer::PrinterContext}; +use lazy_static::lazy_static; use serde::{Deserialize, Serialize}; use sn_client::transfers::{Hash, NanoTokens, SignedSpend, SpendAddress}; use sn_client::{Client, SpendDag, SpendDagGet}; @@ -28,7 +29,16 @@ pub const SPEND_DAG_SVG_FILENAME: &str = "spend_dag.svg"; /// Store a locally copy to restore on restart pub const BETA_PARTICIPANTS_FILENAME: &str = "beta_participants.txt"; -const REATTEMPT_INTERVAL: Duration = Duration::from_secs(3600); +lazy_static! { + /// time in seconds UTXOs are refetched in DAG crawl + static ref UTXO_REATTEMPT_INTERVAL: Duration = Duration::from_secs( + std::env::var("UTXO_REATTEMPT_INTERVAL") + .unwrap_or("3600".to_string()) + .parse::() + .unwrap_or(3600) + ); +} + const SPENDS_PROCESSING_BUFFER_SIZE: usize = 4096; /// Abstraction for the Spend DAG database @@ -223,8 +233,11 @@ impl SpendDagDb { let addrs_to_get = utxos_to_fetch.keys().cloned().collect::>(); if addrs_to_get.is_empty() { - debug!("Sleeping for {REATTEMPT_INTERVAL:?} until next re-attempt..."); - tokio::time::sleep(REATTEMPT_INTERVAL).await; + debug!( + "Sleeping for {:?} until next re-attempt...", + *UTXO_REATTEMPT_INTERVAL + ); + tokio::time::sleep(*UTXO_REATTEMPT_INTERVAL).await; continue; } @@ -241,7 +254,7 @@ impl SpendDagDb { utxo_addresses.extend( new_utxos .into_iter() - .map(|a| (a, Instant::now() + REATTEMPT_INTERVAL)), + .map(|a| (a, Instant::now() + *UTXO_REATTEMPT_INTERVAL)), ); // write updates to local DAG and save to disk