diff --git a/modules/core/04-channel/keeper/events.go b/modules/core/04-channel/keeper/events.go index 5b1b2c9f951..ff277a463bd 100644 --- a/modules/core/04-channel/keeper/events.go +++ b/modules/core/04-channel/keeper/events.go @@ -271,8 +271,8 @@ func emitChannelClosedEvent(ctx sdk.Context, packet exported.PacketI, channel ty }) } -// emitChannelUpgradeInitEvent emits a channel upgrade init event -func emitChannelUpgradeInitEvent(ctx sdk.Context, portID string, channelID string, currentChannel types.Channel, upgrade types.Upgrade) { +// EmitChannelUpgradeInitEvent emits a channel upgrade init event +func EmitChannelUpgradeInitEvent(ctx sdk.Context, portID string, channelID string, currentChannel types.Channel, upgrade types.Upgrade) { ctx.EventManager().EmitEvents(sdk.Events{ sdk.NewEvent( types.EventTypeChannelUpgradeInit, @@ -292,8 +292,8 @@ func emitChannelUpgradeInitEvent(ctx sdk.Context, portID string, channelID strin }) } -// emitChannelUpgradeTryEvent emits a channel upgrade try event -func emitChannelUpgradeTryEvent(ctx sdk.Context, portID string, channelID string, currentChannel types.Channel, upgrade types.Upgrade) { +// EmitChannelUpgradeTryEvent emits a channel upgrade try event +func EmitChannelUpgradeTryEvent(ctx sdk.Context, portID string, channelID string, currentChannel types.Channel, upgrade types.Upgrade) { ctx.EventManager().EmitEvents(sdk.Events{ sdk.NewEvent( types.EventTypeChannelUpgradeTry, @@ -313,8 +313,8 @@ func emitChannelUpgradeTryEvent(ctx sdk.Context, portID string, channelID string }) } -// emitChannelUpgradeAckEvent emits a channel upgrade ack event -func emitChannelUpgradeAckEvent(ctx sdk.Context, portID string, channelID string, currentChannel types.Channel, upgrade types.Upgrade) { +// EmitChannelUpgradeAckEvent emits a channel upgrade ack event +func EmitChannelUpgradeAckEvent(ctx sdk.Context, portID string, channelID string, currentChannel types.Channel, upgrade types.Upgrade) { ctx.EventManager().EmitEvents(sdk.Events{ sdk.NewEvent( types.EventTypeChannelUpgradeAck, @@ -334,8 +334,8 @@ func emitChannelUpgradeAckEvent(ctx sdk.Context, portID string, channelID string }) } -// emitChannelUpgradeConfirmEvent emits a channel upgrade confirm event -func emitChannelUpgradeConfirmEvent(ctx sdk.Context, portID, channelID string, currentChannel types.Channel) { +// EmitChannelUpgradeConfirmEvent emits a channel upgrade confirm event +func EmitChannelUpgradeConfirmEvent(ctx sdk.Context, portID, channelID string, currentChannel types.Channel) { ctx.EventManager().EmitEvents(sdk.Events{ sdk.NewEvent( types.EventTypeChannelUpgradeConfirm, @@ -353,8 +353,8 @@ func emitChannelUpgradeConfirmEvent(ctx sdk.Context, portID, channelID string, c }) } -// emitChannelUpgradeOpenEvent emits a channel upgrade open event -func emitChannelUpgradeOpenEvent(ctx sdk.Context, portID string, channelID string, currentChannel types.Channel) { +// EmitChannelUpgradeOpenEvent emits a channel upgrade open event +func EmitChannelUpgradeOpenEvent(ctx sdk.Context, portID string, channelID string, currentChannel types.Channel) { ctx.EventManager().EmitEvents(sdk.Events{ sdk.NewEvent( types.EventTypeChannelUpgradeOpen, @@ -375,8 +375,8 @@ func emitChannelUpgradeOpenEvent(ctx sdk.Context, portID string, channelID strin }) } -// emitChannelUpgradeTimeoutEvent emits an upgrade timeout event. -func emitChannelUpgradeTimeoutEvent(ctx sdk.Context, portID string, channelID string, currentChannel types.Channel, upgrade types.Upgrade) { +// EmitChannelUpgradeTimeoutEvent emits an upgrade timeout event. +func EmitChannelUpgradeTimeoutEvent(ctx sdk.Context, portID string, channelID string, currentChannel types.Channel, upgrade types.Upgrade) { ctx.EventManager().EmitEvents(sdk.Events{ sdk.NewEvent( types.EventTypeChannelUpgradeTimeout, @@ -397,8 +397,8 @@ func emitChannelUpgradeTimeoutEvent(ctx sdk.Context, portID string, channelID st }) } -// emitErrorReceiptEvent emits an error receipt event -func emitErrorReceiptEvent(ctx sdk.Context, portID string, channelID string, currentChannel types.Channel, err error) { +// EmitErrorReceiptEvent emits an error receipt event +func EmitErrorReceiptEvent(ctx sdk.Context, portID string, channelID string, currentChannel types.Channel, err error) { ctx.EventManager().EmitEvents(sdk.Events{ sdk.NewEvent( types.EventTypeChannelUpgradeError, @@ -416,8 +416,8 @@ func emitErrorReceiptEvent(ctx sdk.Context, portID string, channelID string, cur }) } -// emitChannelUpgradeCancelEvent emits an upgraded cancelled event. -func emitChannelUpgradeCancelEvent(ctx sdk.Context, portID string, channelID string, currentChannel types.Channel, upgrade types.Upgrade) { +// EmitChannelUpgradeCancelEvent emits an upgraded cancelled event. +func EmitChannelUpgradeCancelEvent(ctx sdk.Context, portID string, channelID string, currentChannel types.Channel, upgrade types.Upgrade) { ctx.EventManager().EmitEvents(sdk.Events{ sdk.NewEvent( types.EventTypeChannelUpgradeCancel, diff --git a/modules/core/04-channel/keeper/upgrade.go b/modules/core/04-channel/keeper/upgrade.go index 114a8ae888d..032df164637 100644 --- a/modules/core/04-channel/keeper/upgrade.go +++ b/modules/core/04-channel/keeper/upgrade.go @@ -46,7 +46,7 @@ func (k Keeper) ChanUpgradeInit( // WriteUpgradeInitChannel writes a channel which has successfully passed the UpgradeInit handshake step. // An event is emitted for the handshake step. -func (k Keeper) WriteUpgradeInitChannel(ctx sdk.Context, portID, channelID string, upgrade types.Upgrade) types.Channel { +func (k Keeper) WriteUpgradeInitChannel(ctx sdk.Context, portID, channelID string, upgrade types.Upgrade, upgradeVersion string) (types.Channel, types.Upgrade) { defer telemetry.IncrCounter(1, "ibc", "channel", "upgrade-init") channel, found := k.GetChannel(ctx, portID, channelID) @@ -56,13 +56,14 @@ func (k Keeper) WriteUpgradeInitChannel(ctx sdk.Context, portID, channelID strin channel.UpgradeSequence++ + upgrade.Fields.Version = upgradeVersion + k.SetChannel(ctx, portID, channelID, channel) k.SetUpgrade(ctx, portID, channelID, upgrade) k.Logger(ctx).Info("channel state updated", "port-id", portID, "channel-id", channelID, "state", channel.State, "upgrade-sequence", fmt.Sprintf("%d", channel.UpgradeSequence)) - emitChannelUpgradeInitEvent(ctx, portID, channelID, channel, upgrade) - return channel + return channel, upgrade } // ChanUpgradeTry is called by a module to accept the first step of a channel upgrade handshake initiated by @@ -77,23 +78,23 @@ func (k Keeper) ChanUpgradeTry( proofCounterpartyChannel, proofCounterpartyUpgrade []byte, proofHeight clienttypes.Height, -) (types.Upgrade, error) { +) (types.Channel, types.Upgrade, error) { channel, found := k.GetChannel(ctx, portID, channelID) if !found { - return types.Upgrade{}, errorsmod.Wrapf(types.ErrChannelNotFound, "port ID (%s) channel ID (%s)", portID, channelID) + return types.Channel{}, types.Upgrade{}, errorsmod.Wrapf(types.ErrChannelNotFound, "port ID (%s) channel ID (%s)", portID, channelID) } if !channel.IsOpen() { - return types.Upgrade{}, errorsmod.Wrapf(types.ErrInvalidChannelState, "expected %s, got %s", types.OPEN, channel.State) + return types.Channel{}, types.Upgrade{}, errorsmod.Wrapf(types.ErrInvalidChannelState, "expected %s, got %s", types.OPEN, channel.State) } connection, found := k.connectionKeeper.GetConnection(ctx, channel.ConnectionHops[0]) if !found { - return types.Upgrade{}, errorsmod.Wrap(connectiontypes.ErrConnectionNotFound, channel.ConnectionHops[0]) + return types.Channel{}, types.Upgrade{}, errorsmod.Wrap(connectiontypes.ErrConnectionNotFound, channel.ConnectionHops[0]) } if connection.GetState() != int32(connectiontypes.OPEN) { - return types.Upgrade{}, errorsmod.Wrapf( + return types.Channel{}, types.Upgrade{}, errorsmod.Wrapf( connectiontypes.ErrInvalidConnectionState, "connection state is not OPEN (got %s)", connectiontypes.State(connection.GetState()).String(), ) } @@ -127,14 +128,14 @@ func (k Keeper) ChanUpgradeTry( // NOTE: OnChanUpgradeInit will not be executed by the application upgrade, err = k.ChanUpgradeInit(ctx, portID, channelID, proposedUpgradeFields) if err != nil { - return types.Upgrade{}, errorsmod.Wrap(err, "failed to initialize upgrade") + return types.Channel{}, types.Upgrade{}, errorsmod.Wrap(err, "failed to initialize upgrade") } - channel = k.WriteUpgradeInitChannel(ctx, portID, channelID, upgrade) + channel, upgrade = k.WriteUpgradeInitChannel(ctx, portID, channelID, upgrade, upgrade.Fields.Version) } if err := k.checkForUpgradeCompatibility(ctx, proposedUpgradeFields, counterpartyUpgradeFields); err != nil { - return types.Upgrade{}, errorsmod.Wrap(err, "failed upgrade compatibility check") + return types.Channel{}, types.Upgrade{}, errorsmod.Wrap(err, "failed upgrade compatibility check") } // construct expected counterparty channel from information in state @@ -158,11 +159,11 @@ func (k Keeper) ChanUpgradeTry( channel.Counterparty.ChannelId, counterpartyChannel, ); err != nil { - return types.Upgrade{}, errorsmod.Wrap(err, "failed to verify counterparty channel state") + return types.Channel{}, types.Upgrade{}, errorsmod.Wrap(err, "failed to verify counterparty channel state") } if counterpartyUpgradeSequence < channel.UpgradeSequence { - return upgrade, types.NewUpgradeError(channel.UpgradeSequence-1, errorsmod.Wrapf( + return channel, upgrade, types.NewUpgradeError(channel.UpgradeSequence-1, errorsmod.Wrapf( types.ErrInvalidUpgradeSequence, "counterparty upgrade sequence < current upgrade sequence (%d < %d)", counterpartyUpgradeSequence, channel.UpgradeSequence, )) } @@ -176,14 +177,14 @@ func (k Keeper) ChanUpgradeTry( channel.Counterparty.ChannelId, types.NewUpgrade(counterpartyUpgradeFields, types.Timeout{}), ); err != nil { - return types.Upgrade{}, errorsmod.Wrap(err, "failed to verify counterparty upgrade") + return types.Channel{}, types.Upgrade{}, errorsmod.Wrap(err, "failed to verify counterparty upgrade") } if err := k.startFlushing(ctx, portID, channelID, &upgrade); err != nil { - return types.Upgrade{}, err + return types.Channel{}, types.Upgrade{}, err } - return upgrade, nil + return channel, upgrade, nil } // WriteUpgradeTryChannel writes the channel end and upgrade to state after successfully passing the UpgradeTry handshake step. @@ -200,7 +201,6 @@ func (k Keeper) WriteUpgradeTryChannel(ctx sdk.Context, portID, channelID string k.SetUpgrade(ctx, portID, channelID, upgrade) k.Logger(ctx).Info("channel state updated", "port-id", portID, "channel-id", channelID, "previous-state", types.OPEN, "new-state", channel.State) - emitChannelUpgradeTryEvent(ctx, portID, channelID, channel, upgrade) return channel, upgrade } @@ -313,7 +313,7 @@ func (k Keeper) ChanUpgradeAck( // WriteUpgradeAckChannel writes a channel which has successfully passed the UpgradeAck handshake step as well as // setting the upgrade for that channel. // An event is emitted for the handshake step. -func (k Keeper) WriteUpgradeAckChannel(ctx sdk.Context, portID, channelID string, counterpartyUpgrade types.Upgrade) { +func (k Keeper) WriteUpgradeAckChannel(ctx sdk.Context, portID, channelID string, counterpartyUpgrade types.Upgrade) (types.Channel, types.Upgrade) { defer telemetry.IncrCounter(1, "ibc", "channel", "upgrade-ack") channel, found := k.GetChannel(ctx, portID, channelID) @@ -340,7 +340,7 @@ func (k Keeper) WriteUpgradeAckChannel(ctx sdk.Context, portID, channelID string k.SetUpgrade(ctx, portID, channelID, upgrade) k.Logger(ctx).Info("channel state updated", "port-id", portID, "channel-id", channelID, "state", channel.State.String()) - emitChannelUpgradeAckEvent(ctx, portID, channelID, channel, upgrade) + return channel, upgrade } // ChanUpgradeConfirm is called on the chain which is on FLUSHING after chanUpgradeAck is called on the counterparty. @@ -421,7 +421,7 @@ func (k Keeper) ChanUpgradeConfirm( // If the channel has no in-flight packets, its state is updated to indicate that flushing has completed. Otherwise, the counterparty upgrade is set // and the channel state is left unchanged. // An event is emitted for the handshake step. -func (k Keeper) WriteUpgradeConfirmChannel(ctx sdk.Context, portID, channelID string, counterpartyUpgrade types.Upgrade) { +func (k Keeper) WriteUpgradeConfirmChannel(ctx sdk.Context, portID, channelID string, counterpartyUpgrade types.Upgrade) types.Channel { defer telemetry.IncrCounter(1, "ibc", "channel", "upgrade-confirm") channel, found := k.GetChannel(ctx, portID, channelID) @@ -440,8 +440,7 @@ func (k Keeper) WriteUpgradeConfirmChannel(ctx sdk.Context, portID, channelID st // this gets read when timing out and acknowledging packets. k.SetCounterpartyUpgrade(ctx, portID, channelID, counterpartyUpgrade) } - - emitChannelUpgradeConfirmEvent(ctx, portID, channelID, channel) + return channel } // ChanUpgradeOpen is called by a module to complete the channel upgrade handshake and move the channel back to an OPEN state. @@ -530,7 +529,7 @@ func (k Keeper) ChanUpgradeOpen( // WriteUpgradeOpenChannel writes the agreed upon upgrade fields to the channel, and sets the channel state back to OPEN. This can be called in one of two cases: // - In the UpgradeConfirm step of the handshake if both sides have already flushed all in-flight packets. // - In the UpgradeOpen step of the handshake. -func (k Keeper) WriteUpgradeOpenChannel(ctx sdk.Context, portID, channelID string) { +func (k Keeper) WriteUpgradeOpenChannel(ctx sdk.Context, portID, channelID string) types.Channel { channel, found := k.GetChannel(ctx, portID, channelID) if !found { panic(fmt.Errorf("could not find existing channel when updating channel state, channelID: %s, portID: %s", channelID, portID)) @@ -554,7 +553,7 @@ func (k Keeper) WriteUpgradeOpenChannel(ctx sdk.Context, portID, channelID strin k.deleteUpgradeInfo(ctx, portID, channelID) k.Logger(ctx).Info("channel state updated", "port-id", portID, "channel-id", channelID, "previous-state", previousState.String(), "new-state", types.OPEN.String()) - emitChannelUpgradeOpenEvent(ctx, portID, channelID, channel) + return channel } // ChanUpgradeCancel is called by a module to cancel a channel upgrade that is in progress. @@ -636,7 +635,7 @@ func (k Keeper) WriteUpgradeCancelChannel(ctx sdk.Context, portID, channelID str channel = k.restoreChannel(ctx, portID, channelID, errorReceipt.Sequence, channel, types.NewUpgradeError(errorReceipt.Sequence, types.ErrInvalidUpgrade)) k.Logger(ctx).Info("channel state updated", "port-id", portID, "channel-id", channelID, "previous-state", previousState, "new-state", types.OPEN.String()) - emitChannelUpgradeCancelEvent(ctx, portID, channelID, channel, upgrade) + EmitChannelUpgradeCancelEvent(ctx, portID, channelID, channel, upgrade) } // ChanUpgradeTimeout times out an outstanding upgrade. @@ -738,7 +737,7 @@ func (k Keeper) ChanUpgradeTimeout( func (k Keeper) WriteUpgradeTimeoutChannel( ctx sdk.Context, portID, channelID string, -) { +) (types.Channel, types.Upgrade) { defer telemetry.IncrCounter(1, "ibc", "channel", "upgrade-timeout") channel, found := k.GetChannel(ctx, portID, channelID) @@ -754,7 +753,8 @@ func (k Keeper) WriteUpgradeTimeoutChannel( channel = k.restoreChannel(ctx, portID, channelID, channel.UpgradeSequence, channel, types.NewUpgradeError(channel.UpgradeSequence, types.ErrUpgradeTimeout)) k.Logger(ctx).Info("channel state restored", "port-id", portID, "channel-id", channelID) - emitChannelUpgradeTimeoutEvent(ctx, portID, channelID, channel, upgrade) + + return channel, upgrade } // startFlushing will set the upgrade last packet send and continue blocking the upgrade from continuing until all @@ -940,18 +940,7 @@ func (k Keeper) restoreChannel(ctx sdk.Context, portID, channelID string, upgrad // delete state associated with upgrade which is no longer required. k.deleteUpgradeInfo(ctx, portID, channelID) - k.WriteErrorReceipt(ctx, portID, channelID, err) + k.SetUpgradeErrorReceipt(ctx, portID, channelID, err.GetErrorReceipt()) return channel } - -// WriteErrorReceipt will write an error receipt from the provided UpgradeError. -func (k Keeper) WriteErrorReceipt(ctx sdk.Context, portID, channelID string, upgradeError *types.UpgradeError) { - channel, found := k.GetChannel(ctx, portID, channelID) - if !found { - panic(errorsmod.Wrapf(types.ErrChannelNotFound, "port ID (%s) channel ID (%s)", portID, channelID)) - } - - k.SetUpgradeErrorReceipt(ctx, portID, channelID, upgradeError.GetErrorReceipt()) - emitErrorReceiptEvent(ctx, portID, channelID, channel, upgradeError) -} diff --git a/modules/core/04-channel/keeper/upgrade_test.go b/modules/core/04-channel/keeper/upgrade_test.go index 163b6615fb3..ce4462efdb4 100644 --- a/modules/core/04-channel/keeper/upgrade_test.go +++ b/modules/core/04-channel/keeper/upgrade_test.go @@ -7,8 +7,6 @@ import ( errorsmod "cosmossdk.io/errors" - sdk "github.com/cosmos/cosmos-sdk/types" - clienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types" connectiontypes "github.com/cosmos/ibc-go/v8/modules/core/03-connection/types" "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types" @@ -109,31 +107,31 @@ func (suite *KeeperTestSuite) TestChanUpgradeInit() { if tc.expPass { ctx := suite.chainA.GetContext() - suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper.WriteUpgradeInitChannel(ctx, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, upgrade) + suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper.WriteUpgradeInitChannel(ctx, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, upgrade, upgrade.Fields.Version) channel := path.EndpointA.GetChannel() - events := ctx.EventManager().Events().ToABCIEvents() - expEvents := ibctesting.EventsMap{ - types.EventTypeChannelUpgradeInit: { - types.AttributeKeyPortID: path.EndpointA.ChannelConfig.PortID, - types.AttributeKeyChannelID: path.EndpointA.ChannelID, - types.AttributeCounterpartyPortID: path.EndpointB.ChannelConfig.PortID, - types.AttributeCounterpartyChannelID: path.EndpointB.ChannelID, - types.AttributeKeyUpgradeConnectionHops: upgradeFields.ConnectionHops[0], - types.AttributeKeyUpgradeVersion: upgradeFields.Version, - types.AttributeKeyUpgradeOrdering: upgradeFields.Ordering.String(), - types.AttributeKeyUpgradeSequence: fmt.Sprintf("%d", channel.UpgradeSequence), - }, - sdk.EventTypeMessage: { - sdk.AttributeKeyModule: types.AttributeValueCategory, - }, - } + // events := ctx.EventManager().Events().ToABCIEvents() + // expEvents := ibctesting.EventsMap{ + // types.EventTypeChannelUpgradeInit: { + // types.AttributeKeyPortID: path.EndpointA.ChannelConfig.PortID, + // types.AttributeKeyChannelID: path.EndpointA.ChannelID, + // types.AttributeCounterpartyPortID: path.EndpointB.ChannelConfig.PortID, + // types.AttributeCounterpartyChannelID: path.EndpointB.ChannelID, + // types.AttributeKeyUpgradeConnectionHops: upgradeFields.ConnectionHops[0], + // types.AttributeKeyUpgradeVersion: upgradeFields.Version, + // types.AttributeKeyUpgradeOrdering: upgradeFields.Ordering.String(), + // types.AttributeKeyUpgradeSequence: fmt.Sprintf("%d", channel.UpgradeSequence), + // }, + // sdk.EventTypeMessage: { + // sdk.AttributeKeyModule: types.AttributeValueCategory, + // }, + // } suite.Require().NoError(err) suite.Require().Equal(expSequence, channel.UpgradeSequence) suite.Require().Equal(mock.Version, channel.Version) suite.Require().Equal(types.OPEN, channel.State) - ibctesting.AssertEventsLegacy(&suite.Suite, expEvents, events) + } else { suite.Require().Error(err) } @@ -286,7 +284,7 @@ func (suite *KeeperTestSuite) TestChanUpgradeTry() { proofChannel, proofUpgrade, proofHeight := path.EndpointA.QueryChannelUpgradeProof() - upgrade, err := suite.chainB.GetSimApp().IBCKeeper.ChannelKeeper.ChanUpgradeTry( + _, upgrade, err := suite.chainB.GetSimApp().IBCKeeper.ChannelKeeper.ChanUpgradeTry( suite.chainB.GetContext(), path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, @@ -364,24 +362,22 @@ func (suite *KeeperTestSuite) TestWriteUpgradeTry() { suite.Require().True(found) suite.Require().Equal(upgradeWithAppCallbackVersion, upgrade) - events := ctx.EventManager().Events().ToABCIEvents() - expEvents := ibctesting.EventsMap{ - types.EventTypeChannelUpgradeTry: { - types.AttributeKeyPortID: path.EndpointB.ChannelConfig.PortID, - types.AttributeKeyChannelID: path.EndpointB.ChannelID, - types.AttributeCounterpartyPortID: path.EndpointA.ChannelConfig.PortID, - types.AttributeCounterpartyChannelID: path.EndpointA.ChannelID, - types.AttributeKeyUpgradeConnectionHops: upgrade.Fields.ConnectionHops[0], - types.AttributeKeyUpgradeVersion: upgrade.Fields.Version, - types.AttributeKeyUpgradeOrdering: upgrade.Fields.Ordering.String(), - types.AttributeKeyUpgradeSequence: fmt.Sprintf("%d", channel.UpgradeSequence), - }, - sdk.EventTypeMessage: { - sdk.AttributeKeyModule: types.AttributeValueCategory, - }, - } - - ibctesting.AssertEventsLegacy(&suite.Suite, expEvents, events) + // events := ctx.EventManager().Events().ToABCIEvents() + // expEvents := ibctesting.EventsMap{ + // types.EventTypeChannelUpgradeTry: { + // types.AttributeKeyPortID: path.EndpointB.ChannelConfig.PortID, + // types.AttributeKeyChannelID: path.EndpointB.ChannelID, + // types.AttributeCounterpartyPortID: path.EndpointA.ChannelConfig.PortID, + // types.AttributeCounterpartyChannelID: path.EndpointA.ChannelID, + // types.AttributeKeyUpgradeConnectionHops: upgrade.Fields.ConnectionHops[0], + // types.AttributeKeyUpgradeVersion: upgrade.Fields.Version, + // types.AttributeKeyUpgradeOrdering: upgrade.Fields.Ordering.String(), + // types.AttributeKeyUpgradeSequence: fmt.Sprintf("%d", channel.UpgradeSequence), + // }, + // sdk.EventTypeMessage: { + // sdk.AttributeKeyModule: types.AttributeValueCategory, + // }, + // } }) } } @@ -619,24 +615,22 @@ func (suite *KeeperTestSuite) TestWriteChannelUpgradeAck() { upgrade := path.EndpointA.GetChannelUpgrade() suite.Require().Equal(mock.UpgradeVersion, upgrade.Fields.Version) - events := ctx.EventManager().Events().ToABCIEvents() - expEvents := ibctesting.EventsMap{ - types.EventTypeChannelUpgradeAck: { - types.AttributeKeyPortID: path.EndpointA.ChannelConfig.PortID, - types.AttributeKeyChannelID: path.EndpointA.ChannelID, - types.AttributeCounterpartyPortID: path.EndpointB.ChannelConfig.PortID, - types.AttributeCounterpartyChannelID: path.EndpointB.ChannelID, - types.AttributeKeyUpgradeConnectionHops: upgrade.Fields.ConnectionHops[0], - types.AttributeKeyUpgradeVersion: upgrade.Fields.Version, - types.AttributeKeyUpgradeOrdering: upgrade.Fields.Ordering.String(), - types.AttributeKeyUpgradeSequence: fmt.Sprintf("%d", channel.UpgradeSequence), - }, - sdk.EventTypeMessage: { - sdk.AttributeKeyModule: types.AttributeValueCategory, - }, - } - - ibctesting.AssertEventsLegacy(&suite.Suite, expEvents, events) + // events := ctx.EventManager().Events().ToABCIEvents() + // expEvents := ibctesting.EventsMap{ + // types.EventTypeChannelUpgradeAck: { + // types.AttributeKeyPortID: path.EndpointA.ChannelConfig.PortID, + // types.AttributeKeyChannelID: path.EndpointA.ChannelID, + // types.AttributeCounterpartyPortID: path.EndpointB.ChannelConfig.PortID, + // types.AttributeCounterpartyChannelID: path.EndpointB.ChannelID, + // types.AttributeKeyUpgradeConnectionHops: upgrade.Fields.ConnectionHops[0], + // types.AttributeKeyUpgradeVersion: upgrade.Fields.Version, + // types.AttributeKeyUpgradeOrdering: upgrade.Fields.Ordering.String(), + // types.AttributeKeyUpgradeSequence: fmt.Sprintf("%d", channel.UpgradeSequence), + // }, + // sdk.EventTypeMessage: { + // sdk.AttributeKeyModule: types.AttributeValueCategory, + // }, + // } if !tc.hasPacketCommitments { suite.Require().Equal(types.FLUSHCOMPLETE, channel.State) @@ -913,22 +907,20 @@ func (suite *KeeperTestSuite) TestWriteUpgradeConfirm() { upgrade := path.EndpointA.GetChannelUpgrade() suite.Require().Equal(mock.UpgradeVersion, upgrade.Fields.Version) - events := ctx.EventManager().Events().ToABCIEvents() - expEvents := ibctesting.EventsMap{ - types.EventTypeChannelUpgradeConfirm: { - types.AttributeKeyPortID: path.EndpointA.ChannelConfig.PortID, - types.AttributeKeyChannelID: path.EndpointA.ChannelID, - types.AttributeKeyChannelState: channel.State.String(), - types.AttributeCounterpartyPortID: path.EndpointB.ChannelConfig.PortID, - types.AttributeCounterpartyChannelID: path.EndpointB.ChannelID, - types.AttributeKeyUpgradeSequence: fmt.Sprintf("%d", channel.UpgradeSequence), - }, - sdk.EventTypeMessage: { - sdk.AttributeKeyModule: types.AttributeValueCategory, - }, - } - - ibctesting.AssertEventsLegacy(&suite.Suite, expEvents, events) + // events := ctx.EventManager().Events().ToABCIEvents() + // expEvents := ibctesting.EventsMap{ + // types.EventTypeChannelUpgradeConfirm: { + // types.AttributeKeyPortID: path.EndpointA.ChannelConfig.PortID, + // types.AttributeKeyChannelID: path.EndpointA.ChannelID, + // types.AttributeKeyChannelState: channel.State.String(), + // types.AttributeCounterpartyPortID: path.EndpointB.ChannelConfig.PortID, + // types.AttributeCounterpartyChannelID: path.EndpointB.ChannelID, + // types.AttributeKeyUpgradeSequence: fmt.Sprintf("%d", channel.UpgradeSequence), + // }, + // sdk.EventTypeMessage: { + // sdk.AttributeKeyModule: types.AttributeValueCategory, + // }, + // } if !tc.hasPacketCommitments { suite.Require().Equal(types.FLUSHCOMPLETE, channel.State) @@ -1175,24 +1167,24 @@ func (suite *KeeperTestSuite) TestWriteUpgradeOpenChannel() { suite.Require().Equal(types.Upgrade{}, counterpartyUpgrade) suite.Require().False(found) - events := ctx.EventManager().Events().ToABCIEvents() - expEvents := ibctesting.EventsMap{ - types.EventTypeChannelUpgradeOpen: { - types.AttributeKeyPortID: path.EndpointA.ChannelConfig.PortID, - types.AttributeKeyChannelID: path.EndpointA.ChannelID, - types.AttributeCounterpartyPortID: path.EndpointB.ChannelConfig.PortID, - types.AttributeCounterpartyChannelID: path.EndpointB.ChannelID, - types.AttributeKeyChannelState: types.OPEN.String(), - types.AttributeKeyUpgradeConnectionHops: channel.ConnectionHops[0], - types.AttributeKeyUpgradeVersion: channel.Version, - types.AttributeKeyUpgradeOrdering: channel.Ordering.String(), - types.AttributeKeyUpgradeSequence: fmt.Sprintf("%d", channel.UpgradeSequence), - }, - sdk.EventTypeMessage: { - sdk.AttributeKeyModule: types.AttributeValueCategory, - }, - } - ibctesting.AssertEventsLegacy(&suite.Suite, expEvents, events) + // events := ctx.EventManager().Events().ToABCIEvents() + // expEvents := ibctesting.EventsMap{ + // types.EventTypeChannelUpgradeOpen: { + // types.AttributeKeyPortID: path.EndpointA.ChannelConfig.PortID, + // types.AttributeKeyChannelID: path.EndpointA.ChannelID, + // types.AttributeCounterpartyPortID: path.EndpointB.ChannelConfig.PortID, + // types.AttributeCounterpartyChannelID: path.EndpointB.ChannelID, + // types.AttributeKeyChannelState: types.OPEN.String(), + // types.AttributeKeyUpgradeConnectionHops: channel.ConnectionHops[0], + // types.AttributeKeyUpgradeVersion: channel.Version, + // types.AttributeKeyUpgradeOrdering: channel.Ordering.String(), + // types.AttributeKeyUpgradeSequence: fmt.Sprintf("%d", channel.UpgradeSequence), + // }, + // sdk.EventTypeMessage: { + // sdk.AttributeKeyModule: types.AttributeValueCategory, + // }, + // } + // ibctesting.AssertEventsLegacy(&suite.Suite, expEvents, events) } }) } @@ -1579,25 +1571,24 @@ func (suite *KeeperTestSuite) TestWriteUpgradeCancelChannel() { suite.Require().False(found) // we need to find the event values from the proposed upgrade as the actual upgrade has been deleted. - proposedUpgrade := path.EndpointA.GetProposedUpgrade() - events := ctx.EventManager().Events().ToABCIEvents() - expEvents := ibctesting.EventsMap{ - types.EventTypeChannelUpgradeCancel: { - types.AttributeKeyPortID: path.EndpointA.ChannelConfig.PortID, - types.AttributeKeyChannelID: path.EndpointA.ChannelID, - types.AttributeCounterpartyPortID: path.EndpointB.ChannelConfig.PortID, - types.AttributeCounterpartyChannelID: path.EndpointB.ChannelID, - types.AttributeKeyUpgradeConnectionHops: proposedUpgrade.Fields.ConnectionHops[0], - types.AttributeKeyUpgradeVersion: proposedUpgrade.Fields.Version, - types.AttributeKeyUpgradeOrdering: proposedUpgrade.Fields.Ordering.String(), - types.AttributeKeyUpgradeSequence: fmt.Sprintf("%d", channel.UpgradeSequence), - }, - sdk.EventTypeMessage: { - sdk.AttributeKeyModule: types.AttributeValueCategory, - }, - } + // proposedUpgrade := path.EndpointA.GetProposedUpgrade() + // events := ctx.EventManager().Events().ToABCIEvents() + // expEvents := ibctesting.EventsMap{ + // types.EventTypeChannelUpgradeCancel: { + // types.AttributeKeyPortID: path.EndpointA.ChannelConfig.PortID, + // types.AttributeKeyChannelID: path.EndpointA.ChannelID, + // types.AttributeCounterpartyPortID: path.EndpointB.ChannelConfig.PortID, + // types.AttributeCounterpartyChannelID: path.EndpointB.ChannelID, + // types.AttributeKeyUpgradeConnectionHops: proposedUpgrade.Fields.ConnectionHops[0], + // types.AttributeKeyUpgradeVersion: proposedUpgrade.Fields.Version, + // types.AttributeKeyUpgradeOrdering: proposedUpgrade.Fields.Ordering.String(), + // types.AttributeKeyUpgradeSequence: fmt.Sprintf("%d", channel.UpgradeSequence), + // }, + // sdk.EventTypeMessage: { + // sdk.AttributeKeyModule: types.AttributeValueCategory, + // }, + // } - ibctesting.AssertEventsLegacy(&suite.Suite, expEvents, events) } }) } @@ -2093,19 +2084,17 @@ func (suite *KeeperTestSuite) TestAbortUpgrade() { channelKeeper.MustAbortUpgrade(ctx, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, upgradeError) }) - events := ctx.EventManager().Events().ToABCIEvents() - expEvents := ibctesting.EventsMap{ - "channel_upgrade_error": { - "port_id": path.EndpointA.ChannelConfig.PortID, - "channel_id": path.EndpointA.ChannelID, - "counterparty_port_id": path.EndpointB.ChannelConfig.PortID, - "counterparty_channel_id": path.EndpointB.ChannelID, - "upgrade_sequence": fmt.Sprintf("%d", path.EndpointA.GetChannel().UpgradeSequence), - "upgrade_error_receipt": upgradeError.Error(), - }, - } - - ibctesting.AssertEventsLegacy(&suite.Suite, expEvents, events) + // events := ctx.EventManager().Events().ToABCIEvents() + // expEvents := ibctesting.EventsMap{ + // "channel_upgrade_error": { + // "port_id": path.EndpointA.ChannelConfig.PortID, + // "channel_id": path.EndpointA.ChannelID, + // "counterparty_port_id": path.EndpointB.ChannelConfig.PortID, + // "counterparty_channel_id": path.EndpointB.ChannelID, + // "upgrade_sequence": fmt.Sprintf("%d", path.EndpointA.GetChannel().UpgradeSequence), + // "upgrade_error_receipt": upgradeError.Error(), + // }, + // } channel, found := channelKeeper.GetChannel(suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID) suite.Require().True(found, "channel should be found") @@ -2353,7 +2342,7 @@ func (suite *KeeperTestSuite) TestChanUpgradeCrossingHelloWithHistoricalProofs() tc.malleate() - upgrade, err := suite.chainB.GetSimApp().GetIBCKeeper().ChannelKeeper.ChanUpgradeTry( + _, upgrade, err := suite.chainB.GetSimApp().GetIBCKeeper().ChannelKeeper.ChanUpgradeTry( suite.chainB.GetContext(), path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, diff --git a/modules/core/keeper/msg_server.go b/modules/core/keeper/msg_server.go index b4fcc9f3198..03eb10eaf95 100644 --- a/modules/core/keeper/msg_server.go +++ b/modules/core/keeper/msg_server.go @@ -12,6 +12,7 @@ import ( clienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types" connectiontypes "github.com/cosmos/ibc-go/v8/modules/core/03-connection/types" + "github.com/cosmos/ibc-go/v8/modules/core/04-channel/keeper" channeltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types" porttypes "github.com/cosmos/ibc-go/v8/modules/core/05-port/types" ibcerrors "github.com/cosmos/ibc-go/v8/modules/core/errors" @@ -772,10 +773,10 @@ func (k Keeper) ChannelUpgradeInit(goCtx context.Context, msg *channeltypes.MsgC return nil, errorsmod.Wrapf(err, "channel upgrade init callback failed for port ID: %s, channel ID: %s", msg.PortId, msg.ChannelId) } - upgrade.Fields.Version = upgradeVersion - channel := k.ChannelKeeper.WriteUpgradeInitChannel(ctx, msg.PortId, msg.ChannelId, upgrade) + channel, upgrade := k.ChannelKeeper.WriteUpgradeInitChannel(ctx, msg.PortId, msg.ChannelId, upgrade, upgradeVersion) ctx.Logger().Info("channel upgrade init succeeded", "channel-id", msg.ChannelId, "version", upgradeVersion) + keeper.EmitChannelUpgradeInitEvent(ctx, msg.PortId, msg.ChannelId, channel, upgrade) return &channeltypes.MsgChannelUpgradeInitResponse{ ChannelId: msg.ChannelId, @@ -800,12 +801,12 @@ func (k Keeper) ChannelUpgradeTry(goCtx context.Context, msg *channeltypes.MsgCh return nil, errorsmod.Wrapf(porttypes.ErrInvalidRoute, "route not found to module: %s", module) } - upgrade, err := k.ChannelKeeper.ChanUpgradeTry(ctx, msg.PortId, msg.ChannelId, msg.ProposedUpgradeConnectionHops, msg.CounterpartyUpgradeFields, msg.CounterpartyUpgradeSequence, msg.ProofChannel, msg.ProofUpgrade, msg.ProofHeight) + channel, upgrade, err := k.ChannelKeeper.ChanUpgradeTry(ctx, msg.PortId, msg.ChannelId, msg.ProposedUpgradeConnectionHops, msg.CounterpartyUpgradeFields, msg.CounterpartyUpgradeSequence, msg.ProofChannel, msg.ProofUpgrade, msg.ProofHeight) if err != nil { ctx.Logger().Error("channel upgrade try failed", "error", errorsmod.Wrap(err, "channel upgrade try failed")) if channeltypes.IsUpgradeError(err) { - k.ChannelKeeper.WriteErrorReceipt(ctx, msg.PortId, msg.ChannelId, err.(*channeltypes.UpgradeError)) - + k.ChannelKeeper.SetUpgradeErrorReceipt(ctx, msg.PortId, msg.ChannelId, err.(*channeltypes.UpgradeError).GetErrorReceipt()) + keeper.EmitErrorReceiptEvent(ctx, msg.PortId, msg.ChannelId, channel, err) // NOTE: a FAILURE result is returned to the client and an error receipt is written to state. // This signals to the relayer to begin the cancel upgrade handshake subprotocol. return &channeltypes.MsgChannelUpgradeTryResponse{Result: channeltypes.FAILURE}, nil @@ -821,9 +822,10 @@ func (k Keeper) ChannelUpgradeTry(goCtx context.Context, msg *channeltypes.MsgCh return nil, err } - channel, upgrade := k.ChannelKeeper.WriteUpgradeTryChannel(ctx, msg.PortId, msg.ChannelId, upgrade, upgradeVersion) + channel, upgrade = k.ChannelKeeper.WriteUpgradeTryChannel(ctx, msg.PortId, msg.ChannelId, upgrade, upgradeVersion) ctx.Logger().Info("channel upgrade try succeeded", "port-id", msg.PortId, "channel-id", msg.ChannelId) + keeper.EmitChannelUpgradeTryEvent(ctx, msg.PortId, msg.ChannelId, channel, upgrade) return &channeltypes.MsgChannelUpgradeTryResponse{ Result: channeltypes.SUCCESS, @@ -877,9 +879,10 @@ func (k Keeper) ChannelUpgradeAck(goCtx context.Context, msg *channeltypes.MsgCh writeFn() - k.ChannelKeeper.WriteUpgradeAckChannel(ctx, msg.PortId, msg.ChannelId, msg.CounterpartyUpgrade) + channel, upgrade := k.ChannelKeeper.WriteUpgradeAckChannel(ctx, msg.PortId, msg.ChannelId, msg.CounterpartyUpgrade) ctx.Logger().Info("channel upgrade ack succeeded", "port-id", msg.PortId, "channel-id", msg.ChannelId) + keeper.EmitChannelUpgradeAckEvent(ctx, msg.PortId, msg.ChannelId, channel, upgrade) return &channeltypes.MsgChannelUpgradeAckResponse{Result: channeltypes.SUCCESS}, nil } @@ -916,8 +919,9 @@ func (k Keeper) ChannelUpgradeConfirm(goCtx context.Context, msg *channeltypes.M return nil, errorsmod.Wrap(err, "channel upgrade confirm failed") } - k.ChannelKeeper.WriteUpgradeConfirmChannel(ctx, msg.PortId, msg.ChannelId, msg.CounterpartyUpgrade) + channel := k.ChannelKeeper.WriteUpgradeConfirmChannel(ctx, msg.PortId, msg.ChannelId, msg.CounterpartyUpgrade) ctx.Logger().Info("channel upgrade confirm succeeded", "port-id", msg.PortId, "channel-id", msg.ChannelId) + keeper.EmitChannelUpgradeConfirmEvent(ctx, msg.PortId, msg.ChannelId, channel) // Move channel to OPEN state if both chains have finished flushing in-flight packets. // Counterparty channel state has been verified in ChanUpgradeConfirm. @@ -931,6 +935,7 @@ func (k Keeper) ChannelUpgradeConfirm(goCtx context.Context, msg *channeltypes.M cbs.OnChanUpgradeOpen(ctx, msg.PortId, msg.ChannelId, upgrade.Fields.Ordering, upgrade.Fields.ConnectionHops, upgrade.Fields.Version) ctx.Logger().Info("channel upgrade open succeeded", "port-id", msg.PortId, "channel-id", msg.ChannelId) + keeper.EmitChannelUpgradeOpenEvent(ctx, msg.PortId, msg.ChannelId, channel) } return &channeltypes.MsgChannelUpgradeConfirmResponse{Result: channeltypes.SUCCESS}, nil @@ -964,9 +969,10 @@ func (k Keeper) ChannelUpgradeOpen(goCtx context.Context, msg *channeltypes.MsgC cbs.OnChanUpgradeOpen(ctx, msg.PortId, msg.ChannelId, upgrade.Fields.Ordering, upgrade.Fields.ConnectionHops, upgrade.Fields.Version) - k.ChannelKeeper.WriteUpgradeOpenChannel(ctx, msg.PortId, msg.ChannelId) + channel := k.ChannelKeeper.WriteUpgradeOpenChannel(ctx, msg.PortId, msg.ChannelId) ctx.Logger().Info("channel upgrade open succeeded", "port-id", msg.PortId, "channel-id", msg.ChannelId) + keeper.EmitChannelUpgradeOpenEvent(ctx, msg.PortId, msg.ChannelId, channel) return &channeltypes.MsgChannelUpgradeOpenResponse{}, nil } @@ -991,11 +997,12 @@ func (k Keeper) ChannelUpgradeTimeout(goCtx context.Context, msg *channeltypes.M return nil, errorsmod.Wrapf(err, "could not timeout upgrade for channel: %s", msg.ChannelId) } - k.ChannelKeeper.WriteUpgradeTimeoutChannel(ctx, msg.PortId, msg.ChannelId) + channel, upgrade := k.ChannelKeeper.WriteUpgradeTimeoutChannel(ctx, msg.PortId, msg.ChannelId) cbs.OnChanUpgradeRestore(ctx, msg.PortId, msg.ChannelId) ctx.Logger().Info("channel upgrade timeout callback succeeded: portID %s, channelID %s", msg.PortId, msg.ChannelId) + keeper.EmitChannelUpgradeTimeoutEvent(ctx, msg.PortId, msg.ChannelId, channel, upgrade) return &channeltypes.MsgChannelUpgradeTimeoutResponse{ Result: channeltypes.SUCCESS,