From cb1cd12ca54e1e680efdf08c9f5212ddaa250915 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Colin=20Axn=C3=A9r?= <25233464+colin-axner@users.noreply.github.com> Date: Wed, 31 Jan 2024 10:02:03 +0100 Subject: [PATCH 1/4] refactor: rm GetClientID() from connection interface --- modules/core/03-connection/keeper/keeper.go | 6 ++--- modules/core/03-connection/keeper/verify.go | 24 +++++++++---------- .../core/03-connection/types/connection.go | 5 ---- modules/core/04-channel/keeper/packet.go | 6 ++--- 4 files changed, 18 insertions(+), 23 deletions(-) diff --git a/modules/core/03-connection/keeper/keeper.go b/modules/core/03-connection/keeper/keeper.go index cd18555f56e..169991b0c98 100644 --- a/modules/core/03-connection/keeper/keeper.go +++ b/modules/core/03-connection/keeper/keeper.go @@ -90,14 +90,14 @@ func (k Keeper) SetConnection(ctx sdk.Context, connectionID string, connection t // GetTimestampAtHeight returns the timestamp in nanoseconds of the consensus state at the // given height. func (k Keeper) GetTimestampAtHeight(ctx sdk.Context, connection types.ConnectionEnd, height exported.Height) (uint64, error) { - clientState, found := k.clientKeeper.GetClientState(ctx, connection.GetClientID()) + clientState, found := k.clientKeeper.GetClientState(ctx, connection.ClientId) if !found { return 0, errorsmod.Wrapf( - clienttypes.ErrClientNotFound, "clientID (%s)", connection.GetClientID(), + clienttypes.ErrClientNotFound, "clientID (%s)", connection.ClientId, ) } - timestamp, err := clientState.GetTimestampAtHeight(ctx, k.clientKeeper.ClientStore(ctx, connection.GetClientID()), k.cdc, height) + timestamp, err := clientState.GetTimestampAtHeight(ctx, k.clientKeeper.ClientStore(ctx, connection.ClientId), k.cdc, height) if err != nil { return 0, err } diff --git a/modules/core/03-connection/keeper/verify.go b/modules/core/03-connection/keeper/verify.go index 847b7c77d49..44b4cd63270 100644 --- a/modules/core/03-connection/keeper/verify.go +++ b/modules/core/03-connection/keeper/verify.go @@ -25,7 +25,7 @@ func (k Keeper) VerifyClientState( proof []byte, clientState exported.ClientState, ) error { - clientID := connection.GetClientID() + clientID := connection.ClientId targetClient, clientStore, err := k.getClientStateAndVerificationStore(ctx, clientID) if err != nil { return err @@ -35,7 +35,7 @@ func (k Keeper) VerifyClientState( return errorsmod.Wrapf(clienttypes.ErrClientNotActive, "client (%s) status is %s", clientID, status) } - merklePath := commitmenttypes.NewMerklePath(host.FullClientStatePath(connection.GetCounterparty().GetClientID())) + merklePath := commitmenttypes.NewMerklePath(host.FullClientStatePath(connection.GetCounterparty().ClientId)) merklePath, err = commitmenttypes.ApplyPrefix(connection.GetCounterparty().GetPrefix(), merklePath) if err != nil { return err @@ -67,7 +67,7 @@ func (k Keeper) VerifyClientConsensusState( proof []byte, consensusState exported.ConsensusState, ) error { - clientID := connection.GetClientID() + clientID := connection.ClientId clientState, clientStore, err := k.getClientStateAndVerificationStore(ctx, clientID) if err != nil { return err @@ -77,7 +77,7 @@ func (k Keeper) VerifyClientConsensusState( return errorsmod.Wrapf(clienttypes.ErrClientNotActive, "client (%s) status is %s", clientID, status) } - merklePath := commitmenttypes.NewMerklePath(host.FullConsensusStatePath(connection.GetCounterparty().GetClientID(), consensusHeight)) + merklePath := commitmenttypes.NewMerklePath(host.FullConsensusStatePath(connection.GetCounterparty().ClientId, consensusHeight)) merklePath, err = commitmenttypes.ApplyPrefix(connection.GetCounterparty().GetPrefix(), merklePath) if err != nil { return err @@ -109,7 +109,7 @@ func (k Keeper) VerifyConnectionState( connectionID string, counterpartyConnection types.ConnectionEnd, // opposite connection ) error { - clientID := connection.GetClientID() + clientID := connection.ClientId clientState, clientStore, err := k.getClientStateAndVerificationStore(ctx, clientID) if err != nil { return err @@ -152,7 +152,7 @@ func (k Keeper) VerifyChannelState( channelID string, channel channeltypes.Channel, ) error { - clientID := connection.GetClientID() + clientID := connection.ClientId clientState, clientStore, err := k.getClientStateAndVerificationStore(ctx, clientID) if err != nil { return err @@ -196,7 +196,7 @@ func (k Keeper) VerifyPacketCommitment( sequence uint64, commitmentBytes []byte, ) error { - clientID := connection.GetClientID() + clientID := connection.ClientId clientState, clientStore, err := k.getClientStateAndVerificationStore(ctx, clientID) if err != nil { return err @@ -239,7 +239,7 @@ func (k Keeper) VerifyPacketAcknowledgement( sequence uint64, acknowledgement []byte, ) error { - clientID := connection.GetClientID() + clientID := connection.ClientId clientState, clientStore, err := k.getClientStateAndVerificationStore(ctx, clientID) if err != nil { return err @@ -282,7 +282,7 @@ func (k Keeper) VerifyPacketReceiptAbsence( channelID string, sequence uint64, ) error { - clientID := connection.GetClientID() + clientID := connection.ClientId clientState, clientStore, err := k.getClientStateAndVerificationStore(ctx, clientID) if err != nil { return err @@ -324,7 +324,7 @@ func (k Keeper) VerifyNextSequenceRecv( channelID string, nextSequenceRecv uint64, ) error { - clientID := connection.GetClientID() + clientID := connection.ClientId clientState, clientStore, err := k.getClientStateAndVerificationStore(ctx, clientID) if err != nil { return err @@ -365,7 +365,7 @@ func (k Keeper) VerifyChannelUpgradeError( channelID string, errorReceipt channeltypes.ErrorReceipt, ) error { - clientID := connection.GetClientID() + clientID := connection.ClientId clientState, clientStore, err := k.getClientStateAndVerificationStore(ctx, clientID) if err != nil { return err @@ -407,7 +407,7 @@ func (k Keeper) VerifyChannelUpgrade( channelID string, upgrade channeltypes.Upgrade, ) error { - clientID := connection.GetClientID() + clientID := connection.ClientId clientState, clientStore, err := k.getClientStateAndVerificationStore(ctx, clientID) if err != nil { return err diff --git a/modules/core/03-connection/types/connection.go b/modules/core/03-connection/types/connection.go index a3c5fac54c1..b450781384f 100644 --- a/modules/core/03-connection/types/connection.go +++ b/modules/core/03-connection/types/connection.go @@ -20,11 +20,6 @@ func NewConnectionEnd(state State, clientID string, counterparty Counterparty, v } } -// GetClientID implements the Connection interface -func (c ConnectionEnd) GetClientID() string { - return c.ClientId -} - // GetCounterparty implements the Connection interface func (c ConnectionEnd) GetCounterparty() Counterparty { return c.Counterparty diff --git a/modules/core/04-channel/keeper/packet.go b/modules/core/04-channel/keeper/packet.go index a5bdac63dfc..d4019b32f0e 100644 --- a/modules/core/04-channel/keeper/packet.go +++ b/modules/core/04-channel/keeper/packet.go @@ -63,14 +63,14 @@ func (k Keeper) SendPacket( return 0, errorsmod.Wrap(connectiontypes.ErrConnectionNotFound, channel.ConnectionHops[0]) } - clientState, found := k.clientKeeper.GetClientState(ctx, connectionEnd.GetClientID()) + clientState, found := k.clientKeeper.GetClientState(ctx, connectionEnd.ClientId) if !found { return 0, clienttypes.ErrClientNotFound } // prevent accidental sends with clients that cannot be updated - if status := k.clientKeeper.GetClientStatus(ctx, clientState, connectionEnd.GetClientID()); status != exported.Active { - return 0, errorsmod.Wrapf(clienttypes.ErrClientNotActive, "cannot send packet using client (%s) with status %s", connectionEnd.GetClientID(), status) + if status := k.clientKeeper.GetClientStatus(ctx, clientState, connectionEnd.ClientId); status != exported.Active { + return 0, errorsmod.Wrapf(clienttypes.ErrClientNotActive, "cannot send packet using client (%s) with status %s", connectionEnd.ClientId, status) } latestHeight := clientState.GetLatestHeight() From 1855a66af9620a27234eb6e50ece229e65143d63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Colin=20Axn=C3=A9r?= <25233464+colin-axner@users.noreply.github.com> Date: Wed, 31 Jan 2024 10:04:10 +0100 Subject: [PATCH 2/4] refactor: remove GetCounterparty() from connection type --- modules/core/03-connection/keeper/verify.go | 24 +++++++++---------- .../core/03-connection/types/connection.go | 5 ---- modules/core/04-channel/keeper/handshake.go | 8 +++---- modules/core/04-channel/keeper/timeout.go | 2 +- modules/core/04-channel/keeper/upgrade.go | 16 ++++++------- 5 files changed, 25 insertions(+), 30 deletions(-) diff --git a/modules/core/03-connection/keeper/verify.go b/modules/core/03-connection/keeper/verify.go index 44b4cd63270..612e6302e3f 100644 --- a/modules/core/03-connection/keeper/verify.go +++ b/modules/core/03-connection/keeper/verify.go @@ -35,8 +35,8 @@ func (k Keeper) VerifyClientState( return errorsmod.Wrapf(clienttypes.ErrClientNotActive, "client (%s) status is %s", clientID, status) } - merklePath := commitmenttypes.NewMerklePath(host.FullClientStatePath(connection.GetCounterparty().ClientId)) - merklePath, err = commitmenttypes.ApplyPrefix(connection.GetCounterparty().GetPrefix(), merklePath) + merklePath := commitmenttypes.NewMerklePath(host.FullClientStatePath(connection.Counterparty.ClientId)) + merklePath, err = commitmenttypes.ApplyPrefix(connection.Counterparty.GetPrefix(), merklePath) if err != nil { return err } @@ -77,8 +77,8 @@ func (k Keeper) VerifyClientConsensusState( return errorsmod.Wrapf(clienttypes.ErrClientNotActive, "client (%s) status is %s", clientID, status) } - merklePath := commitmenttypes.NewMerklePath(host.FullConsensusStatePath(connection.GetCounterparty().ClientId, consensusHeight)) - merklePath, err = commitmenttypes.ApplyPrefix(connection.GetCounterparty().GetPrefix(), merklePath) + merklePath := commitmenttypes.NewMerklePath(host.FullConsensusStatePath(connection.Counterparty.ClientId, consensusHeight)) + merklePath, err = commitmenttypes.ApplyPrefix(connection.Counterparty.GetPrefix(), merklePath) if err != nil { return err } @@ -120,7 +120,7 @@ func (k Keeper) VerifyConnectionState( } merklePath := commitmenttypes.NewMerklePath(host.ConnectionPath(connectionID)) - merklePath, err = commitmenttypes.ApplyPrefix(connection.GetCounterparty().GetPrefix(), merklePath) + merklePath, err = commitmenttypes.ApplyPrefix(connection.Counterparty.GetPrefix(), merklePath) if err != nil { return err } @@ -163,7 +163,7 @@ func (k Keeper) VerifyChannelState( } merklePath := commitmenttypes.NewMerklePath(host.ChannelPath(portID, channelID)) - merklePath, err = commitmenttypes.ApplyPrefix(connection.GetCounterparty().GetPrefix(), merklePath) + merklePath, err = commitmenttypes.ApplyPrefix(connection.Counterparty.GetPrefix(), merklePath) if err != nil { return err } @@ -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.GetCounterparty().GetPrefix(), merklePath) + merklePath, err = commitmenttypes.ApplyPrefix(connection.Counterparty.GetPrefix(), merklePath) if err != nil { return err } @@ -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.GetCounterparty().GetPrefix(), merklePath) + merklePath, err = commitmenttypes.ApplyPrefix(connection.Counterparty.GetPrefix(), merklePath) if err != nil { return err } @@ -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.GetCounterparty().GetPrefix(), merklePath) + merklePath, err = commitmenttypes.ApplyPrefix(connection.Counterparty.GetPrefix(), merklePath) if err != nil { return err } @@ -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.GetCounterparty().GetPrefix(), merklePath) + merklePath, err = commitmenttypes.ApplyPrefix(connection.Counterparty.GetPrefix(), merklePath) if err != nil { return err } @@ -376,7 +376,7 @@ func (k Keeper) VerifyChannelUpgradeError( } merklePath := commitmenttypes.NewMerklePath(host.ChannelUpgradeErrorPath(portID, channelID)) - merklePath, err = commitmenttypes.ApplyPrefix(connection.GetCounterparty().GetPrefix(), merklePath) + merklePath, err = commitmenttypes.ApplyPrefix(connection.Counterparty.GetPrefix(), merklePath) if err != nil { return err } @@ -418,7 +418,7 @@ func (k Keeper) VerifyChannelUpgrade( } merklePath := commitmenttypes.NewMerklePath(host.ChannelUpgradePath(portID, channelID)) - merklePath, err = commitmenttypes.ApplyPrefix(connection.GetCounterparty().GetPrefix(), merklePath) + merklePath, err = commitmenttypes.ApplyPrefix(connection.Counterparty.GetPrefix(), merklePath) if err != nil { return err } diff --git a/modules/core/03-connection/types/connection.go b/modules/core/03-connection/types/connection.go index b450781384f..6de77b84451 100644 --- a/modules/core/03-connection/types/connection.go +++ b/modules/core/03-connection/types/connection.go @@ -20,11 +20,6 @@ func NewConnectionEnd(state State, clientID string, counterparty Counterparty, v } } -// GetCounterparty implements the Connection interface -func (c ConnectionEnd) GetCounterparty() Counterparty { - return c.Counterparty -} - // GetVersions implements the Connection interface func (c ConnectionEnd) GetVersions() []*Version { return c.Versions diff --git a/modules/core/04-channel/keeper/handshake.go b/modules/core/04-channel/keeper/handshake.go index eebefb94717..e8a31d4f371 100644 --- a/modules/core/04-channel/keeper/handshake.go +++ b/modules/core/04-channel/keeper/handshake.go @@ -152,7 +152,7 @@ func (k Keeper) ChanOpenTry( ) } - counterpartyHops := []string{connectionEnd.GetCounterparty().GetConnectionID()} + counterpartyHops := []string{connectionEnd.Counterparty.GetConnectionID()} // expectedCounterpaty is the counterparty of the counterparty's channel end // (i.e self) @@ -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.GetCounterparty().GetConnectionID()} + counterpartyHops := []string{connectionEnd.Counterparty.GetConnectionID()} // counterparty of the counterparty channel end (i.e self) expectedCounterparty := types.NewCounterparty(portID, channelID) @@ -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.GetCounterparty().GetConnectionID()} + counterpartyHops := []string{connectionEnd.Counterparty.GetConnectionID()} counterparty := types.NewCounterparty(portID, channelID) expectedChannel := types.NewChannel( @@ -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.GetCounterparty().GetConnectionID()} + counterpartyHops := []string{connectionEnd.Counterparty.GetConnectionID()} counterparty := types.NewCounterparty(portID, channelID) expectedChannel := types.Channel{ diff --git a/modules/core/04-channel/keeper/timeout.go b/modules/core/04-channel/keeper/timeout.go index 05c3f1738d6..77df0ea7f63 100644 --- a/modules/core/04-channel/keeper/timeout.go +++ b/modules/core/04-channel/keeper/timeout.go @@ -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.GetCounterparty().GetConnectionID()} + counterpartyHops := []string{connectionEnd.Counterparty.GetConnectionID()} counterparty := types.NewCounterparty(packet.GetSourcePort(), packet.GetSourceChannel()) expectedChannel := types.Channel{ diff --git a/modules/core/04-channel/keeper/upgrade.go b/modules/core/04-channel/keeper/upgrade.go index 8e3a9e5ede0..3a9512c72d6 100644 --- a/modules/core/04-channel/keeper/upgrade.go +++ b/modules/core/04-channel/keeper/upgrade.go @@ -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.GetCounterparty().GetConnectionID()} + counterpartyConnectionHops := []string{connection.Counterparty.GetConnectionID()} counterpartyChannel := types.Channel{ State: types.OPEN, Ordering: channel.Ordering, @@ -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.GetCounterparty().GetConnectionID()} + counterpartyHops := []string{connection.Counterparty.GetConnectionID()} counterpartyChannel := types.Channel{ State: types.FLUSHING, Ordering: channel.Ordering, @@ -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.GetCounterparty().GetConnectionID()} + counterpartyHops := []string{connection.Counterparty.GetConnectionID()} counterpartyChannel := types.Channel{ State: counterpartyChannelState, Ordering: channel.Ordering, @@ -537,7 +537,7 @@ func (k Keeper) ChanUpgradeOpen( counterpartyChannel = types.Channel{ State: types.OPEN, Ordering: upgrade.Fields.Ordering, - ConnectionHops: []string{upgradeConnection.GetCounterparty().GetConnectionID()}, + ConnectionHops: []string{upgradeConnection.Counterparty.GetConnectionID()}, Counterparty: types.NewCounterparty(portID, channelID), Version: upgrade.Fields.Version, UpgradeSequence: counterpartyUpgradeSequence, @@ -547,7 +547,7 @@ func (k Keeper) ChanUpgradeOpen( counterpartyChannel = types.Channel{ State: types.FLUSHCOMPLETE, Ordering: channel.Ordering, - ConnectionHops: []string{connection.GetCounterparty().GetConnectionID()}, + ConnectionHops: []string{connection.Counterparty.GetConnectionID()}, Counterparty: types.NewCounterparty(portID, channelID), Version: channel.Version, UpgradeSequence: channel.UpgradeSequence, @@ -769,7 +769,7 @@ func (k Keeper) ChanUpgradeTimeout( upgrade.Fields.ConnectionHops[0], ) } - counterpartyHops := []string{upgradeConnection.GetCounterparty().GetConnectionID()} + counterpartyHops := []string{upgradeConnection.Counterparty.GetConnectionID()} upgradeAlreadyComplete := upgrade.Fields.Version == counterpartyChannel.Version && upgrade.Fields.Ordering == counterpartyChannel.Ordering && upgrade.Fields.ConnectionHops[0] == counterpartyHops[0] if upgradeAlreadyComplete { @@ -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.GetCounterparty().GetConnectionID() { + if counterpartyUpgradeFields.ConnectionHops[0] != connection.Counterparty.GetConnectionID() { return errorsmod.Wrapf( - types.ErrIncompatibleCounterpartyUpgrade, "counterparty upgrade connection end is not a counterparty of self proposed connection end (%s != %s)", counterpartyUpgradeFields.ConnectionHops[0], connection.GetCounterparty().GetConnectionID()) + types.ErrIncompatibleCounterpartyUpgrade, "counterparty upgrade connection end is not a counterparty of self proposed connection end (%s != %s)", counterpartyUpgradeFields.ConnectionHops[0], connection.Counterparty.GetConnectionID()) } return nil From 779f4c724969c82d43fe43d77cd485091ee15312 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Colin=20Axn=C3=A9r?= <25233464+colin-axner@users.noreply.github.com> Date: Wed, 31 Jan 2024 10:05:01 +0100 Subject: [PATCH 3/4] refactor: remove GetVersions() from connection type --- modules/core/03-connection/types/connection.go | 5 ----- modules/core/04-channel/keeper/handshake.go | 4 ++-- modules/core/04-channel/keeper/upgrade.go | 2 +- 3 files changed, 3 insertions(+), 8 deletions(-) diff --git a/modules/core/03-connection/types/connection.go b/modules/core/03-connection/types/connection.go index 6de77b84451..14e11451040 100644 --- a/modules/core/03-connection/types/connection.go +++ b/modules/core/03-connection/types/connection.go @@ -20,11 +20,6 @@ func NewConnectionEnd(state State, clientID string, counterparty Counterparty, v } } -// GetVersions implements the Connection interface -func (c ConnectionEnd) GetVersions() []*Version { - return c.Versions -} - // GetDelayPeriod implements the Connection interface func (c ConnectionEnd) GetDelayPeriod() uint64 { return c.DelayPeriod diff --git a/modules/core/04-channel/keeper/handshake.go b/modules/core/04-channel/keeper/handshake.go index e8a31d4f371..a3a58233852 100644 --- a/modules/core/04-channel/keeper/handshake.go +++ b/modules/core/04-channel/keeper/handshake.go @@ -35,7 +35,7 @@ func (k Keeper) ChanOpenInit( return "", nil, errorsmod.Wrap(connectiontypes.ErrConnectionNotFound, connectionHops[0]) } - getVersions := connectionEnd.GetVersions() + getVersions := connectionEnd.Versions if len(getVersions) != 1 { return "", nil, errorsmod.Wrapf( connectiontypes.ErrInvalidVersion, @@ -135,7 +135,7 @@ func (k Keeper) ChanOpenTry( return "", nil, errorsmod.Wrapf(connectiontypes.ErrInvalidConnectionState, "connection state is not OPEN (got %s)", connectionEnd.State) } - getVersions := connectionEnd.GetVersions() + getVersions := connectionEnd.Versions if len(getVersions) != 1 { return "", nil, errorsmod.Wrapf( connectiontypes.ErrInvalidVersion, diff --git a/modules/core/04-channel/keeper/upgrade.go b/modules/core/04-channel/keeper/upgrade.go index 3a9512c72d6..df7c8c30226 100644 --- a/modules/core/04-channel/keeper/upgrade.go +++ b/modules/core/04-channel/keeper/upgrade.go @@ -926,7 +926,7 @@ func (k Keeper) validateSelfUpgradeFields(ctx sdk.Context, proposedUpgrade types return errorsmod.Wrapf(connectiontypes.ErrInvalidConnectionState, "connection state is not OPEN (got %s)", connection.State) } - getVersions := connection.GetVersions() + getVersions := connection.Versions if len(getVersions) != 1 { return errorsmod.Wrapf( connectiontypes.ErrInvalidVersion, From 4d70f3857f747be338aea2b181b726e7be4aa8b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Colin=20Axn=C3=A9r?= <25233464+colin-axner@users.noreply.github.com> Date: Wed, 31 Jan 2024 10:09:48 +0100 Subject: [PATCH 4/4] refactor: remove GetDelayPeriod() on connection + test fixes/docs --- docs/docs/05-migrations/13-v8-to-v9.md | 1 + .../controller/keeper/handshake.go | 2 +- modules/apps/27-interchain-accounts/types/metadata.go | 4 ++-- modules/core/03-connection/keeper/verify.go | 10 +++++----- modules/core/03-connection/types/connection.go | 5 ----- 5 files changed, 9 insertions(+), 13 deletions(-) diff --git a/docs/docs/05-migrations/13-v8-to-v9.md b/docs/docs/05-migrations/13-v8-to-v9.md index 02d0ae5bcff..facc3fa01ce 100644 --- a/docs/docs/05-migrations/13-v8-to-v9.md +++ b/docs/docs/05-migrations/13-v8-to-v9.md @@ -31,6 +31,7 @@ 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. ### API deprecation notice diff --git a/modules/apps/27-interchain-accounts/controller/keeper/handshake.go b/modules/apps/27-interchain-accounts/controller/keeper/handshake.go index fbbccc7d07f..12844a00023 100644 --- a/modules/apps/27-interchain-accounts/controller/keeper/handshake.go +++ b/modules/apps/27-interchain-accounts/controller/keeper/handshake.go @@ -48,7 +48,7 @@ func (k Keeper) OnChanOpenInit( return "", err } - metadata = icatypes.NewDefaultMetadata(connectionHops[0], connection.GetCounterparty().GetConnectionID()) + metadata = icatypes.NewDefaultMetadata(connectionHops[0], connection.Counterparty.GetConnectionID()) } else { metadata, err = icatypes.MetadataFromVersion(version) if err != nil { diff --git a/modules/apps/27-interchain-accounts/types/metadata.go b/modules/apps/27-interchain-accounts/types/metadata.go index a63e4a93083..61058b5e201 100644 --- a/modules/apps/27-interchain-accounts/types/metadata.go +++ b/modules/apps/27-interchain-accounts/types/metadata.go @@ -94,7 +94,7 @@ func ValidateControllerMetadata(ctx sdk.Context, channelKeeper ChannelKeeper, co return err } - if err := validateConnectionParams(metadata, connectionHops[0], connection.GetCounterparty().GetConnectionID()); err != nil { + if err := validateConnectionParams(metadata, connectionHops[0], connection.Counterparty.GetConnectionID()); err != nil { return err } @@ -126,7 +126,7 @@ func ValidateHostMetadata(ctx sdk.Context, channelKeeper ChannelKeeper, connecti return err } - if err := validateConnectionParams(metadata, connection.GetCounterparty().GetConnectionID(), connectionHops[0]); err != nil { + if err := validateConnectionParams(metadata, connection.Counterparty.GetConnectionID(), connectionHops[0]); err != nil { return err } diff --git a/modules/core/03-connection/keeper/verify.go b/modules/core/03-connection/keeper/verify.go index 612e6302e3f..d5e95acf851 100644 --- a/modules/core/03-connection/keeper/verify.go +++ b/modules/core/03-connection/keeper/verify.go @@ -207,7 +207,7 @@ func (k Keeper) VerifyPacketCommitment( } // get time and block delays - timeDelay := connection.GetDelayPeriod() + timeDelay := connection.DelayPeriod blockDelay := k.getBlockDelay(ctx, connection) merklePath := commitmenttypes.NewMerklePath(host.PacketCommitmentPath(portID, channelID, sequence)) @@ -250,7 +250,7 @@ func (k Keeper) VerifyPacketAcknowledgement( } // get time and block delays - timeDelay := connection.GetDelayPeriod() + timeDelay := connection.DelayPeriod blockDelay := k.getBlockDelay(ctx, connection) merklePath := commitmenttypes.NewMerklePath(host.PacketAcknowledgementPath(portID, channelID, sequence)) @@ -293,7 +293,7 @@ func (k Keeper) VerifyPacketReceiptAbsence( } // get time and block delays - timeDelay := connection.GetDelayPeriod() + timeDelay := connection.DelayPeriod blockDelay := k.getBlockDelay(ctx, connection) merklePath := commitmenttypes.NewMerklePath(host.PacketReceiptPath(portID, channelID, sequence)) @@ -335,7 +335,7 @@ func (k Keeper) VerifyNextSequenceRecv( } // get time and block delays - timeDelay := connection.GetDelayPeriod() + timeDelay := connection.DelayPeriod blockDelay := k.getBlockDelay(ctx, connection) merklePath := commitmenttypes.NewMerklePath(host.NextSequenceRecvPath(portID, channelID)) @@ -450,7 +450,7 @@ func (k Keeper) getBlockDelay(ctx sdk.Context, connection types.ConnectionEnd) u } // calculate minimum block delay by dividing time delay period // by the expected time per block. Round up the block delay. - timeDelay := connection.GetDelayPeriod() + timeDelay := connection.DelayPeriod return uint64(math.Ceil(float64(timeDelay) / float64(expectedTimePerBlock))) } diff --git a/modules/core/03-connection/types/connection.go b/modules/core/03-connection/types/connection.go index 14e11451040..0e638b585da 100644 --- a/modules/core/03-connection/types/connection.go +++ b/modules/core/03-connection/types/connection.go @@ -20,11 +20,6 @@ func NewConnectionEnd(state State, clientID string, counterparty Counterparty, v } } -// GetDelayPeriod implements the Connection interface -func (c ConnectionEnd) GetDelayPeriod() uint64 { - return c.DelayPeriod -} - // ValidateBasic implements the Connection interface. // NOTE: the protocol supports that the connection and client IDs match the // counterparty's.