From 4688d3c8f45cab05329906d96d9c63ba9cd9f398 Mon Sep 17 00:00:00 2001 From: Felix Lange Date: Tue, 7 Mar 2023 11:21:23 +0100 Subject: [PATCH] ethclient: fix panic when requesting missing blocks (#26817) 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 6f309030ba..c8353b25ae 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 }