mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 18:32:23 +00:00
ethclient/lightclient: return ethereum.NotFound properly
This commit is contained in:
parent
cd41011cd4
commit
238e47e78a
2 changed files with 13 additions and 8 deletions
|
|
@ -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
|
||||||
|
}
|
||||||
|
block, err = decodeBlock(raw) // returns ethereum.NotFound if block not found
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
if block.Hash() != hash {
|
if block.Hash() != hash {
|
||||||
block, err = nil, errors.New("block hash does not match")
|
return nil, errors.New("block hash does not match")
|
||||||
}
|
}
|
||||||
}
|
return block, nil
|
||||||
return block, err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
||||||
|
|
|
||||||
|
|
@ -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 {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue