Skip to content

Commit

Permalink
chore: CheckSubstituteAndUpdateState stores client state in lightclie…
Browse files Browse the repository at this point in the history
…nts impl (#1170)

* set client state in store in lightclient

* adding changelog entry
  • Loading branch information
damiannolan authored Mar 30, 2022
1 parent 40183b4 commit a4b3d09
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
### Improvements
* [\#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.
* (modules/core/02-client) [\#1196](https://github.com/cosmos/ibc-go/pull/1196) Adding VerifyClientMessage to ClientState interface.
* (modules/core/02-client) [\#1170](https://github.com/cosmos/ibc-go/pull/1170) Updating `ClientUpdateProposal` to set client state in lightclient implementations `CheckSubstituteAndUpdateState` methods.

### Features

Expand Down
1 change: 0 additions & 1 deletion modules/core/02-client/keeper/proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ func (k Keeper) ClientUpdateProposal(ctx sdk.Context, p *types.ClientUpdatePropo
if err != nil {
return err
}
k.SetClientState(ctx, p.SubjectClientId, clientState)

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

Expand Down
2 changes: 2 additions & 0 deletions modules/light-clients/06-solomachine/types/proposal_handle.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,7 @@ func (cs ClientState) CheckSubstituteAndUpdateState(
clientState.ConsensusState = substituteClientState.ConsensusState
clientState.IsFrozen = false

setClientState(subjectClientStore, cdc, clientState)

return clientState, nil
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package types_test

import (
clienttypes "github.com/cosmos/ibc-go/v3/modules/core/02-client/types"
host "github.com/cosmos/ibc-go/v3/modules/core/24-host"
"github.com/cosmos/ibc-go/v3/modules/core/exported"
"github.com/cosmos/ibc-go/v3/modules/light-clients/06-solomachine/types"
ibctmtypes "github.com/cosmos/ibc-go/v3/modules/light-clients/07-tendermint/types"
Expand Down Expand Up @@ -78,6 +80,10 @@ func (suite *SoloMachineTestSuite) TestCheckSubstituteAndUpdateState() {
suite.Require().Equal(substituteClientState.(*types.ClientState).ConsensusState, updatedClient.(*types.ClientState).ConsensusState)
suite.Require().Equal(substituteClientState.(*types.ClientState).Sequence, updatedClient.(*types.ClientState).Sequence)
suite.Require().Equal(false, updatedClient.(*types.ClientState).IsFrozen)

// ensure updated client state is set in store
bz := subjectClientStore.Get(host.ClientStateKey())
suite.Require().Equal(clienttypes.MustMarshalClientState(suite.chainA.Codec, updatedClient), bz)
} else {
suite.Require().Error(err)
suite.Require().Nil(updatedClient)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ func (cs ClientState) CheckSubstituteAndUpdateState(

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

return &cs, nil
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"time"

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

suite.Require().Equal(newChainID, updatedClient.(*types.ClientState).ChainId)

// ensure updated client state is set in store
bz := subjectClientStore.Get(host.ClientStateKey())
suite.Require().Equal(clienttypes.MustMarshalClientState(suite.chainA.Codec, updatedClient), bz)
} else {
suite.Require().Error(err)
suite.Require().Nil(updatedClient)
Expand Down

0 comments on commit a4b3d09

Please sign in to comment.