[ethereum/go-ethereum] Add AccountRangeAt to debug API (#17438)

gballet commented on this pull request.

> + }
+ result = append(result, common.BytesToAddress(key))
+ }
+ return AccountRangeResult{result}, nil
+}
+
+//block hash or number, tx index, start address hash, max results
+func (api *PrivateDebugAPI) AccountRange(ctx context.Context, blockNr uint64, txIndex int, startAddr *common.Address, maxResults int) (AccountRangeResult, error) {
+ zeros := make([]byte, common.HashLength)
+
+ if bytes.Equal(startAddr[:], zeros) {
+ startAddr = nil
+ }
+
+ blockHash := api.eth.blockchain.GetBlockByNumber(blockNr).Hash()
+ _, _, statedb, err := api.computeTxEnv(blockHash, txIndex, 0)

I had a very quick look, and it seems that the message comes from here:
«`go
block := api.eth.blockchain.GetBlockByHash(blockHash)
if block == nil {
return nil, vm.Context{}, nil, fmt.Errorf(«block %x not found», blockHash)
}
parent := api.eth.blockchain.GetBlock(block.ParentHash(), block.NumberU64()-1)
if parent == nil {
return nil, vm.Context{}, nil, fmt.Errorf(«parent %x not found», block.ParentHash())
}
«`
it seems normal that block 0’s parent will not be found. The `GetBlock` function uses both the hash and the block number to find the parent, and the block number will be invalid.