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

make connection lookup calls consistent in 04-channel #4146

Merged
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
51 changes: 27 additions & 24 deletions modules/core/04-channel/keeper/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ func (k Keeper) ChanUpgradeTry(
return types.Upgrade{}, errorsmod.Wrapf(types.ErrInvalidChannelState, "expected one of [%s, %s], got %s", types.OPEN, types.INITUPGRADE, channel.State)
}

connection, err := k.GetConnection(ctx, channel.ConnectionHops[0])
if err != nil {
return types.Upgrade{}, errorsmod.Wrap(err, "failed to retrieve connection using the channel connection hops")
connection, found := k.connectionKeeper.GetConnection(ctx, channel.ConnectionHops[0])
if !found {
return types.Upgrade{}, errorsmod.Wrap(connectiontypes.ErrConnectionNotFound, channel.ConnectionHops[0])
}

if connection.GetState() != int32(connectiontypes.OPEN) {
Expand All @@ -117,7 +117,10 @@ func (k Keeper) ChanUpgradeTry(
Version: counterpartyUpgrade.Fields.Version,
}

var upgrade types.Upgrade
var (
err error
upgrade types.Upgrade
)

switch channel.State {
case types.OPEN:
Expand Down Expand Up @@ -164,7 +167,7 @@ func (k Keeper) ChanUpgradeTry(
FlushStatus: types.NOTINFLUSH,
}

if err := k.startFlushUpgradeHandshake(
if err = k.startFlushUpgradeHandshake(
ctx,
portID, channelID,
proposedUpgradeFields,
Expand Down Expand Up @@ -236,9 +239,9 @@ func (k Keeper) ChanUpgradeAck(
return errorsmod.Wrapf(types.ErrInvalidFlushStatus, "expected one of [%s, %s], got %s", types.FLUSHING, types.FLUSHCOMPLETE, counterpartyFlushStatus)
}

connection, err := k.GetConnection(ctx, channel.ConnectionHops[0])
if err != nil {
return errorsmod.Wrap(err, "failed to retrieve connection using the channel connection hops")
connection, found := k.connectionKeeper.GetConnection(ctx, channel.ConnectionHops[0])
if !found {
return errorsmod.Wrap(connectiontypes.ErrConnectionNotFound, channel.ConnectionHops[0])
}

if connection.GetState() != int32(connectiontypes.OPEN) {
Expand Down Expand Up @@ -339,9 +342,9 @@ func (k Keeper) ChanUpgradeOpen(
return errorsmod.Wrapf(types.ErrInvalidFlushStatus, "expected %s, got %s", types.FLUSHCOMPLETE, channel.FlushStatus)
}

connection, err := k.GetConnection(ctx, channel.ConnectionHops[0])
if err != nil {
return errorsmod.Wrap(err, "failed to retrieve connection using the channel connection hops")
connection, found := k.connectionKeeper.GetConnection(ctx, channel.ConnectionHops[0])
if !found {
return errorsmod.Wrap(connectiontypes.ErrConnectionNotFound, channel.ConnectionHops[0])
}

if connection.GetState() != int32(connectiontypes.OPEN) {
Expand All @@ -356,9 +359,9 @@ func (k Keeper) ChanUpgradeOpen(
return errorsmod.Wrapf(types.ErrUpgradeNotFound, "failed to retrieve channel upgrade: port ID (%s) channel ID (%s)", portID, channelID)
}
// If counterparty has reached OPEN, we must use the upgraded connection to verify the counterparty channel
upgradeConnection, err := k.GetConnection(ctx, upgrade.Fields.ConnectionHops[0])
if err != nil {
return errorsmod.Wrap(err, "failed to retrieve connection using the upgrade connection hops")
upgradeConnection, found := k.connectionKeeper.GetConnection(ctx, upgrade.Fields.ConnectionHops[0])
if !found {
return errorsmod.Wrap(connectiontypes.ErrConnectionNotFound, upgrade.Fields.ConnectionHops[0])
}

if upgradeConnection.GetState() != int32(connectiontypes.OPEN) {
Expand Down Expand Up @@ -406,7 +409,7 @@ func (k Keeper) ChanUpgradeOpen(
panic(fmt.Sprintf("counterparty channel state should be in one of [%s, %s, %s]; got %s", types.TRYUPGRADE, types.ACKUPGRADE, types.OPEN, counterpartyChannelState))
}

if err = k.connectionKeeper.VerifyChannelState(
if err := k.connectionKeeper.VerifyChannelState(
ctx,
connection,
proofHeight, proofCounterpartyChannel,
Expand Down Expand Up @@ -464,9 +467,9 @@ func (k Keeper) ChanUpgradeCancel(ctx sdk.Context, portID, channelID string, err
}

// get underlying connection for proof verification
connection, err := k.GetConnection(ctx, channel.ConnectionHops[0])
if err != nil {
return errorsmod.Wrap(err, "failed to retrieve connection using the channel connection hops")
connection, found := k.connectionKeeper.GetConnection(ctx, channel.ConnectionHops[0])
if !found {
return errorsmod.Wrap(connectiontypes.ErrConnectionNotFound, channel.ConnectionHops[0])
}

if connection.GetState() != int32(connectiontypes.OPEN) {
Expand Down Expand Up @@ -673,9 +676,9 @@ func (k Keeper) startFlushUpgradeHandshake(
return errorsmod.Wrapf(types.ErrChannelNotFound, "port ID (%s) channel ID (%s)", portID, channelID)
}

connection, err := k.GetConnection(ctx, channel.ConnectionHops[0])
if err != nil {
return errorsmod.Wrap(err, "failed to retrieve connection using the channel connection hops")
connection, found := k.connectionKeeper.GetConnection(ctx, channel.ConnectionHops[0])
if !found {
return errorsmod.Wrap(connectiontypes.ErrConnectionNotFound, channel.ConnectionHops[0])
}

if connection.GetState() != int32(connectiontypes.OPEN) {
Expand Down Expand Up @@ -735,11 +738,11 @@ func (k Keeper) checkForUpgradeCompatibility(ctx sdk.Context, proposedUpgradeFie
return errorsmod.Wrapf(types.ErrIncompatibleCounterpartyUpgrade, "expected upgrade ordering (%s) to match counterparty upgrade ordering (%s)", proposedUpgradeFields.Ordering, counterpartyUpgrade.Fields.Ordering)
}

proposedConnection, err := k.GetConnection(ctx, proposedUpgradeFields.ConnectionHops[0])
if err != nil {
proposedConnection, found := k.connectionKeeper.GetConnection(ctx, proposedUpgradeFields.ConnectionHops[0])
if !found {
// NOTE: this error is expected to be unreachable as the proposed upgrade connectionID should have been
// validated in the upgrade INIT and TRY handlers
return errorsmod.Wrap(err, "expected proposed connection to be found")
return errorsmod.Wrap(connectiontypes.ErrConnectionNotFound, proposedUpgradeFields.ConnectionHops[0])
}

if proposedConnection.GetState() != int32(connectiontypes.OPEN) {
Expand Down