From 597c5d38e9a4c0bc737333c9e51907da3eefa83b Mon Sep 17 00:00:00 2001 From: Sina Mahmoodi Date: Tue, 4 Jan 2022 18:33:12 +0100 Subject: [PATCH] graphql: check header first in blocks query --- graphql/graphql.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/graphql/graphql.go b/graphql/graphql.go index e92f1126f66..711989412b7 100644 --- a/graphql/graphql.go +++ b/graphql/graphql.go @@ -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 }