eth: return null for not-found in BlockByNumberOrHash

This commit is contained in:
Felix Lange 2025-06-02 15:52:09 +02:00
parent 99c0ed1154
commit 51a802c66e

View file

@ -196,7 +196,9 @@ func (b *EthAPIBackend) BlockByNumberOrHash(ctx context.Context, blockNrOrHash r
if hash, ok := blockNrOrHash.Hash(); ok {
header := b.eth.blockchain.GetHeaderByHash(hash)
if header == nil {
return nil, errors.New("header for hash not found")
// Return 'null' and no error if block is not found.
// This behavior is required by RPC spec.
return nil, nil
}
if blockNrOrHash.RequireCanonical && b.eth.blockchain.GetCanonicalHash(header.Number.Uint64()) != hash {
return nil, errors.New("hash is not currently canonical")