Skip to content

Commit

Permalink
trace to set txnIndex and blockHash (#13294)
Browse files Browse the repository at this point in the history
  • Loading branch information
AskAlexSharov authored Jan 10, 2025
1 parent 334e628 commit b031b35
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
3 changes: 2 additions & 1 deletion polygon/tracer/trace_bor_state_sync_txn.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,10 @@ func TraceBorStateSyncTxnDebugAPI(
stream *jsoniter.Stream,
callTimeout time.Duration,
msgs []*types.Message,
txIndex int,
) (usedGas uint64, err error) {
txCtx := initStateSyncTxContext(blockNum, blockHash)
tracer, streaming, cancel, err := transactions.AssembleTracer(ctx, traceConfig, txCtx.TxHash, stream, callTimeout)
tracer, streaming, cancel, err := transactions.AssembleTracer(ctx, traceConfig, txCtx.TxHash, blockHash, txIndex, stream, callTimeout)
if err != nil {
stream.WriteNil()
return usedGas, err
Expand Down
16 changes: 9 additions & 7 deletions turbo/jsonrpc/tracing.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ func (api *PrivateDebugAPIImpl) traceBlock(ctx context.Context, blockNrOrHash rp
}

var usedGas uint64
for idx, txn := range txns {
for txnIndex, txn := range txns {
isBorStateSyncTxn := borStateSyncTxn == txn
var txnHash common.Hash
if isBorStateSyncTxn {
Expand All @@ -159,7 +159,7 @@ func (api *PrivateDebugAPIImpl) traceBlock(ctx context.Context, blockNrOrHash rp
stream.WriteArrayEnd()
return ctx.Err()
}
ibs.SetTxContext(idx)
ibs.SetTxContext(txnIndex)
msg, _ := txn.AsMessage(*signer, block.BaseFee(), rules)

if msg.FeeCap().IsZero() && engine != nil {
Expand Down Expand Up @@ -196,11 +196,12 @@ func (api *PrivateDebugAPIImpl) traceBlock(ctx context.Context, blockNrOrHash rp
stream,
api.evmCallTimeout,
stateSyncEvents,
txnIndex,
)
usedGas += _usedGas
} else {
var _usedGas uint64
_usedGas, err = transactions.TraceTx(ctx, msg, blockCtx, txCtx, ibs, config, chainConfig, stream, api.evmCallTimeout)
_usedGas, err = transactions.TraceTx(ctx, msg, blockCtx, txCtx, block.Hash(), txnIndex, ibs, config, chainConfig, stream, api.evmCallTimeout)
usedGas += _usedGas
}
if err == nil {
Expand All @@ -214,7 +215,7 @@ func (api *PrivateDebugAPIImpl) traceBlock(ctx context.Context, blockNrOrHash rp
}

stream.WriteObjectEnd()
if idx != len(txns)-1 {
if txnIndex != len(txns)-1 {
stream.WriteMore()
}

Expand Down Expand Up @@ -352,6 +353,7 @@ func (api *PrivateDebugAPIImpl) TraceTransaction(ctx context.Context, hash commo
stream,
api.evmCallTimeout,
stateSyncEvents,
txnIndex,
)
return err
}
Expand All @@ -363,7 +365,7 @@ func (api *PrivateDebugAPIImpl) TraceTransaction(ctx context.Context, hash commo
}

// Trace the transaction and return
_, err = transactions.TraceTx(ctx, msg, blockCtx, txCtx, ibs, config, chainConfig, stream, api.evmCallTimeout)
_, err = transactions.TraceTx(ctx, msg, blockCtx, txCtx, block.Hash(), txnIndex, ibs, config, chainConfig, stream, api.evmCallTimeout)
return err
}

Expand Down Expand Up @@ -432,7 +434,7 @@ func (api *PrivateDebugAPIImpl) TraceCall(ctx context.Context, args ethapi.CallA
blockCtx := transactions.NewEVMBlockContext(engine, header, blockNrOrHash.RequireCanonical, dbtx, api._blockReader, chainConfig)
txCtx := core.NewEVMTxContext(msg)
// Trace the transaction and return
_, err = transactions.TraceTx(ctx, msg, blockCtx, txCtx, ibs, config, chainConfig, stream, api.evmCallTimeout)
_, err = transactions.TraceTx(ctx, msg, blockCtx, txCtx, hash, 0, ibs, config, chainConfig, stream, api.evmCallTimeout)
return err
}

Expand Down Expand Up @@ -570,7 +572,7 @@ func (api *PrivateDebugAPIImpl) TraceCallMany(ctx context.Context, bundles []Bun
}
txCtx = core.NewEVMTxContext(msg)
ibs.SetTxContext(txnIndex)
_, err = transactions.TraceTx(ctx, msg, blockCtx, txCtx, evm.IntraBlockState(), config, chainConfig, stream, api.evmCallTimeout)
_, err = transactions.TraceTx(ctx, msg, blockCtx, txCtx, block.Hash(), txnIndex, evm.IntraBlockState(), config, chainConfig, stream, api.evmCallTimeout)
if err != nil {
stream.WriteArrayEnd()
stream.WriteArrayEnd()
Expand Down
8 changes: 6 additions & 2 deletions turbo/transactions/tracing.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,15 @@ func TraceTx(
message core.Message,
blockCtx evmtypes.BlockContext,
txCtx evmtypes.TxContext,
blockHash libcommon.Hash,
txnIndex int,
ibs evmtypes.IntraBlockState,
config *tracersConfig.TraceConfig,
chainConfig *chain.Config,
stream *jsoniter.Stream,
callTimeout time.Duration,
) (usedGas uint64, err error) {
tracer, streaming, cancel, err := AssembleTracer(ctx, config, txCtx.TxHash, stream, callTimeout)
tracer, streaming, cancel, err := AssembleTracer(ctx, config, txCtx.TxHash, blockHash, txnIndex, stream, callTimeout)
if err != nil {
stream.WriteNil()
return 0, err
Expand All @@ -134,6 +136,8 @@ func AssembleTracer(
ctx context.Context,
config *tracersConfig.TraceConfig,
txHash libcommon.Hash,
blockHash libcommon.Hash,
txnIndex int,
stream *jsoniter.Stream,
callTimeout time.Duration,
) (vm.EVMLogger, bool, context.CancelFunc, error) {
Expand All @@ -155,7 +159,7 @@ func AssembleTracer(
if config != nil && config.TracerConfig != nil {
cfg = *config.TracerConfig
}
tracer, err := tracers.New(*config.Tracer, &tracers.Context{TxHash: txHash}, cfg)
tracer, err := tracers.New(*config.Tracer, &tracers.Context{TxHash: txHash, TxIndex: txnIndex, BlockHash: blockHash}, cfg)
if err != nil {
return nil, false, func() {}, err
}
Expand Down

0 comments on commit b031b35

Please sign in to comment.