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

Amend timeoutPacket to allow timeouts on any channel state. #4367

Merged
merged 4 commits into from
Aug 24, 2023
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
7 changes: 0 additions & 7 deletions modules/core/04-channel/keeper/timeout.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,6 @@ func (k Keeper) TimeoutPacket(
return types.ErrNoOpMsg
}

if channel.State != types.OPEN {
Copy link
Member

Choose a reason for hiding this comment

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

couldn't we also just extend this to allow timeouts on OPEN and FLUSHING channels?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

that was my initial thought pre-discussion. This isn't spec'ed out in any way (i.e the check for State != types.OPEN also isn't there), so when we talked about it I remember us coming to the conclusion that it could be removed. Happy to wait for a review from @colin-axner when he gets back

Copy link
Contributor

Choose a reason for hiding this comment

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

Why would you want to restrict when packets can be timed out?

Copy link
Contributor

Choose a reason for hiding this comment

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

It should be possible to timeout a packet even after a channel closes

Copy link
Member

Choose a reason for hiding this comment

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

My only thinking was that a closed channel maybe shouldn't be acted on, but its fair, don't see exactly why that would be an issue either.

If you're happy with removing this check, then let's go ahead and do it 👍

I do think restricting to open and flushing makes it very explicit tho, and removes any room for potentially odd side effects when in handshakes or in the case of a channel closed and reopened.

Copy link
Contributor

Choose a reason for hiding this comment

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

In theory that makes sense, but in practice it is problematic. There's a potential state where chainA has a closed channel and chainB doesn't. Until someone calls ChanCloseConfirm, all timeouts are valid, but with a restriction, after calling close confirm, timeouts are no longer valid, but that's a very loose assumption and I don't think apps are built to handle channel closes like that

My preference would be to open an issue on the spec if there's a concern. I don't see why ibc-go should be opinionated in this matter

Copy link
Contributor

Choose a reason for hiding this comment

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

There's also no check on TimeoutOnClose, so this restriction can be bypassed unless you added it there as well

Copy link
Member

Choose a reason for hiding this comment

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

Sounds fair enough to me!

Copy link
Contributor

@colin-axner colin-axner Aug 24, 2023

Choose a reason for hiding this comment

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

I think the other point I'd make is that IBC only specifies optimistic sends as unsafe (potentially not recoverable). I think it's important to build the assumption that all other sends can be reverted regardless of what occurs

return errorsmod.Wrapf(
types.ErrInvalidChannelState,
"channel state is not OPEN (got %s)", channel.State.String(),
)
}

packetCommitment := types.CommitPacket(k.cdc, packet)

// verify we sent the packet and haven't cleared it out yet
Expand Down
16 changes: 0 additions & 16 deletions modules/core/04-channel/keeper/timeout_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,22 +98,6 @@ func (suite *KeeperTestSuite) TestTimeoutPacket() {
suite.coordinator.Setup(path)
packet = types.NewPacket(ibctesting.MockPacketData, 1, ibctesting.InvalidID, ibctesting.InvalidID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, defaultTimeoutHeight, disabledTimeoutTimestamp)
}, false},
{"channel not open", func() {
expError = types.ErrInvalidChannelState
suite.coordinator.Setup(path)

timeoutHeight := path.EndpointA.GetClientState().GetLatestHeight().Increment().(clienttypes.Height)

sequence, err := path.EndpointA.SendPacket(timeoutHeight, 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, timeoutHeight, disabledTimeoutTimestamp)
// need to update chainA's client representing chainB to prove missing ack
err = path.EndpointA.UpdateClient()
suite.Require().NoError(err)

err = path.EndpointA.SetChannelState(types.CLOSED)
suite.Require().NoError(err)
}, false},
{"packet destination port ≠ channel counterparty port", func() {
expError = types.ErrInvalidPacket
suite.coordinator.Setup(path)
Expand Down