Skip to content

Commit e8a1210

Browse files
committed
all: Add AMP chain name aliases to config
AMP-powered subgraphs use different network names than graph-node's internal chain names (e.g., AMP uses "ethereum-mainnet" while graph-node uses "mainnet"). Add a config-level `amp` field on chains that maps AMP names to internal names, so AMP manifests work without renaming chains in the database.
1 parent b28a337 commit e8a1210

File tree

8 files changed

+263
-4
lines changed

8 files changed

+263
-4
lines changed

core/src/subgraph/registrar.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use graph::amp;
55
use graph::blockchain::{Blockchain, BlockchainKind, BlockchainMap};
66
use graph::components::{
77
link_resolver::LinkResolverContext,
8+
network_provider::AmpChainNames,
89
store::{DeploymentId, DeploymentLocator, SubscriptionManager},
910
subgraph::Settings,
1011
};
@@ -30,6 +31,7 @@ pub struct SubgraphRegistrar<P, S, SM, AC> {
3031
version_switching_mode: SubgraphVersionSwitchingMode,
3132
assignment_event_stream_cancel_guard: CancelGuard, // cancels on drop
3233
settings: Arc<Settings>,
34+
amp_chain_names: Arc<AmpChainNames>,
3335
}
3436

3537
impl<P, S, SM, AC> SubgraphRegistrar<P, S, SM, AC>
@@ -50,6 +52,7 @@ where
5052
node_id: NodeId,
5153
version_switching_mode: SubgraphVersionSwitchingMode,
5254
settings: Arc<Settings>,
55+
amp_chain_names: Arc<AmpChainNames>,
5356
) -> Self {
5457
let logger = logger_factory.component_logger("SubgraphRegistrar", None);
5558
let logger_factory = logger_factory.with_parent(logger.clone());
@@ -69,6 +72,7 @@ where
6972
version_switching_mode,
7073
assignment_event_stream_cancel_guard: CancelGuard::new(),
7174
settings,
75+
amp_chain_names,
7276
}
7377
}
7478

@@ -314,6 +318,7 @@ where
314318
&resolver,
315319
self.amp_client.cheap_clone(),
316320
history_blocks,
321+
&self.amp_chain_names,
317322
)
318323
.await?
319324
}
@@ -333,6 +338,7 @@ where
333338
&resolver,
334339
self.amp_client.cheap_clone(),
335340
history_blocks,
341+
&self.amp_chain_names,
336342
)
337343
.await?
338344
}
@@ -460,6 +466,7 @@ async fn create_subgraph_version<C: Blockchain, S: SubgraphStore, AC: amp::Clien
460466
resolver: &Arc<dyn LinkResolver>,
461467
amp_client: Option<Arc<AC>>,
462468
history_blocks_override: Option<i32>,
469+
amp_chain_names: &AmpChainNames,
463470
) -> Result<DeploymentLocator, SubgraphRegistrarError> {
464471
let raw_string = serde_yaml::to_string(&raw).unwrap();
465472

@@ -488,9 +495,10 @@ async fn create_subgraph_version<C: Blockchain, S: SubgraphStore, AC: amp::Clien
488495
.map_err(SubgraphRegistrarError::ManifestValidationError)?;
489496

490497
let network_name: Word = manifest.network_name().into();
498+
let resolved_name = amp_chain_names.resolve(&network_name);
491499

492500
let chain = chains
493-
.get::<C>(network_name.clone())
501+
.get::<C>(resolved_name.clone())
494502
.map_err(SubgraphRegistrarError::NetworkNotSupported)?
495503
.cheap_clone();
496504

@@ -570,7 +578,7 @@ async fn create_subgraph_version<C: Blockchain, S: SubgraphStore, AC: amp::Clien
570578
&manifest.schema,
571579
deployment,
572580
node_id,
573-
network_name.into(),
581+
resolved_name.into(),
574582
version_switching_mode,
575583
)
576584
.await

