From 238e47e78a04f8770a7521fffded2bd66db0ef28 Mon Sep 17 00:00:00 2001 From: Zsolt Felfoldi Date: Sun, 9 Jun 2024 14:39:08 +0200 Subject: [PATCH] ethclient/lightclient: return ethereum.NotFound properly --- ethclient/lightclient/chain.go | 19 +++++++++++++------ ethclient/lightclient/lightclient.go | 2 -- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/ethclient/lightclient/chain.go b/ethclient/lightclient/chain.go index cec6eb66c1..6858f12a55 100644 --- a/ethclient/lightclient/chain.go +++ b/ethclient/lightclient/chain.go @@ -272,6 +272,9 @@ func (c *Client) requestHeader(ctx context.Context, hash common.Hash) (*types.He var header *types.Header log.Debug("Starting RPC request", "type", "eth_getBlockByHash", "hash", hash, "full", false) err := c.client.CallContext(ctx, &header, "eth_getBlockByHash", hash, false) + if err == nil && header == nil { + err = ethereum.NotFound + } if err == nil && header.Hash() != hash { header, err = nil, errors.New("header hash does not match") } @@ -287,13 +290,17 @@ func (c *Client) requestBlock(ctx context.Context, hash common.Hash) (*types.Blo log.Debug("Starting RPC request", "type", "eth_getBlockByHash", "hash", hash, "full", true) err := c.client.CallContext(ctx, &raw, "eth_getBlockByHash", hash, true) log.Debug("Finished RPC request", "type", "eth_getBlockByHash", "hash", hash, "full", true, "error", err) - if err == nil { - block, err = decodeBlock(raw) - if block.Hash() != hash { - block, err = nil, errors.New("block hash does not match") - } + if err != nil { + return nil, err } - return block, err + block, err = decodeBlock(raw) // returns ethereum.NotFound if block not found + if err != nil { + return nil, err + } + if block.Hash() != hash { + return nil, errors.New("block hash does not match") + } + return block, nil } func (c *Client) getHeader(ctx context.Context, hash common.Hash) (*types.Header, error) { diff --git a/ethclient/lightclient/lightclient.go b/ethclient/lightclient/lightclient.go index a13957d4aa..27781d7b3f 100644 --- a/ethclient/lightclient/lightclient.go +++ b/ethclient/lightclient/lightclient.go @@ -84,8 +84,6 @@ func NewClient(clConfig config.LightClientConfig, elConfig *params.ChainConfig, return client } -//TODO return ethereum.NotFound error properly - func (c *Client) Start() { c.scheduler.Start() for _, url := range c.clConfig.ApiUrls {