Skip to content

Commit 18d19bf

Browse files
authored
disable genesis validation by default (#5565)
1 parent db8de9e commit 18d19bf

File tree

8 files changed

+57
-31
lines changed

8 files changed

+57
-31
lines changed

chain/ethereum/src/network.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ impl EthereumNetworkAdapters {
9898

9999
use graph::slog::{o, Discard, Logger};
100100

101-
use graph::components::adapter::MockIdentValidator;
101+
use graph::components::adapter::NoopIdentValidator;
102102
let chain_id: ChainId = "testing".into();
103103
adapters.sort_by(|a, b| {
104104
a.capabilities
@@ -109,7 +109,7 @@ impl EthereumNetworkAdapters {
109109
let provider = ProviderManager::new(
110110
Logger::root(Discard, o!()),
111111
vec![(chain_id.clone(), adapters)].into_iter(),
112-
Arc::new(MockIdentValidator),
112+
Arc::new(NoopIdentValidator),
113113
);
114114
provider.mark_all_valid().await;
115115

@@ -299,7 +299,7 @@ impl EthereumNetworkAdapters {
299299
#[cfg(test)]
300300
mod tests {
301301
use graph::cheap_clone::CheapClone;
302-
use graph::components::adapter::{MockIdentValidator, ProviderManager, ProviderName};
302+
use graph::components::adapter::{NoopIdentValidator, ProviderManager, ProviderName};
303303
use graph::data::value::Word;
304304
use graph::http::HeaderMap;
305305
use graph::{
@@ -746,7 +746,7 @@ mod tests {
746746
.collect(),
747747
)]
748748
.into_iter(),
749-
Arc::new(MockIdentValidator),
749+
Arc::new(NoopIdentValidator),
750750
);
751751
manager.mark_all_valid().await;
752752

@@ -842,7 +842,7 @@ mod tests {
842842
.iter()
843843
.cloned()
844844
.map(|a| (chain_id.clone(), vec![a])),
845-
Arc::new(MockIdentValidator),
845+
Arc::new(NoopIdentValidator),
846846
);
847847
manager.mark_all_valid().await;
848848

@@ -870,7 +870,7 @@ mod tests {
870870
.iter()
871871
.cloned()
872872
.map(|a| (chain_id.clone(), vec![a])),
873-
Arc::new(MockIdentValidator),
873+
Arc::new(NoopIdentValidator),
874874
);
875875
manager.mark_all_valid().await;
876876

@@ -912,7 +912,7 @@ mod tests {
912912
no_available_adapter.iter().cloned().collect(),
913913
)]
914914
.into_iter(),
915-
Arc::new(MockIdentValidator),
915+
Arc::new(NoopIdentValidator),
916916
);
917917
manager.mark_all_valid().await;
918918

graph/src/components/adapter.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -183,9 +183,10 @@ impl<T: ChainStoreTrait, B: BlockStoreTrait<ChainStore = T>> IdentValidator for
183183
}
184184
}
185185

186-
pub struct MockIdentValidator;
186+
/// This is mostly used for testing or for running with disabled genesis validation.
187+
pub struct NoopIdentValidator;
187188

188-
impl IdentValidator for MockIdentValidator {
189+
impl IdentValidator for NoopIdentValidator {
189190
fn check_ident(
190191
&self,
191192
_chain_id: &ChainId,
@@ -227,7 +228,7 @@ impl<T: NetIdentifiable + Clone> Default for ProviderManager<T> {
227228
logger: Logger::root(Discard, o!()),
228229
adapters: HashMap::default(),
229230
status: vec![],
230-
validator: Arc::new(MockIdentValidator {}),
231+
validator: Arc::new(NoopIdentValidator {}),
231232
}),
232233
}
233234
}
@@ -589,7 +590,7 @@ mod test {
589590
use crate::{
590591
bail,
591592
blockchain::BlockHash,
592-
components::adapter::{ChainId, GenesisCheckStatus, MockIdentValidator},
593+
components::adapter::{ChainId, GenesisCheckStatus, NoopIdentValidator},
593594
data::value::Word,
594595
prelude::lazy_static,
595596
};
@@ -782,7 +783,7 @@ mod test {
782783
let chain_id = chain_id.into();
783784

784785
let validator: Arc<dyn IdentValidator> = match validator {
785-
None => Arc::new(MockIdentValidator {}),
786+
None => Arc::new(NoopIdentValidator {}),
786787
Some(validator) => Arc::new(validator),
787788
};
788789

graph/src/env/mod.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,15 @@ pub struct EnvVars {
212212
/// Set the maximum grpc decode size(in MB) for firehose BlockIngestor connections.
213213
/// Defaults to 25MB
214214
pub firehose_grpc_max_decode_size_mb: usize,
215+
/// Defined whether or not graph-node should refuse to perform genesis validation
216+
/// before using an adapter. Disabled by default for the moment, will be enabled
217+
/// on the next release. Disabling validation means the recorded genesis will be 0x00
218+
/// if no genesis hash can be retrieved from an adapter. If enabled, the adapter is
219+
/// ignored if unable to produce a genesis hash or produces a different an unexpected hash.
220+
pub genesis_validation_enabled: bool,
221+
/// How long do we wait for a response from the provider before considering that it is unavailable.
222+
/// Default is 30s.
223+
pub genesis_validation_timeout: Duration,
215224
}
216225

217226
impl EnvVars {
@@ -294,6 +303,8 @@ impl EnvVars {
294303
dips_metrics_object_store_url: inner.dips_metrics_object_store_url,
295304
section_map: inner.section_map,
296305
firehose_grpc_max_decode_size_mb: inner.firehose_grpc_max_decode_size_mb,
306+
genesis_validation_enabled: inner.genesis_validation_enabled.0,
307+
genesis_validation_timeout: Duration::from_secs(inner.genesis_validation_timeout),
297308
})
298309
}
299310

@@ -439,6 +450,10 @@ struct Inner {
439450
section_map: Option<String>,
440451
#[envconfig(from = "GRAPH_NODE_FIREHOSE_MAX_DECODE_SIZE", default = "25")]
441452
firehose_grpc_max_decode_size_mb: usize,
453+
#[envconfig(from = "GRAPH_NODE_GENESIS_VALIDATION_ENABLED", default = "false")]
454+
genesis_validation_enabled: EnvVarBoolean,
455+
#[envconfig(from = "GRAPH_NODE_GENESIS_VALIDATION_TIMEOUT_SECONDS", default = "30")]
456+
genesis_validation_timeout: u64,
442457
}
443458

444459
#[derive(Clone, Debug)]

graph/src/firehose/endpoints.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -638,15 +638,15 @@ impl FirehoseEndpoints {
638638
pub fn for_testing(adapters: Vec<Arc<FirehoseEndpoint>>) -> Self {
639639
use slog::{o, Discard};
640640

641-
use crate::components::adapter::MockIdentValidator;
641+
use crate::components::adapter::NoopIdentValidator;
642642
let chain_id: Word = "testing".into();
643643

644644
Self(
645645
chain_id.clone(),
646646
ProviderManager::new(
647647
Logger::root(Discard, o!()),
648648
vec![(chain_id, adapters)].into_iter(),
649-
Arc::new(MockIdentValidator),
649+
Arc::new(NoopIdentValidator),
650650
),
651651
)
652652
}

node/src/chain.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ use graph::itertools::Itertools;
3131
use graph::log::factory::LoggerFactory;
3232
use graph::prelude::anyhow;
3333
use graph::prelude::MetricsRegistry;
34-
use graph::slog::{debug, error, info, o, Logger};
34+
use graph::slog::{debug, error, info, o, warn, Logger};
3535
use graph::url::Url;
3636
use graph::util::security::SafeDisplay;
3737
use graph_chain_ethereum::{self as ethereum, Transport};
@@ -432,10 +432,14 @@ pub async fn networks_as_chains(
432432
let chain_store = match store.chain_store(chain_id) {
433433
Some(c) => c,
434434
None => {
435-
let ident = networks
436-
.chain_identifier(&logger, chain_id)
437-
.await
438-
.expect("must be able to get chain identity to create a store");
435+
let ident = match networks.chain_identifier(&logger, chain_id).await {
436+
Ok(ident) => ident,
437+
Err(err) if !config.genesis_validation_enabled => {
438+
warn!(&logger, "unable to fetch genesis for {}. Err: {}.falling back to the default value because validation is disabled", chain_id, err);
439+
ChainIdentifier::default()
440+
}
441+
err => err.expect("must be able to get chain identity to create a store"),
442+
};
439443
store
440444
.create_chain_store(chain_id, ident)
441445
.expect("must be able to create store if one is not yet setup for the chain")
@@ -669,7 +673,7 @@ pub async fn networks_as_chains(
669673
mod test {
670674
use crate::config::{Config, Opt};
671675
use crate::network_setup::{AdapterConfiguration, Networks};
672-
use graph::components::adapter::{ChainId, MockIdentValidator};
676+
use graph::components::adapter::{ChainId, NoopIdentValidator};
673677
use graph::endpoint::EndpointMetrics;
674678
use graph::log::logger;
675679
use graph::prelude::{tokio, MetricsRegistry};
@@ -702,7 +706,7 @@ mod test {
702706
let metrics = Arc::new(EndpointMetrics::mock());
703707
let config = Config::load(&logger, &opt).expect("can create config");
704708
let metrics_registry = Arc::new(MetricsRegistry::mock());
705-
let ident_validator = Arc::new(MockIdentValidator);
709+
let ident_validator = Arc::new(NoopIdentValidator);
706710

707711
let networks =
708712
Networks::from_config(logger, &config, metrics_registry, metrics, ident_validator)

node/src/main.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use clap::Parser as _;
22
use git_testament::{git_testament, render_testament};
3-
use graph::components::adapter::IdentValidator;
3+
use graph::components::adapter::{IdentValidator, NoopIdentValidator};
44
use graph::futures01::Future as _;
55
use graph::futures03::compat::Future01CompatExt;
66
use graph::futures03::future::TryFutureExt;
@@ -258,7 +258,13 @@ async fn main() {
258258

259259
let network_store = store_builder.network_store(config.chain_ids());
260260
let block_store = network_store.block_store();
261-
let validator: Arc<dyn IdentValidator> = network_store.block_store();
261+
262+
let validator: Arc<dyn IdentValidator> = if env_vars.genesis_validation_enabled {
263+
network_store.block_store()
264+
} else {
265+
Arc::new(NoopIdentValidator {})
266+
};
267+
262268
let network_adapters = Networks::from_config(
263269
logger.cheap_clone(),
264270
&config,

node/src/manager/commands/config.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::{collections::BTreeMap, sync::Arc};
33
use graph::{
44
anyhow::{bail, Context},
55
components::{
6-
adapter::{ChainId, IdentValidator, IdentValidatorError, MockIdentValidator, ProviderName},
6+
adapter::{ChainId, IdentValidator, IdentValidatorError, NoopIdentValidator, ProviderName},
77
subgraph::{Setting, Settings},
88
},
99
endpoint::EndpointMetrics,
@@ -176,7 +176,7 @@ pub async fn provider(
176176
&config,
177177
registry,
178178
metrics,
179-
Arc::new(MockIdentValidator),
179+
Arc::new(NoopIdentValidator),
180180
)
181181
.await?;
182182
let network: ChainId = network.into();

node/src/network_setup.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ use graph::{
88
cheap_clone::CheapClone,
99
components::{
1010
adapter::{
11-
ChainId, IdentValidator, MockIdentValidator, NetIdentifiable, ProviderManager,
11+
ChainId, IdentValidator, NetIdentifiable, NoopIdentValidator, ProviderManager,
1212
ProviderName,
1313
},
1414
metrics::MetricsRegistry,
1515
},
1616
endpoint::EndpointMetrics,
17-
env::EnvVars,
17+
env::{EnvVars, ENV_VARS},
1818
firehose::{FirehoseEndpoint, FirehoseEndpoints},
1919
futures03::future::TryFutureExt,
2020
itertools::Itertools,
@@ -119,17 +119,17 @@ impl Networks {
119119
rpc_provider_manager: ProviderManager::new(
120120
Logger::root(Discard, o!()),
121121
vec![].into_iter(),
122-
Arc::new(MockIdentValidator),
122+
Arc::new(NoopIdentValidator),
123123
),
124124
firehose_provider_manager: ProviderManager::new(
125125
Logger::root(Discard, o!()),
126126
vec![].into_iter(),
127-
Arc::new(MockIdentValidator),
127+
Arc::new(NoopIdentValidator),
128128
),
129129
substreams_provider_manager: ProviderManager::new(
130130
Logger::root(Discard, o!()),
131131
vec![].into_iter(),
132-
Arc::new(MockIdentValidator),
132+
Arc::new(NoopIdentValidator),
133133
),
134134
}
135135
}
@@ -146,7 +146,7 @@ impl Networks {
146146
&ChainId,
147147
Vec<(ProviderName, Result<ChainIdentifier, anyhow::Error>)>,
148148
)> {
149-
let timeout = Duration::from_secs(20);
149+
let timeout = ENV_VARS.genesis_validation_timeout;
150150
let mut out = vec![];
151151
for chain_id in self.adapters.iter().map(|a| a.chain_id()).sorted().dedup() {
152152
let mut inner = vec![];

0 commit comments

Comments
 (0)