diff --git a/x/ibc/03-connection/keeper/handshake.go b/x/ibc/03-connection/keeper/handshake.go index 48658f65c..87806939b 100644 --- a/x/ibc/03-connection/keeper/handshake.go +++ b/x/ibc/03-connection/keeper/handshake.go @@ -54,8 +54,11 @@ func (k Keeper) ConnOpenTry( proofHeight uint64, // height at which relayer constructs proof of A storing connectionEnd in state consensusHeight uint64, // latest height of chain B which chain A has stored in its chain B client ) error { - if consensusHeight > uint64(ctx.BlockHeight()) { - return sdkerrors.Wrap(sdkerrors.ErrInvalidHeight, "invalid consensus height") + if consensusHeight >= uint64(ctx.BlockHeight()) { + return sdkerrors.Wrapf( + sdkerrors.ErrInvalidHeight, + "consensus height is greater than or equal to the current block height (%d >= %d)", consensusHeight, uint64(ctx.BlockHeight()), + ) } expectedConsensusState, found := k.clientKeeper.GetSelfConsensusState(ctx, consensusHeight) @@ -132,8 +135,11 @@ func (k Keeper) ConnOpenAck( consensusHeight uint64, // latest height of chainA that chainB has stored on its chainA client ) error { // Check that chainB client hasn't stored invalid height - if consensusHeight > uint64(ctx.BlockHeight()) { - return sdkerrors.Wrap(sdkerrors.ErrInvalidHeight, "invalid consensus height") + if consensusHeight >= uint64(ctx.BlockHeight()) { + return sdkerrors.Wrapf( + sdkerrors.ErrInvalidHeight, + "consensus height is greater than or equal to the current block height (%d >= %d)", consensusHeight, uint64(ctx.BlockHeight()), + ) } // Retrieve connection diff --git a/x/ibc/03-connection/keeper/handshake_test.go b/x/ibc/03-connection/keeper/handshake_test.go index 724577f27..a73ea77b2 100644 --- a/x/ibc/03-connection/keeper/handshake_test.go +++ b/x/ibc/03-connection/keeper/handshake_test.go @@ -76,12 +76,12 @@ func (suite *KeeperTestSuite) TestConnOpenTry() { _, _, err := suite.coordinator.ConnOpenInit(suite.chainA, suite.chainB, clientA, clientB) suite.Require().NoError(err) }, true}, - {"consensus height > latest height", func() { + {"consensus height >= latest height", func() { clientA, clientB = suite.coordinator.SetupClients(suite.chainA, suite.chainB, clientexported.Tendermint) _, _, err := suite.coordinator.ConnOpenInit(suite.chainA, suite.chainB, clientA, clientB) suite.Require().NoError(err) - consensusHeight = uint64(suite.chainB.GetContext().BlockHeight()) + 1 + consensusHeight = uint64(suite.chainB.GetContext().BlockHeight()) }, false}, {"self consensus state not found", func() { clientA, clientB = suite.coordinator.SetupClients(suite.chainA, suite.chainB, clientexported.Tendermint) @@ -219,7 +219,7 @@ func (suite *KeeperTestSuite) TestConnOpenAck() { suite.coordinator.UpdateClient(suite.chainA, suite.chainB, clientA, clientexported.Tendermint) }, true}, - {"consensus height > latest height", func() { + {"consensus height >= latest height", func() { clientA, clientB = suite.coordinator.SetupClients(suite.chainA, suite.chainB, clientexported.Tendermint) connA, connB, err := suite.coordinator.ConnOpenInit(suite.chainA, suite.chainB, clientA, clientB) suite.Require().NoError(err) @@ -227,7 +227,7 @@ func (suite *KeeperTestSuite) TestConnOpenAck() { err = suite.coordinator.ConnOpenTry(suite.chainB, suite.chainA, connB, connA) suite.Require().NoError(err) - consensusHeight = uint64(suite.chainA.GetContext().BlockHeight()) + 1 + consensusHeight = uint64(suite.chainA.GetContext().BlockHeight()) }, false}, {"connection not found", func() { // connections are never created