Skip to content

Commit

Permalink
fix: no-op rather than panic in solomachine update state
Browse files Browse the repository at this point in the history
  • Loading branch information
damiannolan committed May 15, 2024
1 parent 340ef64 commit 9ba7b4a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1042,13 +1042,13 @@ func (suite *SoloMachineTestSuite) TestUpdateState() {
nil,
},
{
"failure: invalid type misbehaviour",
"invalid type misbehaviour no-ops",
func() {
clientState = sm.ClientState()
clientMsg = sm.CreateMisbehaviour()
suite.chainA.App.GetIBCKeeper().ClientKeeper.SetClientState(suite.chainA.GetContext(), clientID, clientState)
},
fmt.Errorf("unsupported ClientMessage: %T", sm.CreateMisbehaviour()),
nil,
},
{
"failure: cannot find client state",
Expand Down Expand Up @@ -1092,6 +1092,11 @@ func (suite *SoloMachineTestSuite) TestUpdateState() {

newClientState := clienttypes.MustUnmarshalClientState(suite.chainA.Codec, clientStateBz)

if len(consensusHeights) == 0 {
suite.Require().Equal(clientState, newClientState)
return
}

suite.Require().Len(consensusHeights, 1)
suite.Require().Equal(uint64(0), consensusHeights[0].GetRevisionNumber())
suite.Require().Equal(newClientState.(*solomachine.ClientState).Sequence, consensusHeights[0].GetRevisionHeight())
Expand Down
6 changes: 3 additions & 3 deletions modules/light-clients/06-solomachine/update.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package solomachine

import (
"fmt"

errorsmod "cosmossdk.io/errors"
storetypes "cosmossdk.io/store/types"

Expand Down Expand Up @@ -79,10 +77,12 @@ func (cs ClientState) verifyHeader(cdc codec.BinaryCodec, header *Header) error

// UpdateState updates the consensus state to the new public key and an incremented sequence.
// A list containing the updated consensus height is returned.
// If the provided clientMsg is not of type of Header then the handler will noop and an empty slice is returned.
func (cs ClientState) UpdateState(ctx sdk.Context, cdc codec.BinaryCodec, clientStore storetypes.KVStore, clientMsg exported.ClientMessage) []exported.Height {
smHeader, ok := clientMsg.(*Header)
if !ok {
panic(fmt.Errorf("unsupported ClientMessage: %T", clientMsg))
// clientMsg is invalid Misbehaviour, no update necessary
return []exported.Height{}
}

// create new solomachine ConsensusState
Expand Down

0 comments on commit 9ba7b4a

Please sign in to comment.