Skip to content

Commit

Permalink
revert: unnecessary changes in connection handshake for localhost (#3161
Browse files Browse the repository at this point in the history
)

* imp: change validateHeight function name to validateConsensusHeight and improve code documentation

* revert: change code back to how it is on main

Revert code changes as they were unnecessary given that a localhost connection cannot be created via the connection handshake
  • Loading branch information
colin-axner authored Feb 20, 2023
1 parent d4e24d1 commit 7568559
Showing 1 changed file with 16 additions and 24 deletions.
40 changes: 16 additions & 24 deletions modules/core/03-connection/keeper/handshake.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,14 @@ func (k Keeper) ConnOpenTry(
// generate a new connection
connectionID := k.GenerateConnectionIdentifier(ctx)

if err := k.validateHeight(ctx, clientState.ClientType(), consensusHeight); err != nil {
return "", err
// check that the consensus height the counterparty chain is using to store a representation
// of this chain's consensus state is at a height in the past
selfHeight := clienttypes.GetSelfHeight(ctx)
if consensusHeight.GTE(selfHeight) {
return "", sdkerrors.Wrapf(
sdkerrors.ErrInvalidHeight,
"consensus height is greater than or equal to the current block height (%s >= %s)", consensusHeight, selfHeight,
)
}

// validate client parameters of a chainB client stored on chainA
Expand Down Expand Up @@ -159,9 +165,14 @@ func (k Keeper) ConnOpenAck(
proofHeight exported.Height, // height that relayer constructed proofTry
consensusHeight exported.Height, // latest height of chainA that chainB has stored on its chainA client
) error {
// Check that chainB client hasn't stored invalid height
if err := k.validateHeight(ctx, clientState.ClientType(), consensusHeight); err != nil {
return err
// check that the consensus height the counterparty chain is using to store a representation
// of this chain's consensus state is at a height in the past
selfHeight := clienttypes.GetSelfHeight(ctx)
if consensusHeight.GTE(selfHeight) {
return sdkerrors.Wrapf(
sdkerrors.ErrInvalidHeight,
"consensus height is greater than or equal to the current block height (%s >= %s)", consensusHeight, selfHeight,
)
}

// Retrieve connection
Expand Down Expand Up @@ -287,22 +298,3 @@ func (k Keeper) ConnOpenConfirm(

return nil
}

func (k Keeper) validateHeight(
ctx sdk.Context,
clientType string,
consensusHeight exported.Height,
) error {
if clientType == exported.Localhost {
return nil
}

selfHeight := clienttypes.GetSelfHeight(ctx)
if consensusHeight.GTE(selfHeight) {
return sdkerrors.Wrapf(
sdkerrors.ErrInvalidHeight,
"consensus height is greater than or equal to the current block height (%s >= %s)", consensusHeight, selfHeight,
)
}
return nil
}

0 comments on commit 7568559

Please sign in to comment.