Skip to content

Commit a5fd23d

Browse files
committed
try out to revert hash in tx proto
1 parent 41e0bd2 commit a5fd23d

File tree

13 files changed

+281
-163
lines changed

13 files changed

+281
-163
lines changed

ante/evm/11_emit_event.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func EmitTxHashEvent(ctx sdk.Context, msg *evmtypes.MsgEthereumTx, blockTxIndex,
5757
ctx.EventManager().EmitEvent(
5858
sdk.NewEvent(
5959
evmtypes.EventTypeEthereumTx,
60-
sdk.NewAttribute(evmtypes.AttributeKeyEthereumTxHash, msg.Hash().String()),
60+
sdk.NewAttribute(evmtypes.AttributeKeyEthereumTxHash, msg.Hash),
6161
sdk.NewAttribute(evmtypes.AttributeKeyTxIndex, strconv.FormatUint(blockTxIndex+msgIndex, 10)), // #nosec G115
6262
),
6363
)

ante/tx_listener.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func (d TxListenerDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate boo
2727
if ctx.IsCheckTx() && !simulate && d.pendingTxListener != nil {
2828
for _, msg := range tx.GetMsgs() {
2929
if ethTx, ok := msg.(*evmtypes.MsgEthereumTx); ok {
30-
d.pendingTxListener(ethTx.Hash())
30+
d.pendingTxListener(common.HexToHash(ethTx.Hash))
3131
}
3232
}
3333
}

api/cosmos/evm/vm/v1/tx.pulsar.go

Lines changed: 162 additions & 89 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

indexer/kv_indexer.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ func (kv *KVIndexer) IndexBlock(block *cmttypes.Block, txResults []*abci.ExecTxR
8282
var cumulativeGasUsed uint64
8383
for msgIndex, msg := range tx.GetMsgs() {
8484
ethMsg := msg.(*evmtypes.MsgEthereumTx)
85-
txHash := ethMsg.Hash()
85+
txHash := ethMsg.Hash
8686

8787
txResult := servertypes.TxResult{
8888
Height: height,
@@ -112,7 +112,7 @@ func (kv *KVIndexer) IndexBlock(block *cmttypes.Block, txResults []*abci.ExecTxR
112112
txResult.CumulativeGasUsed = cumulativeGasUsed
113113
ethTxIndex++
114114

115-
if err := saveTxResult(kv.clientCtx.Codec, batch, txHash, &txResult); err != nil {
115+
if err := saveTxResult(kv.clientCtx.Codec, batch, common.HexToHash(txHash), &txResult); err != nil {
116116
return errorsmod.Wrapf(err, "IndexBlock %d", height)
117117
}
118118
}

mempool/mempool.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"fmt"
77
"sync"
88

9+
"github.com/ethereum/go-ethereum/common"
910
ethtypes "github.com/ethereum/go-ethereum/core/types"
1011
"github.com/holiman/uint256"
1112

@@ -224,7 +225,7 @@ func (m *ExperimentalEVMMempool) Insert(goCtx context.Context, tx sdk.Tx) error
224225
ethMsg, err := m.getEVMMessage(tx)
225226
if err == nil {
226227
// Insert into EVM pool
227-
hash := ethMsg.Hash()
228+
hash := ethMsg.Hash
228229
m.logger.Debug("inserting EVM transaction", "tx_hash", hash)
229230
ethTxs := []*ethtypes.Transaction{ethMsg.AsTransaction()}
230231
errs := m.txPool.Add(ethTxs, true)
@@ -320,7 +321,7 @@ func (m *ExperimentalEVMMempool) Remove(tx sdk.Tx) error {
320321
// We should not do this with EVM transactions because removing them causes the subsequent ones to
321322
// be dequeued as temporarily invalid, only to be requeued a block later.
322323
// The EVM mempool handles removal based on account nonce automatically.
323-
hash := msg.Hash()
324+
hash := common.HexToHash(msg.Hash)
324325
if m.shouldRemoveFromEVMPool(tx) {
325326
m.logger.Debug("manually removing EVM transaction", "tx_hash", hash)
326327
m.legacyTxPool.RemoveTx(hash, false, true)

proto/cosmos/evm/vm/v1/tx.proto

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ message MsgEthereumTx {
3737

3838
option (gogoproto.goproto_getters) = false;
3939

40-
reserved 1, 2, 3, 4;
40+
reserved 1, 2, 4;
41+
string hash = 3;
4142

4243
// from is the bytes of ethereum signer address. This address value is checked
4344
// against the address derived from the signature (V, R, S) using the

rpc/backend/comet_to_eth.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -237,9 +237,9 @@ func (b *Backend) ReceiptsFromCometBlock(
237237
receipts := make([]*ethtypes.Receipt, len(msgs))
238238
cumulatedGasUsed := uint64(0)
239239
for i, ethMsg := range msgs {
240-
txResult, err := b.GetTxByEthHash(ethMsg.Hash())
240+
txResult, err := b.GetTxByEthHash(common.HexToHash(ethMsg.Hash))
241241
if err != nil {
242-
return nil, fmt.Errorf("tx not found: hash=%s, error=%s", ethMsg.Hash(), err.Error())
242+
return nil, fmt.Errorf("tx not found: hash=%s, error=%s", common.HexToHash(ethMsg.Hash), err.Error())
243243
}
244244

245245
cumulatedGasUsed += txResult.GasUsed
@@ -285,7 +285,7 @@ func (b *Backend) ReceiptsFromCometBlock(
285285
Logs: logs,
286286

287287
// Implementation fields: These fields are added by geth when processing a transaction.
288-
TxHash: ethMsg.Hash(),
288+
TxHash: common.HexToHash(ethMsg.Hash),
289289
ContractAddress: contractAddress,
290290
GasUsed: txResult.GasUsed,
291291
EffectiveGasPrice: effectiveGasPrice,

rpc/backend/tx_info.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func (b *Backend) GetTransactionByHash(txHash common.Hash) (*rpctypes.RPCTransac
6262
// Fallback to find tx index by iterating all valid eth transactions
6363
msgs := b.EthMsgsFromCometBlock(block, blockRes)
6464
for i := range msgs {
65-
if msgs[i].Hash() == txHash {
65+
if msgs[i].Hash == txHash.Hex() {
6666
if i > math.MaxInt32 {
6767
return nil, errors.New("tx index overflow")
6868
}
@@ -113,7 +113,7 @@ func (b *Backend) GetTransactionByHashPending(txHash common.Hash) (*rpctypes.RPC
113113
continue
114114
}
115115

116-
if msg.Hash() == txHash {
116+
if msg.Hash == txHash.Hex() {
117117
// use zero block values since it's not included in a block yet
118118
return rpctypes.NewTransactionFromMsg(
119119
msg,

rpc/backend/tx_info_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ func TestReceiptsFromCometBlock(t *testing.T) {
485485
}
486486
mockIndexer := &MockIndexer{
487487
txResults: map[common.Hash]*servertypes.TxResult{
488-
msgs[0].Hash(): expectedTxResult,
488+
common.HexToHash(msgs[0].Hash): expectedTxResult,
489489
},
490490
}
491491
backend.Indexer = mockIndexer
@@ -497,7 +497,7 @@ func TestReceiptsFromCometBlock(t *testing.T) {
497497
actualTxIndex := receipts[0].TransactionIndex
498498
require.NotEqual(t, uint(0), actualTxIndex)
499499
require.Equal(t, uint(tc.ethTxIndex), actualTxIndex) // #nosec G115
500-
require.Equal(t, msgs[0].Hash(), receipts[0].TxHash)
500+
require.Equal(t, common.HexToHash(msgs[0].Hash), receipts[0].TxHash)
501501
require.Equal(t, big.NewInt(height), receipts[0].BlockNumber)
502502
require.Equal(t, ethtypes.ReceiptStatusSuccessful, receipts[0].Status)
503503
})

tests/integration/rpc/backend/test_call_tx.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ func (s *TestSuite) TestSendRawTransaction() {
376376
bytes, _ := rlp.EncodeToBytes(ethTx.AsTransaction())
377377
return bytes
378378
},
379-
ethTx.Hash(),
379+
common.HexToHash(ethTx.Hash),
380380
errortypes.ErrInvalidRequest.Error(),
381381
false,
382382
},
@@ -391,7 +391,7 @@ func (s *TestSuite) TestSendRawTransaction() {
391391
RegisterBroadcastTx(client, txBytes)
392392
},
393393
func() []byte { return rlpEncodedBz },
394-
ethTx.Hash(),
394+
common.HexToHash(ethTx.Hash),
395395
"",
396396
true,
397397
},

0 commit comments

Comments
 (0)