Skip to content

Commit 9cd19ae

Browse files
s1najagdeep sidhu
authored andcommitted
graphql: check header first in blocks query (ethereum#24190)
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.
1 parent ca1f041 commit 9cd19ae

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

graphql/graphql.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1110,10 +1110,21 @@ func (r *Resolver) Blocks(ctx context.Context, args struct {
11101110
ret := make([]*Block, 0, to-from+1)
11111111
for i := from; i <= to; i++ {
11121112
numberOrHash := rpc.BlockNumberOrHashWithNumber(i)
1113-
ret = append(ret, &Block{
1113+
block := &Block{
11141114
backend: r.backend,
11151115
numberOrHash: &numberOrHash,
1116-
})
1116+
}
1117+
// Resolve the header to check for existence.
1118+
// Note we don't resolve block directly here since it will require an
1119+
// additional network request for light client.
1120+
h, err := block.resolveHeader(ctx)
1121+
if err != nil {
1122+
return nil, err
1123+
} else if h == nil {
1124+
// Blocks after must be non-existent too, break.
1125+
break
1126+
}
1127+
ret = append(ret, block)
11171128
}
11181129
return ret, nil
11191130
}

0 commit comments

Comments
 (0)