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: adding IsOpen and IsClosed methods to Channel type (#4152) #4155

Merged
merged 2 commits into from
Jul 21, 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
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func (k Keeper) OnChanOpenInit(
panic(fmt.Sprintf("active channel mapping set for %s but channel does not exist in channel store", activeChannelID))
}

if channel.State == channeltypes.OPEN {
if channel.IsOpen() {
return "", errorsmod.Wrapf(icatypes.ErrActiveChannelAlreadySet, "existing active channel %s for portID %s is already OPEN", activeChannelID, portID)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ func (k Keeper) GetOpenActiveChannel(ctx sdk.Context, connectionID, portID strin

channel, found := k.channelKeeper.GetChannel(ctx, portID, channelID)

if found && channel.State == channeltypes.OPEN {
if found && channel.IsOpen() {
return channelID, true
}

Expand All @@ -161,7 +161,7 @@ func (k Keeper) IsActiveChannelClosed(ctx sdk.Context, connectionID, portID stri
}

channel, found := k.channelKeeper.GetChannel(ctx, portID, channelID)
return found && channel.State == channeltypes.CLOSED
return found && channel.IsClosed()
}

// GetAllActiveChannels returns a list of all active interchain accounts controller channels and their associated connection and port identifiers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func (k Keeper) OnChanOpenTry(
panic(fmt.Sprintf("active channel mapping set for %s but channel does not exist in channel store", activeChannelID))
}

if channel.State == channeltypes.OPEN {
if channel.IsOpen() {
return "", errorsmod.Wrapf(icatypes.ErrActiveChannelAlreadySet, "existing active channel %s for portID %s is already OPEN", activeChannelID, portID)
}

Expand Down
3 changes: 1 addition & 2 deletions modules/apps/27-interchain-accounts/host/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
genesistypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/genesis/types"
"github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host/types"
icatypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/types"
channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types"
porttypes "github.com/cosmos/ibc-go/v7/modules/core/05-port/types"
host "github.com/cosmos/ibc-go/v7/modules/core/24-host"
ibcerrors "github.com/cosmos/ibc-go/v7/modules/core/errors"
Expand Down Expand Up @@ -146,7 +145,7 @@ func (k Keeper) GetOpenActiveChannel(ctx sdk.Context, connectionID, portID strin

channel, found := k.channelKeeper.GetChannel(ctx, portID, channelID)

if found && channel.State == channeltypes.OPEN {
if found && channel.IsOpen() {
return channelID, true
}

Expand Down
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 @@ -385,7 +385,7 @@ func (k Keeper) ChanCloseInit(
return errorsmod.Wrapf(types.ErrChannelNotFound, "port ID (%s) channel ID (%s)", portID, channelID)
}

if channel.State == types.CLOSED {
if channel.IsClosed() {
return errorsmod.Wrap(types.ErrInvalidChannelState, "channel is already CLOSED")
}

Expand Down Expand Up @@ -441,7 +441,7 @@ func (k Keeper) ChanCloseConfirm(
return errorsmod.Wrapf(types.ErrChannelNotFound, "port ID (%s) channel ID (%s)", portID, channelID)
}

if channel.State == types.CLOSED {
if channel.IsClosed() {
return errorsmod.Wrap(types.ErrInvalidChannelState, "channel is already CLOSED")
}

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 @@ -171,7 +171,7 @@ func (k Keeper) TimeoutExecuted(
// emit an event marking that we have processed the timeout
emitTimeoutPacketEvent(ctx, packet, channel)

if channel.Ordering == types.ORDERED && channel.State == types.CLOSED {
if channel.Ordering == types.ORDERED && channel.IsClosed() {
emitChannelClosedEvent(ctx, packet, channel)
}

Expand Down
10 changes: 10 additions & 0 deletions modules/core/04-channel/types/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,16 @@ func (ch Channel) GetVersion() string {
return ch.Version
}

// IsOpen returns true if the channel state is OPEN
func (ch Channel) IsOpen() bool {
return ch.State == OPEN
}

// IsClosed returns true if the channel state is CLOSED
func (ch Channel) IsClosed() bool {
return ch.State == CLOSED
}

// ValidateBasic performs a basic validation of the channel fields
func (ch Channel) ValidateBasic() error {
if ch.State == UNINITIALIZED {
Expand Down
Loading