Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor!: remove connection interface #5770

Merged
merged 5 commits into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/docs/05-migrations/13-v8-to-v9.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}

Expand Down
8 changes: 0 additions & 8 deletions modules/core/02-client/migrations/v7/solomachine.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,14 +158,6 @@ func (ClientState) VerifyClientConsensusState(
panic(errors.New("legacy solo machine is deprecated"))
}

// VerifyConnectionState panics!
func (ClientState) VerifyConnectionState(
Copy link
Contributor

@DimitrisJim DimitrisJim Jan 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems legacy solomachine has quite the legacy methods defined on it (Verify* family of funcs, CheckHeaderAndUpdateState etc)? Do we have an issue to clean those up? Do we have a bigger issue for legacy solomachine might be better q tho

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the answer is no to both questions! Definitely would be great to have an issue for both. I've just been removing unnecessary funcs as I bump into them

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,
Expand Down
34 changes: 14 additions & 20 deletions modules/core/03-connection/keeper/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,18 @@ 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"
)

// VerifyClientState verifies a proof of a client state of the running machine
// 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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand All @@ -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
}
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
5 changes: 0 additions & 5 deletions modules/core/03-connection/types/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
5 changes: 0 additions & 5 deletions modules/core/03-connection/types/codec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}),
Expand Down
2 changes: 0 additions & 2 deletions modules/core/03-connection/types/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
10 changes: 5 additions & 5 deletions modules/core/04-channel/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 7 additions & 7 deletions modules/core/04-channel/types/expected_keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -37,7 +37,7 @@ type ConnectionKeeper interface {
) error
VerifyPacketCommitment(
ctx sdk.Context,
connection exported.ConnectionI,
connection connectiontypes.ConnectionEnd,
height exported.Height,
proof []byte,
portID,
Expand All @@ -47,7 +47,7 @@ type ConnectionKeeper interface {
) error
VerifyPacketAcknowledgement(
ctx sdk.Context,
connection exported.ConnectionI,
connection connectiontypes.ConnectionEnd,
height exported.Height,
proof []byte,
portID,
Expand All @@ -57,7 +57,7 @@ type ConnectionKeeper interface {
) error
VerifyPacketReceiptAbsence(
ctx sdk.Context,
connection exported.ConnectionI,
connection connectiontypes.ConnectionEnd,
height exported.Height,
proof []byte,
portID,
Expand All @@ -66,7 +66,7 @@ type ConnectionKeeper interface {
) error
VerifyNextSequenceRecv(
ctx sdk.Context,
connection exported.ConnectionI,
connection connectiontypes.ConnectionEnd,
height exported.Height,
proof []byte,
portID,
Expand All @@ -75,7 +75,7 @@ type ConnectionKeeper interface {
) error
VerifyChannelUpgrade(
ctx sdk.Context,
connection exported.ConnectionI,
connection connectiontypes.ConnectionEnd,
height exported.Height,
proof []byte,
portID,
Expand All @@ -84,7 +84,7 @@ type ConnectionKeeper interface {
) error
VerifyChannelUpgradeError(
ctx sdk.Context,
connection exported.ConnectionI,
connection connectiontypes.ConnectionEnd,
height exported.Height,
proof []byte,
portID,
Expand Down
8 changes: 0 additions & 8 deletions modules/core/exported/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +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
GetCounterparty() CounterpartyConnectionI
GetDelayPeriod() uint64
ValidateBasic() error
}

// CounterpartyConnectionI describes the required methods for a counterparty connection.
type CounterpartyConnectionI interface {
GetClientID() string
Expand Down
Loading