Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ Ref: https://keepachangelog.com/en/1.0.0/

### Bug Fixes

* (core/04-channel/v2) [\#9078](https://github.com/cosmos/ibc-go/pull/9078) Use a fresh cached context for the application callbacks in `MsgRecvPacket` so the core `recv_packet` events are no longer emitted twice on success, and are no longer re-emitted as error events when an application fails.
* (core/02-client) [\#9080](https://github.com/cosmos/ibc-go/pull/9080) Return an error from `RecoverClient` when the substitute client is of a different client type than the subject instead of panicking in the subject light client module.
* (apps/pfm) [\#9006](https://github.com/cosmos/ibc-go/pull/9006) fix(apps/pfm): remove legacy params before the v3 to v4 migration
* (apps/rate-limiting) [\#8767](https://github.com/cosmos/ibc-go/pull/8767) Fix string conflict in rate-limiting prefix iterator
Expand Down
6 changes: 6 additions & 0 deletions modules/core/04-channel/v2/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ func (k *Keeper) RecvPacket(goCtx context.Context, msg *types.MsgRecvPacket) (*t
AppAcknowledgements: [][]byte{},
}

// Use a fresh cached context for the application callbacks so that the
// TAO state and events written above are not written (and emitted) a
// second time, and so that TAO events are not re-emitted as error events
// when an application returns a failure.
cacheCtx, writeFn = ctx.CacheContext()

var isAsync bool
isSuccess := true
for _, pd := range msg.Packet.Payloads {
Expand Down
44 changes: 44 additions & 0 deletions modules/core/04-channel/v2/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ import (
clientv2types "github.com/lfdt-ibc/ibc-go/v11/modules/core/02-client/v2/types"
"github.com/lfdt-ibc/ibc-go/v11/modules/core/04-channel/v2/types"
commitmenttypes "github.com/lfdt-ibc/ibc-go/v11/modules/core/23-commitment/types"
hostv2 "github.com/lfdt-ibc/ibc-go/v11/modules/core/24-host/v2"
ibcerrors "github.com/lfdt-ibc/ibc-go/v11/modules/core/errors"
coretypes "github.com/lfdt-ibc/ibc-go/v11/modules/core/types"
ibctesting "github.com/lfdt-ibc/ibc-go/v11/testing"
mockv1 "github.com/lfdt-ibc/ibc-go/v11/testing/mock"
mockv2 "github.com/lfdt-ibc/ibc-go/v11/testing/mock/v2"
Expand Down Expand Up @@ -709,3 +711,45 @@ func (s *KeeperTestSuite) TestMsgTimeout() {
})
}
}

// TestMsgRecvPacketEventsNotDuplicated ensures that the core packet receipt
// events are emitted exactly once, and are not re-emitted as error events
// when an application callback fails.
func (s *KeeperTestSuite) TestMsgRecvPacketEventsNotDuplicated() {
testCases := []struct {
name string
payload types.Payload
}{
{"success", mockv2.NewMockPayload(mockv2.ModuleNameA, mockv2.ModuleNameB)},
{"application failure", mockv2.NewErrorMockPayload(mockv2.ModuleNameA, mockv2.ModuleNameB)},
}

for _, tc := range testCases {
s.Run(tc.name, func() {
s.SetupTest()

path := ibctesting.NewPath(s.chainA, s.chainB)
path.SetupV2()

packet, err := path.EndpointA.MsgSendPacket(s.chainA.GetTimeoutTimestampSecs(), tc.payload)
s.Require().NoError(err)

packetKey := hostv2.PacketCommitmentKey(packet.SourceClient, packet.Sequence)
proof, proofHeight := path.EndpointA.QueryProof(packetKey)
msg := types.NewMsgRecvPacket(packet, proof, proofHeight, s.chainB.SenderAccount.GetAddress().String())

ctx := s.chainB.GetContext()
_, err = s.chainB.App.GetIBCKeeper().ChannelKeeperV2.RecvPacket(ctx, msg)
s.Require().NoError(err)

eventCounts := make(map[string]int)
for _, event := range ctx.EventManager().Events() {
eventCounts[event.Type]++
}

s.Require().Equal(1, eventCounts[types.EventTypeRecvPacket])
s.Require().Equal(1, eventCounts[types.EventTypeWriteAck])
s.Require().Zero(eventCounts[coretypes.ErrorAttributeKeyPrefix+types.EventTypeRecvPacket])
})
}
}