Skip to content

Commit

Permalink
Add flushing check to WriteUpgradeAckChannel (#3976)
Browse files Browse the repository at this point in the history
* chore: adding check for in flight packets in WriteUpgradeAckChannel

* added test for TestWriteUpgradeAckChannel

* linter

* add client update to UpgradeAckChannel test

* mv test

* merge

* fix post-merge

* fix merge issues

* review comment

---------

Co-authored-by: Charly <[email protected]>
Co-authored-by: Carlos Rodriguez <[email protected]>
  • Loading branch information
3 people authored Jun 30, 2023
1 parent 32930e7 commit a7793bc
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 0 deletions.
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) {
channel.FlushStatus = types.FLUSHCOMPLETE
}

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

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

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
sequence, err := path.EndpointA.SendPacket(suite.chainB.GetTimeoutHeight(), 0, ibctesting.MockPacketData)
suite.Require().NoError(err)
suite.Require().Equal(uint64(1), sequence)
},
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)

// create upgrade proposal with different version in init upgrade to see if the WriteUpgradeAck overwrites the version
path.EndpointA.ChannelConfig.ProposedUpgrade.Fields.Version = "original-version"

tc.malleate()

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

proposedUpgrade = path.EndpointA.GetChannelUpgrade()
suite.Require().Equal("original-version", proposedUpgrade.Fields.Version)

suite.Require().NoError(path.EndpointB.ChanUpgradeTry())

suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper.WriteUpgradeAckChannel(suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, mock.UpgradeVersion)

channel := path.EndpointA.GetChannel()
upgrade := path.EndpointA.GetChannelUpgrade()
suite.Require().Equal(mock.UpgradeVersion, upgrade.Fields.Version)

if tc.hasPacketCommitments {
suite.Require().Equal(types.FLUSHING, channel.FlushStatus)
} else {
suite.Require().Equal(types.FLUSHCOMPLETE, channel.FlushStatus)
}
})
}
}

func (suite *KeeperTestSuite) TestChanUpgradeOpen() {
var path *ibctesting.Path
testCases := []struct {
Expand Down
1 change: 1 addition & 0 deletions modules/core/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -947,6 +947,7 @@ 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)
},
},
{
Expand Down

0 comments on commit a7793bc

Please sign in to comment.