Skip to content
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
2 changes: 1 addition & 1 deletion src/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ impl AuthSettings {
/// Check if any of the deployment's subgraphs is authorized.
///
/// If the set of authorized subgraphs is empty, then any deployment is authorized (including
/// orphaned deployments with no parent subgraphs).
/// unpublished deployments with no parent subgraphs).
pub fn is_any_deployment_subgraph_authorized(&self, subgraphs: &[SubgraphId]) -> bool {
self.authorized_subgraphs.is_empty()
|| subgraphs
Expand Down
12 changes: 6 additions & 6 deletions src/network/pre_processing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,11 +184,11 @@ fn try_into_indexer_raw_info(
})
}

/// Convert orphaned deployments (not linked to any active subgraph) into internal representation.
/// Convert unpublished deployments (not linked to any active subgraph) into internal representation.
///
/// Orphaned deployments have `activeSubgraphCount: 0`. This function filters out deployments
/// Unpublished deployments have `activeSubgraphCount: 0`. This function filters out deployments
/// without a valid manifest or without active allocations.
pub fn into_orphaned_deployments_raw_info(
pub fn into_unpublished_deployments_raw_info(
data: impl Iterator<Item = subgraph_client::types::SubgraphDeployment>,
) -> HashMap<DeploymentId, DeploymentRawInfo> {
data.filter_map(|deployment| {
Expand All @@ -215,16 +215,16 @@ pub fn into_orphaned_deployments_raw_info(
id: deployment.id,
manifest_network: network.clone(),
manifest_start_block: manifest.start_block,
subgraphs: Default::default(), // Empty - orphaned
subgraphs: Default::default(), // Empty - unpublished
allocations,
},
))
})
.collect()
}

