Unverified Commit c0d17bca authored by Sina Mahmoodi's avatar Sina Mahmoodi Committed by GitHub

graphql: check header first in blocks query (#24190)

Fixes #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.
parent 66a908c5
No related merge requests found
......@@ -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
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment