Migrate Consensus State to being proto encoded/decoded in 02-client (#6960)

* flip switch to proto on consensus state in 02-client

* change consensus state to pointer

* fix bug

* remove amino from connection

* some test cleanup
This commit is contained in:
colin axnér 2020-08-06 13:06:14 +02:00 committed by GitHub
parent 3076a8b12e
commit 0e4d67601f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
25 changed files with 117 additions and 93 deletions

View File

@ -124,31 +124,31 @@ func QueryTendermintHeader(clientCtx client.Context) (ibctmtypes.Header, int64,
// QueryNodeConsensusState takes a client context and returns the appropriate
// tendermint consensus state
func QueryNodeConsensusState(clientCtx client.Context) (ibctmtypes.ConsensusState, int64, error) {
func QueryNodeConsensusState(clientCtx client.Context) (*ibctmtypes.ConsensusState, int64, error) {
node, err := clientCtx.GetNode()
if err != nil {
return ibctmtypes.ConsensusState{}, 0, err
return &ibctmtypes.ConsensusState{}, 0, err
}
info, err := node.ABCIInfo()
if err != nil {
return ibctmtypes.ConsensusState{}, 0, err
return &ibctmtypes.ConsensusState{}, 0, err
}
height := info.Response.LastBlockHeight
commit, err := node.Commit(&height)
if err != nil {
return ibctmtypes.ConsensusState{}, 0, err
return &ibctmtypes.ConsensusState{}, 0, err
}
nextHeight := height + 1
nextVals, err := node.Validators(&nextHeight, 0, 10000)
if err != nil {
return ibctmtypes.ConsensusState{}, 0, err
return &ibctmtypes.ConsensusState{}, 0, err
}
state := ibctmtypes.ConsensusState{
state := &ibctmtypes.ConsensusState{
Timestamp: commit.Time,
Root: commitmenttypes.NewMerkleRoot(commit.AppHash),
NextValidatorsHash: tmtypes.NewValidatorSet(nextVals.Validators).Hash(),

View File

@ -30,7 +30,6 @@ type ClientState interface {
VerifyClientConsensusState(
store sdk.KVStore,
cdc codec.BinaryMarshaler,
aminoCdc *codec.Codec,
root commitmentexported.Root,
height uint64,
counterpartyClientIdentifier string,

View File

@ -82,7 +82,7 @@ func (suite *KeeperTestSuite) TestUpdateClientTendermint() {
_, err := suite.keeper.CreateClient(suite.ctx, testClientID, clientState, suite.consensusState)
// store intermediate consensus state to check that trustedHeight does not need to be highest consensus state before header height
intermediateConsState := ibctmtypes.ConsensusState{
intermediateConsState := &ibctmtypes.ConsensusState{
Height: testClientHeight + 1,
Timestamp: suite.now.Add(time.Minute),
NextValidatorsHash: suite.valSetHash,
@ -101,7 +101,7 @@ func (suite *KeeperTestSuite) TestUpdateClientTendermint() {
suite.Require().NoError(err)
// store previous consensus state
prevConsState := ibctmtypes.ConsensusState{
prevConsState := &ibctmtypes.ConsensusState{
Height: 1,
Timestamp: suite.past,
NextValidatorsHash: suite.valSetHash,
@ -109,7 +109,7 @@ func (suite *KeeperTestSuite) TestUpdateClientTendermint() {
suite.keeper.SetClientConsensusState(suite.ctx, testClientID, 1, prevConsState)
// store intermediate consensus state to check that trustedHeight does not need to be hightest consensus state before header height
intermediateConsState := ibctmtypes.ConsensusState{
intermediateConsState := &ibctmtypes.ConsensusState{
Height: 2,
Timestamp: suite.past.Add(time.Minute),
NextValidatorsHash: suite.valSetHash,
@ -161,7 +161,7 @@ func (suite *KeeperTestSuite) TestUpdateClientTendermint() {
suite.Require().NoError(err)
// store previous consensus state
prevConsState := ibctmtypes.ConsensusState{
prevConsState := &ibctmtypes.ConsensusState{
Height: 1,
Timestamp: suite.past,
NextValidatorsHash: suite.valSetHash,
@ -199,7 +199,7 @@ func (suite *KeeperTestSuite) TestUpdateClientTendermint() {
if tc.expPass {
suite.Require().NoError(err, err)
expConsensusState := ibctmtypes.ConsensusState{
expConsensusState := &ibctmtypes.ConsensusState{
Height: updateHeader.GetHeight(),
Timestamp: updateHeader.Time,
Root: commitmenttypes.NewMerkleRoot(updateHeader.AppHash),
@ -303,7 +303,7 @@ func (suite *KeeperTestSuite) TestCheckMisbehaviourAndUpdateState() {
_, err := suite.keeper.CreateClient(suite.ctx, testClientID, clientState, suite.consensusState)
// store intermediate consensus state to check that trustedHeight does not need to be highest consensus state before header height
intermediateConsState := ibctmtypes.ConsensusState{
intermediateConsState := &ibctmtypes.ConsensusState{
Height: testClientHeight + 3,
Timestamp: suite.now.Add(time.Minute),
NextValidatorsHash: suite.valSetHash,

View File

@ -47,3 +47,44 @@ func (k Keeper) UnmarshalClientState(bz []byte) (exported.ClientState, error) {
return clientState, nil
}
// MustUnmarshalConsensusState attempts to decode and return an ConsensusState object from
// raw encoded bytes. It panics on error.
func (k Keeper) MustUnmarshalConsensusState(bz []byte) exported.ConsensusState {
consensusState, err := k.UnmarshalConsensusState(bz)
if err != nil {
panic(fmt.Errorf("failed to decode consensus state: %w", err))
}
return consensusState
}
// MustMarshalConsensusState attempts to encode an ConsensusState object and returns the
// raw encoded bytes. It panics on error.
func (k Keeper) MustMarshalConsensusState(consensusState exported.ConsensusState) []byte {
bz, err := k.MarshalConsensusState(consensusState)
if err != nil {
panic(fmt.Errorf("failed to encode consensus state: %w", err))
}
return bz
}
// MarshalConsensusState marshals an ConsensusState interface. If the given type implements
// the Marshaler interface, it is treated as a Proto-defined message and
// serialized that way.
func (k Keeper) MarshalConsensusState(consensusStateI exported.ConsensusState) ([]byte, error) {
return codec.MarshalAny(k.cdc, consensusStateI)
}
// UnmarshalConsensusState returns an ConsensusState interface from raw encoded clientState
// bytes of a Proto-based ConsensusState type. An error is returned upon decoding
// failure.
func (k Keeper) UnmarshalConsensusState(bz []byte) (exported.ConsensusState, error) {
var consensusState exported.ConsensusState
if err := codec.UnmarshalAny(k.cdc, &consensusState, bz); err != nil {
return nil, err
}
return consensusState, nil
}

View File

@ -21,16 +21,14 @@ import (
type Keeper struct {
storeKey sdk.StoreKey
cdc codec.BinaryMarshaler
aminoCdc *codec.Codec
stakingKeeper types.StakingKeeper
}
// NewKeeper creates a new NewKeeper instance
func NewKeeper(cdc codec.BinaryMarshaler, aminoCdc *codec.Codec, key sdk.StoreKey, sk types.StakingKeeper) Keeper {
func NewKeeper(cdc codec.BinaryMarshaler, key sdk.StoreKey, sk types.StakingKeeper) Keeper {
return Keeper{
storeKey: key,
cdc: cdc,
aminoCdc: aminoCdc,
stakingKeeper: sk,
}
}
@ -83,8 +81,7 @@ func (k Keeper) GetClientConsensusState(ctx sdk.Context, clientID string, height
return nil, false
}
var consensusState exported.ConsensusState
k.aminoCdc.MustUnmarshalBinaryBare(bz, &consensusState)
consensusState := k.MustUnmarshalConsensusState(bz)
return consensusState, true
}
@ -92,8 +89,7 @@ func (k Keeper) GetClientConsensusState(ctx sdk.Context, clientID string, height
// height
func (k Keeper) SetClientConsensusState(ctx sdk.Context, clientID string, height uint64, consensusState exported.ConsensusState) {
store := k.ClientStore(ctx, clientID)
bz := k.aminoCdc.MustMarshalBinaryBare(consensusState)
store.Set(host.KeyConsensusState(height), bz)
store.Set(host.KeyConsensusState(height), k.MustMarshalConsensusState(consensusState))
}
// IterateConsensusStates provides an iterator over all stored consensus states.
@ -111,8 +107,7 @@ func (k Keeper) IterateConsensusStates(ctx sdk.Context, cb func(clientID string,
continue
}
clientID := keySplit[1]
var consensusState exported.ConsensusState
k.aminoCdc.MustUnmarshalBinaryBare(iterator.Value(), &consensusState)
consensusState := k.MustUnmarshalConsensusState(iterator.Value())
if cb(clientID, consensusState) {
break
@ -206,7 +201,7 @@ func (k Keeper) GetSelfConsensusState(ctx sdk.Context, height uint64) (exported.
return nil, false
}
consensusState := ibctmtypes.ConsensusState{
consensusState := &ibctmtypes.ConsensusState{
Height: height,
Timestamp: histInfo.Header.Time,
Root: commitmenttypes.NewMerkleRoot(histInfo.Header.AppHash),

View File

@ -40,10 +40,9 @@ type KeeperTestSuite struct {
suite.Suite
cdc codec.Marshaler
aminoCdc *codec.Codec
ctx sdk.Context
keeper *keeper.Keeper
consensusState ibctmtypes.ConsensusState
consensusState *ibctmtypes.ConsensusState
header ibctmtypes.Header
valSet *tmtypes.ValidatorSet
valSetHash tmbytes.HexBytes
@ -60,7 +59,6 @@ func (suite *KeeperTestSuite) SetupTest() {
app := simapp.Setup(isCheckTx)
suite.cdc = app.AppCodec()
suite.aminoCdc = app.Codec()
suite.ctx = app.BaseApp.NewContext(isCheckTx, abci.Header{Height: testClientHeight, ChainID: testClientID, Time: now2})
suite.keeper = &app.IBCKeeper.ClientKeeper
suite.privVal = tmtypes.NewMockPV()
@ -72,12 +70,7 @@ func (suite *KeeperTestSuite) SetupTest() {
suite.valSet = tmtypes.NewValidatorSet([]*tmtypes.Validator{validator})
suite.valSetHash = suite.valSet.Hash()
suite.header = ibctmtypes.CreateTestHeader(testChainID, testClientHeight, testClientHeight-1, now2, suite.valSet, suite.valSet, []tmtypes.PrivValidator{suite.privVal})
suite.consensusState = ibctmtypes.ConsensusState{
Height: testClientHeight,
Timestamp: suite.now,
Root: commitmenttypes.NewMerkleRoot([]byte("hash")),
NextValidatorsHash: suite.valSetHash,
}
suite.consensusState = ibctmtypes.NewConsensusState(suite.now, commitmenttypes.NewMerkleRoot([]byte("hash")), testClientHeight, suite.valSetHash)
var validators stakingtypes.Validators
for i := 1; i < 11; i++ {
@ -120,7 +113,7 @@ func (suite *KeeperTestSuite) TestSetClientConsensusState() {
retrievedConsState, found := suite.keeper.GetClientConsensusState(suite.ctx, testClientID, testClientHeight)
suite.Require().True(found, "GetConsensusState failed")
tmConsState, ok := retrievedConsState.(ibctmtypes.ConsensusState)
tmConsState, ok := retrievedConsState.(*ibctmtypes.ConsensusState)
suite.Require().True(ok)
suite.Require().Equal(suite.consensusState, tmConsState, "ConsensusState not stored correctly")
}
@ -209,12 +202,7 @@ func (suite KeeperTestSuite) TestConsensusStateHelpers() {
suite.keeper.SetClientState(suite.ctx, testClientID, clientState)
suite.keeper.SetClientConsensusState(suite.ctx, testClientID, testClientHeight, suite.consensusState)
nextState := ibctmtypes.ConsensusState{
Height: testClientHeight + 5,
Timestamp: suite.now,
Root: commitmenttypes.NewMerkleRoot([]byte("next")),
NextValidatorsHash: suite.valSetHash,
}
nextState := ibctmtypes.NewConsensusState(suite.now, commitmenttypes.NewMerkleRoot([]byte("next")), testClientHeight+5, suite.valSetHash)
header := ibctmtypes.CreateTestHeader(testClientID, testClientHeight+5, testClientHeight, suite.header.Time.Add(time.Minute),
suite.valSet, suite.valSet, []tmtypes.PrivValidator{suite.privVal})

View File

@ -22,6 +22,10 @@ func RegisterInterfaces(registry codectypes.InterfaceRegistry) {
"cosmos_sdk.ibc.v1.client.ClientState",
(*exported.ClientState)(nil),
)
registry.RegisterInterface(
"cosmos_sdk.ibc.v1.client.ConsensusState",
(*exported.ConsensusState)(nil),
)
}
var (

View File

@ -116,7 +116,7 @@ func (suite *KeeperTestSuite) TestConnOpenTry() {
consState, found := suite.chainA.App.IBCKeeper.ClientKeeper.GetLatestClientConsensusState(suite.chainA.GetContext(), clientA)
suite.Require().True(found)
tmConsState, ok := consState.(ibctmtypes.ConsensusState)
tmConsState, ok := consState.(*ibctmtypes.ConsensusState)
suite.Require().True(ok)
tmConsState.Timestamp = time.Now()
@ -304,7 +304,7 @@ func (suite *KeeperTestSuite) TestConnOpenAck() {
consState, found := suite.chainB.App.IBCKeeper.ClientKeeper.GetLatestClientConsensusState(suite.chainB.GetContext(), clientB)
suite.Require().True(found)
tmConsState, ok := consState.(ibctmtypes.ConsensusState)
tmConsState, ok := consState.(*ibctmtypes.ConsensusState)
suite.Require().True(ok)
tmConsState.Timestamp = time.Now()

View File

@ -22,16 +22,14 @@ type Keeper struct {
types.QueryServer
storeKey sdk.StoreKey
aminoCdc *codec.Codec // amino codec. TODO: remove after clients have been migrated to proto
cdc codec.BinaryMarshaler
clientKeeper types.ClientKeeper
}
// NewKeeper creates a new IBC connection Keeper instance
func NewKeeper(aminoCdc *codec.Codec, cdc codec.BinaryMarshaler, key sdk.StoreKey, ck types.ClientKeeper) Keeper {
func NewKeeper(cdc codec.BinaryMarshaler, key sdk.StoreKey, ck types.ClientKeeper) Keeper {
return Keeper{
storeKey: key,
aminoCdc: aminoCdc,
cdc: cdc,
clientKeeper: ck,
}

View File

@ -31,7 +31,7 @@ func (k Keeper) VerifyClientConsensusState(
}
if err := clientState.VerifyClientConsensusState(
k.clientKeeper.ClientStore(ctx, clientID), k.cdc, k.aminoCdc, targetConsState.GetRoot(), height,
k.clientKeeper.ClientStore(ctx, clientID), k.cdc, targetConsState.GetRoot(), height,
connection.GetCounterparty().GetClientID(), consensusHeight, connection.GetCounterparty().GetPrefix(), proof, consensusState,
); err != nil {
return sdkerrors.Wrap(err, "failed consensus state verification")

View File

@ -48,7 +48,7 @@ func (suite *KeeperTestSuite) TestVerifyClientConsensusState() {
consState, found := suite.chainB.App.IBCKeeper.ClientKeeper.GetLatestClientConsensusState(suite.chainB.GetContext(), clientB)
suite.Require().True(found)
tmConsState, ok := consState.(ibctmtypes.ConsensusState)
tmConsState, ok := consState.(*ibctmtypes.ConsensusState)
suite.Require().True(ok)
tmConsState.Timestamp = time.Now()

View File

@ -19,7 +19,7 @@ func RegisterInterfaces(registry codectypes.InterfaceRegistry) {
}
var (
// SubModuleCdc references the global x/ibc/03-connectionl module codec. Note, the codec should
// SubModuleCdc references the global x/ibc/03-connection module codec. Note, the codec should
// ONLY be used in certain instances of tests and for JSON encoding.
//
// The actual codec used for serialization should be provided to x/ibc/03-connectionl and

View File

@ -29,7 +29,7 @@ func CheckMisbehaviourAndUpdateState(
// cast the interface to specific types before checking for misbehaviour
tmClientState, ok := clientState.(*types.ClientState)
if !ok {
return nil, sdkerrors.Wrapf(clienttypes.ErrInvalidClientType, "expected type %T, got %T", types.ClientState{}, clientState)
return nil, sdkerrors.Wrapf(clienttypes.ErrInvalidClientType, "expected type %T, got %T", &types.ClientState{}, clientState)
}
// If client is already frozen at earlier height than evidence, return with error
@ -38,9 +38,9 @@ func CheckMisbehaviourAndUpdateState(
"client is already frozen at earlier height %d than misbehaviour height %d", tmClientState.FrozenHeight, misbehaviour.GetHeight())
}
tmConsensusState, ok := consensusState.(types.ConsensusState)
tmConsensusState, ok := consensusState.(*types.ConsensusState)
if !ok {
return nil, sdkerrors.Wrapf(clienttypes.ErrInvalidClientType, "expected type %T, got %T", consensusState, types.ConsensusState{})
return nil, sdkerrors.Wrapf(clienttypes.ErrInvalidClientType, "expected type %T, got %T", &types.ConsensusState{}, consensusState)
}
tmEvidence, ok := misbehaviour.(types.Evidence)
@ -60,7 +60,7 @@ func CheckMisbehaviourAndUpdateState(
// checkMisbehaviour checks if the evidence provided is a valid light client misbehaviour
func checkMisbehaviour(
clientState *types.ClientState, consensusState types.ConsensusState, evidence types.Evidence,
clientState *types.ClientState, consensusState *types.ConsensusState, evidence types.Evidence,
height uint64, currentTimestamp time.Time, consensusParams *abci.ConsensusParams,
) error {
// calculate the age of the misbehaviour evidence

View File

@ -55,7 +55,7 @@ func (suite *TendermintTestSuite) TestCheckMisbehaviour() {
{
"valid misbehavior evidence",
types.NewClientState(chainID, types.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, height, commitmenttypes.GetSDKSpecs()),
types.ConsensusState{Timestamp: suite.now, Root: commitmenttypes.NewMerkleRoot(tmhash.Sum([]byte("app_hash"))), NextValidatorsHash: bothValsHash},
types.NewConsensusState(suite.now, commitmenttypes.NewMerkleRoot(tmhash.Sum([]byte("app_hash"))), height, bothValsHash),
types.Evidence{
Header1: types.CreateTestHeader(chainID, height, height, suite.now, bothValSet, bothValSet, bothSigners),
Header2: types.CreateTestHeader(chainID, height, height, suite.now.Add(time.Minute), bothValSet, bothValSet, bothSigners),
@ -70,7 +70,7 @@ func (suite *TendermintTestSuite) TestCheckMisbehaviour() {
{
"valid misbehavior at height greater than last consensusState",
types.NewClientState(chainID, types.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, height, commitmenttypes.GetSDKSpecs()),
types.ConsensusState{Timestamp: suite.now, Height: height - 1, Root: commitmenttypes.NewMerkleRoot(tmhash.Sum([]byte("app_hash"))), NextValidatorsHash: bothValsHash},
types.NewConsensusState(suite.now, commitmenttypes.NewMerkleRoot(tmhash.Sum([]byte("app_hash"))), height-1, bothValsHash),
types.Evidence{
Header1: types.CreateTestHeader(chainID, height, height-1, suite.now, bothValSet, bothValSet, bothSigners),
Header2: types.CreateTestHeader(chainID, height, height-1, suite.now.Add(time.Minute), bothValSet, bothValSet, bothSigners),
@ -85,7 +85,7 @@ func (suite *TendermintTestSuite) TestCheckMisbehaviour() {
{
"consensus state's valset hash different from evidence should still pass",
types.NewClientState(chainID, types.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, height, commitmenttypes.GetSDKSpecs()),
types.ConsensusState{Timestamp: suite.now, Height: height, Root: commitmenttypes.NewMerkleRoot(tmhash.Sum([]byte("app_hash"))), NextValidatorsHash: suite.valsHash},
types.NewConsensusState(suite.now, commitmenttypes.NewMerkleRoot(tmhash.Sum([]byte("app_hash"))), height, suite.valsHash),
types.Evidence{
Header1: types.CreateTestHeader(chainID, height, height, suite.now, bothValSet, suite.valSet, bothSigners),
Header2: types.CreateTestHeader(chainID, height, height, suite.now.Add(time.Minute), bothValSet, suite.valSet, bothSigners),
@ -100,7 +100,7 @@ func (suite *TendermintTestSuite) TestCheckMisbehaviour() {
{
"invalid tendermint client state",
nil,
types.ConsensusState{Timestamp: suite.now, Root: commitmenttypes.NewMerkleRoot(tmhash.Sum([]byte("app_hash"))), NextValidatorsHash: bothValsHash},
types.NewConsensusState(suite.now, commitmenttypes.NewMerkleRoot(tmhash.Sum([]byte("app_hash"))), height, bothValsHash),
types.Evidence{
Header1: types.CreateTestHeader(chainID, height, height, suite.now, bothValSet, bothValSet, bothSigners),
Header2: types.CreateTestHeader(chainID, height, height, suite.now.Add(time.Minute), bothValSet, altValSet, bothSigners),
@ -114,8 +114,8 @@ func (suite *TendermintTestSuite) TestCheckMisbehaviour() {
},
{
"already frozen client state",
types.ClientState{FrozenHeight: 1},
types.ConsensusState{Timestamp: suite.now, Root: commitmenttypes.NewMerkleRoot(tmhash.Sum([]byte("app_hash"))), NextValidatorsHash: bothValsHash},
&types.ClientState{FrozenHeight: 1},
types.NewConsensusState(suite.now, commitmenttypes.NewMerkleRoot(tmhash.Sum([]byte("app_hash"))), height, bothValsHash),
types.Evidence{
Header1: types.CreateTestHeader(chainID, height, height, suite.now, bothValSet, bothValSet, bothSigners),
Header2: types.CreateTestHeader(chainID, height, height, suite.now.Add(time.Minute), bothValSet, bothValSet, bothSigners),
@ -145,7 +145,7 @@ func (suite *TendermintTestSuite) TestCheckMisbehaviour() {
{
"invalid tendermint misbehaviour evidence",
types.NewClientState(chainID, types.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, height, commitmenttypes.GetSDKSpecs()),
types.ConsensusState{Timestamp: suite.now, Root: commitmenttypes.NewMerkleRoot(tmhash.Sum([]byte("app_hash"))), NextValidatorsHash: bothValsHash},
types.NewConsensusState(suite.now, commitmenttypes.NewMerkleRoot(tmhash.Sum([]byte("app_hash"))), height, bothValsHash),
nil,
simapp.DefaultConsensusParams,
height,
@ -155,7 +155,7 @@ func (suite *TendermintTestSuite) TestCheckMisbehaviour() {
{
"rejected misbehaviour due to expired age",
types.NewClientState(chainID, types.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, height, commitmenttypes.GetSDKSpecs()),
types.ConsensusState{Timestamp: suite.now, Root: commitmenttypes.NewMerkleRoot(tmhash.Sum([]byte("app_hash"))), NextValidatorsHash: bothValsHash},
types.NewConsensusState(suite.now, commitmenttypes.NewMerkleRoot(tmhash.Sum([]byte("app_hash"))), height, bothValsHash),
types.Evidence{
Header1: types.CreateTestHeader(chainID, int64(2*height+uint64(simapp.DefaultConsensusParams.Evidence.MaxAgeNumBlocks)), height,
suite.now, bothValSet, bothValSet, bothSigners),
@ -172,7 +172,7 @@ func (suite *TendermintTestSuite) TestCheckMisbehaviour() {
{
"provided height > header height",
types.NewClientState(chainID, types.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, height, commitmenttypes.GetSDKSpecs()),
types.ConsensusState{Timestamp: suite.now, Root: commitmenttypes.NewMerkleRoot(tmhash.Sum([]byte("app_hash"))), NextValidatorsHash: bothValsHash},
types.NewConsensusState(suite.now, commitmenttypes.NewMerkleRoot(tmhash.Sum([]byte("app_hash"))), height, bothValsHash),
types.Evidence{
Header1: types.CreateTestHeader(chainID, height, height-1, suite.now, bothValSet, bothValSet, bothSigners),
Header2: types.CreateTestHeader(chainID, height, height-1, suite.now.Add(time.Minute), bothValSet, bothValSet, bothSigners),
@ -187,7 +187,7 @@ func (suite *TendermintTestSuite) TestCheckMisbehaviour() {
{
"unbonding period expired",
types.NewClientState(chainID, types.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, height, commitmenttypes.GetSDKSpecs()),
types.ConsensusState{Timestamp: time.Time{}, Root: commitmenttypes.NewMerkleRoot(tmhash.Sum([]byte("app_hash"))), NextValidatorsHash: bothValsHash},
types.NewConsensusState(time.Time{}, commitmenttypes.NewMerkleRoot(tmhash.Sum([]byte("app_hash"))), height, bothValsHash),
types.Evidence{
Header1: types.CreateTestHeader(chainID, height, height, suite.now, bothValSet, bothValSet, bothSigners),
Header2: types.CreateTestHeader(chainID, height, height, suite.now.Add(time.Minute), bothValSet, bothValSet, bothSigners),
@ -202,7 +202,7 @@ func (suite *TendermintTestSuite) TestCheckMisbehaviour() {
{
"trusted validators is incorrect for given consensus state",
types.NewClientState(chainID, types.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, height, commitmenttypes.GetSDKSpecs()),
types.ConsensusState{Timestamp: suite.now, Root: commitmenttypes.NewMerkleRoot(tmhash.Sum([]byte("app_hash"))), NextValidatorsHash: bothValsHash},
types.NewConsensusState(suite.now, commitmenttypes.NewMerkleRoot(tmhash.Sum([]byte("app_hash"))), height, bothValsHash),
types.Evidence{
Header1: types.CreateTestHeader(chainID, height, height, suite.now, bothValSet, suite.valSet, bothSigners),
Header2: types.CreateTestHeader(chainID, height, height, suite.now.Add(time.Minute), bothValSet, suite.valSet, bothSigners),
@ -217,7 +217,7 @@ func (suite *TendermintTestSuite) TestCheckMisbehaviour() {
{
"first valset has too much change",
types.NewClientState(chainID, types.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, height, commitmenttypes.GetSDKSpecs()),
types.ConsensusState{Timestamp: suite.now, Root: commitmenttypes.NewMerkleRoot(tmhash.Sum([]byte("app_hash"))), NextValidatorsHash: bothValsHash},
types.NewConsensusState(suite.now, commitmenttypes.NewMerkleRoot(tmhash.Sum([]byte("app_hash"))), height, bothValsHash),
types.Evidence{
Header1: types.CreateTestHeader(chainID, height, height, suite.now, altValSet, bothValSet, altSigners),
Header2: types.CreateTestHeader(chainID, height, height, suite.now.Add(time.Minute), bothValSet, bothValSet, bothSigners),
@ -232,7 +232,7 @@ func (suite *TendermintTestSuite) TestCheckMisbehaviour() {
{
"second valset has too much change",
types.NewClientState(chainID, types.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, height, commitmenttypes.GetSDKSpecs()),
types.ConsensusState{Timestamp: suite.now, Root: commitmenttypes.NewMerkleRoot(tmhash.Sum([]byte("app_hash"))), NextValidatorsHash: bothValsHash},
types.NewConsensusState(suite.now, commitmenttypes.NewMerkleRoot(tmhash.Sum([]byte("app_hash"))), height, bothValsHash),
types.Evidence{
Header1: types.CreateTestHeader(chainID, height, height, suite.now, bothValSet, bothValSet, bothSigners),
Header2: types.CreateTestHeader(chainID, height, height, suite.now.Add(time.Minute), altValSet, bothValSet, altSigners),
@ -247,7 +247,7 @@ func (suite *TendermintTestSuite) TestCheckMisbehaviour() {
{
"both valsets have too much change",
types.NewClientState(chainID, types.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, height, commitmenttypes.GetSDKSpecs()),
types.ConsensusState{Timestamp: suite.now, Root: commitmenttypes.NewMerkleRoot(tmhash.Sum([]byte("app_hash"))), NextValidatorsHash: bothValsHash},
types.NewConsensusState(suite.now, commitmenttypes.NewMerkleRoot(tmhash.Sum([]byte("app_hash"))), height, bothValsHash),
types.Evidence{
Header1: types.CreateTestHeader(chainID, height, height, suite.now, altValSet, bothValSet, altSigners),
Header2: types.CreateTestHeader(chainID, height, height, suite.now.Add(time.Minute), altValSet, bothValSet, altSigners),

View File

@ -125,7 +125,6 @@ func (cs ClientState) GetProofSpecs() []*ics23.ProofSpec {
func (cs ClientState) VerifyClientConsensusState(
_ sdk.KVStore,
cdc codec.BinaryMarshaler,
aminoCdc *codec.Codec,
provingRoot commitmentexported.Root,
height uint64,
counterpartyClientIdentifier string,
@ -145,7 +144,7 @@ func (cs ClientState) VerifyClientConsensusState(
return err
}
bz, err := aminoCdc.MarshalBinaryBare(consensusState)
bz, err := codec.MarshalAny(cdc, consensusState)
if err != nil {
return err
}
@ -404,9 +403,9 @@ func sanitizeVerificationArgs(
return commitmenttypes.MerkleProof{}, sdkerrors.Wrap(clienttypes.ErrInvalidConsensus, "consensus state cannot be empty")
}
_, ok = consensusState.(ConsensusState)
_, ok = consensusState.(*ConsensusState)
if !ok {
return commitmenttypes.MerkleProof{}, sdkerrors.Wrapf(clienttypes.ErrInvalidConsensus, "invalid consensus type %T, expected %T", consensusState, ConsensusState{})
return commitmenttypes.MerkleProof{}, sdkerrors.Wrapf(clienttypes.ErrInvalidConsensus, "invalid consensus type %T, expected %T", consensusState, &ConsensusState{})
}
return merkleProof, nil

View File

@ -149,7 +149,7 @@ func (suite *TendermintTestSuite) TestVerifyClientConsensusState() {
tc := tc
err := tc.clientState.VerifyClientConsensusState(
nil, suite.cdc, suite.aminoCdc, tc.consensusState.Root, height, "chainA", tc.consensusState.GetHeight(), tc.prefix, tc.proof, tc.consensusState,
nil, suite.cdc, tc.consensusState.Root, height, "chainA", tc.consensusState.GetHeight(), tc.prefix, tc.proof, tc.consensusState,
)
if tc.expPass {

View File

@ -17,8 +17,8 @@ import (
func NewConsensusState(
timestamp time.Time, root commitmenttypes.MerkleRoot, height uint64,
nextValsHash tmbytes.HexBytes,
) ConsensusState {
return ConsensusState{
) *ConsensusState {
return &ConsensusState{
Timestamp: timestamp,
Root: root,
Height: height,

View File

@ -4,18 +4,18 @@ import (
"time"
clientexported "github.com/cosmos/cosmos-sdk/x/ibc/02-client/exported"
ibctmtypes "github.com/cosmos/cosmos-sdk/x/ibc/07-tendermint/types"
"github.com/cosmos/cosmos-sdk/x/ibc/07-tendermint/types"
commitmenttypes "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/types"
)
func (suite *TendermintTestSuite) TestConsensusStateValidateBasic() {
testCases := []struct {
msg string
consensusState ibctmtypes.ConsensusState
consensusState *types.ConsensusState
expectPass bool
}{
{"success",
ibctmtypes.ConsensusState{
&types.ConsensusState{
Timestamp: suite.now,
Height: height,
Root: commitmenttypes.NewMerkleRoot([]byte("app_hash")),
@ -23,7 +23,7 @@ func (suite *TendermintTestSuite) TestConsensusStateValidateBasic() {
},
true},
{"root is nil",
ibctmtypes.ConsensusState{
&types.ConsensusState{
Timestamp: suite.now,
Height: height,
Root: commitmenttypes.MerkleRoot{},
@ -31,7 +31,7 @@ func (suite *TendermintTestSuite) TestConsensusStateValidateBasic() {
},
false},
{"root is empty",
ibctmtypes.ConsensusState{
&types.ConsensusState{
Timestamp: suite.now,
Height: height,
Root: commitmenttypes.MerkleRoot{},
@ -39,7 +39,7 @@ func (suite *TendermintTestSuite) TestConsensusStateValidateBasic() {
},
false},
{"nextvalshash is invalid",
ibctmtypes.ConsensusState{
&types.ConsensusState{
Timestamp: suite.now,
Height: height,
Root: commitmenttypes.NewMerkleRoot([]byte("app_hash")),
@ -48,7 +48,7 @@ func (suite *TendermintTestSuite) TestConsensusStateValidateBasic() {
false},
{"height is 0",
ibctmtypes.ConsensusState{
&types.ConsensusState{
Timestamp: suite.now,
Height: 0,
Root: commitmenttypes.NewMerkleRoot([]byte("app_hash")),
@ -56,7 +56,7 @@ func (suite *TendermintTestSuite) TestConsensusStateValidateBasic() {
},
false},
{"timestamp is zero",
ibctmtypes.ConsensusState{
&types.ConsensusState{
Timestamp: time.Time{},
Height: height,
Root: commitmenttypes.NewMerkleRoot([]byte("app_hash")),

View File

@ -36,8 +36,8 @@ func (h Header) ClientType() clientexported.ClientType {
}
// ConsensusState returns the updated consensus state associated with the header
func (h Header) ConsensusState() ConsensusState {
return ConsensusState{
func (h Header) ConsensusState() *ConsensusState {
return &ConsensusState{
Height: uint64(h.Height),
Timestamp: h.Time,
Root: commitmenttypes.NewMerkleRoot(h.AppHash),

View File

@ -140,7 +140,7 @@ func (msg MsgCreateClient) GetClientType() string {
func (msg MsgCreateClient) GetConsensusState() clientexported.ConsensusState {
// Construct initial consensus state from provided Header
root := commitmenttypes.NewMerkleRoot(msg.Header.AppHash)
return ConsensusState{
return &ConsensusState{
Timestamp: msg.Header.Time,
Root: root,
Height: uint64(msg.Header.Height),

View File

@ -44,7 +44,7 @@ func CheckValidityAndUpdateState(
)
}
tmConsState, ok := consState.(types.ConsensusState)
tmConsState, ok := consState.(*types.ConsensusState)
if !ok {
return nil, nil, sdkerrors.Wrapf(
clienttypes.ErrInvalidConsensus, "expected type %T, got %T", types.ConsensusState{}, consState,
@ -69,7 +69,7 @@ func CheckValidityAndUpdateState(
// checkValidity checks if the Tendermint header is valid.
// CONTRACT: consState.Height == header.TrustedHeight
func checkValidity(
clientState *types.ClientState, consState types.ConsensusState,
clientState *types.ClientState, consState *types.ConsensusState,
header types.Header, currentTimestamp time.Time,
) error {
// assert that trustedVals is NextValidators of last trusted header
@ -140,11 +140,11 @@ func checkValidity(
}
// update the consensus state from a new header
func update(clientState *types.ClientState, header types.Header) (*types.ClientState, types.ConsensusState) {
func update(clientState *types.ClientState, header types.Header) (*types.ClientState, *types.ConsensusState) {
if uint64(header.Height) > clientState.LatestHeight {
clientState.LatestHeight = uint64(header.Height)
}
consensusState := types.ConsensusState{
consensusState := &types.ConsensusState{
Height: uint64(header.Height),
Timestamp: header.Time,
Root: commitmenttypes.NewMerkleRoot(header.AppHash),

View File

@ -14,7 +14,7 @@ import (
func (suite *TendermintTestSuite) TestCheckValidity() {
var (
clientState *types.ClientState
consensusState types.ConsensusState
consensusState *types.ConsensusState
newHeader types.Header
currentTime time.Time
)
@ -192,7 +192,7 @@ func (suite *TendermintTestSuite) TestCheckValidity() {
// setup test
tc.setup()
expectedConsensus := types.ConsensusState{
expectedConsensus := &types.ConsensusState{
Height: uint64(newHeader.Height),
Timestamp: newHeader.Time,
Root: commitmenttypes.NewMerkleRoot(newHeader.AppHash),

View File

@ -75,7 +75,7 @@ func (cs ClientState) GetProofSpecs() []*ics23.ProofSpec {
// VerifyClientConsensusState returns an error since a local host client does not store consensus
// states.
func (cs ClientState) VerifyClientConsensusState(
sdk.KVStore, codec.BinaryMarshaler, *codec.Codec, commitmentexported.Root,
sdk.KVStore, codec.BinaryMarshaler, commitmentexported.Root,
uint64, string, uint64, commitmentexported.Prefix, []byte, clientexported.ConsensusState,
) error {
return ErrConsensusStatesNotStored

View File

@ -50,7 +50,7 @@ func (suite *LocalhostTestSuite) TestValidate() {
func (suite *LocalhostTestSuite) TestVerifyClientConsensusState() {
clientState := types.NewClientState("chainID", 10)
err := clientState.VerifyClientConsensusState(
nil, nil, nil, nil, 0, "", 0, nil, nil, nil,
nil, nil, nil, 0, "", 0, nil, nil, nil,
)
suite.Require().Error(err)
}

View File

@ -34,8 +34,8 @@ type Keeper struct {
func NewKeeper(
aminoCdc *codec.Codec, cdc codec.BinaryMarshaler, key sdk.StoreKey, stakingKeeper clienttypes.StakingKeeper, scopedKeeper capabilitykeeper.ScopedKeeper,
) *Keeper {
clientKeeper := clientkeeper.NewKeeper(cdc, aminoCdc, key, stakingKeeper)
connectionKeeper := connectionkeeper.NewKeeper(aminoCdc, cdc, key, clientKeeper)
clientKeeper := clientkeeper.NewKeeper(cdc, key, stakingKeeper)
connectionKeeper := connectionkeeper.NewKeeper(cdc, key, clientKeeper)
portKeeper := portkeeper.NewKeeper(scopedKeeper)
channelKeeper := channelkeeper.NewKeeper(cdc, key, clientKeeper, connectionKeeper, portKeeper, scopedKeeper)