docs/config.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,9 @@ The configuration for a chain `name` is specified in the section
114114
- `protocol`: the protocol type being indexed, default `ethereum`
115115
(alternatively `near`, `cosmos`,`arweave`,`starknet`)
116116
- `polling_interval`: the polling interval for the block ingestor (default 500ms)
117+
- `amp`: the network name used by AMP for this chain; defaults to the chain name.
118+
Set this when AMP uses a different name than graph-node (e.g., `amp = "ethereum-mainnet"`
119+
on a chain named `mainnet`).
117120
- `provider`: a list of providers for that chain
118121

119122
A `provider` is an object with the following characteristics:
@@ -164,6 +167,7 @@ optimisations.
164167
ingestor = "block_ingestor_node"
165168
[chains.mainnet]
166169
shard = "vip"
170+
amp = "ethereum-mainnet"
167171
provider = [
168172
{ label = "mainnet1", url = "http://..", features = [], headers = { Authorization = "Bearer foo" } },
169173
{ label = "mainnet2", url = "http://..", features = [ "archive", "traces" ] }

graph/src/components/network_provider/mod.rs

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,60 @@ pub use self::provider_check::ProviderCheckStatus;
1616
pub use self::provider_manager::ProviderCheckStrategy;
1717
pub use self::provider_manager::ProviderManager;
1818

19+
use std::collections::HashMap;
20+
1921
// Used to increase memory efficiency.
2022
// Currently, there is no need to create a separate type for this.
2123
pub type ChainName = crate::data::value::Word;
2224

2325
// Used to increase memory efficiency.
2426
// Currently, there is no need to create a separate type for this.
2527
pub type ProviderName = crate::data::value::Word;
28+
29+
/// Maps AMP network names to internal graph-node chain names.
30+
///
31+
/// AMP-powered subgraphs may use different network names than graph-node
32+
/// (e.g., AMP uses `"ethereum-mainnet"` while graph-node uses `"mainnet"`).
33+
/// This type provides a config-driven translation layer.
34+
#[derive(Clone, Debug, Default)]
35+
pub struct AmpChainNames(HashMap<ChainName, ChainName>);
36+
37+
impl AmpChainNames {
38+
pub fn new(mapping: HashMap<ChainName, ChainName>) -> Self {
39+
AmpChainNames(mapping)
40+
}
41+
42+
/// Returns the internal chain name for an AMP alias, or the input
43+
/// unchanged if no alias matches.
44+
pub fn resolve(&self, name: &ChainName) -> ChainName {
45+
self.0.get(name).cloned().unwrap_or_else(|| name.clone())
46+
}
47+
}
48+
49+
#[cfg(test)]
50+
mod tests {
51+
use super::*;
52+
53+
#[test]
54+
fn amp_chain_names_resolve_known_alias() {
55+
let mut map = HashMap::new();
56+
map.insert(
57+
ChainName::from("ethereum-mainnet"),
58+
ChainName::from("mainnet"),
59+
);
60+
let names = AmpChainNames::new(map);
61+
assert_eq!(
62+
names.resolve(&ChainName::from("ethereum-mainnet")),
63+
ChainName::from("mainnet")
64+
);
65+
}
66+
67+
#[test]
68+
fn amp_chain_names_resolve_unknown_passthrough() {
69+
let names = AmpChainNames::default();
70+
assert_eq!(
71+
names.resolve(&ChainName::from("mainnet")),
72+
ChainName::from("mainnet")
73+
);
74+
}
75+
}

node/resources/tests/full_config.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ ingestor = "index_0"
4545

4646
[chains.mainnet]
4747
shard = "primary"
48+
amp = "ethereum-mainnet"
4849
provider = [
4950
{ label = "mainnet-0", url = "http://rpc.mainnet.io", features = ["archive", "traces"] },
5051
{ label = "mainnet-1", details = { type = "web3call", url = "http://rpc.mainnet.io", features = ["archive", "traces"] }},

0 commit comments

Comments
 (0)