Skip to content

Commit a4b3d09

Browse files
authored
chore: CheckSubstituteAndUpdateState stores client state in lightclients impl (#1170)
* set client state in store in lightclient * adding changelog entry
1 parent 40183b4 commit a4b3d09

File tree

6 files changed

+15
-1
lines changed

6 files changed

+15
-1
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
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.
4747
* (modules/core/02-client) [\#1196](https://github.com/cosmos/ibc-go/pull/1196) Adding VerifyClientMessage to ClientState interface.
48+
* (modules/core/02-client) [\#1170](https://github.com/cosmos/ibc-go/pull/1170) Updating `ClientUpdateProposal` to set client state in lightclient implementations `CheckSubstituteAndUpdateState` methods.
4849

4950
### Features
5051

modules/core/02-client/keeper/proposal.go

-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ func (k Keeper) ClientUpdateProposal(ctx sdk.Context, p *types.ClientUpdatePropo
5353
if err != nil {
5454
return err
5555
}
56-
k.SetClientState(ctx, p.SubjectClientId, clientState)
5756

5857
k.Logger(ctx).Info("client updated after governance proposal passed", "client-id", p.SubjectClientId, "height", clientState.GetLatestHeight().String())
5958

modules/light-clients/06-solomachine/types/proposal_handle.go

+2
Original file line numberDiff line numberDiff line change
@@ -60,5 +60,7 @@ func (cs ClientState) CheckSubstituteAndUpdateState(
6060
clientState.ConsensusState = substituteClientState.ConsensusState
6161
clientState.IsFrozen = false
6262

63+
setClientState(subjectClientStore, cdc, clientState)
64+
6365
return clientState, nil
6466
}

modules/light-clients/06-solomachine/types/proposal_handle_test.go

+6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package types_test
22

33
import (
4+
clienttypes "github.com/cosmos/ibc-go/v3/modules/core/02-client/types"
5+
host "github.com/cosmos/ibc-go/v3/modules/core/24-host"
46
"github.com/cosmos/ibc-go/v3/modules/core/exported"
57
"github.com/cosmos/ibc-go/v3/modules/light-clients/06-solomachine/types"
68
ibctmtypes "github.com/cosmos/ibc-go/v3/modules/light-clients/07-tendermint/types"
@@ -78,6 +80,10 @@ func (suite *SoloMachineTestSuite) TestCheckSubstituteAndUpdateState() {
7880
suite.Require().Equal(substituteClientState.(*types.ClientState).ConsensusState, updatedClient.(*types.ClientState).ConsensusState)
7981
suite.Require().Equal(substituteClientState.(*types.ClientState).Sequence, updatedClient.(*types.ClientState).Sequence)
8082
suite.Require().Equal(false, updatedClient.(*types.ClientState).IsFrozen)
83+
84+
// ensure updated client state is set in store
85+
bz := subjectClientStore.Get(host.ClientStateKey())
86+
suite.Require().Equal(clienttypes.MustMarshalClientState(suite.chainA.Codec, updatedClient), bz)
8187
} else {
8288
suite.Require().Error(err)
8389
suite.Require().Nil(updatedClient)

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

+1
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ func (cs ClientState) CheckSubstituteAndUpdateState(
8787

8888
// no validation is necessary since the substitute is verified to be Active
8989
// in 02-client.
90+
setClientState(subjectClientStore, cdc, &cs)
9091

9192
return &cs, nil
9293
}

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

+5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"time"
55

66
clienttypes "github.com/cosmos/ibc-go/v3/modules/core/02-client/types"
7+
host "github.com/cosmos/ibc-go/v3/modules/core/24-host"
78
"github.com/cosmos/ibc-go/v3/modules/core/exported"
89
"github.com/cosmos/ibc-go/v3/modules/light-clients/07-tendermint/types"
910
ibctesting "github.com/cosmos/ibc-go/v3/testing"
@@ -299,6 +300,10 @@ func (suite *TendermintTestSuite) TestCheckSubstituteAndUpdateState() {
299300
suite.Require().Equal(expectedIterationKey, subjectIterationKey)
300301

301302
suite.Require().Equal(newChainID, updatedClient.(*types.ClientState).ChainId)
303+
304+
// ensure updated client state is set in store
305+
bz := subjectClientStore.Get(host.ClientStateKey())
306+
suite.Require().Equal(clienttypes.MustMarshalClientState(suite.chainA.Codec, updatedClient), bz)
302307
} else {
303308
suite.Require().Error(err)
304309
suite.Require().Nil(updatedClient)

0 commit comments

Comments
 (0)