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

imp: add logic for setting NextSeqRecv, NextSeqAck in OnChanUpgradeOpen #5438

Merged
merged 26 commits into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
b7fbb39
add logic for setting next seq recv, update tests
charleenfei Dec 18, 2023
a3a10ab
update next seq recv and ack logic to spec
charleenfei Dec 19, 2023
045fdd2
Merge branch '04-channel-upgrades' into charly/set_nextseqrecv
charleenfei Dec 19, 2023
129cc62
typos
charleenfei Dec 19, 2023
c95192b
update test
charleenfei Dec 19, 2023
d7379a0
Merge branch 'charly/set_nextseqrecv' of github.com:cosmos/ibc-go int…
charleenfei Dec 19, 2023
972faa6
wip changes for spec
charleenfei Dec 19, 2023
3864e91
wip set counterparty upgrade
charleenfei Dec 19, 2023
122c25b
update naming
charleenfei Dec 19, 2023
81c31ee
update endpoint
charleenfei Dec 19, 2023
0ca4bca
spec changes
charleenfei Dec 19, 2023
a7a0834
test that counterparty upgrade has been set
charleenfei Dec 19, 2023
adaac86
Merge branch '04-channel-upgrades' into charly/set_nextseqrecv
charleenfei Dec 19, 2023
9a6f4c1
update err message
charleenfei Dec 19, 2023
ed80a45
pr review
charleenfei Dec 19, 2023
1dd6dcd
Merge branch 'charly/set_nextseqrecv' of github.com:cosmos/ibc-go int…
charleenfei Dec 19, 2023
7b2b487
naming nit
crodriguezvega Dec 19, 2023
4fcc075
Merge branch '04-channel-upgrades' into charly/set_nextseqrecv
charleenfei Dec 20, 2023
70973c9
pr review
charleenfei Dec 20, 2023
c6cd056
Merge branch '04-channel-upgrades' into charly/set_nextseqrecv
charleenfei Dec 20, 2023
9e96b13
refactor test
charleenfei Dec 20, 2023
09fafce
Merge branch 'charly/set_nextseqrecv' of github.com:cosmos/ibc-go int…
charleenfei Dec 20, 2023
8fdc927
small test changes
charleenfei Dec 20, 2023
7d7f60a
lint
charleenfei Dec 20, 2023
608d9e2
Add key for storing counterparty next sequence send during WriteUpgra…
DimitrisJim Dec 20, 2023
add52f8
Merge branch '04-channel-upgrades' into charly/set_nextseqrecv
charleenfei Dec 20, 2023
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
24 changes: 0 additions & 24 deletions modules/core/04-channel/keeper/packet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -351,30 +351,6 @@ func (suite *KeeperTestSuite) TestRecvPacket() {
channel := path.EndpointB.GetChannel()
channel.State = types.FLUSHING
path.EndpointB.SetChannel(channel)

Copy link
Contributor Author

@charleenfei charleenfei Dec 19, 2023

Choose a reason for hiding this comment

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

i removed these tests bc we aren't checking these sequences in RecvPacket anymore

// set last packet sent sequence to sequence + 1
counterpartyUpgrade := types.Upgrade{LatestSequenceSend: sequence + 1}
path.EndpointB.SetChannelCounterpartyUpgrade(counterpartyUpgrade)
},
nil,
},
{
"success with an counterparty latest sequence send set to 0",
func() {
suite.coordinator.Setup(path)
sequence, err := path.EndpointA.SendPacket(defaultTimeoutHeight, disabledTimeoutTimestamp, ibctesting.MockPacketData)
suite.Require().NoError(err)

packet = types.NewPacket(ibctesting.MockPacketData, sequence, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, defaultTimeoutHeight, disabledTimeoutTimestamp)
channelCap = suite.chainB.GetChannelCapability(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID)

channel := path.EndpointB.GetChannel()
channel.State = types.FLUSHING
path.EndpointB.SetChannel(channel)

// set last packet sent sequence to zero.
counterpartyUpgrade := types.Upgrade{LatestSequenceSend: 0}
path.EndpointB.SetChannelCounterpartyUpgrade(counterpartyUpgrade)
},
nil,
},
Expand Down
34 changes: 24 additions & 10 deletions modules/core/04-channel/keeper/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -350,10 +350,6 @@ func (k Keeper) WriteUpgradeAckChannel(ctx sdk.Context, portID, channelID string
if !k.HasInflightPackets(ctx, portID, channelID) {
channel.State = types.FLUSHCOMPLETE
k.SetChannel(ctx, portID, channelID, channel)
} else {
// the counterparty upgrade is only required if the channel is still in the FLUSHING state.
// this gets read when timing out and acknowledging packets.
k.SetCounterpartyUpgrade(ctx, portID, channelID, counterpartyUpgrade)
}

upgrade, found := k.GetUpgrade(ctx, portID, channelID)
Expand All @@ -364,6 +360,7 @@ func (k Keeper) WriteUpgradeAckChannel(ctx sdk.Context, portID, channelID string
upgrade.Fields.Version = counterpartyUpgrade.Fields.Version

k.SetUpgrade(ctx, portID, channelID, upgrade)
k.SetCounterpartyUpgrade(ctx, portID, channelID, counterpartyUpgrade)

k.Logger(ctx).Info("channel state updated", "port-id", portID, "channel-id", channelID, "state", channel.State.String())
return channel, upgrade
Expand Down Expand Up @@ -461,13 +458,10 @@ func (k Keeper) WriteUpgradeConfirmChannel(ctx sdk.Context, portID, channelID st
previousState := channel.State
channel.State = types.FLUSHCOMPLETE
k.SetChannel(ctx, portID, channelID, channel)

k.Logger(ctx).Info("channel state updated", "port-id", portID, "channel-id", channelID, "previous-state", previousState, "new-state", channel.State)
} else {
// the counterparty upgrade is only required if the channel is still in the FLUSHING state.
// this gets read when timing out and acknowledging packets.
k.SetCounterpartyUpgrade(ctx, portID, channelID, counterpartyUpgrade)
}

k.SetCounterpartyUpgrade(ctx, portID, channelID, counterpartyUpgrade)
charleenfei marked this conversation as resolved.
Show resolved Hide resolved
return channel
}

Expand Down Expand Up @@ -568,6 +562,26 @@ func (k Keeper) WriteUpgradeOpenChannel(ctx sdk.Context, portID, channelID strin
panic(fmt.Errorf("could not find upgrade when updating channel state, channelID: %s, portID: %s", channelID, portID))
}

counterpartyUpgrade, found := k.GetCounterpartyUpgrade(ctx, portID, channelID)
if !found {
panic(fmt.Errorf("could not find counterparty upgrade when updating channel state, channelID: %s, portID: %s", channelID, portID))
}

// next seq recv and ack is used for ordered channels to verify the packet has been received/acked in the correct order
// this is no longer necessary if the channel is UNORDERED and should be reset to 1
if channel.Ordering == types.ORDERED && upgrade.Fields.Ordering == types.UNORDERED {
k.SetNextSequenceRecv(ctx, portID, channelID, 1)
k.SetNextSequenceAck(ctx, portID, channelID, 1)
}

// next seq recv and ack should updated when moving from UNORDERED to ORDERED using the latest packet sequence sent before the upgrade
charleenfei marked this conversation as resolved.
Show resolved Hide resolved
// we can be sure that the next packet we are set to receive will be the first packet the counterparty sends after reopening.
// we can be sure that our next acknowledgement will be our first packet sent after upgrade, as the counterparty processed all sent packets after flushing completes.
if channel.Ordering == types.UNORDERED && upgrade.Fields.Ordering == types.ORDERED {
k.SetNextSequenceRecv(ctx, portID, channelID, counterpartyUpgrade.NextSequenceSend)
k.SetNextSequenceAck(ctx, portID, channelID, upgrade.NextSequenceSend)
}

charleenfei marked this conversation as resolved.
Show resolved Hide resolved
// Switch channel fields to upgrade fields and set channel state to OPEN
previousState := channel.State
channel.Ordering = upgrade.Fields.Ordering
Expand Down Expand Up @@ -803,7 +817,7 @@ func (k Keeper) startFlushing(ctx sdk.Context, portID, channelID string, upgrade
return errorsmod.Wrapf(types.ErrSequenceSendNotFound, "port ID (%s) channel ID (%s)", portID, channelID)
}

upgrade.LatestSequenceSend = nextSequenceSend - 1
upgrade.NextSequenceSend = nextSequenceSend
upgrade.Timeout = k.getAbsoluteUpgradeTimeout(ctx)
k.SetUpgrade(ctx, portID, channelID, *upgrade)

Expand Down
193 changes: 172 additions & 21 deletions modules/core/04-channel/keeper/upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ func (suite *KeeperTestSuite) TestChanUpgradeTry() {

nextSequenceSend, found := path.EndpointB.Chain.GetSimApp().IBCKeeper.ChannelKeeper.GetNextSequenceSend(path.EndpointB.Chain.GetContext(), path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID)
suite.Require().True(found)
suite.Require().Equal(nextSequenceSend-1, upgrade.LatestSequenceSend)
suite.Require().Equal(nextSequenceSend, upgrade.NextSequenceSend)
} else {
suite.assertUpgradeError(err, tc.expError)
}
Expand Down Expand Up @@ -752,7 +752,7 @@ func (suite *KeeperTestSuite) TestChanUpgradeAck() {
"fails due to proof verification failure, counterparty update has unexpected sequence",
func() {
// Decrementing LatestSequenceSend is sufficient to cause the proof to fail.
counterpartyUpgrade.LatestSequenceSend--
counterpartyUpgrade.NextSequenceSend--
},
commitmenttypes.ErrInvalidProof,
},
Expand Down Expand Up @@ -909,13 +909,10 @@ func (suite *KeeperTestSuite) TestWriteChannelUpgradeAck() {

if !tc.hasPacketCommitments {
suite.Require().Equal(types.FLUSHCOMPLETE, channel.State)
_, ok := suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper.GetCounterpartyUpgrade(suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID)
suite.Require().False(ok)
} else {
counterpartyUpgrade, ok := suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper.GetCounterpartyUpgrade(suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID)
suite.Require().True(ok)
suite.Require().Equal(proposedUpgrade, counterpartyUpgrade)
}
counterpartyUpgrade, ok := suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper.GetCounterpartyUpgrade(suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID)
suite.Require().True(ok)
suite.Require().Equal(proposedUpgrade, counterpartyUpgrade)
})
}
}
Expand Down Expand Up @@ -1199,15 +1196,12 @@ func (suite *KeeperTestSuite) TestWriteUpgradeConfirm() {

if !tc.hasPacketCommitments {
suite.Require().Equal(types.FLUSHCOMPLETE, channel.State)
// Counterparty was set in UPGRADETRY but without timeout, latest sequence send set.
_, ok := suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper.GetCounterpartyUpgrade(suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID)
suite.Require().False(ok, "counterparty upgrade should not be present when there are no in flight packets")
} else {
suite.Require().Equal(types.FLUSHING, channel.State)
counterpartyUpgrade, ok := suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper.GetCounterpartyUpgrade(suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID)
suite.Require().True(ok, "counterparty upgrade should be present when there are in flight packets")
suite.Require().Equal(proposedUpgrade, counterpartyUpgrade)
}
counterpartyUpgrade, ok := suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper.GetCounterpartyUpgrade(suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID)
suite.Require().True(ok, "counterparty upgrade should be present")
suite.Require().Equal(proposedUpgrade, counterpartyUpgrade)
})
}
}
Expand Down Expand Up @@ -1359,7 +1353,7 @@ func (suite *KeeperTestSuite) TestChanUpgradeOpen() {
}
}

