Skip to content

Commit 40183b4

Browse files
seantkingcolin-axnerdamiannolan
authored
Adding VerifyClientMessage to ClientState interface (#1196)
* feat: adding VerifyClientMessage to ClientState interface * fix: legacy * remove todo + fix test * Update modules/core/exported/client.go Co-authored-by: colin axnér <25233464+colin-axner@users.noreply.github.com> * Update modules/core/02-client/legacy/v100/solomachine.go Co-authored-by: Damian Nolan <damiannolan@gmail.com> * chore: changelog Co-authored-by: colin axnér <25233464+colin-axner@users.noreply.github.com> Co-authored-by: Damian Nolan <damiannolan@gmail.com>
1 parent c2602a5 commit 40183b4

File tree

8 files changed

+25
-13
lines changed

8 files changed

+25
-13
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
4444

4545
### Improvements
4646
* [\#1186](https://github.com/cosmos/ibc-go/pull/1186/files) Removing `GetRoot` function from ConsensusState interface in `02-client`. `GetRoot` is unused by core IBC.
47+
* (modules/core/02-client) [\#1196](https://github.com/cosmos/ibc-go/pull/1196) Adding VerifyClientMessage to ClientState interface.
4748

4849
### Features
4950

modules/core/02-client/legacy/v100/solomachine.go

+7
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,13 @@ func (cs ClientState) ExportMetadata(_ sdk.KVStore) []exported.GenesisMetadata {
8888
panic("legacy solo machine is deprecated!")
8989
}
9090

91+
// VerifyClientMessage panics!
92+
func (cs *ClientState) VerifyClientMessage(
93+
_ sdk.Context, _ codec.BinaryCodec, _ sdk.KVStore, _ exported.ClientMessage,
94+
) error {
95+
panic("legacy solo machine is deprecated!")
96+
}
97+
9198
// CheckHeaderAndUpdateState panics!
9299
func (cs *ClientState) CheckHeaderAndUpdateState(
93100
_ sdk.Context, _ codec.BinaryCodec, _ sdk.KVStore, _ exported.ClientMessage,

modules/core/exported/client.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,10 @@ type ClientState interface {
5656
// Genesis function
5757
ExportMetadata(sdk.KVStore) []GenesisMetadata
5858

59-
// Update and Misbehaviour functions
59+
// VerifyClientMessage verifies a ClientMessage. A ClientMessage could be a Header, Misbehaviour, or batch update.
60+
VerifyClientMessage(ctx sdk.Context, cdc codec.BinaryCodec, clientStore sdk.KVStore, clientMsg ClientMessage) error
6061

62+
// Update and Misbehaviour functions
6163
CheckHeaderAndUpdateState(sdk.Context, codec.BinaryCodec, sdk.KVStore, ClientMessage) (ClientState, ConsensusState, error)
6264
CheckMisbehaviourAndUpdateState(sdk.Context, codec.BinaryCodec, sdk.KVStore, ClientMessage) (ClientState, error)
6365
CheckSubstituteAndUpdateState(ctx sdk.Context, cdc codec.BinaryCodec, subjectClientStore, substituteClientStore sdk.KVStore, substituteClient ClientState) (ClientState, error)

modules/light-clients/07-tendermint/types/misbehaviour_handle.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func (cs ClientState) CheckMisbehaviourAndUpdateState(
3232
return nil, sdkerrors.Wrapf(clienttypes.ErrInvalidClientType, "expected type %T, got %T", misbehaviour, &Misbehaviour{})
3333
}
3434

35-
if err := cs.VerifyClientMessage(ctx, clientStore, cdc, tmMisbehaviour); err != nil {
35+
if err := cs.VerifyClientMessage(ctx, cdc, clientStore, tmMisbehaviour); err != nil {
3636
return nil, err
3737
}
3838

modules/light-clients/07-tendermint/types/misbehaviour_handle_test.go

+1-5
Original file line numberDiff line numberDiff line change
@@ -775,15 +775,11 @@ func (suite *TendermintTestSuite) TestVerifyMisbehaviour() {
775775

776776
clientState := path.EndpointA.GetClientState()
777777

778-
// TODO: remove casting when `VerifyClientMessage` is apart of ClientState interface
779-
tmClientState, ok := clientState.(*types.ClientState)
780-
suite.Require().True(ok)
781-
782778
tc.malleate()
783779

784780
clientStore := suite.chainA.App.GetIBCKeeper().ClientKeeper.ClientStore(suite.chainA.GetContext(), path.EndpointA.ClientID)
785781

786-
err = tmClientState.VerifyClientMessage(suite.chainA.GetContext(), clientStore, suite.chainA.App.AppCodec(), misbehaviour)
782+
err = clientState.VerifyClientMessage(suite.chainA.GetContext(), suite.chainA.App.AppCodec(), clientStore, misbehaviour)
787783

788784
if tc.expPass {
789785
suite.Require().NoError(err)

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ func (cs ClientState) CheckHeaderAndUpdateState(
6464
conflictingHeader = true
6565
}
6666

67-
if err := cs.VerifyClientMessage(ctx, clientStore, cdc, tmHeader); err != nil {
67+
if err := cs.VerifyClientMessage(ctx, cdc, clientStore, tmHeader); err != nil {
6868
return nil, nil, err
6969
}
7070

@@ -119,7 +119,7 @@ func checkTrustedHeader(header *Header, consState *ConsensusState) error {
119119

120120
// VerifyClientMessage checks if the clientMessage is of type Header or Misbehaviour and verifies the message
121121
func (cs *ClientState) VerifyClientMessage(
122-
ctx sdk.Context, clientStore sdk.KVStore, cdc codec.BinaryCodec,
122+
ctx sdk.Context, cdc codec.BinaryCodec, clientStore sdk.KVStore,
123123
clientMsg exported.ClientMessage,
124124
) error {
125125
switch msg := clientMsg.(type) {

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

+1-4
Original file line numberDiff line numberDiff line change
@@ -382,10 +382,7 @@ func (suite *TendermintTestSuite) TestVerifyHeader() {
382382

383383
tc.malleate()
384384

385-
tmClientState, ok := clientState.(*types.ClientState)
386-
suite.Require().True(ok)
387-
388-
err = tmClientState.VerifyClientMessage(suite.chainA.GetContext(), clientStore, suite.chainA.App.AppCodec(), header)
385+
err = clientState.VerifyClientMessage(suite.chainA.GetContext(), suite.chainA.App.AppCodec(), clientStore, header)
389386

390387
if tc.expPass {
391388
suite.Require().NoError(err)

modules/light-clients/09-localhost/types/client_state.go

+9
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,15 @@ func (cs ClientState) VerifyUpgradeAndUpdateState(
142142
return sdkerrors.Wrap(clienttypes.ErrInvalidUpgradeClient, "cannot upgrade localhost client")
143143
}
144144

145+
// VerifyClientMessage
146+
// TODO: localhost client will be removed
147+
func (cs ClientState) VerifyClientMessage(
148+
_ sdk.Context, _ codec.BinaryCodec, _ sdk.KVStore,
149+
_ exported.ClientMessage,
150+
) error {
151+
return nil
152+
}
153+
145154
// VerifyClientState verifies that the localhost client state is stored locally
146155
func (cs ClientState) VerifyClientState(
147156
store sdk.KVStore, cdc codec.BinaryCodec,

0 commit comments

Comments
 (0)