Skip to content

Commit 766e5e6

Browse files
authored
fix: wrong TransactionIndex in receipt (#806)
* fix: wrong TransactionIndex in receipt * enable indexer
1 parent 5217b59 commit 766e5e6

4 files changed

Lines changed: 12 additions & 12 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
- [\#687](https://github.com/cosmos/evm/pull/687) Avoid blocking node shutdown when evm indexer is enabled, log startup failures instead of using errgroup.
4949
- [\#689](https://github.com/cosmos/evm/pull/689) Align debug addr for hex address.
5050
- [\#668](https://github.com/cosmos/evm/pull/668) Fix panic in legacy mempool when Reset() was called with a skipped header between old and new block.
51-
- [\#723](https://github.com/cosmos/evm/pull/723) Fix TransactionIndex in receipt generation to use actual EthTxIndex instead of loop index.
51+
- [\#723](https://github.com/cosmos/evm/pull/723), [\#806](https://github.com/cosmos/evm/pull/806) Fix TransactionIndex in receipt generation to use actual EthTxIndex instead of loop index.
5252
- [\#729](https://github.com/cosmos/evm/pull/729) Remove non-deterministic state mutation from EVM pre-blocker.
5353
- [\#725](https://github.com/cosmos/evm/pull/725) Fix inconsistent block hash in json-rpc.
5454
- [\#727](https://github.com/cosmos/evm/pull/727) Avoid nil pointer for `tx evm raw` due to uninitialized EVM coin info.

local_node.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,7 @@ if [[ $overwrite == "y" || $overwrite == "Y" ]]; then
272272
sed -i.bak 's/prometheus-retention-time = "0"/prometheus-retention-time = "1000000000000"/g' "$APP_TOML"
273273
sed -i.bak 's/enabled = false/enabled = true/g' "$APP_TOML"
274274
sed -i.bak 's/enable = false/enable = true/g' "$APP_TOML"
275+
sed -i.bak 's/enable-indexer = false/enable-indexer = true/g' "$APP_TOML"
275276

276277
# --------- maybe generate additional users ---------
277278
# start with provided/default list

rpc/backend/comet_to_eth.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ func (b *Backend) ReceiptsFromCometBlock(
296296
// transaction corresponding to this receipt.
297297
BlockHash: blockHash,
298298
BlockNumber: big.NewInt(resBlock.Block.Height),
299-
TransactionIndex: uint(i), // #nosec G115 -- no overflow here
299+
TransactionIndex: uint(txResult.EthTxIndex), // #nosec G115 -- checked for int overflow already
300300
}
301301

302302
receipts[i] = receipt

rpc/backend/tx_info_test.go

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -467,21 +467,20 @@ func TestReceiptsFromCometBlock(t *testing.T) {
467467
}
468468
tcs := []struct {
469469
name string
470-
ethTxIndex int
470+
ethTxIndex int32
471471
}{
472472
{"tx_with_index_5", 5},
473473
{"tx_with_index_10", 10},
474474
}
475475
for _, tc := range tcs {
476476
t.Run(tc.name, func(t *testing.T) {
477-
var msgs []*evmtypes.MsgEthereumTx
478-
for range tc.ethTxIndex + 1 {
479-
msgs = append(msgs, buildMsgEthereumTx(t))
477+
msgs := []*evmtypes.MsgEthereumTx{
478+
buildMsgEthereumTx(t),
480479
}
481480
expectedTxResult := &servertypes.TxResult{
482481
Height: height,
483482
TxIndex: 0,
484-
EthTxIndex: int32(tc.ethTxIndex), // #nosec G115 -- no overflow here
483+
EthTxIndex: tc.ethTxIndex,
485484
MsgIndex: 0,
486485
}
487486
mockIndexer := &MockIndexer{
@@ -494,13 +493,13 @@ func TestReceiptsFromCometBlock(t *testing.T) {
494493
mockEVMQueryClient.On("BaseFee", mock.Anything, mock.Anything).Return(&evmtypes.QueryBaseFeeResponse{}, nil)
495494
receipts, err := backend.ReceiptsFromCometBlock(resBlock, blockRes, msgs)
496495
require.NoError(t, err)
497-
require.Len(t, receipts, tc.ethTxIndex+1)
498-
actualTxIndex := receipts[tc.ethTxIndex].TransactionIndex
496+
require.Len(t, receipts, 1)
497+
actualTxIndex := receipts[0].TransactionIndex
499498
require.NotEqual(t, uint(0), actualTxIndex)
500499
require.Equal(t, uint(tc.ethTxIndex), actualTxIndex) // #nosec G115
501-
require.Equal(t, msgs[tc.ethTxIndex].Hash(), receipts[tc.ethTxIndex].TxHash)
502-
require.Equal(t, big.NewInt(height), receipts[tc.ethTxIndex].BlockNumber)
503-
require.Equal(t, ethtypes.ReceiptStatusSuccessful, receipts[tc.ethTxIndex].Status)
500+
require.Equal(t, msgs[0].Hash(), receipts[0].TxHash)
501+
require.Equal(t, big.NewInt(height), receipts[0].BlockNumber)
502+
require.Equal(t, ethtypes.ReceiptStatusSuccessful, receipts[0].Status)
504503
})
505504
}
506505
}

0 commit comments

Comments
 (0)