From b4a6d73c443786534966de7abab14efd97f7a349 Mon Sep 17 00:00:00 2001 From: Felix Lange Date: Mon, 6 Mar 2023 20:53:59 +0100 Subject: [PATCH] ethclient: fix panic when requesting missing blocks This fixes a regression introduced by #26723. Fixes #26816. --- ethclient/ethclient.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/ethclient/ethclient.go b/ethclient/ethclient.go index 6f309030bab9..c8353b25ae21 100644 --- a/ethclient/ethclient.go +++ b/ethclient/ethclient.go @@ -113,15 +113,19 @@ func (ec *Client) getBlock(ctx context.Context, method string, args ...interface err := ec.c.CallContext(ctx, &raw, method, args...) if err != nil { return nil, err - } else if len(raw) == 0 { - return nil, ethereum.NotFound } + // Decode header and transactions. var head *types.Header - var body rpcBlock if err := json.Unmarshal(raw, &head); err != nil { return nil, err } + // When the block is not found, the API returns JSON null. + if head == nil { + return nil, ethereum.NotFound + } + + var body rpcBlock if err := json.Unmarshal(raw, &body); err != nil { return nil, err }