Skip to content

Commit 9458fc5

Browse files
authored
Use the new Firehose info endpoint (#5672)
* graph: refactor provider manager to support extended block checks * firehose: use endpoint info * node: add optional extended block checks for providers * node: enable extended blocks checks for all chains by default * graph: add provider check strategy to make api nicer * graph: add tests for provider checks * graph: prepare graphman cli integration & clean-up tests * node: update graphman provider checks command * graphman: enable extended blocks check on deployment run
1 parent 4c49952 commit 9458fc5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+2934
-1496
lines changed

Cargo.lock

Lines changed: 12 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ anyhow = "1.0"
3030
async-graphql = { version = "7.0.11", features = ["chrono", "uuid"] }
3131
async-graphql-axum = "7.0.11"
3232
axum = "0.7.5"
33+
bs58 = "0.5.1"
3334
chrono = "0.4.38"
3435
clap = { version = "4.5.4", features = ["derive", "env"] }
3536
derivative = "2.2.0"

chain/arweave/src/chain.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use graph::blockchain::{
66
EmptyNodeCapabilities, NoopDecoderHook, NoopRuntimeAdapter,
77
};
88
use graph::cheap_clone::CheapClone;
9-
use graph::components::adapter::ChainId;
9+
use graph::components::network_provider::ChainName;
1010
use graph::components::store::DeploymentCursorTracker;
1111
use graph::data::subgraph::UnifiedMappingApiVersion;
1212
use graph::env::EnvVars;
@@ -42,7 +42,7 @@ use graph::blockchain::block_stream::{
4242

4343
pub struct Chain {
4444
logger_factory: LoggerFactory,
45-
name: ChainId,
45+
name: ChainName,
4646
client: Arc<ChainClient<Self>>,
4747
chain_store: Arc<dyn ChainStore>,
4848
metrics_registry: Arc<MetricsRegistry>,

chain/cosmos/src/chain.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use graph::blockchain::firehose_block_ingestor::FirehoseBlockIngestor;
22
use graph::blockchain::{BlockIngestor, NoopDecoderHook};
3-
use graph::components::adapter::ChainId;
3+
use graph::components::network_provider::ChainName;
44
use graph::env::EnvVars;
55
use graph::prelude::MetricsRegistry;
66
use graph::substreams::Clock;
@@ -37,7 +37,7 @@ use crate::{codec, TriggerFilter};
3737

3838
pub struct Chain {
3939
logger_factory: LoggerFactory,
40-
name: ChainId,
40+
name: ChainName,
4141
client: Arc<ChainClient<Self>>,
4242
chain_store: Arc<dyn ChainStore>,
4343
metrics_registry: Arc<MetricsRegistry>,

chain/ethereum/examples/firehose.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use anyhow::Error;
22
use graph::{
33
endpoint::EndpointMetrics,
44
env::env_var,
5-
firehose::{self, FirehoseEndpoint, NoopGenesisDecoder, SubgraphLimit},
5+
firehose::{self, FirehoseEndpoint, SubgraphLimit},
66
log::logger,
77
prelude::{prost, tokio, tonic, MetricsRegistry},
88
};
@@ -38,7 +38,6 @@ async fn main() -> Result<(), Error> {
3838
false,
3939
SubgraphLimit::Unlimited,
4040
metrics,
41-
NoopGenesisDecoder::boxed(),
4241
));
4342

4443
loop {

chain/ethereum/src/chain.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use graph::blockchain::firehose_block_ingestor::{FirehoseBlockIngestor, Transfor
55
use graph::blockchain::{
66
BlockIngestor, BlockTime, BlockchainKind, ChainIdentifier, TriggersAdapterSelector,
77
};
8-
use graph::components::adapter::ChainId;
8+
use graph::components::network_provider::ChainName;
99
use graph::components::store::DeploymentCursorTracker;
1010
use graph::data::subgraph::UnifiedMappingApiVersion;
1111
use graph::firehose::{FirehoseEndpoint, ForkStep};
@@ -288,7 +288,7 @@ impl RuntimeAdapterBuilder for EthereumRuntimeAdapterBuilder {
288288

289289
pub struct Chain {
290290
logger_factory: LoggerFactory,
291-
pub name: ChainId,
291+
pub name: ChainName,
292292
node_id: NodeId,
293293
registry: Arc<MetricsRegistry>,
294294
client: Arc<ChainClient<Self>>,
@@ -315,7 +315,7 @@ impl Chain {
315315
/// Creates a new Ethereum [`Chain`].
316316
pub fn new(
317317
logger_factory: LoggerFactory,
318-
name: ChainId,
318+
name: ChainName,
319319
node_id: NodeId,
320320
registry: Arc<MetricsRegistry>,
321321
chain_store: Arc<dyn ChainStore>,

chain/ethereum/src/ingestor.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::{chain::BlockFinality, ENV_VARS};
22
use crate::{EthereumAdapter, EthereumAdapterTrait as _};
33
use graph::blockchain::client::ChainClient;
44
use graph::blockchain::BlockchainKind;
5-
use graph::components::adapter::ChainId;
5+
use graph::components::network_provider::ChainName;
66
use graph::futures03::compat::Future01CompatExt as _;
77
use graph::slog::o;
88
use graph::util::backoff::ExponentialBackoff;
@@ -22,7 +22,7 @@ pub struct PollingBlockIngestor {
2222
chain_client: Arc<ChainClient<crate::chain::Chain>>,
2323
chain_store: Arc<dyn ChainStore>,
2424
polling_interval: Duration,
25-
network_name: ChainId,
25+
network_name: ChainName,
2626
}
2727

2828
impl PollingBlockIngestor {
@@ -32,7 +32,7 @@ impl PollingBlockIngestor {
3232
chain_client: Arc<ChainClient<crate::chain::Chain>>,
3333
chain_store: Arc<dyn ChainStore>,
3434
polling_interval: Duration,
35-
network_name: ChainId,
35+
network_name: ChainName,
3636
) -> Result<PollingBlockIngestor, Error> {
3737
Ok(PollingBlockIngestor {
3838
logger,
@@ -266,7 +266,7 @@ impl BlockIngestor for PollingBlockIngestor {
266266
}
267267
}
268268

269-
fn network_name(&self) -> ChainId {
269+
fn network_name(&self) -> ChainName {
270270
self.network_name.clone()
271271
}
272272

chain/ethereum/src/network.rs

Lines changed: 41 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
use anyhow::{anyhow, bail};
22
use graph::blockchain::ChainIdentifier;
3-
use graph::components::adapter::{ChainId, NetIdentifiable, ProviderManager, ProviderName};
3+
use graph::components::network_provider::ChainName;
4+
use graph::components::network_provider::NetworkDetails;
5+
use graph::components::network_provider::ProviderManager;
6+
use graph::components::network_provider::ProviderName;
47
use graph::endpoint::EndpointMetrics;
58
use graph::firehose::{AvailableCapacity, SubgraphLimit};
69
use graph::prelude::rand::seq::IteratorRandom;
710
use graph::prelude::rand::{self, Rng};
11+
use itertools::Itertools;
812
use std::sync::Arc;
913

1014
pub use graph::impl_slog_value;
@@ -29,13 +33,18 @@ pub struct EthereumNetworkAdapter {
2933
}
3034

3135
#[async_trait]
32-
impl NetIdentifiable for EthereumNetworkAdapter {
33-
async fn net_identifiers(&self) -> Result<ChainIdentifier, anyhow::Error> {
34-
self.adapter.net_identifiers().await
35-
}
36+
impl NetworkDetails for EthereumNetworkAdapter {
3637
fn provider_name(&self) -> ProviderName {
3738
self.adapter.provider().into()
3839
}
40+
41+
async fn chain_identifier(&self) -> Result<ChainIdentifier, Error> {
42+
self.adapter.net_identifiers().await
43+
}
44+
45+
async fn provides_extended_blocks(&self) -> Result<bool, Error> {
46+
Ok(true)
47+
}
3948
}
4049

4150
impl EthereumNetworkAdapter {
@@ -72,7 +81,7 @@ impl EthereumNetworkAdapter {
7281

7382
#[derive(Debug, Clone)]
7483
pub struct EthereumNetworkAdapters {
75-
chain_id: ChainId,
84+
chain_id: ChainName,
7685
manager: ProviderManager<EthereumNetworkAdapter>,
7786
call_only_adapters: Vec<EthereumNetworkAdapter>,
7887
// Percentage of request that should be used to retest errored adapters.
@@ -96,10 +105,10 @@ impl EthereumNetworkAdapters {
96105
) -> Self {
97106
use std::cmp::Ordering;
98107

108+
use graph::components::network_provider::ProviderCheckStrategy;
99109
use graph::slog::{o, Discard, Logger};
100110

101-
use graph::components::adapter::NoopIdentValidator;
102-
let chain_id: ChainId = "testing".into();
111+
let chain_id: ChainName = "testing".into();
103112
adapters.sort_by(|a, b| {
104113
a.capabilities
105114
.partial_cmp(&b.capabilities)
@@ -109,15 +118,14 @@ impl EthereumNetworkAdapters {
109118
let provider = ProviderManager::new(
110119
Logger::root(Discard, o!()),
111120
vec![(chain_id.clone(), adapters)].into_iter(),
112-
Arc::new(NoopIdentValidator),
121+
ProviderCheckStrategy::MarkAsValid,
113122
);
114-
provider.mark_all_valid().await;
115123

116124
Self::new(chain_id, provider, call_only, None)
117125
}
118126

119127
pub fn new(
120-
chain_id: ChainId,
128+
chain_id: ChainName,
121129
manager: ProviderManager<EthereumNetworkAdapter>,
122130
call_only_adapters: Vec<EthereumNetworkAdapter>,
123131
retest_percent: Option<f64>,
@@ -159,8 +167,9 @@ impl EthereumNetworkAdapters {
159167
) -> impl Iterator<Item = &EthereumNetworkAdapter> + '_ {
160168
let all = self
161169
.manager
162-
.get_all(&self.chain_id)
170+
.providers(&self.chain_id)
163171
.await
172+
.map(|adapters| adapters.collect_vec())
164173
.unwrap_or_default();
165174

166175
Self::available_with_capabilities(all, required_capabilities)
@@ -172,7 +181,10 @@ impl EthereumNetworkAdapters {
172181
&self,
173182
required_capabilities: &NodeCapabilities,
174183
) -> impl Iterator<Item = &EthereumNetworkAdapter> + '_ {
175-
let all = self.manager.get_all_unverified(&self.chain_id);
184+
let all = self
185+
.manager
186+
.providers_unchecked(&self.chain_id)
187+
.collect_vec();
176188

177189
Self::available_with_capabilities(all, required_capabilities)
178190
}
@@ -242,10 +254,10 @@ impl EthereumNetworkAdapters {
242254
// EthereumAdapters are sorted by their NodeCapabilities when the EthereumNetworks
243255
// struct is instantiated so they do not need to be sorted here
244256
self.manager
245-
.get_all(&self.chain_id)
257+
.providers(&self.chain_id)
246258
.await
259+
.map(|mut adapters| adapters.next())
247260
.unwrap_or_default()
248-
.first()
249261
.map(|ethereum_network_adapter| ethereum_network_adapter.adapter.clone())
250262
}
251263

@@ -299,7 +311,9 @@ impl EthereumNetworkAdapters {
299311
#[cfg(test)]
300312
mod tests {
301313
use graph::cheap_clone::CheapClone;
302-
use graph::components::adapter::{NoopIdentValidator, ProviderManager, ProviderName};
314+
use graph::components::network_provider::ProviderCheckStrategy;
315+
use graph::components::network_provider::ProviderManager;
316+
use graph::components::network_provider::ProviderName;
303317
use graph::data::value::Word;
304318
use graph::http::HeaderMap;
305319
use graph::{
@@ -746,18 +760,14 @@ mod tests {
746760
.collect(),
747761
)]
748762
.into_iter(),
749-
Arc::new(NoopIdentValidator),
763+
ProviderCheckStrategy::MarkAsValid,
750764
);
751-
manager.mark_all_valid().await;
752765

753-
let no_retest_adapters = EthereumNetworkAdapters::new(
754-
chain_id.clone(),
755-
manager.cheap_clone(),
756-
vec![],
757-
Some(0f64),
758-
);
766+
let no_retest_adapters =
767+
EthereumNetworkAdapters::new(chain_id.clone(), manager.clone(), vec![], Some(0f64));
768+
759769
let always_retest_adapters =
760-
EthereumNetworkAdapters::new(chain_id, manager.cheap_clone(), vec![], Some(1f64));
770+
EthereumNetworkAdapters::new(chain_id, manager.clone(), vec![], Some(1f64));
761771

762772
assert_eq!(
763773
no_retest_adapters
@@ -842,16 +852,12 @@ mod tests {
842852
.iter()
843853
.cloned()
844854
.map(|a| (chain_id.clone(), vec![a])),
845-
Arc::new(NoopIdentValidator),
855+
ProviderCheckStrategy::MarkAsValid,
846856
);
847-
manager.mark_all_valid().await;
848857

849-
let always_retest_adapters = EthereumNetworkAdapters::new(
850-
chain_id.clone(),
851-
manager.cheap_clone(),
852-
vec![],
853-
Some(1f64),
854-
);
858+
let always_retest_adapters =
859+
EthereumNetworkAdapters::new(chain_id.clone(), manager.clone(), vec![], Some(1f64));
860+
855861
assert_eq!(
856862
always_retest_adapters
857863
.cheapest_with(&NodeCapabilities {
@@ -870,9 +876,8 @@ mod tests {
870876
.iter()
871877
.cloned()
872878
.map(|a| (chain_id.clone(), vec![a])),
873-
Arc::new(NoopIdentValidator),
879+
ProviderCheckStrategy::MarkAsValid,
874880
);
875-
manager.mark_all_valid().await;
876881

877882
let no_retest_adapters =
878883
EthereumNetworkAdapters::new(chain_id.clone(), manager, vec![], Some(0f64));
@@ -912,9 +917,8 @@ mod tests {
912917
no_available_adapter.iter().cloned().collect(),
913918
)]
914919
.into_iter(),
915-
Arc::new(NoopIdentValidator),
920+
ProviderCheckStrategy::MarkAsValid,
916921
);
917-
manager.mark_all_valid().await;
918922

919923
let no_available_adapter = EthereumNetworkAdapters::new(chain_id, manager, vec![], None);
920924
let res = no_available_adapter

chain/ethereum/src/transport.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use graph::components::adapter::ProviderName;
1+
use graph::components::network_provider::ProviderName;
22
use graph::endpoint::{EndpointMetrics, RequestLabels};
33
use jsonrpc_core::types::Call;
44
use jsonrpc_core::Value;

chain/near/src/chain.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use graph::blockchain::{
77
NoopRuntimeAdapter,
88
};
99
use graph::cheap_clone::CheapClone;
10-
use graph::components::adapter::ChainId;
10+
use graph::components::network_provider::ChainName;
1111
use graph::components::store::DeploymentCursorTracker;
1212
use graph::data::subgraph::UnifiedMappingApiVersion;
1313
use graph::env::EnvVars;
@@ -161,7 +161,7 @@ impl BlockStreamBuilder<Chain> for NearStreamBuilder {
161161

162162
pub struct Chain {
163163
logger_factory: LoggerFactory,
164-
name: ChainId,
164+
name: ChainName,
165165
client: Arc<ChainClient<Self>>,
166166
chain_store: Arc<dyn ChainStore>,
167167
metrics_registry: Arc<MetricsRegistry>,

0 commit comments

Comments
 (0)