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 30c2d2c commit 64ae36a
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 4 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 @@ -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" }
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
21 changes: 17 additions & 4 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 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::<u64>()
.unwrap_or(3600)
);
}

const SPENDS_PROCESSING_BUFFER_SIZE: usize = 4096;

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

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

Expand All @@ -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
Expand Down

0 comments on commit 64ae36a

Please sign in to comment.