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

Add flushing check to WriteUpgradeAckChannel #3976

Merged
4 changes: 4 additions & 0 deletions modules/core/04-channel/keeper/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,10 @@ func (k Keeper) WriteUpgradeAckChannel(
channel.State = types.ACKUPGRADE
channel.FlushStatus = types.FLUSHING

if !k.hasInflightPackets(ctx, portID, channelID) {
Copy link
Contributor

Choose a reason for hiding this comment

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

should we add a unit test similar to that in #3964?

channel.FlushStatus = types.FLUSHCOMPLETE
}

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

upgrade, found := k.GetUpgrade(ctx, portID, channelID)
Expand Down
60 changes: 60 additions & 0 deletions modules/core/04-channel/keeper/upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1254,3 +1254,63 @@ func (suite *KeeperTestSuite) TestChanUpgradeCancel() {
})
}
}

func (suite *KeeperTestSuite) TestWriteChannelUpgradeAck() {
var (
path *ibctesting.Path
proposedUpgrade types.Upgrade
)

testCases := []struct {
name string
malleate func()
hasPacketCommitments bool
}{
{
"success with no packet commitments",
func() {},
false,
},
{
"success with packet commitments",
func() {
// manually set packet commitment
_, err := path.EndpointA.SendPacket(suite.chainB.GetTimeoutHeight(), 0, ibctesting.MockPacketData)
DimitrisJim marked this conversation as resolved.
Show resolved Hide resolved
suite.Require().NoError(err)
},
true,
},
}

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

path = ibctesting.NewPath(suite.chainA, suite.chainB)
suite.coordinator.Setup(path)

path.EndpointA.ChannelConfig.ProposedUpgrade.Fields.Version = mock.UpgradeVersion
charleenfei marked this conversation as resolved.
Show resolved Hide resolved
path.EndpointB.ChannelConfig.ProposedUpgrade.Fields.Version = mock.UpgradeVersion

proposedUpgrade = path.EndpointB.GetProposedUpgrade()

tc.malleate()

// perform the upgrade handshake.
suite.Require().NoError(path.EndpointA.ChanUpgradeInit())
suite.Require().NoError(path.EndpointB.ChanUpgradeTry())
suite.Require().NoError(path.EndpointA.UpdateClient())

suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper.WriteUpgradeAckChannel(suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, proposedUpgrade.Fields.Version)

channel := path.EndpointA.GetChannel()

if tc.hasPacketCommitments {
suite.Require().Equal(types.FLUSHING, channel.FlushStatus)
} else {
suite.Require().Equal(types.FLUSHCOMPLETE, channel.FlushStatus)
}
})
}
}
18 changes: 18 additions & 0 deletions modules/core/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -947,6 +947,24 @@ func (suite *KeeperTestSuite) TestChannelUpgradeAck() {
channel := path.EndpointA.GetChannel()
suite.Require().Equal(channeltypes.ACKUPGRADE, channel.State)
suite.Require().Equal(uint64(1), channel.UpgradeSequence)
suite.Require().Equal(channeltypes.FLUSHCOMPLETE, channel.FlushStatus)
},
},
{
"in flight packets",
func() {
charleenfei marked this conversation as resolved.
Show resolved Hide resolved
_, err := path.EndpointA.SendPacket(suite.chainA.GetTimeoutHeight(), 0, ibctesting.MockPacketData)
suite.Require().NoError(err)
},
func(res *channeltypes.MsgChannelUpgradeAckResponse, err error) {
suite.Require().NoError(err)
suite.Require().NotNil(res)
suite.Require().Equal(channeltypes.SUCCESS, res.Result)

channel := path.EndpointA.GetChannel()
suite.Require().Equal(channeltypes.ACKUPGRADE, channel.State)
suite.Require().Equal(uint64(1), channel.UpgradeSequence)
suite.Require().Equal(channeltypes.FLUSHING, channel.FlushStatus)
},
},
{
Expand Down