Skip to content

Commit

Permalink
Merge branch 'main' into charly/paginate
Browse files Browse the repository at this point in the history
  • Loading branch information
charleenfei committed Jan 18, 2023
2 parents e6987b5 + c56f789 commit e2aa674
Show file tree
Hide file tree
Showing 15 changed files with 67 additions and 49 deletions.
6 changes: 5 additions & 1 deletion docs/migrations/v6-to-v7.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ ModuleBasics = module.NewBasicManager(

It may be useful to reference the [PR](https://github.com/cosmos/ibc-go/pull/2826) which added the `AppModuleBasic` for the solo machine client.

### Testing package API

The `SetChannelClosed` utility method in `testing/endpoint.go` has been updated to `SetChannelState`, which will take a `channeltypes.State` argument so that the `ChannelState` can be set to any of the possible channel states.

## IBC Apps

- No relevant changes were made in this release.
Expand Down Expand Up @@ -286,4 +290,4 @@ import (

- host.RouterKey
+ ibcexported.RouterKey
```
```
Original file line number Diff line number Diff line change
Expand Up @@ -887,9 +887,9 @@ func (suite *InterchainAccountsTestSuite) TestClosedChannelReopensWithMsgServer(
suite.Require().NoError(err)

// set the channel state to closed
err = path.EndpointA.SetChannelClosed()
err = path.EndpointA.SetChannelState(channeltypes.CLOSED)
suite.Require().NoError(err)
err = path.EndpointB.SetChannelClosed()
err = path.EndpointB.SetChannelState(channeltypes.CLOSED)
suite.Require().NoError(err)

// reset endpoint channel ids
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ func (suite *KeeperTestSuite) TestOnChanOpenInit() {
err := SetupICAPath(path, TestOwnerAddress)
suite.Require().NoError(err)

err = path.EndpointA.SetChannelClosed()
err = path.EndpointA.SetChannelState(channeltypes.CLOSED)
suite.Require().NoError(err)

err = path.EndpointB.SetChannelClosed()
err = path.EndpointB.SetChannelState(channeltypes.CLOSED)
suite.Require().NoError(err)

path.EndpointA.ChannelID = ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func (suite *KeeperTestSuite) TestSendTx() {
{
"sendPacket fails - channel closed",
func() {
err := path.EndpointA.SetChannelClosed()
err := path.EndpointA.SetChannelState(channeltypes.CLOSED)
suite.Require().NoError(err)
},
false,
Expand Down
6 changes: 3 additions & 3 deletions modules/apps/27-interchain-accounts/host/ibc_module_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -685,17 +685,17 @@ func (suite *InterchainAccountsTestSuite) TestControlAccountAfterChannelClose()
suite.assertBalance(icaAddr, expBalAfterFirstSend)

// close the channel
err = path.EndpointA.SetChannelClosed()
err = path.EndpointA.SetChannelState(channeltypes.CLOSED)
suite.Require().NoError(err)
err = path.EndpointB.SetChannelClosed()
err = path.EndpointB.SetChannelState(channeltypes.CLOSED)
suite.Require().NoError(err)

// open a new channel on the same port
path.EndpointA.ChannelID = ""
path.EndpointB.ChannelID = ""
suite.coordinator.CreateChannels(path)

//nolint: staticcheck // SA1019: ibctesting.FirstConnectionID is deprecated: use path.EndpointA.ConnectionID instead. (staticcheck)/nolint
//nolint: staticcheck // SA1019: ibctesting.FirstConnectionID is deprecated: use path.EndpointA.ConnectionID instead. (staticcheck)
_, err = suite.chainA.GetSimApp().ICAControllerKeeper.SendTx(suite.chainA.GetContext(), nil, ibctesting.FirstConnectionID, path.EndpointA.ChannelConfig.PortID, icaPacketData, ^uint64(0))
suite.Require().NoError(err)
err = path.EndpointB.UpdateClient()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ func (suite *KeeperTestSuite) openAndCloseChannel(path *ibctesting.Path) {
err = path.EndpointB.ChanOpenConfirm()
suite.Require().NoError(err)

err = path.EndpointA.SetChannelClosed()
err = path.EndpointA.SetChannelState(channeltypes.CLOSED)
suite.Require().NoError(err)

err = path.EndpointB.SetChannelClosed()
err = path.EndpointB.SetChannelState(channeltypes.CLOSED)
suite.Require().NoError(err)

path.EndpointA.ChannelID = ""
Expand Down
10 changes: 5 additions & 5 deletions modules/core/04-channel/keeper/handshake_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,7 @@ func (suite *KeeperTestSuite) TestChanCloseInit() {
channelCap = suite.chainA.GetChannelCapability(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID)

// close channel
err := path.EndpointA.SetChannelClosed()
err := path.EndpointA.SetChannelState(types.CLOSED)
suite.Require().NoError(err)
}, false},
{"connection not found", func() {
Expand Down Expand Up @@ -693,7 +693,7 @@ func (suite *KeeperTestSuite) TestChanCloseConfirm() {
suite.coordinator.Setup(path)
channelCap = suite.chainB.GetChannelCapability(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID)

err := path.EndpointA.SetChannelClosed()
err := path.EndpointA.SetChannelState(types.CLOSED)
suite.Require().NoError(err)
}, true},
{"channel doesn't exist", func() {
Expand All @@ -709,7 +709,7 @@ func (suite *KeeperTestSuite) TestChanCloseConfirm() {
suite.coordinator.Setup(path)
channelCap = suite.chainB.GetChannelCapability(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID)

err := path.EndpointB.SetChannelClosed()
err := path.EndpointB.SetChannelState(types.CLOSED)
suite.Require().NoError(err)
}, false},
{"connection not found", func() {
Expand Down Expand Up @@ -740,7 +740,7 @@ func (suite *KeeperTestSuite) TestChanCloseConfirm() {
suite.coordinator.Setup(path)
channelCap = suite.chainB.GetChannelCapability(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID)

err := path.EndpointA.SetChannelClosed()
err := path.EndpointA.SetChannelState(types.CLOSED)
suite.Require().NoError(err)

heightDiff = 3
Expand All @@ -754,7 +754,7 @@ func (suite *KeeperTestSuite) TestChanCloseConfirm() {
suite.coordinator.Setup(path)
channelCap = suite.chainB.GetChannelCapability(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID)

err := path.EndpointA.SetChannelClosed()
err := path.EndpointA.SetChannelState(types.CLOSED)
suite.Require().NoError(err)

channelCap = capabilitytypes.NewCapability(3)
Expand Down
4 changes: 2 additions & 2 deletions modules/core/04-channel/keeper/packet.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ func (k Keeper) SendPacket(
return 0, sdkerrors.Wrap(types.ErrChannelNotFound, sourceChannel)
}

if channel.State == types.CLOSED {
if channel.State != types.OPEN {
return 0, sdkerrors.Wrapf(
types.ErrInvalidChannelState,
"channel is CLOSED (got %s)", channel.State.String(),
"channel is not OPEN (got %s)", channel.State.String(),
)
}

Expand Down
24 changes: 19 additions & 5 deletions modules/core/04-channel/keeper/packet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,25 @@ func (suite *KeeperTestSuite) TestSendPacket() {
sourceChannel = ibctesting.InvalidID
channelCap = suite.chainA.GetChannelCapability(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID)
}, false},
{"channel closed", func() {
{"channel is in CLOSED state", func() {
suite.coordinator.Setup(path)
sourceChannel = path.EndpointA.ChannelID

err := path.EndpointA.SetChannelClosed()
err := path.EndpointA.SetChannelState(types.CLOSED)
suite.Require().NoError(err)
}, false},
{"channel is in INIT state", func() {
suite.coordinator.Setup(path)
sourceChannel = path.EndpointA.ChannelID

err := path.EndpointA.SetChannelState(types.INIT)
suite.Require().NoError(err)
}, false},
{"channel is in TRYOPEN stage", func() {
suite.coordinator.Setup(path)
sourceChannel = path.EndpointA.ChannelID

err := path.EndpointA.SetChannelState(types.TRYOPEN)
suite.Require().NoError(err)
}, false},
{"connection not found", func() {
Expand Down Expand Up @@ -337,7 +351,7 @@ func (suite *KeeperTestSuite) TestRecvPacket() {
suite.coordinator.Setup(path)
packet = types.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, defaultTimeoutHeight, disabledTimeoutTimestamp)

err := path.EndpointB.SetChannelClosed()
err := path.EndpointB.SetChannelState(types.CLOSED)
suite.Require().NoError(err)
channelCap = suite.chainB.GetChannelCapability(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID)
}, false},
Expand Down Expand Up @@ -535,7 +549,7 @@ func (suite *KeeperTestSuite) TestWriteAcknowledgement() {
packet = types.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, defaultTimeoutHeight, disabledTimeoutTimestamp)
ack = ibcmock.MockAcknowledgement

err := path.EndpointB.SetChannelClosed()
err := path.EndpointB.SetChannelState(types.CLOSED)
suite.Require().NoError(err)
channelCap = suite.chainB.GetChannelCapability(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID)
}, false},
Expand Down Expand Up @@ -695,7 +709,7 @@ func (suite *KeeperTestSuite) TestAcknowledgePacket() {
suite.coordinator.Setup(path)
packet = types.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, defaultTimeoutHeight, disabledTimeoutTimestamp)

err := path.EndpointA.SetChannelClosed()
err := path.EndpointA.SetChannelState(types.CLOSED)
suite.Require().NoError(err)
channelCap = suite.chainA.GetChannelCapability(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID)
}, false},
Expand Down
14 changes: 7 additions & 7 deletions modules/core/04-channel/keeper/timeout_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func (suite *KeeperTestSuite) TestTimeoutPacket() {
err = path.EndpointA.UpdateClient()
suite.Require().NoError(err)

err = path.EndpointA.SetChannelClosed()
err = path.EndpointA.SetChannelState(types.CLOSED)
suite.Require().NoError(err)
}, false},
{"packet destination port ≠ channel counterparty port", func() {
Expand Down Expand Up @@ -332,7 +332,7 @@ func (suite *KeeperTestSuite) TestTimeoutOnClose() {

sequence, err := path.EndpointA.SendPacket(timeoutHeight, timeoutTimestamp, ibctesting.MockPacketData)
suite.Require().NoError(err)
err = path.EndpointB.SetChannelClosed()
err = path.EndpointB.SetChannelState(types.CLOSED)
suite.Require().NoError(err)
// need to update chainA's client representing chainB to prove missing ack
err = path.EndpointA.UpdateClient()
Expand All @@ -349,7 +349,7 @@ func (suite *KeeperTestSuite) TestTimeoutOnClose() {

sequence, err := path.EndpointA.SendPacket(timeoutHeight, disabledTimeoutTimestamp, ibctesting.MockPacketData)
suite.Require().NoError(err)
err = path.EndpointB.SetChannelClosed()
err = path.EndpointB.SetChannelState(types.CLOSED)
suite.Require().NoError(err)
// need to update chainA's client representing chainB to prove missing ack
err = path.EndpointA.UpdateClient()
Expand Down Expand Up @@ -406,7 +406,7 @@ func (suite *KeeperTestSuite) TestTimeoutOnClose() {

sequence, err := path.EndpointA.SendPacket(timeoutHeight, timeoutTimestamp, ibctesting.MockPacketData)
suite.Require().NoError(err)
err = path.EndpointB.SetChannelClosed()
err = path.EndpointB.SetChannelState(types.CLOSED)
suite.Require().NoError(err)
// need to update chainA's client representing chainB to prove missing ack
err = path.EndpointA.UpdateClient()
Expand Down Expand Up @@ -439,7 +439,7 @@ func (suite *KeeperTestSuite) TestTimeoutOnClose() {

sequence, err := path.EndpointA.SendPacket(timeoutHeight, timeoutTimestamp, ibctesting.MockPacketData)
suite.Require().NoError(err)
err = path.EndpointB.SetChannelClosed()
err = path.EndpointB.SetChannelState(types.CLOSED)
suite.Require().NoError(err)
err = path.EndpointA.UpdateClient()
suite.Require().NoError(err)
Expand All @@ -456,7 +456,7 @@ func (suite *KeeperTestSuite) TestTimeoutOnClose() {

sequence, err := path.EndpointA.SendPacket(timeoutHeight, disabledTimeoutTimestamp, ibctesting.MockPacketData)
suite.Require().NoError(err)
err = path.EndpointB.SetChannelClosed()
err = path.EndpointB.SetChannelState(types.CLOSED)
suite.Require().NoError(err)
err = path.EndpointA.UpdateClient()
suite.Require().NoError(err)
Expand All @@ -474,7 +474,7 @@ func (suite *KeeperTestSuite) TestTimeoutOnClose() {

sequence, err := path.EndpointA.SendPacket(timeoutHeight, timeoutTimestamp, ibctesting.MockPacketData)
suite.Require().NoError(err)
err = path.EndpointB.SetChannelClosed()
err = path.EndpointB.SetChannelState(types.CLOSED)
suite.Require().NoError(err)
// need to update chainA's client representing chainB to prove missing ack
err = path.EndpointA.UpdateClient()
Expand Down
2 changes: 1 addition & 1 deletion modules/core/ante/ante_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func (suite *AnteTestSuite) createTimeoutOnCloseMessage(isRedundant bool) sdk.Ms

sequence, err := suite.path.EndpointB.SendPacket(timeoutHeight, 0, ibctesting.MockPacketData)
suite.Require().NoError(err)
err = suite.path.EndpointA.SetChannelClosed()
err = suite.path.EndpointA.SetChannelState(channeltypes.CLOSED)
suite.Require().NoError(err)

packet := channeltypes.NewPacket(ibctesting.MockPacketData, sequence,
Expand Down
12 changes: 6 additions & 6 deletions modules/core/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,15 +282,15 @@ func (k Keeper) ChannelOpenAck(goCtx context.Context, msg *channeltypes.MsgChann
return nil, sdkerrors.Wrap(err, "channel handshake open ack failed")
}

// Write channel into state
k.ChannelKeeper.WriteOpenAckChannel(ctx, msg.PortId, msg.ChannelId, msg.CounterpartyVersion, msg.CounterpartyChannelId)

// Perform application logic callback
if err = cbs.OnChanOpenAck(ctx, msg.PortId, msg.ChannelId, msg.CounterpartyChannelId, msg.CounterpartyVersion); err != nil {
ctx.Logger().Error("channel handshake open ack callback failed", "port-id", msg.PortId, "channel-id", msg.ChannelId, "error", err.Error())
return nil, sdkerrors.Wrapf(err, "channel open ack callback failed for port ID: %s, channel ID: %s", msg.PortId, msg.ChannelId)
}

// Write channel into state
k.ChannelKeeper.WriteOpenAckChannel(ctx, msg.PortId, msg.ChannelId, msg.CounterpartyVersion, msg.CounterpartyChannelId)

ctx.Logger().Info("channel open ack callback succeeded", "channel-id", msg.ChannelId, "port-id", msg.PortId)

return &channeltypes.MsgChannelOpenAckResponse{}, nil
Expand Down Expand Up @@ -322,15 +322,15 @@ func (k Keeper) ChannelOpenConfirm(goCtx context.Context, msg *channeltypes.MsgC
return nil, sdkerrors.Wrap(err, "channel handshake open confirm failed")
}

// Write channel into state
k.ChannelKeeper.WriteOpenConfirmChannel(ctx, msg.PortId, msg.ChannelId)

// Perform application logic callback
if err = cbs.OnChanOpenConfirm(ctx, msg.PortId, msg.ChannelId); err != nil {
ctx.Logger().Error("channel handshake open confirm callback failed", "port-id", msg.PortId, "channel-id", msg.ChannelId, "error", err.Error())
return nil, sdkerrors.Wrapf(err, "channel open confirm callback failed for port ID: %s, channel ID: %s", msg.PortId, msg.ChannelId)
}

// Write channel into state
k.ChannelKeeper.WriteOpenConfirmChannel(ctx, msg.PortId, msg.ChannelId)

ctx.Logger().Info("channel open confirm callback succeeded", "channel-id", msg.ChannelId, "port-id", msg.PortId)

return &channeltypes.MsgChannelOpenConfirmResponse{}, nil
Expand Down
10 changes: 5 additions & 5 deletions modules/core/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ func (suite *KeeperTestSuite) TestHandleTimeoutOnClosePacket() {
packetKey = host.NextSequenceRecvKey(packet.GetDestPort(), packet.GetDestChannel())

// close counterparty channel
err = path.EndpointB.SetChannelClosed()
err = path.EndpointB.SetChannelState(channeltypes.CLOSED)
suite.Require().NoError(err)
}, true},
{"success: UNORDERED", func() {
Expand All @@ -538,7 +538,7 @@ func (suite *KeeperTestSuite) TestHandleTimeoutOnClosePacket() {
packetKey = host.PacketReceiptKey(packet.GetDestPort(), packet.GetDestChannel(), packet.GetSequence())

// close counterparty channel
err = path.EndpointB.SetChannelClosed()
err = path.EndpointB.SetChannelState(channeltypes.CLOSED)
suite.Require().NoError(err)
}, true},
{"success: UNORDERED timeout out of order packet", func() {
Expand All @@ -561,7 +561,7 @@ func (suite *KeeperTestSuite) TestHandleTimeoutOnClosePacket() {
packetKey = host.PacketReceiptKey(packet.GetDestPort(), packet.GetDestChannel(), packet.GetSequence())

// close counterparty channel
err = path.EndpointB.SetChannelClosed()
err = path.EndpointB.SetChannelState(channeltypes.CLOSED)
suite.Require().NoError(err)
}, true},
{"success: ORDERED timeout out of order packet", func() {
Expand All @@ -584,7 +584,7 @@ func (suite *KeeperTestSuite) TestHandleTimeoutOnClosePacket() {
packetKey = host.NextSequenceRecvKey(packet.GetDestPort(), packet.GetDestChannel())

// close counterparty channel
err = path.EndpointB.SetChannelClosed()
err = path.EndpointB.SetChannelState(channeltypes.CLOSED)
suite.Require().NoError(err)
}, true},
{"channel does not exist", func() {
Expand All @@ -599,7 +599,7 @@ func (suite *KeeperTestSuite) TestHandleTimeoutOnClosePacket() {
packetKey = host.PacketAcknowledgementKey(packet.GetDestPort(), packet.GetDestChannel(), packet.GetSequence())

// close counterparty channel
err := path.EndpointB.SetChannelClosed()
err := path.EndpointB.SetChannelState(channeltypes.CLOSED)
suite.Require().NoError(err)
}, true},
{"ORDERED: channel not closed", func() {
Expand Down
8 changes: 4 additions & 4 deletions modules/light-clients/07-tendermint/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,11 @@ func IterateConsensusMetadata(store sdk.KVStore, cb func(key, val []byte) bool)
}

// iterate over iteration keys
iterator = sdk.KVStorePrefixIterator(store, []byte(KeyIterateConsensusStatePrefix))
iter := sdk.KVStorePrefixIterator(store, []byte(KeyIterateConsensusStatePrefix))

defer iterator.Close()
for ; iterator.Valid(); iterator.Next() {
if cb(iterator.Key(), iterator.Value()) {
defer iter.Close()
for ; iter.Valid(); iter.Next() {
if cb(iter.Key(), iter.Value()) {
break
}
}
Expand Down
6 changes: 3 additions & 3 deletions testing/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -566,11 +566,11 @@ func (endpoint *Endpoint) TimeoutOnClose(packet channeltypes.Packet) error {
return endpoint.Chain.sendMsgs(timeoutOnCloseMsg)
}

// SetChannelClosed sets a channel state to CLOSED.
func (endpoint *Endpoint) SetChannelClosed() error {
// SetChannelState sets a channel state
func (endpoint *Endpoint) SetChannelState(state channeltypes.State) error {
channel := endpoint.GetChannel()

channel.State = channeltypes.CLOSED
channel.State = state
endpoint.Chain.App.GetIBCKeeper().ChannelKeeper.SetChannel(endpoint.Chain.GetContext(), endpoint.ChannelConfig.PortID, endpoint.ChannelID, channel)

endpoint.Chain.Coordinator.CommitBlock(endpoint.Chain)
Expand Down

0 comments on commit e2aa674

Please sign in to comment.