From 2163ed4352b1650946112e4c29234631e2e06f30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Colin=20Axn=C3=A9r?= <25233464+colin-axner@users.noreply.github.com> Date: Tue, 30 Jan 2024 13:44:00 +0100 Subject: [PATCH 1/4] refactor: remove connection interface --- .../types/expected_keepers.go | 4 +-- .../02-client/migrations/v7/solomachine.go | 8 ----- modules/core/03-connection/keeper/verify.go | 34 ++++++++----------- modules/core/03-connection/types/codec.go | 5 --- .../core/03-connection/types/codec_test.go | 5 --- .../core/03-connection/types/connection.go | 2 -- modules/core/04-channel/keeper/keeper.go | 10 +++--- .../core/04-channel/types/expected_keepers.go | 15 ++++---- modules/core/exported/connection.go | 9 ----- 9 files changed, 29 insertions(+), 63 deletions(-) diff --git a/modules/apps/27-interchain-accounts/types/expected_keepers.go b/modules/apps/27-interchain-accounts/types/expected_keepers.go index 09cf6c22024..de2eb9de245 100644 --- a/modules/apps/27-interchain-accounts/types/expected_keepers.go +++ b/modules/apps/27-interchain-accounts/types/expected_keepers.go @@ -7,8 +7,8 @@ import ( paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types" + connectiontypes "github.com/cosmos/ibc-go/v8/modules/core/03-connection/types" channeltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types" - ibcexported "github.com/cosmos/ibc-go/v8/modules/core/exported" ) // AccountKeeper defines the expected account keeper @@ -24,7 +24,7 @@ type AccountKeeper interface { type ChannelKeeper interface { GetChannel(ctx sdk.Context, srcPort, srcChan string) (channel channeltypes.Channel, found bool) GetNextSequenceSend(ctx sdk.Context, portID, channelID string) (uint64, bool) - GetConnection(ctx sdk.Context, connectionID string) (ibcexported.ConnectionI, error) + GetConnection(ctx sdk.Context, connectionID string) (connectiontypes.ConnectionEnd, error) GetAllChannelsWithPortPrefix(ctx sdk.Context, portPrefix string) []channeltypes.IdentifiedChannel } diff --git a/modules/core/02-client/migrations/v7/solomachine.go b/modules/core/02-client/migrations/v7/solomachine.go index d083af969ea..4f0e219097a 100644 --- a/modules/core/02-client/migrations/v7/solomachine.go +++ b/modules/core/02-client/migrations/v7/solomachine.go @@ -158,14 +158,6 @@ func (ClientState) VerifyClientConsensusState( panic(errors.New("legacy solo machine is deprecated")) } -// VerifyConnectionState panics! -func (ClientState) VerifyConnectionState( - storetypes.KVStore, codec.BinaryCodec, exported.Height, - exported.Prefix, []byte, string, exported.ConnectionI, -) error { - panic(errors.New("legacy solo machine is deprecated")) -} - // VerifyPacketCommitment panics! func (ClientState) VerifyPacketCommitment( sdk.Context, storetypes.KVStore, codec.BinaryCodec, exported.Height, diff --git a/modules/core/03-connection/keeper/verify.go b/modules/core/03-connection/keeper/verify.go index 17948b8c020..847b7c77d49 100644 --- a/modules/core/03-connection/keeper/verify.go +++ b/modules/core/03-connection/keeper/verify.go @@ -9,11 +9,10 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" clienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types" - connectiontypes "github.com/cosmos/ibc-go/v8/modules/core/03-connection/types" + "github.com/cosmos/ibc-go/v8/modules/core/03-connection/types" channeltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types" commitmenttypes "github.com/cosmos/ibc-go/v8/modules/core/23-commitment/types" host "github.com/cosmos/ibc-go/v8/modules/core/24-host" - ibcerrors "github.com/cosmos/ibc-go/v8/modules/core/errors" "github.com/cosmos/ibc-go/v8/modules/core/exported" ) @@ -21,7 +20,7 @@ import ( // stored on the target machine func (k Keeper) VerifyClientState( ctx sdk.Context, - connection exported.ConnectionI, + connection types.ConnectionEnd, height exported.Height, proof []byte, clientState exported.ClientState, @@ -62,7 +61,7 @@ func (k Keeper) VerifyClientState( // specified client stored on the target machine. func (k Keeper) VerifyClientConsensusState( ctx sdk.Context, - connection exported.ConnectionI, + connection types.ConnectionEnd, height exported.Height, consensusHeight exported.Height, proof []byte, @@ -104,11 +103,11 @@ func (k Keeper) VerifyClientConsensusState( // specified connection end stored on the target machine. func (k Keeper) VerifyConnectionState( ctx sdk.Context, - connection exported.ConnectionI, + connection types.ConnectionEnd, height exported.Height, proof []byte, connectionID string, - counterpartyConnection exported.ConnectionI, // opposite connection + counterpartyConnection types.ConnectionEnd, // opposite connection ) error { clientID := connection.GetClientID() clientState, clientStore, err := k.getClientStateAndVerificationStore(ctx, clientID) @@ -126,12 +125,7 @@ func (k Keeper) VerifyConnectionState( return err } - connectionEnd, ok := counterpartyConnection.(connectiontypes.ConnectionEnd) - if !ok { - return errorsmod.Wrapf(ibcerrors.ErrInvalidType, "invalid connection type %T", counterpartyConnection) - } - - bz, err := k.cdc.Marshal(&connectionEnd) + bz, err := k.cdc.Marshal(&counterpartyConnection) if err != nil { return err } @@ -151,7 +145,7 @@ func (k Keeper) VerifyConnectionState( // channel end, under the specified port, stored on the target machine. func (k Keeper) VerifyChannelState( ctx sdk.Context, - connection exported.ConnectionI, + connection types.ConnectionEnd, height exported.Height, proof []byte, portID, @@ -194,7 +188,7 @@ func (k Keeper) VerifyChannelState( // the specified port, specified channel, and specified sequence. func (k Keeper) VerifyPacketCommitment( ctx sdk.Context, - connection exported.ConnectionI, + connection types.ConnectionEnd, height exported.Height, proof []byte, portID, @@ -237,7 +231,7 @@ func (k Keeper) VerifyPacketCommitment( // acknowledgement at the specified port, specified channel, and specified sequence. func (k Keeper) VerifyPacketAcknowledgement( ctx sdk.Context, - connection exported.ConnectionI, + connection types.ConnectionEnd, height exported.Height, proof []byte, portID, @@ -281,7 +275,7 @@ func (k Keeper) VerifyPacketAcknowledgement( // specified sequence. func (k Keeper) VerifyPacketReceiptAbsence( ctx sdk.Context, - connection exported.ConnectionI, + connection types.ConnectionEnd, height exported.Height, proof []byte, portID, @@ -323,7 +317,7 @@ func (k Keeper) VerifyPacketReceiptAbsence( // received of the specified channel at the specified port. func (k Keeper) VerifyNextSequenceRecv( ctx sdk.Context, - connection exported.ConnectionI, + connection types.ConnectionEnd, height exported.Height, proof []byte, portID, @@ -364,7 +358,7 @@ func (k Keeper) VerifyNextSequenceRecv( // VerifyChannelUpgradeError verifies a proof of the provided upgrade error receipt. func (k Keeper) VerifyChannelUpgradeError( ctx sdk.Context, - connection exported.ConnectionI, + connection types.ConnectionEnd, height exported.Height, proof []byte, portID, @@ -406,7 +400,7 @@ func (k Keeper) VerifyChannelUpgradeError( // VerifyChannelUpgrade verifies the proof that a particular proposed upgrade has been stored in the upgrade path. func (k Keeper) VerifyChannelUpgrade( ctx sdk.Context, - connection exported.ConnectionI, + connection types.ConnectionEnd, proofHeight exported.Height, upgradeProof []byte, portID, @@ -447,7 +441,7 @@ func (k Keeper) VerifyChannelUpgrade( // getBlockDelay calculates the block delay period from the time delay of the connection // and the maximum expected time per block. -func (k Keeper) getBlockDelay(ctx sdk.Context, connection exported.ConnectionI) uint64 { +func (k Keeper) getBlockDelay(ctx sdk.Context, connection types.ConnectionEnd) uint64 { // expectedTimePerBlock should never be zero, however if it is then return a 0 block delay for safety // as the expectedTimePerBlock parameter was not set. expectedTimePerBlock := k.GetParams(ctx).MaxExpectedTimePerBlock diff --git a/modules/core/03-connection/types/codec.go b/modules/core/03-connection/types/codec.go index e551228ca5e..9da606deab4 100644 --- a/modules/core/03-connection/types/codec.go +++ b/modules/core/03-connection/types/codec.go @@ -12,11 +12,6 @@ import ( // RegisterInterfaces register the ibc interfaces submodule implementations to protobuf // Any. func RegisterInterfaces(registry codectypes.InterfaceRegistry) { - registry.RegisterInterface( - "ibc.core.connection.v1.ConnectionI", - (*exported.ConnectionI)(nil), - &ConnectionEnd{}, - ) registry.RegisterInterface( "ibc.core.connection.v1.CounterpartyConnectionI", (*exported.CounterpartyConnectionI)(nil), diff --git a/modules/core/03-connection/types/codec_test.go b/modules/core/03-connection/types/codec_test.go index ca1d5b7c7c2..829ca77d7bc 100644 --- a/modules/core/03-connection/types/codec_test.go +++ b/modules/core/03-connection/types/codec_test.go @@ -18,11 +18,6 @@ func TestCodecTypeRegistration(t *testing.T) { typeURL string expPass bool }{ - { - "success: ConnectionEnd", - sdk.MsgTypeURL(&types.ConnectionEnd{}), - true, - }, { "success: Counterparty", sdk.MsgTypeURL(&types.Counterparty{}), diff --git a/modules/core/03-connection/types/connection.go b/modules/core/03-connection/types/connection.go index d9c1a554437..94020f421ce 100644 --- a/modules/core/03-connection/types/connection.go +++ b/modules/core/03-connection/types/connection.go @@ -9,8 +9,6 @@ import ( "github.com/cosmos/ibc-go/v8/modules/core/exported" ) -var _ exported.ConnectionI = (*ConnectionEnd)(nil) - // NewConnectionEnd creates a new ConnectionEnd instance. func NewConnectionEnd(state State, clientID string, counterparty Counterparty, versions []*Version, delayPeriod uint64) ConnectionEnd { return ConnectionEnd{ diff --git a/modules/core/04-channel/keeper/keeper.go b/modules/core/04-channel/keeper/keeper.go index 2aa04fae6ae..5272554204d 100644 --- a/modules/core/04-channel/keeper/keeper.go +++ b/modules/core/04-channel/keeper/keeper.go @@ -457,27 +457,27 @@ func (k Keeper) GetChannelClientState(ctx sdk.Context, portID, channelID string) } // GetConnection wraps the connection keeper's GetConnection function. -func (k Keeper) GetConnection(ctx sdk.Context, connectionID string) (exported.ConnectionI, error) { +func (k Keeper) GetConnection(ctx sdk.Context, connectionID string) (connectiontypes.ConnectionEnd, error) { connection, found := k.connectionKeeper.GetConnection(ctx, connectionID) if !found { - return nil, errorsmod.Wrapf(connectiontypes.ErrConnectionNotFound, "connection-id: %s", connectionID) + return connectiontypes.ConnectionEnd{}, errorsmod.Wrapf(connectiontypes.ErrConnectionNotFound, "connection-id: %s", connectionID) } return connection, nil } // GetChannelConnection returns the connection ID and state associated with the given port and channel identifier. -func (k Keeper) GetChannelConnection(ctx sdk.Context, portID, channelID string) (string, exported.ConnectionI, error) { +func (k Keeper) GetChannelConnection(ctx sdk.Context, portID, channelID string) (string, connectiontypes.ConnectionEnd, error) { channel, found := k.GetChannel(ctx, portID, channelID) if !found { - return "", nil, errorsmod.Wrapf(types.ErrChannelNotFound, "port-id: %s, channel-id: %s", portID, channelID) + return "", connectiontypes.ConnectionEnd{}, errorsmod.Wrapf(types.ErrChannelNotFound, "port-id: %s, channel-id: %s", portID, channelID) } connectionID := channel.ConnectionHops[0] connection, found := k.connectionKeeper.GetConnection(ctx, connectionID) if !found { - return "", nil, errorsmod.Wrapf(connectiontypes.ErrConnectionNotFound, "connection-id: %s", connectionID) + return "", connectiontypes.ConnectionEnd{}, errorsmod.Wrapf(connectiontypes.ErrConnectionNotFound, "connection-id: %s", connectionID) } return connectionID, connection, nil diff --git a/modules/core/04-channel/types/expected_keepers.go b/modules/core/04-channel/types/expected_keepers.go index 3a40aaab978..38cddb3c3bd 100644 --- a/modules/core/04-channel/types/expected_keepers.go +++ b/modules/core/04-channel/types/expected_keepers.go @@ -28,7 +28,7 @@ type ConnectionKeeper interface { ) (uint64, error) VerifyChannelState( ctx sdk.Context, - connection exported.ConnectionI, + connection connectiontypes.ConnectionEnd, height exported.Height, proof []byte, portID, @@ -37,7 +37,7 @@ type ConnectionKeeper interface { ) error VerifyPacketCommitment( ctx sdk.Context, - connection exported.ConnectionI, + connection connectiontypes.ConnectionEnd, height exported.Height, proof []byte, portID, @@ -47,7 +47,7 @@ type ConnectionKeeper interface { ) error VerifyPacketAcknowledgement( ctx sdk.Context, - connection exported.ConnectionI, + connection connectiontypes.ConnectionEnd, height exported.Height, proof []byte, portID, @@ -57,7 +57,7 @@ type ConnectionKeeper interface { ) error VerifyPacketReceiptAbsence( ctx sdk.Context, - connection exported.ConnectionI, + connection connectiontypes.ConnectionEnd, height exported.Height, proof []byte, portID, @@ -66,7 +66,7 @@ type ConnectionKeeper interface { ) error VerifyNextSequenceRecv( ctx sdk.Context, - connection exported.ConnectionI, + connection connectiontypes.ConnectionEnd, height exported.Height, proof []byte, portID, @@ -75,7 +75,7 @@ type ConnectionKeeper interface { ) error VerifyChannelUpgrade( ctx sdk.Context, - connection exported.ConnectionI, + connection connectiontypes.ConnectionEnd, height exported.Height, proof []byte, portID, @@ -84,7 +84,8 @@ type ConnectionKeeper interface { ) error VerifyChannelUpgradeError( ctx sdk.Context, - connection exported.ConnectionI, + connection connectiontypes.ConnectionEnd, + height exported.Height, proof []byte, portID, diff --git a/modules/core/exported/connection.go b/modules/core/exported/connection.go index a8341a255a9..00b55913bd0 100644 --- a/modules/core/exported/connection.go +++ b/modules/core/exported/connection.go @@ -3,15 +3,6 @@ package exported // LocalhostConnectionID is the sentinel connection ID for the localhost connection. const LocalhostConnectionID string = "connection-localhost" -// ConnectionI describes the required methods for a connection. -type ConnectionI interface { - GetClientID() string - GetState() int32 - GetCounterparty() CounterpartyConnectionI - GetDelayPeriod() uint64 - ValidateBasic() error -} - // CounterpartyConnectionI describes the required methods for a counterparty connection. type CounterpartyConnectionI interface { GetClientID() string From e8041b4c5fbd5eea2a4d503fcd0a003af4b601c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Colin=20Axn=C3=A9r?= <25233464+colin-axner@users.noreply.github.com> Date: Tue, 30 Jan 2024 13:47:21 +0100 Subject: [PATCH 2/4] fix spacing --- modules/core/04-channel/types/expected_keepers.go | 1 - 1 file changed, 1 deletion(-) diff --git a/modules/core/04-channel/types/expected_keepers.go b/modules/core/04-channel/types/expected_keepers.go index 38cddb3c3bd..b5025a253ac 100644 --- a/modules/core/04-channel/types/expected_keepers.go +++ b/modules/core/04-channel/types/expected_keepers.go @@ -85,7 +85,6 @@ type ConnectionKeeper interface { VerifyChannelUpgradeError( ctx sdk.Context, connection connectiontypes.ConnectionEnd, - height exported.Height, proof []byte, portID, From 96423845cd8a069f288b18898cbe5fa0f3f88088 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Colin=20Axn=C3=A9r?= <25233464+colin-axner@users.noreply.github.com> Date: Tue, 30 Jan 2024 13:48:21 +0100 Subject: [PATCH 3/4] docs: add migration doc entry --- docs/docs/05-migrations/13-v8-to-v9.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/docs/05-migrations/13-v8-to-v9.md b/docs/docs/05-migrations/13-v8-to-v9.md index d8db9c400af..6479e64ae63 100644 --- a/docs/docs/05-migrations/13-v8-to-v9.md +++ b/docs/docs/05-migrations/13-v8-to-v9.md @@ -27,6 +27,7 @@ There are four sections based on the four potential user groups of this document ### API removals The `exported.ChannelI` and `exported.CounterpartyChannelI` interfaces has been removed. Please use the concrete types. +The `exported.ConnectionI` interface has been removed. Please use the concrete types. The functions `GetState()`, `GetOrdering()`, `GetCounterparty()`, `GetConnectionHops()`, `GetVersion()` of the `Channel` type have been removed. The functions `GetPortID()`, `GetChannelID()` of the `CounterpartyChannel` type have been removed. From 49391488c837a96ad70eb192b467e8431672e30f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Colin=20Axn=C3=A9r?= <25233464+colin-axner@users.noreply.github.com> Date: Tue, 30 Jan 2024 13:54:00 +0100 Subject: [PATCH 4/4] lint --- e2e/tests/interchain_accounts/upgrades_test.go | 7 ++++--- e2e/tests/upgrades/upgrade_test.go | 3 +-- e2e/testsuite/sanitize/messages.go | 3 +-- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/e2e/tests/interchain_accounts/upgrades_test.go b/e2e/tests/interchain_accounts/upgrades_test.go index 46342dcdcbd..a14641b8336 100644 --- a/e2e/tests/interchain_accounts/upgrades_test.go +++ b/e2e/tests/interchain_accounts/upgrades_test.go @@ -7,16 +7,17 @@ import ( "testing" "time" - sdkmath "cosmossdk.io/math" + "github.com/cosmos/gogoproto/proto" "github.com/strangelove-ventures/interchaintest/v8" "github.com/strangelove-ventures/interchaintest/v8/ibc" test "github.com/strangelove-ventures/interchaintest/v8/testutil" testifysuite "github.com/stretchr/testify/suite" + sdkmath "cosmossdk.io/math" + sdk "github.com/cosmos/cosmos-sdk/types" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" - "github.com/cosmos/gogoproto/proto" "github.com/cosmos/ibc-go/e2e/testsuite" "github.com/cosmos/ibc-go/e2e/testvalues" @@ -162,7 +163,7 @@ func (s *InterchainAccountsChannelUpgradesTestSuite) TestChannelUpgrade_ICAChann Memo: "e2e", } - timeout := uint64(1) + timeout := uint64(1) msgSendTx := controllertypes.NewMsgSendTx(controllerAddress, ibctesting.FirstConnectionID, timeout, packetData) resp := s.BroadcastMessages( diff --git a/e2e/tests/upgrades/upgrade_test.go b/e2e/tests/upgrades/upgrade_test.go index 4e00bc5e07b..6dd0219efc3 100644 --- a/e2e/tests/upgrades/upgrade_test.go +++ b/e2e/tests/upgrades/upgrade_test.go @@ -9,8 +9,6 @@ import ( "testing" "time" - transfertypes "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types" - "github.com/cosmos/gogoproto/proto" interchaintest "github.com/strangelove-ventures/interchaintest/v8" "github.com/strangelove-ventures/interchaintest/v8/chain/cosmos" @@ -29,6 +27,7 @@ import ( "github.com/cosmos/ibc-go/e2e/testsuite" "github.com/cosmos/ibc-go/e2e/testvalues" feetypes "github.com/cosmos/ibc-go/v8/modules/apps/29-fee/types" + transfertypes "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types" v7migrations "github.com/cosmos/ibc-go/v8/modules/core/02-client/migrations/v7" clienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types" connectiontypes "github.com/cosmos/ibc-go/v8/modules/core/03-connection/types" diff --git a/e2e/testsuite/sanitize/messages.go b/e2e/testsuite/sanitize/messages.go index ac475314f4e..7cf901d6913 100644 --- a/e2e/testsuite/sanitize/messages.go +++ b/e2e/testsuite/sanitize/messages.go @@ -5,10 +5,9 @@ import ( govtypesv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" grouptypes "github.com/cosmos/cosmos-sdk/x/group" + "github.com/cosmos/ibc-go/e2e/semverutil" icacontrollertypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/controller/types" channeltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types" - - "github.com/cosmos/ibc-go/e2e/semverutil" ) var (