From 53de3ed004da400893eb880b665109eb9185ecd9 Mon Sep 17 00:00:00 2001 From: grumbach Date: Tue, 4 Jun 2024 06:32:57 +0200 Subject: [PATCH] feat: utxo reattempt by env --- Cargo.lock | 1 + sn_auditor/Cargo.toml | 1 + sn_auditor/README.md | 7 +++++++ sn_auditor/src/dag_db.rs | 23 ++++++++++++++++++----- 4 files changed, 27 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 28edd35876..8fd36c6229 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6990,6 +6990,7 @@ dependencies = [ "dirs-next", "futures", "graphviz-rust", + "lazy_static", "serde", "serde_json", "sn_client", diff --git a/sn_auditor/Cargo.toml b/sn_auditor/Cargo.toml index 4e943af532..587f700a29 100644 --- a/sn_auditor/Cargo.toml +++ b/sn_auditor/Cargo.toml @@ -28,6 +28,7 @@ color-eyre = "~0.6" dirs-next = "~2.0.0" futures = "0.3.28" 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 c00770dd73..f674917a2d 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 DAG_RECRAWL_INTERVAL: Duration = Duration::from_secs(60); +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 @@ -224,8 +234,11 @@ impl SpendDagDb { let addrs_to_get = utxos_to_fetch.keys().cloned().collect::>(); if addrs_to_get.is_empty() { - debug!("Sleeping for {DAG_RECRAWL_INTERVAL:?} until next re-attempt..."); - tokio::time::sleep(DAG_RECRAWL_INTERVAL).await; + debug!( + "Sleeping for {:?} until next re-attempt...", + *UTXO_REATTEMPT_INTERVAL + ); + tokio::time::sleep(*UTXO_REATTEMPT_INTERVAL).await; continue; } @@ -250,7 +263,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)), ); } else { panic!("There is no point in running the auditor if we are not collecting the DAG or collecting data through crawling. Please enable the `dag-collection` feature or provide beta program related arguments."); @@ -272,7 +285,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