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

Allow receiving of packets if the counterparty latest sequence send has not been set #4480

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 4 additions & 2 deletions modules/core/04-channel/keeper/packet.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,12 @@ func (k Keeper) RecvPacket(
return errorsmod.Wrapf(types.ErrUpgradeNotFound, "counterparty upgrade not found for channel: %s", packet.GetDestChannel())
}

if packet.GetSequence() > counterpartyUpgrade.LatestSequenceSend {
// only error if the counterparty latest sequence send is set (> 0)
counterpartyLatestSequenceSend := counterpartyUpgrade.LatestSequenceSend
if counterpartyLatestSequenceSend != 0 && packet.GetSequence() > counterpartyLatestSequenceSend {
return errorsmod.Wrapf(
types.ErrInvalidPacket,
"failed to receive packet, cannot flush packet at sequence greater than counterparty last sequence send (%d) > (%d)", packet.GetSequence(), counterpartyUpgrade.LatestSequenceSend,
"failed to receive packet, cannot flush packet at sequence greater than counterparty last sequence send (%d) > (%d)", packet.GetSequence(), counterpartyLatestSequenceSend,
)
}
}
Expand Down
23 changes: 23 additions & 0 deletions modules/core/04-channel/keeper/packet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,26 @@ func (suite *KeeperTestSuite) TestRecvPacket() {
},
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}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Followed what the rests of the tests are doing which is mutating state directly, tho would be nicer if we'd consistently use the handlers to get here.

Copy link
Member

Choose a reason for hiding this comment

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

I think this is fine and probably more maintainable for packet tests. It's nice to use the handlers to do the full handshake but its also covering a lot of code in doing so, and when we came back to do this refactor, the fact that we relied on the endpoint helpers so much meant that even more tests were breaking when we made changes.

Its a bit of a double edged sword. I think there's pros and cons to both approaches.

path.EndpointB.SetChannelCounterpartyUpgrade(counterpartyUpgrade)
},
nil,
},
{
"failure while upgrading channel, counterparty upgrade not found",
func() {
Expand All @@ -373,6 +393,9 @@ func (suite *KeeperTestSuite) TestRecvPacket() {
"failure while upgrading channel, packet sequence > counterparty last send sequence",
func() {
suite.coordinator.Setup(path)
// send 2 packets so that when LatestSequenceSend is set to sequence - 1, it is not 0.
_, err := path.EndpointA.SendPacket(defaultTimeoutHeight, disabledTimeoutTimestamp, ibctesting.MockPacketData)
suite.Require().NoError(err)
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)
Expand Down
Loading