Skip to content

Commit f6b3de5

Browse files
feat: add config option for network_subgraph_max_lag_seconds (#1124)
This is mostly relevant for testing on the local-network. Co-authored-by: Joseph Livesey <[email protected]>
1 parent 55f8145 commit f6b3de5

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

src/config.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ pub struct Config {
4848
pub min_indexer_version: Version,
4949
/// Indexers used to query the network subgraph
5050
pub trusted_indexers: Vec<TrustedIndexer>,
51+
/// Maximum acceptable lag (in seconds) for network subgraph responses (default: 120)
52+
#[serde(default = "default_network_subgraph_max_lag_seconds")]
53+
pub network_subgraph_max_lag_seconds: u64,
5154
/// Check payment state of client (disable for testnets)
5255
pub payment_required: bool,
5356
/// public API port
@@ -60,6 +63,11 @@ pub struct Config {
6063
pub receipts: Receipts,
6164
}
6265

66+
/// Default network subgraph max lag threshold (120 seconds)
67+
fn default_network_subgraph_max_lag_seconds() -> u64 {
68+
120
69+
}
70+
6371
/// Deserialize a `NotNan<f64>` from a `f64` and return an error if the value is NaN.
6472
fn deserialize_not_nan_f64<'de, D>(deserializer: D) -> Result<NotNan<f64>, D::Error>
6573
where

src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ async fn main() {
112112
indexers: conf.trusted_indexers,
113113
latest_block: None,
114114
page_size: 500,
115+
max_lag_seconds: conf.network_subgraph_max_lag_seconds,
115116
};
116117
let indexer_host_blocklist = match &conf.ip_blocker_db {
117118
Some(path) => {

src/network/subgraph_client.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ pub struct Client {
125125
pub indexers: Vec<TrustedIndexer>,
126126
pub page_size: usize,
127127
pub latest_block: Option<Block>,
128+
pub max_lag_seconds: u64,
128129
}
129130

130131
impl Client {
@@ -271,7 +272,8 @@ impl Client {
271272
"response block before latest",
272273
);
273274
ensure!(
274-
(unix_timestamp() / 1_000).saturating_sub(block.timestamp) < 120,
275+
(unix_timestamp() / 1_000).saturating_sub(block.timestamp)
276+
< self.max_lag_seconds,
275277
"response too far behind",
276278
);
277279
query_block = Some(block);

0 commit comments

Comments
 (0)