Skip to content

Commit

Permalink
refactor: remove unnecessary getters on counterparty connection type (c…
Browse files Browse the repository at this point in the history
  • Loading branch information
colin-axner committed Jan 31, 2024
1 parent e67435b commit 661356e
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 43 deletions.
3 changes: 2 additions & 1 deletion docs/docs/05-migrations/13-v8-to-v9.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ The `exported.ConnectionI` and `exported.CounterpartyConnectionI` interfaces hav

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.
The function `GetClientID()`, `GetState()`, `GetCounterparty()`, `GetVersions()`, and `GetDelayPeriod` of the `Connection` type have been removed.
The functions `GetClientID()`, `GetState()`, `GetCounterparty()`, `GetVersions()`, and `GetDelayPeriod` of the `Connection` type have been removed.
The functions `GetClientID()`, `GetConnectionID()`, and `GetPrefix()` of the `CounterpartyConnection` type have been removed.

### API deprecation notice

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (k Keeper) OnChanOpenInit(
return "", err
}

metadata = icatypes.NewDefaultMetadata(connectionHops[0], connection.Counterparty.GetConnectionID())
metadata = icatypes.NewDefaultMetadata(connectionHops[0], connection.Counterparty.ConnectionId)
} else {
metadata, err = icatypes.MetadataFromVersion(version)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions modules/apps/27-interchain-accounts/types/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func ValidateControllerMetadata(ctx sdk.Context, channelKeeper ChannelKeeper, co
return err
}

if err := validateConnectionParams(metadata, connectionHops[0], connection.Counterparty.GetConnectionID()); err != nil {
if err := validateConnectionParams(metadata, connectionHops[0], connection.Counterparty.ConnectionId); err != nil {
return err
}

Expand Down Expand Up @@ -126,7 +126,7 @@ func ValidateHostMetadata(ctx sdk.Context, channelKeeper ChannelKeeper, connecti
return err
}

if err := validateConnectionParams(metadata, connection.Counterparty.GetConnectionID(), connectionHops[0]); err != nil {
if err := validateConnectionParams(metadata, connection.Counterparty.ConnectionId, connectionHops[0]); err != nil {
return err
}

Expand Down
20 changes: 10 additions & 10 deletions modules/core/03-connection/keeper/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func (k Keeper) VerifyClientState(
}

merklePath := commitmenttypes.NewMerklePath(host.FullClientStatePath(connection.Counterparty.ClientId))
merklePath, err = commitmenttypes.ApplyPrefix(connection.Counterparty.GetPrefix(), merklePath)
merklePath, err = commitmenttypes.ApplyPrefix(connection.Counterparty.Prefix, merklePath)
if err != nil {
return err
}
Expand Down Expand Up @@ -78,7 +78,7 @@ func (k Keeper) VerifyClientConsensusState(
}

merklePath := commitmenttypes.NewMerklePath(host.FullConsensusStatePath(connection.Counterparty.ClientId, consensusHeight))
merklePath, err = commitmenttypes.ApplyPrefix(connection.Counterparty.GetPrefix(), merklePath)
merklePath, err = commitmenttypes.ApplyPrefix(connection.Counterparty.Prefix, merklePath)
if err != nil {
return err
}
Expand Down Expand Up @@ -120,7 +120,7 @@ func (k Keeper) VerifyConnectionState(
}

merklePath := commitmenttypes.NewMerklePath(host.ConnectionPath(connectionID))
merklePath, err = commitmenttypes.ApplyPrefix(connection.Counterparty.GetPrefix(), merklePath)
merklePath, err = commitmenttypes.ApplyPrefix(connection.Counterparty.Prefix, merklePath)
if err != nil {
return err
}
Expand Down Expand Up @@ -163,7 +163,7 @@ func (k Keeper) VerifyChannelState(
}

merklePath := commitmenttypes.NewMerklePath(host.ChannelPath(portID, channelID))
merklePath, err = commitmenttypes.ApplyPrefix(connection.Counterparty.GetPrefix(), merklePath)
merklePath, err = commitmenttypes.ApplyPrefix(connection.Counterparty.Prefix, merklePath)
if err != nil {
return err
}
Expand Down Expand Up @@ -211,7 +211,7 @@ func (k Keeper) VerifyPacketCommitment(
blockDelay := k.getBlockDelay(ctx, connection)

merklePath := commitmenttypes.NewMerklePath(host.PacketCommitmentPath(portID, channelID, sequence))
merklePath, err = commitmenttypes.ApplyPrefix(connection.Counterparty.GetPrefix(), merklePath)
merklePath, err = commitmenttypes.ApplyPrefix(connection.Counterparty.Prefix, merklePath)
if err != nil {
return err
}
Expand Down Expand Up @@ -254,7 +254,7 @@ func (k Keeper) VerifyPacketAcknowledgement(
blockDelay := k.getBlockDelay(ctx, connection)

merklePath := commitmenttypes.NewMerklePath(host.PacketAcknowledgementPath(portID, channelID, sequence))
merklePath, err = commitmenttypes.ApplyPrefix(connection.Counterparty.GetPrefix(), merklePath)
merklePath, err = commitmenttypes.ApplyPrefix(connection.Counterparty.Prefix, merklePath)
if err != nil {
return err
}
Expand Down Expand Up @@ -297,7 +297,7 @@ func (k Keeper) VerifyPacketReceiptAbsence(
blockDelay := k.getBlockDelay(ctx, connection)

merklePath := commitmenttypes.NewMerklePath(host.PacketReceiptPath(portID, channelID, sequence))
merklePath, err = commitmenttypes.ApplyPrefix(connection.Counterparty.GetPrefix(), merklePath)
merklePath, err = commitmenttypes.ApplyPrefix(connection.Counterparty.Prefix, merklePath)
if err != nil {
return err
}
Expand Down Expand Up @@ -339,7 +339,7 @@ func (k Keeper) VerifyNextSequenceRecv(
blockDelay := k.getBlockDelay(ctx, connection)

merklePath := commitmenttypes.NewMerklePath(host.NextSequenceRecvPath(portID, channelID))
merklePath, err = commitmenttypes.ApplyPrefix(connection.Counterparty.GetPrefix(), merklePath)
merklePath, err = commitmenttypes.ApplyPrefix(connection.Counterparty.Prefix, merklePath)
if err != nil {
return err
}
Expand Down Expand Up @@ -376,7 +376,7 @@ func (k Keeper) VerifyChannelUpgradeError(
}

merklePath := commitmenttypes.NewMerklePath(host.ChannelUpgradeErrorPath(portID, channelID))
merklePath, err = commitmenttypes.ApplyPrefix(connection.Counterparty.GetPrefix(), merklePath)
merklePath, err = commitmenttypes.ApplyPrefix(connection.Counterparty.Prefix, merklePath)
if err != nil {
return err
}
Expand Down Expand Up @@ -418,7 +418,7 @@ func (k Keeper) VerifyChannelUpgrade(
}

merklePath := commitmenttypes.NewMerklePath(host.ChannelUpgradePath(portID, channelID))
merklePath, err = commitmenttypes.ApplyPrefix(connection.Counterparty.GetPrefix(), merklePath)
merklePath, err = commitmenttypes.ApplyPrefix(connection.Counterparty.Prefix, merklePath)
if err != nil {
return err
}
Expand Down
16 changes: 0 additions & 16 deletions modules/core/03-connection/types/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
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"
)

// NewConnectionEnd creates a new ConnectionEnd instance.
Expand Down Expand Up @@ -47,21 +46,6 @@ func NewCounterparty(clientID, connectionID string, prefix commitmenttypes.Merkl
}
}

// GetClientID implements the CounterpartyConnectionI interface
func (c Counterparty) GetClientID() string {
return c.ClientId
}

// GetConnectionID implements the CounterpartyConnectionI interface
func (c Counterparty) GetConnectionID() string {
return c.ConnectionId
}

// GetPrefix implements the CounterpartyConnectionI interface
func (c Counterparty) GetPrefix() exported.Prefix {
return &c.Prefix
}

// ValidateBasic performs a basic validation check of the identifiers and prefix
func (c Counterparty) ValidateBasic() error {
if c.ConnectionId != "" {
Expand Down
8 changes: 4 additions & 4 deletions modules/core/04-channel/keeper/handshake.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ func (k Keeper) ChanOpenTry(
)
}

counterpartyHops := []string{connectionEnd.Counterparty.GetConnectionID()}
counterpartyHops := []string{connectionEnd.Counterparty.ConnectionId}

// expectedCounterpaty is the counterparty of the counterparty's channel end
// (i.e self)
Expand Down Expand Up @@ -243,7 +243,7 @@ func (k Keeper) ChanOpenAck(
return errorsmod.Wrapf(connectiontypes.ErrInvalidConnectionState, "connection state is not OPEN (got %s)", connectionEnd.State)
}

counterpartyHops := []string{connectionEnd.Counterparty.GetConnectionID()}
counterpartyHops := []string{connectionEnd.Counterparty.ConnectionId}

// counterparty of the counterparty channel end (i.e self)
expectedCounterparty := types.NewCounterparty(portID, channelID)
Expand Down Expand Up @@ -319,7 +319,7 @@ func (k Keeper) ChanOpenConfirm(
return errorsmod.Wrapf(connectiontypes.ErrInvalidConnectionState, "connection state is not OPEN (got %s)", connectionEnd.State)
}

counterpartyHops := []string{connectionEnd.Counterparty.GetConnectionID()}
counterpartyHops := []string{connectionEnd.Counterparty.ConnectionId}

counterparty := types.NewCounterparty(portID, channelID)
expectedChannel := types.NewChannel(
Expand Down Expand Up @@ -445,7 +445,7 @@ func (k Keeper) ChanCloseConfirm(
return errorsmod.Wrapf(connectiontypes.ErrInvalidConnectionState, "connection state is not OPEN (got %s)", connectionEnd.State)
}

counterpartyHops := []string{connectionEnd.Counterparty.GetConnectionID()}
counterpartyHops := []string{connectionEnd.Counterparty.ConnectionId}

counterparty := types.NewCounterparty(portID, channelID)
expectedChannel := types.Channel{
Expand Down
2 changes: 1 addition & 1 deletion modules/core/04-channel/keeper/timeout.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ func (k Keeper) TimeoutOnClose(
return errorsmod.Wrapf(types.ErrInvalidPacket, "packet commitment bytes are not equal: got (%v), expected (%v)", commitment, packetCommitment)
}

counterpartyHops := []string{connectionEnd.Counterparty.GetConnectionID()}
counterpartyHops := []string{connectionEnd.Counterparty.ConnectionId}

counterparty := types.NewCounterparty(packet.GetSourcePort(), packet.GetSourceChannel())
expectedChannel := types.Channel{
Expand Down
16 changes: 8 additions & 8 deletions modules/core/04-channel/keeper/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func (k Keeper) ChanUpgradeTry(

// construct expected counterparty channel from information in state
// only the counterpartyUpgradeSequence is provided by the relayer
counterpartyConnectionHops := []string{connection.Counterparty.GetConnectionID()}
counterpartyConnectionHops := []string{connection.Counterparty.ConnectionId}
counterpartyChannel := types.Channel{
State: types.OPEN,
Ordering: channel.Ordering,
Expand Down Expand Up @@ -278,7 +278,7 @@ func (k Keeper) ChanUpgradeAck(
return errorsmod.Wrapf(connectiontypes.ErrInvalidConnectionState, "connection state is not OPEN (got %s)", connection.State)
}

counterpartyHops := []string{connection.Counterparty.GetConnectionID()}
counterpartyHops := []string{connection.Counterparty.ConnectionId}
counterpartyChannel := types.Channel{
State: types.FLUSHING,
Ordering: channel.Ordering,
Expand Down Expand Up @@ -414,7 +414,7 @@ func (k Keeper) ChanUpgradeConfirm(
return errorsmod.Wrapf(connectiontypes.ErrInvalidConnectionState, "connection state is not OPEN (got %s)", connection.State)
}

counterpartyHops := []string{connection.Counterparty.GetConnectionID()}
counterpartyHops := []string{connection.Counterparty.ConnectionId}
counterpartyChannel := types.Channel{
State: counterpartyChannelState,
Ordering: channel.Ordering,
Expand Down Expand Up @@ -537,7 +537,7 @@ func (k Keeper) ChanUpgradeOpen(
counterpartyChannel = types.Channel{
State: types.OPEN,
Ordering: upgrade.Fields.Ordering,
ConnectionHops: []string{upgradeConnection.Counterparty.GetConnectionID()},
ConnectionHops: []string{upgradeConnection.Counterparty.ConnectionId},
Counterparty: types.NewCounterparty(portID, channelID),
Version: upgrade.Fields.Version,
UpgradeSequence: counterpartyUpgradeSequence,
Expand All @@ -547,7 +547,7 @@ func (k Keeper) ChanUpgradeOpen(
counterpartyChannel = types.Channel{
State: types.FLUSHCOMPLETE,
Ordering: channel.Ordering,
ConnectionHops: []string{connection.Counterparty.GetConnectionID()},
ConnectionHops: []string{connection.Counterparty.ConnectionId},
Counterparty: types.NewCounterparty(portID, channelID),
Version: channel.Version,
UpgradeSequence: channel.UpgradeSequence,
Expand Down Expand Up @@ -769,7 +769,7 @@ func (k Keeper) ChanUpgradeTimeout(
upgrade.Fields.ConnectionHops[0],
)
}
counterpartyHops := []string{upgradeConnection.Counterparty.GetConnectionID()}
counterpartyHops := []string{upgradeConnection.Counterparty.ConnectionId}

upgradeAlreadyComplete := upgrade.Fields.Version == counterpartyChannel.Version && upgrade.Fields.Ordering == counterpartyChannel.Ordering && upgrade.Fields.ConnectionHops[0] == counterpartyHops[0]
if upgradeAlreadyComplete {
Expand Down Expand Up @@ -895,9 +895,9 @@ func (k Keeper) checkForUpgradeCompatibility(ctx sdk.Context, upgradeFields, cou
}

// connectionHops can change in a channelUpgrade, however both sides must still be each other's counterparty.
if counterpartyUpgradeFields.ConnectionHops[0] != connection.Counterparty.GetConnectionID() {
if counterpartyUpgradeFields.ConnectionHops[0] != connection.Counterparty.ConnectionId {
return errorsmod.Wrapf(
types.ErrIncompatibleCounterpartyUpgrade, "counterparty upgrade connection end is not a counterparty of self proposed connection end (%s != %s)", counterpartyUpgradeFields.ConnectionHops[0], connection.Counterparty.GetConnectionID())
types.ErrIncompatibleCounterpartyUpgrade, "counterparty upgrade connection end is not a counterparty of self proposed connection end (%s != %s)", counterpartyUpgradeFields.ConnectionHops[0], connection.Counterparty.ConnectionId)
}

return nil
Expand Down

0 comments on commit 661356e

Please sign in to comment.