Skip to content

Commit cebb0e5

Browse files
author
Matthieu Vachon
authored
Added an environment to control if Firehoe is preferred or not when present (#3166)
chain/ethereum: added an environment to control if Firehoe is preferred or not when present If the environment is **not** set, the current behavior and Firehose is automatically picked up if there is endpoints configured with it. If the environment set, firehose is preferred only if the variable is true and there is endpoints configured with it.
1 parent c440b3e commit cebb0e5

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

chain/ethereum/src/chain.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use anyhow::{Context, Error};
22
use graph::blockchain::BlockchainKind;
33
use graph::components::store::WritableStore;
44
use graph::data::subgraph::UnifiedMappingApiVersion;
5+
use graph::env::env_var;
56
use graph::firehose::{FirehoseEndpoints, ForkStep};
67
use graph::prelude::{
78
EthereumBlock, EthereumCallCache, LightEthereumBlock, LightEthereumBlockExt, StopwatchMetrics,
@@ -48,16 +49,14 @@ use graph::blockchain::block_stream::{BlockStream, FirehoseCursor};
4849

4950
lazy_static! {
5051
/// Maximum number of blocks to request in each chunk.
51-
static ref MAX_BLOCK_RANGE_SIZE: BlockNumber = std::env::var("GRAPH_ETHEREUM_MAX_BLOCK_RANGE_SIZE")
52-
.unwrap_or("2000".into())
53-
.parse::<BlockNumber>()
54-
.expect("invalid GRAPH_ETHEREUM_MAX_BLOCK_RANGE_SIZE");
52+
static ref MAX_BLOCK_RANGE_SIZE: BlockNumber = env_var("GRAPH_ETHEREUM_MAX_BLOCK_RANGE_SIZE", 2000);
5553

5654
/// Ideal number of triggers in a range. The range size will adapt to try to meet this.
57-
static ref TARGET_TRIGGERS_PER_BLOCK_RANGE: u64 = std::env::var("GRAPH_ETHEREUM_TARGET_TRIGGERS_PER_BLOCK_RANGE")
58-
.unwrap_or("100".into())
59-
.parse::<u64>()
60-
.expect("invalid GRAPH_ETHEREUM_TARGET_TRIGGERS_PER_BLOCK_RANGE");
55+
static ref TARGET_TRIGGERS_PER_BLOCK_RANGE: u64 = env_var("GRAPH_ETHEREUM_TARGET_TRIGGERS_PER_BLOCK_RANGE", 100);
56+
57+
/// Controls if firehose should be preferred over RPC if Firehose endpoints are present, if not set, the default behavior is
58+
/// is kept which is to automatically favor Firehose.
59+
static ref IS_FIREHOSE_PREFERRED: bool = env_var("GRAPH_ETHEREUM_IS_FIREHOSE_PREFERRED", true);
6160
}
6261

6362
/// Celo Mainnet: 42220, Testnet Alfajores: 44787, Testnet Baklava: 62320
@@ -319,7 +318,7 @@ impl Blockchain for Chain {
319318
}
320319

321320
fn is_firehose_supported(&self) -> bool {
322-
self.firehose_endpoints.len() > 0
321+
*IS_FIREHOSE_PREFERRED && self.firehose_endpoints.len() > 0
323322
}
324323
}
325324

0 commit comments

Comments
 (0)