Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: no-op rather than panic in solomachine update state #6313

Merged
merged 5 commits into from
May 19, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
### State Machine Breaking

* (light-clients/07-tendermint) [\#6276](https://github.com/cosmos/ibc-go/pull/6276) Fix: No-op to avoid panicking on `UpdateState` for invalid misbehaviour submissions.
* (light-clients/06-solomachine) [\#6313](https://github.com/cosmos/ibc-go/pull/6313) Fix: No-op to avoid panicking on `UpdateState` for invalid misbehaviour submissions.

### Improvements

Expand Down
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 Header, the handler will no-op and return an empty slice.
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{}
damiannolan marked this conversation as resolved.
Show resolved Hide resolved
}

// create new solomachine ConsensusState
Expand Down
Loading