Skip to content

Commit

Permalink
update consensus height check (cosmos#6625)
Browse files Browse the repository at this point in the history
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
colin-axner and mergify[bot] committed Jul 7, 2020
1 parent 8670a10 commit b4a027c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
14 changes: 10 additions & 4 deletions x/ibc/03-connection/keeper/handshake.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions x/ibc/03-connection/keeper/handshake_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -219,15 +219,15 @@ 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)

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
Expand Down

0 comments on commit b4a027c

Please sign in to comment.