Skip to content

Commit

Permalink
graphql: check header first in blocks query (ethereum#24190)
Browse files Browse the repository at this point in the history
Fixes ethereum#24167

New behaviour is that the endpoint returns results only for available
blocks without returning an error when it doesn't find a block. Note we
skip any block after a non-existent block.

This adds a header fetch for every block in range (even if header
is not needed). Alternatively, we could do the check in every field's
resolver method to avoid this overhead.
  • Loading branch information
s1na authored Jan 5, 2022
1 parent 66a908c commit c0d17bc
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions graphql/graphql.go
Original file line number Diff line number Diff line change
Expand Up @@ -1110,10 +1110,21 @@ func (r *Resolver) Blocks(ctx context.Context, args struct {
ret := make([]*Block, 0, to-from+1)
for i := from; i <= to; i++ {
numberOrHash := rpc.BlockNumberOrHashWithNumber(i)
ret = append(ret, &Block{
block := &Block{
backend: r.backend,
numberOrHash: &numberOrHash,
})
}
// Resolve the header to check for existence.
// Note we don't resolve block directly here since it will require an
// additional network request for light client.
h, err := block.resolveHeader(ctx)
if err != nil {
return nil, err
} else if h == nil {
// Blocks after must be non-existent too, break.
break
}
ret = append(ret, block)
}
return ret, nil
}
Expand Down

0 comments on commit c0d17bc

Please sign in to comment.