From cd41c4807511de307309e2014cf98c4153abc8ee Mon Sep 17 00:00:00 2001 From: Victor Pham Date: Wed, 20 Jul 2022 21:48:50 +0700 Subject: [PATCH] fix(evm): `TxIndex` is wrong when trace is the first tx of a block (#1187) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fix TxIndex wrongly when trace first Tx of a block If `Predecessors` is empty, `txConfig.TxIndex` originally = 0 and when it reachs line 401 `txConfig.TxIndex++`, it will becomes 1. It should be 0 * apply suggestion and add change-log * fix comment Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> --- CHANGELOG.md | 1 + x/evm/keeper/grpc_query.go | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2b058690..b1ea114c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -53,6 +53,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Bug Fixes +* (evm) [\#1187](https://github.com/evmos/ethermint/pull/1187) Fix `TxIndex` value (expected 0, actual 1) when trace the first tx of a block via `debug_traceTransaction` api * (rpc) [\#1190](https://github.com/evmos/ethermint/issues/1190) Fix `UnmarshalJSON` panig of breaking EVM and fee market `Params`. * (rpc) [#1179](https://github.com/evmos/ethermint/pull/1179) Fix gas used in traceTransaction response. diff --git a/x/evm/keeper/grpc_query.go b/x/evm/keeper/grpc_query.go index 76b79301..f05b16f1 100644 --- a/x/evm/keeper/grpc_query.go +++ b/x/evm/keeper/grpc_query.go @@ -398,7 +398,10 @@ func (k Keeper) TraceTx(c context.Context, req *types.QueryTraceTxRequest) (*typ tx := req.Msg.AsTransaction() txConfig.TxHash = tx.Hash() - txConfig.TxIndex++ + if len(req.Predecessors) > 0 { + txConfig.TxIndex++ + } + result, _, err := k.traceTx(ctx, cfg, txConfig, signer, tx, req.TraceConfig, false) if err != nil { // error will be returned with detail status from traceTx