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 3 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
types.CloseChannel(&channel)
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
types.CloseChannel(&channel)
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
types.CloseChannel(&channel)
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
types.CloseChannel(&counterpartyChannel)
},
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()
}

// CloseChannel modifies the Channel with the new State set to CLOSED and FlushStatus set to NOTINFLUSH.
func CloseChannel(channel *Channel) {
DimitrisJim marked this conversation as resolved.
Show resolved Hide resolved
channel.State = CLOSED
channel.FlushStatus = NOTINFLUSH
}

// 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

types.CloseChannel(&ch)

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
channeltypes.CloseChannel(&channel)
value = suite.chain.Codec.MustMarshal(&channel)
},
false,
Expand Down