Skip to content

Commit

Permalink
chore (api)!: remove LookupModuleByPort (#7252)
Browse files Browse the repository at this point in the history
* chore (api)! remove LookupModuleByPort

* Update CHANGELOG.md

Co-authored-by: DimitrisJim <[email protected]>

---------

Co-authored-by: DimitrisJim <[email protected]>
  • Loading branch information
bznein and DimitrisJim authored Sep 4, 2024
1 parent a953d38 commit 4685670
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 63 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* (core, apps) [\#7213](https://github.com/cosmos/ibc-go/pull/7225) Remove capabilities from `WriteAcknowledgement`.
* (core, apps) [\#7232](https://github.com/cosmos/ibc-go/pull/7232) Remove capabilities from channel handshake methods. TODO list all changes
* (core/04-channel) [\#7239](https://github.com/cosmos/ibc-go/pull/7239) Removed function `LookupModuleByChannel`
* (core/05-port) [\#7252](https://github.com/cosmos/ibc-go/pull/7252) Removed function `LookupModuleByPort`
* (core/24-host) [\#7239](https://github.com/cosmos/ibc-go/pull/7239) Removed function `ChannelCapabilityPath`
* (apps/27-interchain-accounts) [\#7239](https://github.com/cosmos/ibc-go/pull/7239) The following functions have been removed: `AuthenticateCapability`, `ClaimCapability`
* (apps/transfer) [\#7239](https://github.com/cosmos/ibc-go/pull/7239) The following functions have been removed: `BindPort`, `AuthenticateCapability`, `ClaimCapability`
Expand Down
59 changes: 12 additions & 47 deletions modules/apps/29-fee/ibc_middleware_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,7 @@ func (suite *FeeTestSuite) TestOnChanOpenInit() {
Version: tc.version,
}

module, _, err := suite.chainA.App.GetIBCKeeper().PortKeeper.LookupModuleByPort(suite.chainA.GetContext(), ibctesting.MockFeePort)
suite.Require().NoError(err)

cbs, ok := suite.chainA.App.GetIBCKeeper().PortKeeper.Route(module)
cbs, ok := suite.chainA.App.GetIBCKeeper().PortKeeper.Route(ibctesting.MockFeePort)
suite.Require().True(ok)

version, err := cbs.OnChanOpenInit(suite.chainA.GetContext(), channel.Ordering, channel.ConnectionHops,
Expand Down Expand Up @@ -205,10 +202,7 @@ func (suite *FeeTestSuite) TestOnChanOpenTry() {
Version: tc.cpVersion,
}

module, _, err := suite.chainA.App.GetIBCKeeper().PortKeeper.LookupModuleByPort(suite.chainA.GetContext(), ibctesting.MockFeePort)
suite.Require().NoError(err)

cbs, ok := suite.chainA.App.GetIBCKeeper().PortKeeper.Route(module)
cbs, ok := suite.chainA.App.GetIBCKeeper().PortKeeper.Route(ibctesting.MockFeePort)
suite.Require().True(ok)

_, err = cbs.OnChanOpenTry(suite.chainA.GetContext(), channel.Ordering, channel.ConnectionHops,
Expand Down Expand Up @@ -292,10 +286,7 @@ func (suite *FeeTestSuite) TestOnChanOpenAck() {
err = suite.path.EndpointB.ChanOpenTry()
suite.Require().NoError(err)

module, _, err := suite.chainA.App.GetIBCKeeper().PortKeeper.LookupModuleByPort(suite.chainA.GetContext(), ibctesting.MockFeePort)
suite.Require().NoError(err)

cbs, ok := suite.chainA.App.GetIBCKeeper().PortKeeper.Route(module)
cbs, ok := suite.chainA.App.GetIBCKeeper().PortKeeper.Route(ibctesting.MockFeePort)
suite.Require().True(ok)

err = cbs.OnChanOpenAck(suite.chainA.GetContext(), suite.path.EndpointA.ChannelConfig.PortID, suite.path.EndpointA.ChannelID, suite.path.EndpointA.Counterparty.ChannelID, tc.cpVersion)
Expand Down Expand Up @@ -379,10 +370,7 @@ func (suite *FeeTestSuite) TestOnChanCloseInit() {

tc.malleate()

module, _, err := suite.chainA.App.GetIBCKeeper().PortKeeper.LookupModuleByPort(suite.chainA.GetContext(), ibctesting.MockFeePort)
suite.Require().NoError(err)

cbs, ok := suite.chainA.App.GetIBCKeeper().PortKeeper.Route(module)
cbs, ok := suite.chainA.App.GetIBCKeeper().PortKeeper.Route(ibctesting.MockFeePort)
suite.Require().True(ok)

err = cbs.OnChanCloseInit(suite.chainA.GetContext(), suite.path.EndpointA.ChannelConfig.PortID, suite.path.EndpointA.ChannelID)
Expand Down Expand Up @@ -469,10 +457,7 @@ func (suite *FeeTestSuite) TestOnChanCloseConfirm() {

tc.malleate()

module, _, err := suite.chainA.App.GetIBCKeeper().PortKeeper.LookupModuleByPort(suite.chainA.GetContext(), ibctesting.MockFeePort)
suite.Require().NoError(err)

cbs, ok := suite.chainA.App.GetIBCKeeper().PortKeeper.Route(module)
cbs, ok := suite.chainA.App.GetIBCKeeper().PortKeeper.Route(ibctesting.MockFeePort)
suite.Require().True(ok)

err = cbs.OnChanCloseConfirm(suite.chainA.GetContext(), suite.path.EndpointA.ChannelConfig.PortID, suite.path.EndpointA.ChannelID)
Expand Down Expand Up @@ -548,10 +533,8 @@ func (suite *FeeTestSuite) TestOnRecvPacket() {
packet := suite.CreateMockPacket()

// set up module and callbacks
module, _, err := suite.chainB.App.GetIBCKeeper().PortKeeper.LookupModuleByPort(suite.chainB.GetContext(), ibctesting.MockFeePort)
suite.Require().NoError(err)

cbs, ok := suite.chainB.App.GetIBCKeeper().PortKeeper.Route(module)
cbs, ok := suite.chainB.App.GetIBCKeeper().PortKeeper.Route(ibctesting.MockFeePort)
suite.Require().True(ok)

suite.chainB.GetSimApp().IBCFeeKeeper.SetCounterpartyPayeeAddress(suite.chainB.GetContext(), suite.chainA.SenderAccount.GetAddress().String(), suite.chainB.SenderAccount.GetAddress().String(), suite.path.EndpointB.ChannelID)
Expand Down Expand Up @@ -827,10 +810,7 @@ func (suite *FeeTestSuite) TestOnAcknowledgementPacket() {
initialRefundAccBal = sdk.NewCoins(suite.chainA.GetSimApp().BankKeeper.GetBalance(suite.chainA.GetContext(), refundAddr, sdk.DefaultBondDenom))

// retrieve module callbacks
module, _, err := suite.chainA.App.GetIBCKeeper().PortKeeper.LookupModuleByPort(suite.chainA.GetContext(), ibctesting.MockFeePort)
suite.Require().NoError(err)

cbs, ok := suite.chainA.App.GetIBCKeeper().PortKeeper.Route(module)
cbs, ok := suite.chainA.App.GetIBCKeeper().PortKeeper.Route(ibctesting.MockFeePort)
suite.Require().True(ok)

err = cbs.OnAcknowledgementPacket(suite.chainA.GetContext(), suite.path.EndpointA.GetChannel().Version, packet, ack, relayerAddr)
Expand Down Expand Up @@ -1038,10 +1018,7 @@ func (suite *FeeTestSuite) TestOnTimeoutPacket() {
initialRelayerAccBal = sdk.NewCoins(suite.chainA.GetSimApp().BankKeeper.GetBalance(suite.chainA.GetContext(), relayerAddr, sdk.DefaultBondDenom))

// retrieve module callbacks
module, _, err := suite.chainA.App.GetIBCKeeper().PortKeeper.LookupModuleByPort(suite.chainA.GetContext(), ibctesting.MockFeePort)
suite.Require().NoError(err)

cbs, ok := suite.chainA.App.GetIBCKeeper().PortKeeper.Route(module)
cbs, ok := suite.chainA.App.GetIBCKeeper().PortKeeper.Route(ibctesting.MockFeePort)
suite.Require().True(ok)

err = cbs.OnTimeoutPacket(suite.chainA.GetContext(), suite.path.EndpointA.GetChannel().Version, packet, relayerAddr)
Expand Down Expand Up @@ -1353,10 +1330,7 @@ func (suite *FeeTestSuite) TestOnChanUpgradeAck() {

counterpartyUpgrade := path.EndpointB.GetChannelUpgrade()

module, _, err := suite.chainA.App.GetIBCKeeper().PortKeeper.LookupModuleByPort(suite.chainA.GetContext(), ibctesting.MockFeePort)
suite.Require().NoError(err)

app, ok := suite.chainA.App.GetIBCKeeper().PortKeeper.Route(module)
app, ok := suite.chainA.App.GetIBCKeeper().PortKeeper.Route(ibctesting.MockFeePort)
suite.Require().True(ok)

cbs, ok := app.(porttypes.UpgradableModule)
Expand Down Expand Up @@ -1463,10 +1437,7 @@ func (suite *FeeTestSuite) TestOnChanUpgradeOpen() {
err = path.EndpointB.ChanUpgradeConfirm()
suite.Require().NoError(err)

module, _, err := suite.chainA.App.GetIBCKeeper().PortKeeper.LookupModuleByPort(suite.chainA.GetContext(), ibctesting.MockFeePort)
suite.Require().NoError(err)

app, ok := suite.chainA.App.GetIBCKeeper().PortKeeper.Route(module)
app, ok := suite.chainA.App.GetIBCKeeper().PortKeeper.Route(ibctesting.MockFeePort)
suite.Require().True(ok)

cbs, ok := app.(porttypes.UpgradableModule)
Expand Down Expand Up @@ -1539,10 +1510,7 @@ func (suite *FeeTestSuite) TestGetAppVersion() {
// malleate test case
tc.malleate()

module, _, err := suite.chainA.App.GetIBCKeeper().PortKeeper.LookupModuleByPort(suite.chainA.GetContext(), ibctesting.MockFeePort)
suite.Require().NoError(err)

cbs, ok := suite.chainA.App.GetIBCKeeper().PortKeeper.Route(module)
cbs, ok := suite.chainA.App.GetIBCKeeper().PortKeeper.Route(ibctesting.MockFeePort)
suite.Require().True(ok)

feeModule, ok := cbs.(porttypes.ICS4Wrapper)
Expand All @@ -1562,10 +1530,7 @@ func (suite *FeeTestSuite) TestGetAppVersion() {
}

func (suite *FeeTestSuite) TestPacketDataUnmarshalerInterface() {
module, _, err := suite.chainA.App.GetIBCKeeper().PortKeeper.LookupModuleByPort(suite.chainA.GetContext(), ibctesting.MockFeePort)
suite.Require().NoError(err)

cbs, ok := suite.chainA.App.GetIBCKeeper().PortKeeper.Route(module)
cbs, ok := suite.chainA.App.GetIBCKeeper().PortKeeper.Route(ibctesting.MockFeePort)
suite.Require().True(ok)

feeModule, ok := cbs.(porttypes.PacketDataUnmarshaler)
Expand Down
9 changes: 3 additions & 6 deletions modules/apps/callbacks/ibc_middleware_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -952,10 +952,9 @@ func (s *CallbacksTestSuite) TestProcessCallback() {
}

tc.malleate()
var err error

module, _, err := s.chainA.App.GetIBCKeeper().PortKeeper.LookupModuleByPort(s.chainA.GetContext(), ibctesting.MockFeePort)
s.Require().NoError(err)
cbs, ok := s.chainA.App.GetIBCKeeper().PortKeeper.Route(module)
cbs, ok := s.chainA.App.GetIBCKeeper().PortKeeper.Route(ibctesting.MockFeePort)
s.Require().True(ok)
mockCallbackStack, ok := cbs.(ibccallbacks.IBCMiddleware)
s.Require().True(ok)
Expand Down Expand Up @@ -1112,9 +1111,7 @@ func (s *CallbacksTestSuite) TestOnChanCloseConfirm() {
func (s *CallbacksTestSuite) TestOnRecvPacketAsyncAck() {
s.SetupMockFeeTest()

module, _, err := s.chainA.App.GetIBCKeeper().PortKeeper.LookupModuleByPort(s.chainA.GetContext(), ibctesting.MockFeePort)
s.Require().NoError(err)
cbs, ok := s.chainA.App.GetIBCKeeper().PortKeeper.Route(module)
cbs, ok := s.chainA.App.GetIBCKeeper().PortKeeper.Route(ibctesting.MockFeePort)
s.Require().True(ok)
mockFeeCallbackStack, ok := cbs.(porttypes.Middleware)
s.Require().True(ok)
Expand Down
10 changes: 0 additions & 10 deletions modules/core/05-port/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,6 @@ func (k *Keeper) Authenticate(ctx context.Context, key *capabilitytypes.Capabili
return k.scopedKeeper.AuthenticateCapability(ctx, key, host.PortPath(portID))
}

// LookupModuleByPort will return the IBCModule along with the capability associated with a given portID
func (k *Keeper) LookupModuleByPort(ctx context.Context, portID string) (string, *capabilitytypes.Capability, error) {
modules, capability, err := k.scopedKeeper.LookupModules(ctx, host.PortPath(portID))
if err != nil {
return "", nil, err
}

return types.GetModuleOwner(modules), capability, nil
}

// Route returns a IBCModule for a given module, and a boolean indicating
// whether or not the route is present.
func (k *Keeper) Route(module string) (types.IBCModule, bool) {
Expand Down

0 comments on commit 4685670

Please sign in to comment.