From 13f047080ed39f9cc0b80d92fd17297a611886af 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 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 }