ethclient/lightclient: return ethereum.NotFound properly

This commit is contained in:
Zsolt Felfoldi 2024-06-09 14:39:08 +02:00
parent cd41011cd4
commit 238e47e78a
2 changed files with 13 additions and 8 deletions

View file

@ -272,6 +272,9 @@ func (c *Client) requestHeader(ctx context.Context, hash common.Hash) (*types.He
var header *types.Header var header *types.Header
log.Debug("Starting RPC request", "type", "eth_getBlockByHash", "hash", hash, "full", false) log.Debug("Starting RPC request", "type", "eth_getBlockByHash", "hash", hash, "full", false)
err := c.client.CallContext(ctx, &header, "eth_getBlockByHash", hash, 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 { if err == nil && header.Hash() != hash {
header, err = nil, errors.New("header hash does not match") 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) log.Debug("Starting RPC request", "type", "eth_getBlockByHash", "hash", hash, "full", true)
err := c.client.CallContext(ctx, &raw, "eth_getBlockByHash", hash, 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) log.Debug("Finished RPC request", "type", "eth_getBlockByHash", "hash", hash, "full", true, "error", err)
if err == nil { if err != nil {
block, err = decodeBlock(raw) return nil, err
if block.Hash() != hash {
block, err = nil, errors.New("block hash does not match")
}
} }
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) { func (c *Client) getHeader(ctx context.Context, hash common.Hash) (*types.Header, error) {

View file

@ -84,8 +84,6 @@ func NewClient(clConfig config.LightClientConfig, elConfig *params.ChainConfig,
return client return client
} }
//TODO return ethereum.NotFound error properly
func (c *Client) Start() { func (c *Client) Start() {
c.scheduler.Start() c.scheduler.Start()
for _, url := range c.clConfig.ApiUrls { for _, url := range c.clConfig.ApiUrls {