Skip to content

Commit

Permalink
chore: require active channel be CLOSED before re-opening. (#5601)
Browse files Browse the repository at this point in the history
  • Loading branch information
DimitrisJim authored Jan 15, 2024
1 parent 3f83cf6 commit 78415d1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ func (k Keeper) OnChanOpenInit(
panic(fmt.Errorf("active channel mapping set for %s but channel does not exist in channel store", activeChannelID))
}

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

if channel.Ordering != order {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ func (suite *KeeperTestSuite) TestOnChanOpenInit() {
icatypes.ErrInvalidVersion,
},
{
"channel is already active",
"channel is already active (OPEN state)",
func() {
suite.chainA.GetSimApp().ICAControllerKeeper.SetActiveChannelID(suite.chainA.GetContext(), ibctesting.FirstConnectionID, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID)

Expand All @@ -237,6 +237,23 @@ func (suite *KeeperTestSuite) TestOnChanOpenInit() {
},
icatypes.ErrActiveChannelAlreadySet,
},
{
"channel is already active (FLUSHING state)",
func() {
suite.chainA.GetSimApp().ICAControllerKeeper.SetActiveChannelID(suite.chainA.GetContext(), ibctesting.FirstConnectionID, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID)

counterparty := channeltypes.NewCounterparty(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID)
channel := channeltypes.Channel{
State: channeltypes.FLUSHING,
Ordering: channeltypes.ORDERED,
Counterparty: counterparty,
ConnectionHops: []string{path.EndpointA.ConnectionID},
Version: TestVersion,
}
suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper.SetChannel(suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, channel)
},
icatypes.ErrActiveChannelAlreadySet,
},
}

for _, tc := range testCases {
Expand Down

0 comments on commit 78415d1

Please sign in to comment.