diff --git a/x/ibc/02-client/exported/exported.go b/x/ibc/02-client/exported/exported.go index 2a1e85cae..b22400523 100644 --- a/x/ibc/02-client/exported/exported.go +++ b/x/ibc/02-client/exported/exported.go @@ -16,7 +16,6 @@ import ( // ClientState defines the required common functions for light clients. type ClientState interface { - GetChainID() string ClientType() ClientType GetLatestHeight() uint64 IsFrozen() bool diff --git a/x/ibc/09-localhost/types/client_state.go b/x/ibc/09-localhost/types/client_state.go index acf04de1b..d15b276ba 100644 --- a/x/ibc/09-localhost/types/client_state.go +++ b/x/ibc/09-localhost/types/client_state.go @@ -73,15 +73,15 @@ func (cs ClientState) GetProofSpecs() []*ics23.ProofSpec { } // CheckHeaderAndUpdateState updates the localhost client. It only needs access to the context -func (cs ClientState) CheckHeaderAndUpdateState( +func (cs *ClientState) CheckHeaderAndUpdateState( ctx sdk.Context, _ codec.BinaryMarshaler, _ sdk.KVStore, _ clientexported.Header, ) (clientexported.ClientState, clientexported.ConsensusState, error) { + // use the chain ID from context since the localhost client is from the running chain (i.e self). + cs.ChainId = ctx.ChainID() // Hardcode 0 for epoch number for now // TODO: Retrieve epoch number from chain-id - return NewClientState( - ctx.ChainID(), // use the chain ID from context since the client is from the running chain (i.e self). - clienttypes.NewHeight(0, uint64(ctx.BlockHeight())), - ), nil, nil + cs.Height = clienttypes.NewHeight(0, uint64(ctx.BlockHeight())) + return cs, nil, nil } // CheckMisbehaviourAndUpdateState implements ClientState diff --git a/x/ibc/09-localhost/types/client_state_test.go b/x/ibc/09-localhost/types/client_state_test.go index 327153b86..32c3f8aa7 100644 --- a/x/ibc/09-localhost/types/client_state_test.go +++ b/x/ibc/09-localhost/types/client_state_test.go @@ -118,6 +118,13 @@ func (suite *LocalhostTestSuite) TestVerifyClientConsensusState() { ) suite.Require().NoError(err) } +func (suite *LocalhostTestSuite) TestCheckHeaderAndUpdateState() { + clientState := types.NewClientState("chainID", clientHeight) + cs, _, err := clientState.CheckHeaderAndUpdateState(suite.ctx, nil, nil, nil) + suite.Require().NoError(err) + suite.Require().Equal(suite.ctx.BlockHeight(), int64(cs.GetLatestHeight())) + suite.Require().Equal(suite.ctx.BlockHeader().ChainID, clientState.ChainId) +} func (suite *LocalhostTestSuite) TestVerifyConnectionState() { counterparty := connectiontypes.NewCounterparty("clientB", testConnectionID, commitmenttypes.NewMerklePrefix([]byte("ibc"))) diff --git a/x/ibc/09-localhost/types/localhost_test.go b/x/ibc/09-localhost/types/localhost_test.go index febdf46a9..af73381ac 100644 --- a/x/ibc/09-localhost/types/localhost_test.go +++ b/x/ibc/09-localhost/types/localhost_test.go @@ -25,6 +25,7 @@ type LocalhostTestSuite struct { suite.Suite cdc codec.Marshaler + ctx sdk.Context store sdk.KVStore } @@ -33,8 +34,8 @@ func (suite *LocalhostTestSuite) SetupTest() { app := simapp.Setup(isCheckTx) suite.cdc = app.AppCodec() - ctx := app.BaseApp.NewContext(isCheckTx, tmproto.Header{Height: 1}) - suite.store = app.IBCKeeper.ClientKeeper.ClientStore(ctx, clientexported.ClientTypeLocalHost) + suite.ctx = app.BaseApp.NewContext(isCheckTx, tmproto.Header{Height: 1, ChainID: "ibc-chain"}) + suite.store = app.IBCKeeper.ClientKeeper.ClientStore(suite.ctx, clientexported.ClientTypeLocalHost) } func TestLocalhostTestSuite(t *testing.T) { diff --git a/x/ibc/light-clients/solomachine/types/client_state.go b/x/ibc/light-clients/solomachine/types/client_state.go index 6ad450104..3ac79ed05 100644 --- a/x/ibc/light-clients/solomachine/types/client_state.go +++ b/x/ibc/light-clients/solomachine/types/client_state.go @@ -25,11 +25,6 @@ func NewClientState(consensusState *ConsensusState) *ClientState { } } -// GetChainID returns an empty string. -func (cs ClientState) GetChainID() string { - return "" -} - // ClientType is Solo Machine. func (cs ClientState) ClientType() clientexported.ClientType { return clientexported.SoloMachine