Skip to content

Commit bd33f93

Browse files
committed
add fallback
1 parent a98db91 commit bd33f93

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

rpc/backend/blocks.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package backend
22

33
import (
44
"fmt"
5+
"math"
56
"math/big"
67
"strconv"
78

@@ -568,6 +569,7 @@ func (b *Backend) GetBlockReceipts(
568569
result[i], err = b.formatTxReceipt(
569570
msg,
570571
txResult,
572+
resBlock,
571573
blockRes,
572574
blockHash,
573575
)
@@ -582,6 +584,7 @@ func (b *Backend) GetBlockReceipts(
582584
func (b *Backend) formatTxReceipt(
583585
ethMsg *evmtypes.MsgEthereumTx,
584586
txResult *cosmosevmtypes.TxResult,
587+
resBlock *cmtrpctypes.ResultBlock,
585588
blockRes *cmtrpctypes.ResultBlockResults,
586589
blockHeaderHash string,
587590
) (map[string]interface{}, error) {
@@ -626,6 +629,20 @@ func (b *Backend) formatTxReceipt(
626629
b.Logger.Debug("failed to parse logs", "hash", ethMsg.Hash().String(), "error", err.Error())
627630
}
628631

632+
if txResult.EthTxIndex == -1 {
633+
// Fallback to find tx index by iterating all valid eth transactions
634+
msgs := b.EthMsgsFromCometBlock(resBlock, blockRes)
635+
for i := range msgs {
636+
if msgs[i].Hash() == ethTx.Hash() {
637+
if i > math.MaxInt32 {
638+
return nil, errors.New("tx index overflow")
639+
}
640+
txResult.EthTxIndex = int32(i) //#nosec G115 -- checked for int overflow already
641+
break
642+
}
643+
}
644+
}
645+
629646
// return error if still unable to find the eth tx index
630647
if txResult.EthTxIndex == -1 {
631648
return nil, fmt.Errorf("can't find index of ethereum tx")

rpc/backend/tx_info.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ func (b *Backend) GetTransactionReceipt(hash common.Hash) (map[string]interface{
191191

192192
ethMsg := tx.GetMsgs()[res.MsgIndex].(*evmtypes.MsgEthereumTx)
193193
blockHeaderHash := common.BytesToHash(resBlock.Block.Header.Hash()).Hex()
194-
return b.formatTxReceipt(ethMsg, res, blockRes, blockHeaderHash)
194+
return b.formatTxReceipt(ethMsg, res, resBlock, blockRes, blockHeaderHash)
195195
}
196196

197197
// GetTransactionLogs returns the transaction logs identified by hash.

0 commit comments

Comments
 (0)