Skip to content

Commit

Permalink
Problem: patch cmd may use incorrect tx hash (#587)
Browse files Browse the repository at this point in the history
* Problem: patch cmd may use incorrect tx hash

Solution:
- always recompute tx hash

* Update CHANGELOG.md

* fix type
  • Loading branch information
yihuang authored Jul 15, 2022
1 parent 21b7bc0 commit 76a18ce
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
9 changes: 6 additions & 3 deletions cmd/cronosd/cmd/fix-unlucky-tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -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},
},
}
Expand All @@ -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 {
Expand Down

0 comments on commit 76a18ce

Please sign in to comment.