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

Set channel state to NOTINFLUSH when Closing #3995

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
4 changes: 2 additions & 2 deletions modules/core/04-channel/keeper/handshake.go
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ func (k Keeper) ChanCloseInit(

defer telemetry.IncrCounter(1, "ibc", "channel", "close-init")

channel.State = types.CLOSED
channel.Close()
k.SetChannel(ctx, portID, channelID, channel)

emitChannelCloseInitEvent(ctx, portID, channelID, channel)
Expand Down Expand Up @@ -476,7 +476,7 @@ func (k Keeper) ChanCloseConfirm(

defer telemetry.IncrCounter(1, "ibc", "channel", "close-confirm")

channel.State = types.CLOSED
channel.Close()
k.SetChannel(ctx, portID, channelID, channel)

emitChannelCloseConfirmEvent(ctx, portID, channelID, channel)
Expand Down
2 changes: 1 addition & 1 deletion modules/core/04-channel/keeper/timeout.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ func (k Keeper) TimeoutExecuted(
k.deletePacketCommitment(ctx, packet.GetSourcePort(), packet.GetSourceChannel(), packet.GetSequence())

if channel.Ordering == types.ORDERED {
channel.State = types.CLOSED
channel.Close()
k.SetChannel(ctx, packet.GetSourcePort(), packet.GetSourceChannel(), channel)
}

Expand Down
2 changes: 1 addition & 1 deletion modules/core/04-channel/keeper/upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -991,7 +991,7 @@ func (suite *KeeperTestSuite) TestStartFlushUpgradeHandshake() {
{
"failed verification for counterparty channel state due to incorrectly constructed counterparty channel",
func() {
counterpartyChannel.State = types.CLOSED
counterpartyChannel.Close()
},
commitmenttypes.ErrInvalidProof,
},
Expand Down
6 changes: 6 additions & 0 deletions modules/core/04-channel/types/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ func (ch Channel) ValidateBasic() error {
return ch.Counterparty.ValidateBasic()
}

// Close modifies the Channel with the new State set to CLOSED and FlushStatus set to NOTINFLUSH.
func (ch *Channel) Close() {
ch.State = CLOSED
ch.FlushStatus = NOTINFLUSH
}
Comment on lines +78 to +82
Copy link
Contributor

Choose a reason for hiding this comment

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

if we refactor things to put the flush status on the Upgrade then I don't think we'll need this method

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yep good point, We can maybe just revert this PR if that happens


// NewCounterparty returns a new Counterparty instance
func NewCounterparty(portID, channelID string) Counterparty {
return Counterparty{
Expand Down
10 changes: 10 additions & 0 deletions modules/core/04-channel/types/channel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,13 @@ func TestCounterpartyValidateBasic(t *testing.T) {
}
}
}

func TestCloseChannel(t *testing.T) {
ch := types.NewChannel(types.OPEN, types.ORDERED, types.Counterparty{"portidone", "channelidone"}, connHops, version)
ch.FlushStatus = types.FLUSHING

ch.Close()

require.Equal(t, types.CLOSED, ch.State)
require.Equal(t, types.NOTINFLUSH, ch.FlushStatus)
}
3 changes: 2 additions & 1 deletion modules/light-clients/09-localhost/client_state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,8 @@ func (suite *LocalhostTestSuite) TestVerifyMembership() {

path = merklePath

channel.State = channeltypes.CLOSED // modify the channel before marshalling to value bz
// modify the channel before marshalling to value bz
channel.Close()
value = suite.chain.Codec.MustMarshal(&channel)
},
false,
Expand Down