Skip to content

Commit 725fe10

Browse files
fix: noop on UpdateState for invalid misbehaviour (backport #6276) (#6297)
* fix: noop on UpdateState for invalid misbehaviour (#6276) * fix: noop on UpdateState for invalid misbehaviour * godoc: update godoc for UpdateState * Update modules/light-clients/07-tendermint/update.go Co-authored-by: colin axnér <25233464+colin-axner@users.noreply.github.com> * chore: add changelog --------- Co-authored-by: colin axnér <25233464+colin-axner@users.noreply.github.com> Co-authored-by: Carlos Rodriguez <carlos@interchain.io> (cherry picked from commit 4f31a3c) * chore: rm unused import --------- Co-authored-by: Damian Nolan <damiannolan@gmail.com>
1 parent 0cece8d commit 725fe10

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ Ref: https://keepachangelog.com/en/1.0.0/
4242

4343
### State Machine Breaking
4444

45+
* (light-clients/07-tendermint) Fix: No-op to avoid panicking on `UpdateState` for invalid misbehaviour submissions.
46+
4547
### Improvements
4648

4749
* (apps/27-interchain-accounts, apps/tranfer, apps/29-fee) [\#6253](https://github.com/cosmos/ibc-go/pull/6253) Allow channel handshake to succeed if fee middleware is wired up on one side, but not the other.

modules/light-clients/07-tendermint/update.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package tendermint
22

33
import (
44
"bytes"
5-
"fmt"
65

76
errorsmod "cosmossdk.io/errors"
87
storetypes "cosmossdk.io/store/types"
@@ -131,10 +130,12 @@ func (cs *ClientState) verifyHeader(
131130
// UpdateState must only be used to update within a single revision, thus header revision number and trusted height's revision
132131
// number must be the same. To update to a new revision, use a separate upgrade path
133132
// UpdateState will prune the oldest consensus state if it is expired.
133+
// If the provided clientMsg is not of type of Header then the handler will noop and empty slice is returned.
134134
func (cs ClientState) UpdateState(ctx sdk.Context, cdc codec.BinaryCodec, clientStore storetypes.KVStore, clientMsg exported.ClientMessage) []exported.Height {
135135
header, ok := clientMsg.(*Header)
136136
if !ok {
137-
panic(fmt.Errorf("expected type %T, got %T", &Header{}, clientMsg))
137+
// clientMsg is invalid Misbehaviour, no update necessary
138+
return []exported.Height{}
138139
}
139140

140141
cs.pruneOldestConsensusState(ctx, cdc, clientStore)

modules/light-clients/07-tendermint/update_test.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -509,9 +509,12 @@ func (suite *TendermintTestSuite) TestUpdateState() {
509509
suite.Require().Equal(expConsensusState, updatedConsensusState)
510510

511511
} else {
512-
suite.Require().Panics(func() {
513-
clientState.UpdateState(suite.chainA.GetContext(), suite.chainA.App.AppCodec(), clientStore, clientMessage)
514-
})
512+
consensusHeights = clientState.UpdateState(suite.chainA.GetContext(), suite.chainA.App.AppCodec(), clientStore, clientMessage)
513+
suite.Require().Empty(consensusHeights)
514+
515+
consensusState, found := suite.chainA.GetSimApp().GetIBCKeeper().ClientKeeper.GetClientConsensusState(suite.chainA.GetContext(), path.EndpointA.ClientID, clienttypes.NewHeight(1, uint64(suite.chainB.GetContext().BlockHeight())))
516+
suite.Require().False(found)
517+
suite.Require().Nil(consensusState)
515518
}
516519

517520
// perform custom checks

0 commit comments

Comments
 (0)