From 5cada7592cf9853c6b5c1f83f228ddaeeab0b270 Mon Sep 17 00:00:00 2001 From: chatton Date: Tue, 4 Jul 2023 10:20:17 +0100 Subject: [PATCH 1/3] chore: update counterparty last packet sequence in ack and try --- modules/core/04-channel/keeper/upgrade.go | 8 +++----- modules/core/04-channel/keeper/upgrade_test.go | 10 +++++++++- modules/core/keeper/msg_server.go | 2 +- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/modules/core/04-channel/keeper/upgrade.go b/modules/core/04-channel/keeper/upgrade.go index f2d3dae35bf..ff8450f1cac 100644 --- a/modules/core/04-channel/keeper/upgrade.go +++ b/modules/core/04-channel/keeper/upgrade.go @@ -199,6 +199,7 @@ func (k Keeper) WriteUpgradeTryChannel(ctx sdk.Context, portID, channelID string upgrade.Fields.Version = upgradeVersion + k.SetCounterpartyLastPacketSequence(ctx, portID, channelID, upgrade.LatestSequenceSend) k.SetChannel(ctx, portID, channelID, channel) k.SetUpgrade(ctx, portID, channelID, upgrade) @@ -278,11 +279,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, - upgradeVersion string, -) { +func (k Keeper) WriteUpgradeAckChannel(ctx sdk.Context, portID, channelID, upgradeVersion string, lastSequenceSend uint64) { defer telemetry.IncrCounter(1, "ibc", "channel", "upgrade-ack") channel, found := k.GetChannel(ctx, portID, channelID) @@ -298,6 +295,7 @@ func (k Keeper) WriteUpgradeAckChannel( channel.FlushStatus = types.FLUSHCOMPLETE } + k.SetCounterpartyLastPacketSequence(ctx, portID, channelID, lastSequenceSend) k.SetChannel(ctx, portID, channelID, channel) upgrade, found := k.GetUpgrade(ctx, portID, channelID) diff --git a/modules/core/04-channel/keeper/upgrade_test.go b/modules/core/04-channel/keeper/upgrade_test.go index 15a15ed12d9..d3f86b4a3af 100644 --- a/modules/core/04-channel/keeper/upgrade_test.go +++ b/modules/core/04-channel/keeper/upgrade_test.go @@ -377,6 +377,10 @@ func (suite *KeeperTestSuite) TestWriteUpgradeTry() { suite.Require().Equal(types.TRYUPGRADE, channel.State) suite.Require().Equal(upgradeWithAppCallbackVersion, upgrade) + actualCounterpartyLastSequenceSend, ok := suite.chainB.GetSimApp().IBCKeeper.ChannelKeeper.GetCounterpartyLastPacketSequence(suite.chainB.GetContext(), path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID) + suite.Require().True(ok) + suite.Require().Equal(proposedUpgrade.LatestSequenceSend, actualCounterpartyLastSequenceSend) + if tc.hasPacketCommitments { suite.Require().Equal(types.FLUSHING, channel.FlushStatus) } else { @@ -601,12 +605,16 @@ func (suite *KeeperTestSuite) TestWriteChannelUpgradeAck() { suite.Require().NoError(path.EndpointB.ChanUpgradeTry()) - suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper.WriteUpgradeAckChannel(suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, mock.UpgradeVersion) + suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper.WriteUpgradeAckChannel(suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, mock.UpgradeVersion, proposedUpgrade.LatestSequenceSend) channel := path.EndpointA.GetChannel() upgrade := path.EndpointA.GetChannelUpgrade() suite.Require().Equal(mock.UpgradeVersion, upgrade.Fields.Version) + actualCounterpartyLastSequenceSend, ok := suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper.GetCounterpartyLastPacketSequence(suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID) + suite.Require().True(ok) + suite.Require().Equal(proposedUpgrade.LatestSequenceSend, actualCounterpartyLastSequenceSend) + if tc.hasPacketCommitments { suite.Require().Equal(types.FLUSHING, channel.FlushStatus) } else { diff --git a/modules/core/keeper/msg_server.go b/modules/core/keeper/msg_server.go index 4a58da37500..ca4a9e34196 100644 --- a/modules/core/keeper/msg_server.go +++ b/modules/core/keeper/msg_server.go @@ -853,7 +853,7 @@ func (k Keeper) ChannelUpgradeAck(goCtx context.Context, msg *channeltypes.MsgCh writeFn() - k.ChannelKeeper.WriteUpgradeAckChannel(ctx, msg.PortId, msg.ChannelId, msg.CounterpartyUpgrade.Fields.Version) + k.ChannelKeeper.WriteUpgradeAckChannel(ctx, msg.PortId, msg.ChannelId, msg.CounterpartyUpgrade.Fields.Version, msg.CounterpartyUpgrade.LatestSequenceSend) ctx.Logger().Info("channel upgrade ack succeeded", "port-id", msg.PortId, "channel-id", msg.ChannelId) From 2b50097811a1a8477080a2e7807ed61c7f81b60f Mon Sep 17 00:00:00 2001 From: chatton Date: Wed, 5 Jul 2023 11:05:39 +0100 Subject: [PATCH 2/3] chore: addressing PR feedback --- modules/core/04-channel/keeper/upgrade.go | 4 ++-- modules/core/04-channel/keeper/upgrade_test.go | 9 ++++++++- modules/core/keeper/msg_server.go | 3 +-- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/modules/core/04-channel/keeper/upgrade.go b/modules/core/04-channel/keeper/upgrade.go index ff8450f1cac..d94ff4cab89 100644 --- a/modules/core/04-channel/keeper/upgrade.go +++ b/modules/core/04-channel/keeper/upgrade.go @@ -181,7 +181,7 @@ func (k Keeper) ChanUpgradeTry( // WriteUpgradeTryChannel writes the channel end and upgrade to state after successfully passing the UpgradeTry handshake step. // An event is emitted for the handshake step. -func (k Keeper) WriteUpgradeTryChannel(ctx sdk.Context, portID, channelID string, upgrade types.Upgrade, upgradeVersion string) (types.Channel, types.Upgrade) { +func (k Keeper) WriteUpgradeTryChannel(ctx sdk.Context, portID, channelID string, upgrade types.Upgrade, upgradeVersion string, counterpartyLastPacketSequence uint64) (types.Channel, types.Upgrade) { defer telemetry.IncrCounter(1, "ibc", "channel", "upgrade-try") channel, found := k.GetChannel(ctx, portID, channelID) @@ -199,7 +199,7 @@ func (k Keeper) WriteUpgradeTryChannel(ctx sdk.Context, portID, channelID string upgrade.Fields.Version = upgradeVersion - k.SetCounterpartyLastPacketSequence(ctx, portID, channelID, upgrade.LatestSequenceSend) + k.SetCounterpartyLastPacketSequence(ctx, portID, channelID, counterpartyLastPacketSequence) k.SetChannel(ctx, portID, channelID, channel) k.SetUpgrade(ctx, portID, channelID, upgrade) diff --git a/modules/core/04-channel/keeper/upgrade_test.go b/modules/core/04-channel/keeper/upgrade_test.go index d3f86b4a3af..315bb65a7a9 100644 --- a/modules/core/04-channel/keeper/upgrade_test.go +++ b/modules/core/04-channel/keeper/upgrade_test.go @@ -367,7 +367,14 @@ func (suite *KeeperTestSuite) TestWriteUpgradeTry() { tc.malleate() - upgradedChannelEnd, upgradeWithAppCallbackVersion := suite.chainB.GetSimApp().IBCKeeper.ChannelKeeper.WriteUpgradeTryChannel(suite.chainB.GetContext(), path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, proposedUpgrade, proposedUpgrade.Fields.Version) + upgradedChannelEnd, upgradeWithAppCallbackVersion := suite.chainB.GetSimApp().IBCKeeper.ChannelKeeper.WriteUpgradeTryChannel( + suite.chainB.GetContext(), + path.EndpointB.ChannelConfig.PortID, + path.EndpointB.ChannelID, + proposedUpgrade, + proposedUpgrade.Fields.Version, + proposedUpgrade.LatestSequenceSend, + ) channel := path.EndpointB.GetChannel() suite.Require().Equal(upgradedChannelEnd, channel) diff --git a/modules/core/keeper/msg_server.go b/modules/core/keeper/msg_server.go index ca4a9e34196..4e202658d53 100644 --- a/modules/core/keeper/msg_server.go +++ b/modules/core/keeper/msg_server.go @@ -792,10 +792,9 @@ func (k Keeper) ChannelUpgradeTry(goCtx context.Context, msg *channeltypes.MsgCh return &channeltypes.MsgChannelUpgradeTryResponse{Result: channeltypes.FAILURE}, nil } - writeFn() - channel, upgrade := k.ChannelKeeper.WriteUpgradeTryChannel(ctx, msg.PortId, msg.ChannelId, upgrade, upgradeVersion) + channel, upgrade := k.ChannelKeeper.WriteUpgradeTryChannel(ctx, msg.PortId, msg.ChannelId, upgrade, upgradeVersion, msg.CounterpartyProposedUpgrade.LatestSequenceSend) ctx.Logger().Info("channel upgrade try succeeded", "port-id", msg.PortId, "channel-id", msg.ChannelId) From be10567b097c831e364cc164cd8c535372775fdd Mon Sep 17 00:00:00 2001 From: chatton Date: Wed, 5 Jul 2023 11:10:09 +0100 Subject: [PATCH 3/3] make naming consistent --- modules/core/04-channel/keeper/upgrade.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/core/04-channel/keeper/upgrade.go b/modules/core/04-channel/keeper/upgrade.go index d94ff4cab89..581989fbe62 100644 --- a/modules/core/04-channel/keeper/upgrade.go +++ b/modules/core/04-channel/keeper/upgrade.go @@ -181,7 +181,7 @@ func (k Keeper) ChanUpgradeTry( // WriteUpgradeTryChannel writes the channel end and upgrade to state after successfully passing the UpgradeTry handshake step. // An event is emitted for the handshake step. -func (k Keeper) WriteUpgradeTryChannel(ctx sdk.Context, portID, channelID string, upgrade types.Upgrade, upgradeVersion string, counterpartyLastPacketSequence uint64) (types.Channel, types.Upgrade) { +func (k Keeper) WriteUpgradeTryChannel(ctx sdk.Context, portID, channelID string, upgrade types.Upgrade, upgradeVersion string, counterpartyLastSequenceSend uint64) (types.Channel, types.Upgrade) { defer telemetry.IncrCounter(1, "ibc", "channel", "upgrade-try") channel, found := k.GetChannel(ctx, portID, channelID) @@ -199,7 +199,7 @@ func (k Keeper) WriteUpgradeTryChannel(ctx sdk.Context, portID, channelID string upgrade.Fields.Version = upgradeVersion - k.SetCounterpartyLastPacketSequence(ctx, portID, channelID, counterpartyLastPacketSequence) + k.SetCounterpartyLastPacketSequence(ctx, portID, channelID, counterpartyLastSequenceSend) k.SetChannel(ctx, portID, channelID, channel) k.SetUpgrade(ctx, portID, channelID, upgrade) @@ -279,7 +279,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, upgradeVersion string, lastSequenceSend uint64) { +func (k Keeper) WriteUpgradeAckChannel(ctx sdk.Context, portID, channelID, upgradeVersion string, counterpartyLastSequenceSend uint64) { defer telemetry.IncrCounter(1, "ibc", "channel", "upgrade-ack") channel, found := k.GetChannel(ctx, portID, channelID) @@ -295,7 +295,7 @@ func (k Keeper) WriteUpgradeAckChannel(ctx sdk.Context, portID, channelID, upgra channel.FlushStatus = types.FLUSHCOMPLETE } - k.SetCounterpartyLastPacketSequence(ctx, portID, channelID, lastSequenceSend) + k.SetCounterpartyLastPacketSequence(ctx, portID, channelID, counterpartyLastSequenceSend) k.SetChannel(ctx, portID, channelID, channel) upgrade, found := k.GetUpgrade(ctx, portID, channelID)