update consensus height check (#6625)

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
This commit is contained in:
colin axner 2020-07-07 17:45:30 +02:00 committed by GitHub
parent 8670a10564
commit b4a027cb5d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 8 deletions

View File

@ -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

View File

@ -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