From 310a4bd7661f91c271b595020efa43a8a18a6786 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?colin=20axn=C3=A9r?= <25233464+colin-axner@users.noreply.github.com> Date: Thu, 25 Jan 2024 12:42:55 +0100 Subject: [PATCH] refactor(api)!: remove unnecessary channel getter functions (#5705) * refactor: remove unnecessary channelI interface * rm: unused GetChannel function * rm: channel.GetVersion() function * rm: channel.GetCounterparty() * rm: channel.GetOrdering() * rm: channel.GetConnectionHops() * lint * update v9 migration docs * rm: GetConnectinoHops() usage in e2es --------- Co-authored-by: Carlos Rodriguez --- docs/docs/05-migrations/13-v8-to-v9.md | 2 ++ .../interchain_accounts/localhost_test.go | 6 ++--- e2e/tests/transfer/localhost_test.go | 2 +- .../controller/ibc_middleware_test.go | 4 +-- .../controller/keeper/handshake_test.go | 2 +- .../host/ibc_module_test.go | 2 +- .../host/keeper/handshake_test.go | 2 +- modules/apps/29-fee/ibc_middleware_test.go | 4 +-- modules/apps/transfer/ibc_module_test.go | 6 ++--- modules/apps/transfer/keeper/relay.go | 4 +-- modules/core/04-channel/types/channel.go | 25 ------------------- 11 files changed, 18 insertions(+), 41 deletions(-) diff --git a/docs/docs/05-migrations/13-v8-to-v9.md b/docs/docs/05-migrations/13-v8-to-v9.md index 6ccc6276448..216ea061127 100644 --- a/docs/docs/05-migrations/13-v8-to-v9.md +++ b/docs/docs/05-migrations/13-v8-to-v9.md @@ -28,6 +28,8 @@ There are four sections based on the four potential user groups of this document The `exported.ChannelI` interface has been removed. Please use the concrete type. +The functions `GetState()`, `GetOrdering()`, `GetCounterparty()`, `GetConnectionHops()`, `GetVersion()` of the `Channel` type have been removed. + ### API deprecation notice The testing package functions `coordinator.Setup`, `coordinator.SetupClients`, `coordinator.SetupConnections`, `coordinator.CreateConnections`, and `coordinator.CreateChannels` have been deprecated and will be removed in v10. diff --git a/e2e/tests/interchain_accounts/localhost_test.go b/e2e/tests/interchain_accounts/localhost_test.go index d486041de2e..fdd875686e4 100644 --- a/e2e/tests/interchain_accounts/localhost_test.go +++ b/e2e/tests/interchain_accounts/localhost_test.go @@ -116,7 +116,7 @@ func (s *LocalhostInterchainAccountsTestSuite) TestInterchainAccounts_Localhost( s.Require().NoError(err) s.Require().NotNil(channelEndB) - s.Require().Equal(channelEndA.GetConnectionHops(), channelEndB.GetConnectionHops()) + s.Require().Equal(channelEndA.ConnectionHops, channelEndB.ConnectionHops) }) t.Run("verify interchain account registration and deposit funds", func(t *testing.T) { @@ -271,7 +271,7 @@ func (s *LocalhostInterchainAccountsTestSuite) TestInterchainAccounts_ReopenChan s.Require().NoError(err) s.Require().NotNil(channelEndB) - s.Require().Equal(channelEndA.GetConnectionHops(), channelEndB.GetConnectionHops()) + s.Require().Equal(channelEndA.ConnectionHops, channelEndB.ConnectionHops) }) t.Run("verify interchain account registration and deposit funds", func(t *testing.T) { @@ -401,7 +401,7 @@ func (s *LocalhostInterchainAccountsTestSuite) TestInterchainAccounts_ReopenChan s.Require().NoError(err) s.Require().NotNil(channelEndB) - s.Require().Equal(channelEndA.GetConnectionHops(), channelEndB.GetConnectionHops()) + s.Require().Equal(channelEndA.ConnectionHops, channelEndB.ConnectionHops) }) t.Run("verify interchain account and existing balance", func(t *testing.T) { diff --git a/e2e/tests/transfer/localhost_test.go b/e2e/tests/transfer/localhost_test.go index df8a0bf976c..00825c266ed 100644 --- a/e2e/tests/transfer/localhost_test.go +++ b/e2e/tests/transfer/localhost_test.go @@ -123,7 +123,7 @@ func (s *LocalhostTransferTestSuite) TestMsgTransfer_Localhost() { s.Require().NoError(err) s.Require().NotNil(channelEndB) - s.Require().Equal(channelEndA.GetConnectionHops(), channelEndB.GetConnectionHops()) + s.Require().Equal(channelEndA.ConnectionHops, channelEndB.ConnectionHops) }) t.Run("send packet localhost ibc transfer", func(t *testing.T) { diff --git a/modules/apps/27-interchain-accounts/controller/ibc_middleware_test.go b/modules/apps/27-interchain-accounts/controller/ibc_middleware_test.go index fd39dee3d8f..8d76424a6ca 100644 --- a/modules/apps/27-interchain-accounts/controller/ibc_middleware_test.go +++ b/modules/apps/27-interchain-accounts/controller/ibc_middleware_test.go @@ -239,8 +239,8 @@ func (suite *InterchainAccountsTestSuite) TestOnChanOpenInit() { cbs = controller.NewIBCMiddleware(nil, suite.chainA.GetSimApp().ICAControllerKeeper) } - version, err := cbs.OnChanOpenInit(suite.chainA.GetContext(), channel.Ordering, channel.GetConnectionHops(), - path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, chanCap, channel.Counterparty, channel.GetVersion(), + version, err := cbs.OnChanOpenInit(suite.chainA.GetContext(), channel.Ordering, channel.ConnectionHops, + path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, chanCap, channel.Counterparty, channel.Version, ) if tc.expPass { diff --git a/modules/apps/27-interchain-accounts/controller/keeper/handshake_test.go b/modules/apps/27-interchain-accounts/controller/keeper/handshake_test.go index e715b314aec..c5fd02350cb 100644 --- a/modules/apps/27-interchain-accounts/controller/keeper/handshake_test.go +++ b/modules/apps/27-interchain-accounts/controller/keeper/handshake_test.go @@ -292,7 +292,7 @@ func (suite *KeeperTestSuite) TestOnChanOpenInit() { tc.malleate() // malleate mutates test data - version, err := suite.chainA.GetSimApp().ICAControllerKeeper.OnChanOpenInit(suite.chainA.GetContext(), channel.Ordering, channel.GetConnectionHops(), + version, err := suite.chainA.GetSimApp().ICAControllerKeeper.OnChanOpenInit(suite.chainA.GetContext(), channel.Ordering, channel.ConnectionHops, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, chanCap, channel.Counterparty, channel.Version, ) diff --git a/modules/apps/27-interchain-accounts/host/ibc_module_test.go b/modules/apps/27-interchain-accounts/host/ibc_module_test.go index f8dfb7d5795..c0f05fb5c58 100644 --- a/modules/apps/27-interchain-accounts/host/ibc_module_test.go +++ b/modules/apps/27-interchain-accounts/host/ibc_module_test.go @@ -214,7 +214,7 @@ func (suite *InterchainAccountsTestSuite) TestOnChanOpenTry() { cbs, ok := suite.chainB.App.GetIBCKeeper().Router.GetRoute(module) suite.Require().True(ok) - version, err := cbs.OnChanOpenTry(suite.chainB.GetContext(), channel.Ordering, channel.GetConnectionHops(), + version, err := cbs.OnChanOpenTry(suite.chainB.GetContext(), channel.Ordering, channel.ConnectionHops, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, chanCap, channel.Counterparty, path.EndpointA.ChannelConfig.Version, ) diff --git a/modules/apps/27-interchain-accounts/host/keeper/handshake_test.go b/modules/apps/27-interchain-accounts/host/keeper/handshake_test.go index da485a2eafd..a9e463e05bb 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/handshake_test.go +++ b/modules/apps/27-interchain-accounts/host/keeper/handshake_test.go @@ -323,7 +323,7 @@ func (suite *KeeperTestSuite) TestOnChanOpenTry() { tc.malleate() // malleate mutates test data - version, err := suite.chainB.GetSimApp().ICAHostKeeper.OnChanOpenTry(suite.chainB.GetContext(), channel.Ordering, channel.GetConnectionHops(), + version, err := suite.chainB.GetSimApp().ICAHostKeeper.OnChanOpenTry(suite.chainB.GetContext(), channel.Ordering, channel.ConnectionHops, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, chanCap, channel.Counterparty, path.EndpointA.ChannelConfig.Version, ) diff --git a/modules/apps/29-fee/ibc_middleware_test.go b/modules/apps/29-fee/ibc_middleware_test.go index 22513266275..7c87f703f96 100644 --- a/modules/apps/29-fee/ibc_middleware_test.go +++ b/modules/apps/29-fee/ibc_middleware_test.go @@ -112,7 +112,7 @@ func (suite *FeeTestSuite) TestOnChanOpenInit() { cbs, ok := suite.chainA.App.GetIBCKeeper().Router.GetRoute(module) suite.Require().True(ok) - version, err := cbs.OnChanOpenInit(suite.chainA.GetContext(), channel.Ordering, channel.GetConnectionHops(), + version, err := cbs.OnChanOpenInit(suite.chainA.GetContext(), channel.Ordering, channel.ConnectionHops, suite.path.EndpointA.ChannelConfig.PortID, suite.path.EndpointA.ChannelID, chanCap, counterparty, channel.Version) if tc.expPass { @@ -215,7 +215,7 @@ func (suite *FeeTestSuite) TestOnChanOpenTry() { cbs, ok := suite.chainA.App.GetIBCKeeper().Router.GetRoute(module) suite.Require().True(ok) - _, err = cbs.OnChanOpenTry(suite.chainA.GetContext(), channel.Ordering, channel.GetConnectionHops(), + _, err = cbs.OnChanOpenTry(suite.chainA.GetContext(), channel.Ordering, channel.ConnectionHops, suite.path.EndpointA.ChannelConfig.PortID, suite.path.EndpointA.ChannelID, chanCap, counterparty, tc.cpVersion) if tc.expPass { diff --git a/modules/apps/transfer/ibc_module_test.go b/modules/apps/transfer/ibc_module_test.go index 82a94c1d1c8..f0f42f52f51 100644 --- a/modules/apps/transfer/ibc_module_test.go +++ b/modules/apps/transfer/ibc_module_test.go @@ -97,8 +97,8 @@ func (suite *TransferTestSuite) TestOnChanOpenInit() { tc.malleate() // explicitly change fields in channel and testChannel transferModule := transfer.NewIBCModule(suite.chainA.GetSimApp().TransferKeeper) - version, err := transferModule.OnChanOpenInit(suite.chainA.GetContext(), channel.Ordering, channel.GetConnectionHops(), - path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, chanCap, counterparty, channel.GetVersion(), + version, err := transferModule.OnChanOpenInit(suite.chainA.GetContext(), channel.Ordering, channel.ConnectionHops, + path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, chanCap, counterparty, channel.Version, ) if tc.expPass { @@ -188,7 +188,7 @@ func (suite *TransferTestSuite) TestOnChanOpenTry() { tc.malleate() // explicitly change fields in channel and testChannel - version, err := cbs.OnChanOpenTry(suite.chainA.GetContext(), channel.Ordering, channel.GetConnectionHops(), + version, err := cbs.OnChanOpenTry(suite.chainA.GetContext(), channel.Ordering, channel.ConnectionHops, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, chanCap, channel.Counterparty, counterpartyVersion, ) diff --git a/modules/apps/transfer/keeper/relay.go b/modules/apps/transfer/keeper/relay.go index f598faec012..20847e0cf4e 100644 --- a/modules/apps/transfer/keeper/relay.go +++ b/modules/apps/transfer/keeper/relay.go @@ -68,8 +68,8 @@ func (k Keeper) sendTransfer( return 0, errorsmod.Wrapf(channeltypes.ErrChannelNotFound, "port ID (%s) channel ID (%s)", sourcePort, sourceChannel) } - destinationPort := channel.GetCounterparty().GetPortID() - destinationChannel := channel.GetCounterparty().GetChannelID() + destinationPort := channel.Counterparty.GetPortID() + destinationChannel := channel.Counterparty.GetChannelID() // begin createOutgoingPacket logic // See spec for this logic: https://github.com/cosmos/ibc/tree/master/spec/app/ics-020-fungible-token-transfer#packet-relay diff --git a/modules/core/04-channel/types/channel.go b/modules/core/04-channel/types/channel.go index 2981cd21f65..f5dd319ad06 100644 --- a/modules/core/04-channel/types/channel.go +++ b/modules/core/04-channel/types/channel.go @@ -27,31 +27,6 @@ func NewChannel( } } -// GetState implements Channel interface. -func (ch Channel) GetState() int32 { - return int32(ch.State) -} - -// GetOrdering implements Channel interface. -func (ch Channel) GetOrdering() int32 { - return int32(ch.Ordering) -} - -// GetCounterparty implements Channel interface. -func (ch Channel) GetCounterparty() exported.CounterpartyChannelI { - return ch.Counterparty -} - -// GetConnectionHops implements Channel interface. -func (ch Channel) GetConnectionHops() []string { - return ch.ConnectionHops -} - -// GetVersion implements Channel interface. -func (ch Channel) GetVersion() string { - return ch.Version -} - // ValidateBasic performs a basic validation of the channel fields func (ch Channel) ValidateBasic() error { if ch.State == UNINITIALIZED {