Skip to content

Commit deb974d

Browse files
committed
cleanup
1 parent f5c9459 commit deb974d

File tree

2 files changed

+24
-26
lines changed

2 files changed

+24
-26
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
- [\#774](https://github.com/cosmos/evm/pull/774) Emit proper allowance amount in erc20 event.
2626
- [\#790](https://github.com/cosmos/evm/pull/790) fix panic in historical query due to missing EvmCoinInfo.
2727
- [\#800](https://github.com/cosmos/evm/pull/800) Fix denom exponent validation in virtual fee deduct in vm module.
28+
- [\#812](https://github.com/cosmos/evm/pull/812) Patch evm tx index and log indexes, cleanup EmitTxHashEvent and ResetTransientGasUsed.
2829

2930
## v0.5.0
3031

x/vm/types/response.go

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,11 @@ func PatchTxResponses(input []*abci.ExecTxResult) []*abci.ExecTxResult {
2828
panic(err)
2929
}
3030

31-
var dataDirty bool
32-
ethTxHashes := make(map[string]uint64)
33-
31+
var (
32+
anteEvents []abci.Event
33+
// if the response data is modified and need to be marshaled back
34+
dataDirty bool
35+
)
3436
for i, rsp := range txMsgData.MsgResponses {
3537
var response MsgEthereumTxResponse
3638
if rsp.TypeUrl != "/"+proto.MessageName(&response) {
@@ -41,7 +43,13 @@ func PatchTxResponses(input []*abci.ExecTxResult) []*abci.ExecTxResult {
4143
panic(err)
4244
}
4345

44-
ethTxHashes[response.Hash] = txIndex
46+
anteEvents = append(anteEvents, abci.Event{
47+
Type: EventTypeEthereumTx,
48+
Attributes: []abci.EventAttribute{
49+
{Key: AttributeKeyEthereumTxHash, Value: response.Hash},
50+
{Key: AttributeKeyTxIndex, Value: strconv.FormatUint(txIndex, 10)},
51+
},
52+
})
4553

4654
if len(response.Logs) > 0 {
4755
for _, log := range response.Logs {
@@ -62,32 +70,21 @@ func PatchTxResponses(input []*abci.ExecTxResult) []*abci.ExecTxResult {
6270
txIndex++
6371
}
6472

65-
for i := range res.Events {
66-
if res.Events[i].Type == EventTypeEthereumTx {
67-
var txHash string
68-
for _, attr := range res.Events[i].Attributes {
69-
if attr.Key == AttributeKeyEthereumTxHash {
70-
txHash = attr.Value
71-
break
72-
}
73-
}
73+
if len(anteEvents) > 0 {
74+
// prepend ante events in front to emulate the side effect of `EthEmitEventDecorator`
75+
events := make([]abci.Event, len(anteEvents)+len(res.Events))
76+
copy(events, anteEvents)
77+
copy(events[len(anteEvents):], res.Events)
78+
res.Events = events
7479

75-
if idx, ok := ethTxHashes[txHash]; ok {
76-
res.Events[i].Attributes = append(res.Events[i].Attributes, abci.EventAttribute{
77-
Key: AttributeKeyTxIndex,
78-
Value: strconv.FormatUint(idx, 10),
79-
})
80+
if dataDirty {
81+
data, err := proto.Marshal(&txMsgData)
82+
if err != nil {
83+
panic(err)
8084
}
81-
}
82-
}
8385

84-
if dataDirty {
85-
data, err := proto.Marshal(&txMsgData)
86-
if err != nil {
87-
panic(err)
86+
res.Data = data
8887
}
89-
90-
res.Data = data
9188
}
9289
}
9390
return input

0 commit comments

Comments
 (0)