Skip to content

Commit 329c421

Browse files
committed
fix patch
1 parent deb974d commit 329c421

File tree

2 files changed

+27
-24
lines changed

2 files changed

+27
-24
lines changed

evmd/tests/integration/balance_handler/balance_handler_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ func (s *BalanceHandlerTestSuite) TestRecursivePrecompileCallsWithDebugPrecompil
9191
s.Require().NoError(err, "callback transaction should succeed")
9292
s.Require().False(res.IsErr(), "callback should not fail: %s", res.Events)
9393

94-
s.Require().Equal(len(res.Events), 15, "callback should have 15 events")
94+
s.Require().Equal(len(res.Events), 14, "callback should have 14 events")
9595
debug_count := 0
9696
for _, event := range res.Events {
9797
if event.Type == "debug_precompile" {

x/vm/types/response.go

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

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

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-
})
44+
ethTxHashes[response.Hash] = txIndex
5345

5446
if len(response.Logs) > 0 {
5547
for _, log := range response.Logs {
@@ -70,21 +62,32 @@ func PatchTxResponses(input []*abci.ExecTxResult) []*abci.ExecTxResult {
7062
txIndex++
7163
}
7264

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
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+
}
7974

80-
if dataDirty {
81-
data, err := proto.Marshal(&txMsgData)
82-
if err != nil {
83-
panic(err)
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+
})
8480
}
81+
}
82+
}
8583

86-
res.Data = data
84+
if dataDirty {
85+
data, err := proto.Marshal(&txMsgData)
86+
if err != nil {
87+
panic(err)
8788
}
89+
90+
res.Data = data
8891
}
8992
}
9093
return input

0 commit comments

Comments
 (0)