Skip to content

Commit 8155ed5

Browse files
committed
ethereum: Env var for getLogs batch, lower default
1 parent a3c13bd commit 8155ed5

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

chain/ethereum/src/adapter.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use anyhow::Error;
22
use ethabi::{Error as ABIError, Function, ParamType, Token};
33
use futures::Future;
44
use graph::blockchain::ChainIdentifier;
5+
use graph::env::env_var;
56
use mockall::automock;
67
use mockall::predicate::*;
78
use std::cmp;
@@ -26,7 +27,10 @@ use crate::{data_source::DataSource, Chain};
2627
pub type EventSignature = H256;
2728
pub type FunctionSelector = [u8; 4];
2829

29-
const ETH_GET_LOGS_MAX_CONTRACTS: usize = 1000;
30+
lazy_static! {
31+
static ref ETH_GET_LOGS_MAX_CONTRACTS: usize =
32+
env_var("GRAPH_ETH_GET_LOGS_MAX_CONTRACTS", 2000);
33+
}
3034

3135
#[derive(Clone, Debug)]
3236
pub struct EthereumContractCall {
@@ -263,7 +267,7 @@ impl EthereumLogFilter {
263267
for neighbor in g.neighbors(max_vertex) {
264268
match neighbor {
265269
LogFilterNode::Contract(address) => {
266-
if filter.contracts.len() == ETH_GET_LOGS_MAX_CONTRACTS {
270+
if filter.contracts.len() == *ETH_GET_LOGS_MAX_CONTRACTS {
267271
// The batch size was reached, register the filter and start a new one.
268272
let event = filter.event_signatures[0];
269273
push_filter(filter);
@@ -818,7 +822,7 @@ fn complete_log_filter() {
818822

819823
// Assert that chunking works.
820824
for filter in logs_filters {
821-
assert!(filter.contracts.len() <= 1000);
825+
assert!(filter.contracts.len() <= *ETH_GET_LOGS_MAX_CONTRACTS);
822826
}
823827
}
824828
}

graph/src/env.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,20 @@ pub fn unsafe_env_var<E: std::error::Error + Send + Sync, T: FromStr<Err = E> +
3636

3737
value
3838
}
39+
40+
/// Panics if:
41+
/// - The value is not UTF8.
42+
/// - The value cannot be parsed as T..
43+
pub fn env_var<E: std::error::Error + Send + Sync, T: FromStr<Err = E> + Eq>(
44+
name: &'static str,
45+
default_value: T,
46+
) -> T {
47+
let var = match std::env::var(name) {
48+
Ok(var) => var,
49+
Err(VarError::NotPresent) => return default_value,
50+
Err(VarError::NotUnicode(_)) => panic!("environment variable {} is not UTF8", name),
51+
};
52+
53+
var.parse::<T>()
54+
.unwrap_or_else(|e| panic!("failed to parse environment variable {}: {}", name, e))
55+
}

0 commit comments

Comments
 (0)