Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set Counterparty Last Sequence Send #4005

Merged
Show file tree
Hide file tree
Changes from 2 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
8 changes: 3 additions & 5 deletions modules/core/04-channel/keeper/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is our Upgrade's last sequence send, right? I think we'll need to accept an additional arg and pass msg.CounterpartyProposedUpgrade.LastSequenceSend from msg server

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes! Great catch, we'll need to add that as an arg.

k.SetChannel(ctx, portID, channelID, channel)
k.SetUpgrade(ctx, portID, channelID, upgrade)

Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down
10 changes: 9 additions & 1 deletion modules/core/04-channel/keeper/upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion modules/core/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down