eth, les: add error when accessing missing block state (#18346)
This change makes getBalance, getCode, getStorageAt, getProof, call, getTransactionCount return an error if the block number in the request doesn't exist. getHeaderByNumber still returns null for missing headers.
This commit is contained in:
committed by
Felix Lange
parent
4c90efdf57
commit
5036992b06
@ -18,6 +18,7 @@ package eth
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"math/big"
|
||||
|
||||
"github.com/ethereum/go-ethereum/accounts"
|
||||
@ -95,9 +96,12 @@ func (b *EthAPIBackend) StateAndHeaderByNumber(ctx context.Context, blockNr rpc.
|
||||
}
|
||||
// Otherwise resolve the block number and return its state
|
||||
header, err := b.HeaderByNumber(ctx, blockNr)
|
||||
if header == nil || err != nil {
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
if header == nil {
|
||||
return nil, nil, errors.New("header not found")
|
||||
}
|
||||
stateDb, err := b.eth.BlockChain().StateAt(header.Root)
|
||||
return stateDb, header, err
|
||||
}
|
||||
|
Reference in New Issue
Block a user