From 76a18ce6beebc1d6ecf536c4b0030eda3b6d61ec Mon Sep 17 00:00:00 2001 From: yihuang Date: Fri, 15 Jul 2022 16:46:27 +0800 Subject: [PATCH] Problem: patch cmd may use incorrect tx hash (#587) * Problem: patch cmd may use incorrect tx hash Solution: - always recompute tx hash * Update CHANGELOG.md * fix type --- CHANGELOG.md | 1 + cmd/cronosd/cmd/fix-unlucky-tx.go | 9 ++++++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6fc5ad0ca6..3503c89c80 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ - [cronos#503](https://github.com/crypto-org-chain/cronos/pull/503) Fix failed tx are ignored in json-rpc apis (backport #502). - [#526](https://github.com/crypto-org-chain/cronos/pull/526) Fix tendermint duplicated tx issue. - [#584](https://github.com/crypto-org-chain/cronos/pull/584) Validate eth tx hash in ante handler and fix tx hashes returned in some JSON-RPC apis. +- [#587](https://github.com/crypto-org-chain/cronos/pull/587) Unlucky tx patch cmd recompute eth tx hash. ### Improvements diff --git a/cmd/cronosd/cmd/fix-unlucky-tx.go b/cmd/cronosd/cmd/fix-unlucky-tx.go index 6307aa34f3..e086208927 100644 --- a/cmd/cronosd/cmd/fix-unlucky-tx.go +++ b/cmd/cronosd/cmd/fix-unlucky-tx.go @@ -111,14 +111,17 @@ func FixUnluckyTxCmd() *cobra.Command { break } + var hashes []string txIndex++ for msgIndex, msg := range tx.GetMsgs() { ethTxIndex := txIndex + int64(msgIndex) ethTx := msg.(*evmtypes.MsgEthereumTx) + txHash := ethTx.AsTransaction().Hash().Hex() + hashes = append(hashes, txHash) evt := abci.Event{ Type: evmtypes.TypeMsgEthereumTx, Attributes: []abci.EventAttribute{ - {Key: []byte(evmtypes.AttributeKeyEthereumTxHash), Value: []byte(ethTx.Hash), Index: true}, + {Key: []byte(evmtypes.AttributeKeyEthereumTxHash), Value: []byte(txHash), Index: true}, {Key: []byte(evmtypes.AttributeKeyTxIndex), Value: []byte(strconv.FormatInt(ethTxIndex, 10)), Index: true}, }, } @@ -140,8 +143,8 @@ func FixUnluckyTxCmd() *cobra.Command { }); err != nil { return err } - for _, msg := range tx.GetMsgs() { - fmt.Println("patched", height, msg.(*evmtypes.MsgEthereumTx).Hash) + for _, txHash := range hashes { + fmt.Println("patched", height, txHash) } return nil } else if txResult.Code == 0 {