Skip to content

Commit

Permalink
feat: utxo reattempt by env
Browse files Browse the repository at this point in the history
  • Loading branch information
grumbach committed Jun 4, 2024
1 parent e415c04 commit 53de3ed
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 5 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions sn_auditor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
7 changes: 7 additions & 0 deletions sn_auditor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
23 changes: 18 additions & 5 deletions sn_auditor/src/dag_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -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::<u64>()
.unwrap_or(3600)
);
}

const SPENDS_PROCESSING_BUFFER_SIZE: usize = 4096;

/// Abstraction for the Spend DAG database
Expand Down Expand Up @@ -224,8 +234,11 @@ impl SpendDagDb {
let addrs_to_get = utxos_to_fetch.keys().cloned().collect::<BTreeSet<_>>();

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;
}

Expand All @@ -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.");
Expand All @@ -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
Expand Down

0 comments on commit 53de3ed

Please sign in to comment.