Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: improve topology access to indexing #577

Merged
merged 1 commit into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions graph-gateway/src/client_query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,8 @@ async fn handle_client_query_inner(
.iter()
.flat_map(move |deployment| {
let id = deployment.id;
deployment.indexers.iter().map(move |indexer| Indexing {
indexer: indexer.id,
deployment.indexers.keys().map(move |indexer| Indexing {
indexer: *indexer,
deployment: id,
})
})
Expand Down
2 changes: 1 addition & 1 deletion graph-gateway/src/indexers/indexing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ async fn update_statuses(
// There can only be one URL per indexer entity in the network subgraph
let mut indexers: HashMap<Address, (Url, Vec<DeploymentId>)> = Default::default();
for deployment in deployments.values() {
for indexer in &deployment.indexers {
for indexer in deployment.indexers.values() {
let (_, deployments) = indexers
.entry(indexer.id)
.or_insert_with(|| (indexer.url.clone(), vec![]));
Expand Down
8 changes: 1 addition & 7 deletions graph-gateway/src/indexings_blocklist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,7 @@ pub fn deployment_indexer_addresses(
) -> Vec<Address> {
deployments
.get(deployment_id)
.map(|deployment| {
deployment
.indexers
.iter()
.map(|indexer| indexer.id)
.collect::<Vec<_>>()
})
.map(|deployment| deployment.indexers.keys().cloned().collect())
.unwrap_or_default()
}

Expand Down
4 changes: 2 additions & 2 deletions graph-gateway/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -485,8 +485,8 @@ async fn write_indexer_inputs(
for (deployment, indexer) in deployments.values().flat_map(|deployment| {
deployment
.indexers
.iter()
.map(move |indexer| (deployment.as_ref(), indexer.as_ref()))
.values()
.map(|indexer| (deployment.as_ref(), indexer.as_ref()))
}) {
let indexing = Indexing {
indexer: indexer.id,
Expand Down
18 changes: 14 additions & 4 deletions graph-gateway/src/topology.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use thegraph::types::{DeploymentId, SubgraphId};
use tokio::sync::RwLock;
use toolshed::url::Url;

use gateway_common::types::GRT;
use gateway_common::types::{Indexing, GRT};
use gateway_framework::{ipfs, network::network_subgraph};

/// Representation of the graph network being used to serve queries
Expand Down Expand Up @@ -40,7 +40,7 @@ pub struct Deployment {
pub manifest: Arc<Manifest>,
/// An indexer may have multiple active allocations on a deployment. We collapse them into a
/// single logical allocation using the largest allocation ID and sum of the allocated tokens.
pub indexers: Vec<Arc<Indexer>>,
pub indexers: HashMap<Address, Arc<Indexer>>,
/// A deployment may be associated with multiple subgraphs.
pub subgraphs: BTreeSet<SubgraphId>,
/// Indicates that the deployment should not be served directly by this gateway. This will
Expand Down Expand Up @@ -113,7 +113,7 @@ impl GraphNetwork {
.values()
.flat_map(|subgraph| &subgraph.deployments)
.flat_map(|deployment| &deployment.indexers)
.map(|indexer| (indexer.id, indexer.clone()))
.map(|(id, indexer)| (*id, indexer.clone()))
.collect::<HashMap<Address, Arc<Indexer>>>()
.into()
});
Expand Down Expand Up @@ -207,7 +207,7 @@ impl GraphNetwork {
indexer.allocated_tokens = total_allocation;
Some(indexer)
})
.map(Arc::new)
.map(|indexer| (indexer.id, indexer.into()))
.collect();

// abf62a6d-c071-4507-b528-ddc8e250127a
Expand All @@ -232,6 +232,16 @@ impl GraphNetwork {
pub fn deployment_by_id(&self, id: &DeploymentId) -> Option<Arc<Deployment>> {
self.deployments.value_immediate()?.get(id).cloned()
}

// Get then indexer data for some deployment.
pub fn indexing(&self, indexing: &Indexing) -> Option<Arc<Indexer>> {
self.deployments
.value_immediate()?
.get(&indexing.deployment)?
.indexers
.get(&indexing.indexer)
.cloned()
}
}

struct IpfsCache {
Expand Down
Loading