From 19861d8639055d826a614ad5aa041e12033aad21 Mon Sep 17 00:00:00 2001 From: Delweng Zheng Date: Wed, 17 Oct 2018 10:57:21 +0800 Subject: [PATCH] eth: fix an issue when use debug.storageRangeAt apply the transaction with the previous found state --- eth/api.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/eth/api.go b/eth/api.go index 3ec3afb81e..305b7050ba 100644 --- a/eth/api.go +++ b/eth/api.go @@ -34,6 +34,7 @@ import ( "github.com/ethereum/go-ethereum/core/rawdb" "github.com/ethereum/go-ethereum/core/state" "github.com/ethereum/go-ethereum/core/types" + "github.com/ethereum/go-ethereum/core/vm" "github.com/ethereum/go-ethereum/internal/ethapi" "github.com/ethereum/go-ethereum/params" "github.com/ethereum/go-ethereum/rlp" @@ -351,10 +352,20 @@ type storageEntry struct { // StorageRangeAt returns the storage at the given block height and transaction index. func (api *PrivateDebugAPI) StorageRangeAt(ctx context.Context, blockHash common.Hash, txIndex int, contractAddress common.Address, keyStart hexutil.Bytes, maxResult int) (StorageRangeResult, error) { - _, _, statedb, err := api.computeTxEnv(blockHash, txIndex, 0) + msg, context, statedb, err := api.computeTxEnv(blockHash, txIndex, 0) if err != nil { return StorageRangeResult{}, err } + + // execute the tx on top of the current state + vmenv := vm.NewEVM(context, statedb, api.config, vm.Config{}) + if _, _, _, err = core.ApplyMessage(vmenv, msg, new(core.GasPool).AddGas(msg.Gas())); err != nil { + return StorageRangeResult{}, err + } + + // Ensure any modifications are committed to the state + statedb.Finalise(true) + st := statedb.StorageTrie(contractAddress) if st == nil { return StorageRangeResult{}, fmt.Errorf("account %x doesn't exist", contractAddress)