func (suite *KeeperTestSuite) TestWriteUpgradeOpenChannel() {
func (suite *KeeperTestSuite) TestWriteUpgradeOpenChannel_UnorderedToOrdered() {
charleenfei marked this conversation as resolved.
Show resolved Hide resolved
var path *ibctesting.Path

testCases := []struct {
Expand Down Expand Up @@ -1397,10 +1391,17 @@ func (suite *KeeperTestSuite) TestWriteUpgradeOpenChannel() {
suite.coordinator.Setup(path)

// Need to create a packet commitment on A so as to keep it from going to OPEN if no inflight packets exist.
sequence, err := path.EndpointA.SendPacket(defaultTimeoutHeight, disabledTimeoutTimestamp, ibctesting.MockPacketData)
sequence0, err := path.EndpointA.SendPacket(defaultTimeoutHeight, disabledTimeoutTimestamp, ibctesting.MockPacketData)
charleenfei marked this conversation as resolved.
Show resolved Hide resolved
suite.Require().NoError(err)
packet0 := types.NewPacket(ibctesting.MockPacketData, sequence0, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, defaultTimeoutHeight, disabledTimeoutTimestamp)
err = path.EndpointB.RecvPacket(packet0)
suite.Require().NoError(err)
packet := types.NewPacket(ibctesting.MockPacketData, sequence, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, defaultTimeoutHeight, disabledTimeoutTimestamp)
err = path.EndpointB.RecvPacket(packet)

// send second packet from B to A
sequence1, err := path.EndpointB.SendPacket(defaultTimeoutHeight, disabledTimeoutTimestamp, ibctesting.MockPacketData)
suite.Require().NoError(err)
packet1 := types.NewPacket(ibctesting.MockPacketData, sequence1, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, defaultTimeoutHeight, disabledTimeoutTimestamp)
err = path.EndpointA.RecvPacket(packet1)
suite.Require().NoError(err)

path.EndpointA.ChannelConfig.ProposedUpgrade.Fields.Version = mock.UpgradeVersion
Expand All @@ -1413,11 +1414,25 @@ func (suite *KeeperTestSuite) TestWriteUpgradeOpenChannel() {
suite.Require().NoError(path.EndpointA.ChanUpgradeAck())
suite.Require().NoError(path.EndpointB.ChanUpgradeConfirm())

// Ack packet to delete packet commitment before calling WriteUpgradeOpenChannel
err = path.EndpointA.AcknowledgePacket(packet, ibctesting.MockAcknowledgement)
// Ack packets to delete packet commitments before calling WriteUpgradeOpenChannel
err = path.EndpointA.AcknowledgePacket(packet0, ibctesting.MockAcknowledgement)
suite.Require().NoError(err)

err = path.EndpointB.AcknowledgePacket(packet1, ibctesting.MockAcknowledgement)
suite.Require().NoError(err)

ctx := suite.chainA.GetContext()

// assert that sequence (reset in ChanUpgradeTry) is 1 because channel is UNORDERED
Copy link
Member

Choose a reason for hiding this comment

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

I don't understand the reset comment

Copy link
Member

Choose a reason for hiding this comment

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

Should we also be assert the counterpartyNextSequenceSend is 2 here?

Copy link
Contributor Author

@charleenfei charleenfei Dec 19, 2023

Choose a reason for hiding this comment

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

i believe we set the sequences to 1 so that the upgrade proof can be verified without the exact last sequences

charleenfei marked this conversation as resolved.
Show resolved Hide resolved
seq, found := suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper.GetNextSequenceRecv(ctx, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID)
suite.Require().True(found)
suite.Require().Equal(uint64(1), seq)

// assert that NextSeqAck is 1 because channel is UNORDERED
seq, found = suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper.GetNextSequenceAck(ctx, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID)
suite.Require().True(found)
suite.Require().Equal(uint64(1), seq)

tc.malleate()

if tc.expPanic {
Expand All @@ -1433,6 +1448,142 @@ func (suite *KeeperTestSuite) TestWriteUpgradeOpenChannel() {
suite.Require().Equal(mock.UpgradeVersion, channel.Version)
suite.Require().Equal(types.ORDERED, channel.Ordering)

// assert that NextSeqRecv is incremented to 2, because channel is now ORDERED
// seq updated in WriteUpgradeOpenChannel to latest sequence (one packet sent) + 1
seq, found = suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper.GetNextSequenceRecv(ctx, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID)
suite.Require().True(found)
suite.Require().Equal(uint64(2), seq)

// assert that NextSeqAck is incremented to 2 because channel is now ORDERED
seq, found = suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper.GetNextSequenceAck(ctx, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID)
suite.Require().True(found)
suite.Require().Equal(uint64(2), seq)

// Assert that state stored for upgrade has been deleted
upgrade, found := suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper.GetUpgrade(suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID)
suite.Require().Equal(types.Upgrade{}, upgrade)
suite.Require().False(found)

counterpartyUpgrade, found := suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper.GetCounterpartyUpgrade(suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID)
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)
}
})
}
}

func (suite *KeeperTestSuite) TestWriteUpgradeOpenChannel_OrderedToUnordered() {
var path *ibctesting.Path

testCases := []struct {
name string
malleate func()
expPanic bool
}{
{
name: "success",
malleate: func() {},
expPanic: false,
},
}

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

path = ibctesting.NewPath(suite.chainA, suite.chainB)
path.EndpointA.ChannelConfig.Order = types.ORDERED
path.EndpointB.ChannelConfig.Order = types.ORDERED
suite.coordinator.Setup(path)

// Need to create a packet commitment on A so as to keep it from going to OPEN if no inflight packets exist.
sequenc0, err := path.EndpointA.SendPacket(defaultTimeoutHeight, disabledTimeoutTimestamp, ibctesting.MockPacketData)
suite.Require().NoError(err)
packe0 := types.NewPacket(ibctesting.MockPacketData, sequenc0, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, defaultTimeoutHeight, disabledTimeoutTimestamp)
err = path.EndpointB.RecvPacket(packe0)
suite.Require().NoError(err)

// send second packet from B to A
sequence1, err := path.EndpointB.SendPacket(defaultTimeoutHeight, disabledTimeoutTimestamp, ibctesting.MockPacketData)
suite.Require().NoError(err)
packet1 := types.NewPacket(ibctesting.MockPacketData, sequence1, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, defaultTimeoutHeight, disabledTimeoutTimestamp)
err = path.EndpointA.RecvPacket(packet1)
suite.Require().NoError(err)

path.EndpointA.ChannelConfig.ProposedUpgrade.Fields.Version = mock.UpgradeVersion
path.EndpointB.ChannelConfig.ProposedUpgrade.Fields.Version = mock.UpgradeVersion
path.EndpointA.ChannelConfig.ProposedUpgrade.Fields.Ordering = types.UNORDERED
path.EndpointB.ChannelConfig.ProposedUpgrade.Fields.Ordering = types.UNORDERED

suite.Require().NoError(path.EndpointA.ChanUpgradeInit())
suite.Require().NoError(path.EndpointB.ChanUpgradeTry())
suite.Require().NoError(path.EndpointA.ChanUpgradeAck())
suite.Require().NoError(path.EndpointB.ChanUpgradeConfirm())

// Ack packets to delete packet commitments before calling WriteUpgradeOpenChannel
err = path.EndpointA.AcknowledgePacket(packe0, ibctesting.MockAcknowledgement)
suite.Require().NoError(err)

err = path.EndpointB.AcknowledgePacket(packet1, ibctesting.MockAcknowledgement)
suite.Require().NoError(err)

ctx := suite.chainA.GetContext()

// assert that NextSeqAck is incremented to 2 because channel is still ordered
seq, found := suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper.GetNextSequenceAck(ctx, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID)
suite.Require().True(found)
suite.Require().Equal(uint64(2), seq)

// assert that sequence (set in ChanUpgradeTry) is incremented to 2 because channel is still ordered
charleenfei marked this conversation as resolved.
Show resolved Hide resolved
seq, found = suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper.GetNextSequenceRecv(ctx, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID)
charleenfei marked this conversation as resolved.
Show resolved Hide resolved
suite.Require().True(found)
suite.Require().Equal(uint64(2), seq)

tc.malleate()

if tc.expPanic {
suite.Require().Panics(func() {
suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper.WriteUpgradeOpenChannel(ctx, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID)
})
} else {
suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper.WriteUpgradeOpenChannel(ctx, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID)
channel := path.EndpointA.GetChannel()

// Assert that channel state has been updated
suite.Require().Equal(types.OPEN, channel.State)
suite.Require().Equal(mock.UpgradeVersion, channel.Version)
suite.Require().Equal(types.UNORDERED, channel.Ordering)

// assert that NextSeqRecv is now 1, because channel is now UNORDERED
seq, found := suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper.GetNextSequenceRecv(ctx, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID)
suite.Require().True(found)
suite.Require().Equal(uint64(1), seq)

// assert that NextSeqAck is now 1, because channel is now UNORDERED
seq, found = suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper.GetNextSequenceAck(ctx, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID)
suite.Require().True(found)
suite.Require().Equal(uint64(1), seq)

// Assert that state stored for upgrade has been deleted
upgrade, found := suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper.GetUpgrade(suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID)
suite.Require().Equal(types.Upgrade{}, upgrade)
Expand Down Expand Up @@ -2145,7 +2296,7 @@ func (suite *KeeperTestSuite) TestStartFlush() {
suite.Require().True(ok)

suite.Require().Equal(types.FLUSHING, channel.State)
suite.Require().Equal(nextSequenceSend-1, upgrade.LatestSequenceSend)
suite.Require().Equal(nextSequenceSend, upgrade.NextSequenceSend)

expectedTimeoutTimestamp := types.DefaultTimeout.Timestamp + uint64(suite.chainB.GetContext().BlockTime().UnixNano())
suite.Require().Equal(expectedTimeoutTimestamp, upgrade.Timeout.Timestamp)
Expand Down
8 changes: 4 additions & 4 deletions modules/core/04-channel/types/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ import (
)

// NewUpgrade creates a new Upgrade instance.
func NewUpgrade(upgradeFields UpgradeFields, timeout Timeout, latestPacketSent uint64) Upgrade {
func NewUpgrade(upgradeFields UpgradeFields, timeout Timeout, nextSequenceSend uint64) Upgrade {
return Upgrade{
Fields: upgradeFields,
Timeout: timeout,
LatestSequenceSend: latestPacketSent,
Fields: upgradeFields,
Timeout: timeout,
NextSequenceSend: nextSequenceSend,
}
}

Expand Down
Loading
Loading