Skip to content

Commit

Permalink
fix: make L2 transfer decision consistent across client query params
Browse files Browse the repository at this point in the history
  • Loading branch information
Theodus committed Aug 30, 2023
1 parent d7c0c2a commit d0220b3
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 23 deletions.
40 changes: 18 additions & 22 deletions graph-gateway/src/client_query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,34 +140,30 @@ pub async fn handle_query(
.context("Invalid auth");

let resolved_deployments = resolve_subgraph_deployments(&ctx.network, &params).await;
// Forward query to L2 gateway if subgraph has transferred to L2. On deployment queries, only
// forward when deployments also have no allocations. We only resolve a subgraph when a subgraph
// ID is given as a URL param.
// We only resolve a subgraph when a subgraph ID is given as a URL param.
let subgraph = resolved_deployments
.as_ref()
.ok()
.and_then(|(_, s)| s.as_ref());
let l2_subgraph_id = subgraph.and_then(|s| s.l2_id);
let deployments_migrated = ctx.l2_gateway.is_some()
&& matches!(

if let Some(l2_url) = ctx.l2_gateway.as_ref() {
// Forward query to L2 gateway if it's marked as transferred & there are no allocations.
// abf62a6d-c071-4507-b528-ddc8e250127a
let transferred_to_l2 = matches!(
resolved_deployments.as_ref(),
Ok((deployments, _)) if deployments.iter().all(|d| d.indexers.is_empty()),
Ok((deployments, _)) if deployments.iter().all(|d| d.transferred_to_l2),
);

if l2_subgraph_id.is_some() || (subgraph.is_none() && deployments_migrated) {
// We validate the configuration correctness at startup: L2 transfer redirection requires
// the L2 gateway URL to be configured.
// be8f0ed1-262e-426f-877a-613368eed3ca
let l2_url = ctx.l2_gateway.as_ref().unwrap();
return forward_request_to_l2(
&ctx.indexer_client.client,
l2_url,
&original_uri,
headers,
payload,
l2_subgraph_id,
)
.await;
if transferred_to_l2 {
return forward_request_to_l2(
&ctx.indexer_client.client,
l2_url,
&original_uri,
headers,
payload,
subgraph.and_then(|s| s.l2_id),
)
.await;
}
}

// This is very useful for investigating gateway logs in production.
Expand Down
1 change: 1 addition & 0 deletions graph-gateway/src/topology.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ impl GraphNetwork {
.map(Arc::new)
.collect();

// abf62a6d-c071-4507-b528-ddc8e250127a
let transferred_to_l2 = version.subgraph_deployment.transferred_to_l2
&& version.subgraph_deployment.allocations.is_empty();

Expand Down
1 change: 0 additions & 1 deletion indexer-selection/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,6 @@ fn favor_higher_version() {
};

let candidates: Vec<Indexing> = (0..2)
.into_iter()
.map(|i| Indexing {
indexer: bytes_from_id(0).into(),
deployment: DeploymentId(bytes_from_id(i).into()),
Expand Down

0 comments on commit d0220b3

Please sign in to comment.