Skip to content

Commit

Permalink
fix: allow block_gte constraints below min block of manifest (#430)
Browse files Browse the repository at this point in the history
  • Loading branch information
Theodus authored Nov 27, 2023
1 parent da1a8e1 commit 05c0413
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions graph-gateway/src/client_query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -474,8 +474,19 @@ async fn handle_client_query_inner(
}),
};

// Reject queries for blocks before minimum start block in the manifest.
if matches!(min_block, Some(min_block) if min_block < manifest_min_block) {
// Reject queries for blocks before the minimum start block in the manifest, but only if the
// constraint is for an exact block. For example, we always want to allow `block_gte: 0`.
let request_contains_invalid_blocks = resolved_blocks
.iter()
.filter(|b| {
block_constraints.iter().any(|c| match c {
BlockConstraint::Unconstrained | BlockConstraint::NumberGTE(_) => false,
BlockConstraint::Hash(hash) => hash == &b.hash,
BlockConstraint::Number(number) => number == &b.number,
})
})
.any(|b| b.number < manifest_min_block);
if request_contains_invalid_blocks {
return Err(Error::InvalidQuery(anyhow!(
"Requested block before minimum `startBlock` of manifest: {}",
min_block.unwrap_or_default()
Expand Down

0 comments on commit 05c0413

Please sign in to comment.