From 048bc9b0640fcfcdffefb0869f92e9254939e1c6 Mon Sep 17 00:00:00 2001 From: Viraj Bhartiya Date: Fri, 11 Apr 2025 09:57:40 +0530 Subject: [PATCH] eth, debug: make txIndex parameter optional in storageRangeAt --- eth/api_debug.go | 15 +++++++++++++-- internal/web3ext/web3ext.go | 1 + 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/eth/api_debug.go b/eth/api_debug.go index d5e4dda140..7dd69b30eb 100644 --- a/eth/api_debug.go +++ b/eth/api_debug.go @@ -28,6 +28,7 @@ import ( "github.com/ethereum/go-ethereum/core/state" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/crypto" + "github.com/ethereum/go-ethereum/eth/tracers" "github.com/ethereum/go-ethereum/internal/ethapi" "github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/rlp" @@ -210,7 +211,8 @@ type storageEntry struct { } // StorageRangeAt returns the storage at the given block height and transaction index. -func (api *DebugAPI) StorageRangeAt(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash, txIndex int, contractAddress common.Address, keyStart hexutil.Bytes, maxResult int) (StorageRangeResult, error) { +// If txIndex is nil, it returns the storage at the end of the given block. +func (api *DebugAPI) StorageRangeAt(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash, txIndex *int, contractAddress common.Address, keyStart hexutil.Bytes, maxResult int) (StorageRangeResult, error) { var block *types.Block block, err := api.eth.APIBackend.BlockByNumberOrHash(ctx, blockNrOrHash) @@ -220,7 +222,16 @@ func (api *DebugAPI) StorageRangeAt(ctx context.Context, blockNrOrHash rpc.Block if block == nil { return StorageRangeResult{}, fmt.Errorf("block %v not found", blockNrOrHash) } - _, _, statedb, release, err := api.eth.stateAtTransaction(ctx, block, txIndex, 0) + + var statedb *state.StateDB + var release tracers.StateReleaseFunc + + if txIndex != nil { + _, _, statedb, release, err = api.eth.stateAtTransaction(ctx, block, *txIndex, 0) + } else { + statedb, release, err = api.eth.stateAtBlock(ctx, block, 0, nil, true, false) + } + if err != nil { return StorageRangeResult{}, err } diff --git a/internal/web3ext/web3ext.go b/internal/web3ext/web3ext.go index 8ac8f44958..023c8b2bd7 100644 --- a/internal/web3ext/web3ext.go +++ b/internal/web3ext/web3ext.go @@ -419,6 +419,7 @@ web3._extend({ name: 'storageRangeAt', call: 'debug_storageRangeAt', params: 5, + inputFormatter: [null, null, null, null, null] }), new web3._extend.Method({ name: 'getModifiedAccountsByNumber',