/// Extract indexer information from orphaned deployments.
pub fn into_indexers_raw_info_from_orphaned_deployments<'a>(
/// Extract indexer information from unpublished deployments.
pub fn into_indexers_raw_info_from_unpublished_deployments<'a>(
data: impl Iterator<Item = &'a subgraph_client::types::SubgraphDeployment>,
) -> HashMap<IndexerId, IndexerRawInfo> {
let mut indexers = HashMap::new();
Expand Down
21 changes: 11 additions & 10 deletions src/network/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,17 +250,17 @@ fn spawn_updater_task(
/// Fetch the subgraphs information from the graph network subgraph and performs pre-processing
/// steps, i.e., validation and conversion into the internal representation.
///
/// 1. Fetch the subgraphs and orphaned deployments from the graph network subgraph.
/// 1. Fetch the subgraphs and unpublished deployments from the graph network subgraph.
/// 2. Validate and convert the fetched info into the internal representation.
/// 3. Merge orphaned deployments into the deployments map.
/// 3. Merge unpublished deployments into the deployments map.
///
/// If the fetch fails or the response is empty, an error is returned.
///
/// Invalid info is filtered out before converting into the internal representation.
pub async fn fetch_and_preprocess_subgraph_info(
client: &mut SubgraphClient,
) -> anyhow::Result<PreprocessedNetworkInfo> {
// Fetch the subgraphs and orphaned deployments from the graph network subgraph
// Fetch the subgraphs and unpublished deployments from the graph network subgraph
let data = client.fetch().await?;
anyhow::ensure!(!data.subgraphs.is_empty(), "empty subgraph response");

Expand All @@ -269,18 +269,19 @@ pub async fn fetch_and_preprocess_subgraph_info(
let subgraphs = pre_processing::into_internal_subgraphs_raw_info(data.subgraphs.into_iter());
let mut deployments = pre_processing::into_internal_deployments_raw_info(subgraphs.values());

// Pre-process orphaned deployments and merge them
let orphaned_indexers = pre_processing::into_indexers_raw_info_from_orphaned_deployments(
data.orphaned_deployments.iter(),
// Pre-process unpublished deployments and merge them
let unpublished_indexers = pre_processing::into_indexers_raw_info_from_unpublished_deployments(
data.unpublished_deployments.iter(),
);
let unpublished_deployments = pre_processing::into_unpublished_deployments_raw_info(
data.unpublished_deployments.into_iter(),
);
let orphaned_deployments =
pre_processing::into_orphaned_deployments_raw_info(data.orphaned_deployments.into_iter());

for (id, indexer) in orphaned_indexers {
for (id, indexer) in unpublished_indexers {
indexers.entry(id).or_insert(indexer);
}

for (id, deployment) in orphaned_deployments {
for (id, deployment) in unpublished_deployments {
deployments.entry(id).or_insert(deployment);
}

Expand Down
40 changes: 20 additions & 20 deletions src/network/subgraph_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,12 @@ pub struct Client {
pub struct FetchResult {
/// Active subgraphs with their versions and deployments.
pub subgraphs: Vec<Subgraph>,
/// Orphaned deployments (not linked to any active subgraph but with active allocations).
pub orphaned_deployments: Vec<SubgraphDeployment>,
/// Unpublished deployments (not linked to any active subgraph but with active allocations).
pub unpublished_deployments: Vec<SubgraphDeployment>,
}

impl Client {
/// Fetch the list of subgraphs and orphaned deployments from the network subgraph.
/// Fetch the list of subgraphs and unpublished deployments from the network subgraph.
pub async fn fetch(&mut self) -> anyhow::Result<FetchResult> {
for indexer in &self.indexers.clone() {
match self.fetch_from_indexer(indexer).await {
Expand All @@ -159,7 +159,7 @@ impl Client {
) -> anyhow::Result<FetchResult> {
// ref: 9936786a-e286-45f3-9190-8409d8389e88
let query = r#"
query ($block: Block_height!, $first: Int!, $last: String!, $lastOrphaned: String!) {
query ($block: Block_height!, $first: Int!, $last: String!, $lastUnpublished: String!) {
meta: _meta(block: $block) { block { number hash timestamp } }
results: subgraphs(
block: $block
Expand Down Expand Up @@ -197,12 +197,12 @@ impl Client {
}
}
}
orphanedDeployments: subgraphDeployments(
unpublishedDeployments: subgraphDeployments(
block: $block
orderBy: id, orderDirection: asc
first: $first
where: {
id_gt: $lastOrphaned
id_gt: $lastUnpublished
activeSubgraphCount: 0
}
) {
Expand Down Expand Up @@ -238,7 +238,7 @@ impl Client {
pub struct QueryData {
meta: Meta,
results: Vec<Subgraph>,
orphaned_deployments: Vec<SubgraphDeployment>,
unpublished_deployments: Vec<SubgraphDeployment>,
}
#[derive(Debug, Deserialize)]
pub struct Meta {
Expand All @@ -254,13 +254,13 @@ impl Client {
debug_assert!(self.page_size > 0);
let mut query_block: Option<Block> = None;
let mut last_id: Option<String> = None;
let mut last_orphaned_id: Option<String> = None;
let mut last_unpublished_id: Option<String> = None;
let mut subgraphs_done = false;
let mut orphaned_done = false;
let mut unpublished_done = false;
let mut results: Vec<Subgraph> = Default::default();
let mut orphaned_results: Vec<SubgraphDeployment> = Default::default();
let mut unpublished_results: Vec<SubgraphDeployment> = Default::default();

// Pagination uses independent cursors for subgraphs and orphaned deployments. Both
// Pagination uses independent cursors for subgraphs and unpublished deployments. Both
// subqueries are included in every request, even after one completes. When one finishes,
// its cursor remains at the final value causing subsequent queries to return empty results
// for that subquery. This avoids the complexity of dynamically constructing the query string
Expand All @@ -278,7 +278,7 @@ impl Client {
"block": block_height,
"first": self.page_size,
"last": last_id.clone().unwrap_or_default(),
"lastOrphaned": last_orphaned_id.clone().unwrap_or_default(),
"lastUnpublished": last_unpublished_id.clone().unwrap_or_default(),
},
});
let response = self
Expand Down Expand Up @@ -334,18 +334,18 @@ impl Client {
results.append(&mut data.results);
}

if !orphaned_done {
last_orphaned_id = data
.orphaned_deployments
if !unpublished_done {
last_unpublished_id = data
.unpublished_deployments
.last()
.map(|entry| entry.id.to_string());
if data.orphaned_deployments.len() < self.page_size {
orphaned_done = true;
if data.unpublished_deployments.len() < self.page_size {
unpublished_done = true;
}
orphaned_results.append(&mut data.orphaned_deployments);
unpublished_results.append(&mut data.unpublished_deployments);
}

if subgraphs_done && orphaned_done {
if subgraphs_done && unpublished_done {
break;
}
}
Expand All @@ -354,7 +354,7 @@ impl Client {

Ok(FetchResult {
subgraphs: results,
orphaned_deployments: orphaned_results,
unpublished_deployments: unpublished_results,
})
}
}
Loading