Skip to content

Commit

Permalink
eth/tracers: support traceCall with txIndex (#8736)
Browse files Browse the repository at this point in the history
This is a similar PR of
ethereum/go-ethereum#28460, support traceCall in
the middle of a block

Signed-off-by: jsvisa <[email protected]>
  • Loading branch information
jsvisa authored Nov 16, 2023
1 parent 4873502 commit 32d05a3
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
2 changes: 2 additions & 0 deletions eth/tracers/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package tracers
import (
"encoding/json"

"github.com/ledgerwatch/erigon-lib/common/hexutil"
"github.com/ledgerwatch/erigon/eth/tracers/logger"
"github.com/ledgerwatch/erigon/turbo/adapter/ethapi"
)
Expand All @@ -19,4 +20,5 @@ type TraceConfig struct {

BorTraceEnabled *bool
BorTx *bool
TxIndex *hexutil.Uint
}
1 change: 1 addition & 0 deletions turbo/jsonrpc/debug_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package jsonrpc
import (
"context"
"fmt"

"github.com/ledgerwatch/erigon-lib/common/hexutil"

jsoniter "github.com/json-iterator/go"
Expand Down
20 changes: 12 additions & 8 deletions turbo/jsonrpc/tracing.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,27 @@ package jsonrpc
import (
"context"
"fmt"
"github.com/ledgerwatch/erigon-lib/common/hexutil"
"math/big"
"time"

"github.com/holiman/uint256"
jsoniter "github.com/json-iterator/go"
"github.com/ledgerwatch/erigon-lib/common"
"github.com/ledgerwatch/log/v3"

"github.com/ledgerwatch/erigon/core/vm/evmtypes"

"github.com/ledgerwatch/erigon-lib/common/hexutil"
"github.com/ledgerwatch/erigon/common/math"
"github.com/ledgerwatch/erigon/core"
"github.com/ledgerwatch/erigon/core/rawdb"
"github.com/ledgerwatch/erigon/core/state"
"github.com/ledgerwatch/erigon/core/types"
"github.com/ledgerwatch/erigon/core/vm"
"github.com/ledgerwatch/erigon/core/vm/evmtypes"
"github.com/ledgerwatch/erigon/eth/tracers"
"github.com/ledgerwatch/erigon/rpc"
"github.com/ledgerwatch/erigon/turbo/adapter/ethapi"
"github.com/ledgerwatch/erigon/turbo/rpchelper"
"github.com/ledgerwatch/erigon/turbo/transactions"
"github.com/ledgerwatch/log/v3"

jsoniter "github.com/json-iterator/go"
)

// TraceBlockByNumber implements debug_traceBlockByNumber. Returns Geth style block traces.
Expand Down Expand Up @@ -267,7 +266,7 @@ func (api *PrivateDebugAPIImpl) TraceCall(ctx context.Context, args ethapi.CallA
}
engine := api.engine()

blockNumber, hash, _, err := rpchelper.GetBlockNumber(blockNrOrHash, dbtx, api.filters)
blockNumber, hash, isLatest, err := rpchelper.GetBlockNumber(blockNrOrHash, dbtx, api.filters)
if err != nil {
return fmt.Errorf("get block number: %v", err)
}
Expand All @@ -277,7 +276,12 @@ func (api *PrivateDebugAPIImpl) TraceCall(ctx context.Context, args ethapi.CallA
return err
}

stateReader, err := rpchelper.CreateStateReader(ctx, dbtx, blockNrOrHash, 0, api.filters, api.stateCache, api.historyV3(dbtx), chainConfig.ChainName)
var stateReader state.StateReader
if config.TxIndex == nil || isLatest {
stateReader, err = rpchelper.CreateStateReader(ctx, dbtx, blockNrOrHash, 0, api.filters, api.stateCache, api.historyV3(dbtx), chainConfig.ChainName)
} else {
stateReader, err = rpchelper.CreateHistoryStateReader(dbtx, blockNumber, int(*config.TxIndex), api.historyV3(dbtx), chainConfig.ChainName)
}
if err != nil {
return fmt.Errorf("create state reader: %v", err)
}
Expand Down

0 comments on commit 32d05a3

Please sign in to comment.