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:
parent
3076a8b12e
commit
0e4d67601f
|
@ -124,31 +124,31 @@ func QueryTendermintHeader(clientCtx client.Context) (ibctmtypes.Header, int64,
|
||||||
|
|
||||||
// QueryNodeConsensusState takes a client context and returns the appropriate
|
// QueryNodeConsensusState takes a client context and returns the appropriate
|
||||||
// tendermint consensus state
|
// 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()
|
node, err := clientCtx.GetNode()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ibctmtypes.ConsensusState{}, 0, err
|
return &ibctmtypes.ConsensusState{}, 0, err
|
||||||
}
|
}
|
||||||
|
|
||||||
info, err := node.ABCIInfo()
|
info, err := node.ABCIInfo()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ibctmtypes.ConsensusState{}, 0, err
|
return &ibctmtypes.ConsensusState{}, 0, err
|
||||||
}
|
}
|
||||||
|
|
||||||
height := info.Response.LastBlockHeight
|
height := info.Response.LastBlockHeight
|
||||||
|
|
||||||
commit, err := node.Commit(&height)
|
commit, err := node.Commit(&height)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ibctmtypes.ConsensusState{}, 0, err
|
return &ibctmtypes.ConsensusState{}, 0, err
|
||||||
}
|
}
|
||||||
|
|
||||||
nextHeight := height + 1
|
nextHeight := height + 1
|
||||||
nextVals, err := node.Validators(&nextHeight, 0, 10000)
|
nextVals, err := node.Validators(&nextHeight, 0, 10000)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ibctmtypes.ConsensusState{}, 0, err
|
return &ibctmtypes.ConsensusState{}, 0, err
|
||||||
}
|
}
|
||||||
|
|
||||||
state := ibctmtypes.ConsensusState{
|
state := &ibctmtypes.ConsensusState{
|
||||||
Timestamp: commit.Time,
|
Timestamp: commit.Time,
|
||||||
Root: commitmenttypes.NewMerkleRoot(commit.AppHash),
|
Root: commitmenttypes.NewMerkleRoot(commit.AppHash),
|
||||||
NextValidatorsHash: tmtypes.NewValidatorSet(nextVals.Validators).Hash(),
|
NextValidatorsHash: tmtypes.NewValidatorSet(nextVals.Validators).Hash(),
|
||||||
|
|
|
@ -30,7 +30,6 @@ type ClientState interface {
|
||||||
VerifyClientConsensusState(
|
VerifyClientConsensusState(
|
||||||
store sdk.KVStore,
|
store sdk.KVStore,
|
||||||
cdc codec.BinaryMarshaler,
|
cdc codec.BinaryMarshaler,
|
||||||
aminoCdc *codec.Codec,
|
|
||||||
root commitmentexported.Root,
|
root commitmentexported.Root,
|
||||||
height uint64,
|
height uint64,
|
||||||
counterpartyClientIdentifier string,
|
counterpartyClientIdentifier string,
|
||||||
|
|
|
@ -82,7 +82,7 @@ func (suite *KeeperTestSuite) TestUpdateClientTendermint() {
|
||||||
_, err := suite.keeper.CreateClient(suite.ctx, testClientID, clientState, suite.consensusState)
|
_, 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
|
// 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,
|
Height: testClientHeight + 1,
|
||||||
Timestamp: suite.now.Add(time.Minute),
|
Timestamp: suite.now.Add(time.Minute),
|
||||||
NextValidatorsHash: suite.valSetHash,
|
NextValidatorsHash: suite.valSetHash,
|
||||||
|
@ -101,7 +101,7 @@ func (suite *KeeperTestSuite) TestUpdateClientTendermint() {
|
||||||
suite.Require().NoError(err)
|
suite.Require().NoError(err)
|
||||||
|
|
||||||
// store previous consensus state
|
// store previous consensus state
|
||||||
prevConsState := ibctmtypes.ConsensusState{
|
prevConsState := &ibctmtypes.ConsensusState{
|
||||||
Height: 1,
|
Height: 1,
|
||||||
Timestamp: suite.past,
|
Timestamp: suite.past,
|
||||||
NextValidatorsHash: suite.valSetHash,
|
NextValidatorsHash: suite.valSetHash,
|
||||||
|
@ -109,7 +109,7 @@ func (suite *KeeperTestSuite) TestUpdateClientTendermint() {
|
||||||
suite.keeper.SetClientConsensusState(suite.ctx, testClientID, 1, prevConsState)
|
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
|
// 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,
|
Height: 2,
|
||||||
Timestamp: suite.past.Add(time.Minute),
|
Timestamp: suite.past.Add(time.Minute),
|
||||||
NextValidatorsHash: suite.valSetHash,
|
NextValidatorsHash: suite.valSetHash,
|
||||||
|
@ -161,7 +161,7 @@ func (suite *KeeperTestSuite) TestUpdateClientTendermint() {
|
||||||
suite.Require().NoError(err)
|
suite.Require().NoError(err)
|
||||||
|
|
||||||
// store previous consensus state
|
// store previous consensus state
|
||||||
prevConsState := ibctmtypes.ConsensusState{
|
prevConsState := &ibctmtypes.ConsensusState{
|
||||||
Height: 1,
|
Height: 1,
|
||||||
Timestamp: suite.past,
|
Timestamp: suite.past,
|
||||||
NextValidatorsHash: suite.valSetHash,
|
NextValidatorsHash: suite.valSetHash,
|
||||||
|
@ -199,7 +199,7 @@ func (suite *KeeperTestSuite) TestUpdateClientTendermint() {
|
||||||
if tc.expPass {
|
if tc.expPass {
|
||||||
suite.Require().NoError(err, err)
|
suite.Require().NoError(err, err)
|
||||||
|
|
||||||
expConsensusState := ibctmtypes.ConsensusState{
|
expConsensusState := &ibctmtypes.ConsensusState{
|
||||||
Height: updateHeader.GetHeight(),
|
Height: updateHeader.GetHeight(),
|
||||||
Timestamp: updateHeader.Time,
|
Timestamp: updateHeader.Time,
|
||||||
Root: commitmenttypes.NewMerkleRoot(updateHeader.AppHash),
|
Root: commitmenttypes.NewMerkleRoot(updateHeader.AppHash),
|
||||||
|
@ -303,7 +303,7 @@ func (suite *KeeperTestSuite) TestCheckMisbehaviourAndUpdateState() {
|
||||||
_, err := suite.keeper.CreateClient(suite.ctx, testClientID, clientState, suite.consensusState)
|
_, 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
|
// 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,
|
Height: testClientHeight + 3,
|
||||||
Timestamp: suite.now.Add(time.Minute),
|
Timestamp: suite.now.Add(time.Minute),
|
||||||
NextValidatorsHash: suite.valSetHash,
|
NextValidatorsHash: suite.valSetHash,
|
||||||
|
|
|
@ -47,3 +47,44 @@ func (k Keeper) UnmarshalClientState(bz []byte) (exported.ClientState, error) {
|
||||||
|
|
||||||
return clientState, nil
|
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
|
||||||
|
}
|
||||||
|
|
|
@ -21,16 +21,14 @@ import (
|
||||||
type Keeper struct {
|
type Keeper struct {
|
||||||
storeKey sdk.StoreKey
|
storeKey sdk.StoreKey
|
||||||
cdc codec.BinaryMarshaler
|
cdc codec.BinaryMarshaler
|
||||||
aminoCdc *codec.Codec
|
|
||||||
stakingKeeper types.StakingKeeper
|
stakingKeeper types.StakingKeeper
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewKeeper creates a new NewKeeper instance
|
// 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{
|
return Keeper{
|
||||||
storeKey: key,
|
storeKey: key,
|
||||||
cdc: cdc,
|
cdc: cdc,
|
||||||
aminoCdc: aminoCdc,
|
|
||||||
stakingKeeper: sk,
|
stakingKeeper: sk,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -83,8 +81,7 @@ func (k Keeper) GetClientConsensusState(ctx sdk.Context, clientID string, height
|
||||||
return nil, false
|
return nil, false
|
||||||
}
|
}
|
||||||
|
|
||||||
var consensusState exported.ConsensusState
|
consensusState := k.MustUnmarshalConsensusState(bz)
|
||||||
k.aminoCdc.MustUnmarshalBinaryBare(bz, &consensusState)
|
|
||||||
return consensusState, true
|
return consensusState, true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -92,8 +89,7 @@ func (k Keeper) GetClientConsensusState(ctx sdk.Context, clientID string, height
|
||||||
// height
|
// height
|
||||||
func (k Keeper) SetClientConsensusState(ctx sdk.Context, clientID string, height uint64, consensusState exported.ConsensusState) {
|
func (k Keeper) SetClientConsensusState(ctx sdk.Context, clientID string, height uint64, consensusState exported.ConsensusState) {
|
||||||
store := k.ClientStore(ctx, clientID)
|
store := k.ClientStore(ctx, clientID)
|
||||||
bz := k.aminoCdc.MustMarshalBinaryBare(consensusState)
|
store.Set(host.KeyConsensusState(height), k.MustMarshalConsensusState(consensusState))
|
||||||
store.Set(host.KeyConsensusState(height), bz)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// IterateConsensusStates provides an iterator over all stored consensus states.
|
// 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
|
continue
|
||||||
}
|
}
|
||||||
clientID := keySplit[1]
|
clientID := keySplit[1]
|
||||||
var consensusState exported.ConsensusState
|
consensusState := k.MustUnmarshalConsensusState(iterator.Value())
|
||||||
k.aminoCdc.MustUnmarshalBinaryBare(iterator.Value(), &consensusState)
|
|
||||||
|
|
||||||
if cb(clientID, consensusState) {
|
if cb(clientID, consensusState) {
|
||||||
break
|
break
|
||||||
|
@ -206,7 +201,7 @@ func (k Keeper) GetSelfConsensusState(ctx sdk.Context, height uint64) (exported.
|
||||||
return nil, false
|
return nil, false
|
||||||
}
|
}
|
||||||
|
|
||||||
consensusState := ibctmtypes.ConsensusState{
|
consensusState := &ibctmtypes.ConsensusState{
|
||||||
Height: height,
|
Height: height,
|
||||||
Timestamp: histInfo.Header.Time,
|
Timestamp: histInfo.Header.Time,
|
||||||
Root: commitmenttypes.NewMerkleRoot(histInfo.Header.AppHash),
|
Root: commitmenttypes.NewMerkleRoot(histInfo.Header.AppHash),
|
||||||
|
|
|
@ -40,10 +40,9 @@ type KeeperTestSuite struct {
|
||||||
suite.Suite
|
suite.Suite
|
||||||
|
|
||||||
cdc codec.Marshaler
|
cdc codec.Marshaler
|
||||||
aminoCdc *codec.Codec
|
|
||||||
ctx sdk.Context
|
ctx sdk.Context
|
||||||
keeper *keeper.Keeper
|
keeper *keeper.Keeper
|
||||||
consensusState ibctmtypes.ConsensusState
|
consensusState *ibctmtypes.ConsensusState
|
||||||
header ibctmtypes.Header
|
header ibctmtypes.Header
|
||||||
valSet *tmtypes.ValidatorSet
|
valSet *tmtypes.ValidatorSet
|
||||||
valSetHash tmbytes.HexBytes
|
valSetHash tmbytes.HexBytes
|
||||||
|
@ -60,7 +59,6 @@ func (suite *KeeperTestSuite) SetupTest() {
|
||||||
app := simapp.Setup(isCheckTx)
|
app := simapp.Setup(isCheckTx)
|
||||||
|
|
||||||
suite.cdc = app.AppCodec()
|
suite.cdc = app.AppCodec()
|
||||||
suite.aminoCdc = app.Codec()
|
|
||||||
suite.ctx = app.BaseApp.NewContext(isCheckTx, abci.Header{Height: testClientHeight, ChainID: testClientID, Time: now2})
|
suite.ctx = app.BaseApp.NewContext(isCheckTx, abci.Header{Height: testClientHeight, ChainID: testClientID, Time: now2})
|
||||||
suite.keeper = &app.IBCKeeper.ClientKeeper
|
suite.keeper = &app.IBCKeeper.ClientKeeper
|
||||||
suite.privVal = tmtypes.NewMockPV()
|
suite.privVal = tmtypes.NewMockPV()
|
||||||
|
@ -72,12 +70,7 @@ func (suite *KeeperTestSuite) SetupTest() {
|
||||||
suite.valSet = tmtypes.NewValidatorSet([]*tmtypes.Validator{validator})
|
suite.valSet = tmtypes.NewValidatorSet([]*tmtypes.Validator{validator})
|
||||||
suite.valSetHash = suite.valSet.Hash()
|
suite.valSetHash = suite.valSet.Hash()
|
||||||
suite.header = ibctmtypes.CreateTestHeader(testChainID, testClientHeight, testClientHeight-1, now2, suite.valSet, suite.valSet, []tmtypes.PrivValidator{suite.privVal})
|
suite.header = ibctmtypes.CreateTestHeader(testChainID, testClientHeight, testClientHeight-1, now2, suite.valSet, suite.valSet, []tmtypes.PrivValidator{suite.privVal})
|
||||||
suite.consensusState = ibctmtypes.ConsensusState{
|
suite.consensusState = ibctmtypes.NewConsensusState(suite.now, commitmenttypes.NewMerkleRoot([]byte("hash")), testClientHeight, suite.valSetHash)
|
||||||
Height: testClientHeight,
|
|
||||||
Timestamp: suite.now,
|
|
||||||
Root: commitmenttypes.NewMerkleRoot([]byte("hash")),
|
|
||||||
NextValidatorsHash: suite.valSetHash,
|
|
||||||
}
|
|
||||||
|
|
||||||
var validators stakingtypes.Validators
|
var validators stakingtypes.Validators
|
||||||
for i := 1; i < 11; i++ {
|
for i := 1; i < 11; i++ {
|
||||||
|
@ -120,7 +113,7 @@ func (suite *KeeperTestSuite) TestSetClientConsensusState() {
|
||||||
retrievedConsState, found := suite.keeper.GetClientConsensusState(suite.ctx, testClientID, testClientHeight)
|
retrievedConsState, found := suite.keeper.GetClientConsensusState(suite.ctx, testClientID, testClientHeight)
|
||||||
suite.Require().True(found, "GetConsensusState failed")
|
suite.Require().True(found, "GetConsensusState failed")
|
||||||
|
|
||||||
tmConsState, ok := retrievedConsState.(ibctmtypes.ConsensusState)
|
tmConsState, ok := retrievedConsState.(*ibctmtypes.ConsensusState)
|
||||||
suite.Require().True(ok)
|
suite.Require().True(ok)
|
||||||
suite.Require().Equal(suite.consensusState, tmConsState, "ConsensusState not stored correctly")
|
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.SetClientState(suite.ctx, testClientID, clientState)
|
||||||
suite.keeper.SetClientConsensusState(suite.ctx, testClientID, testClientHeight, suite.consensusState)
|
suite.keeper.SetClientConsensusState(suite.ctx, testClientID, testClientHeight, suite.consensusState)
|
||||||
|
|
||||||
nextState := ibctmtypes.ConsensusState{
|
nextState := ibctmtypes.NewConsensusState(suite.now, commitmenttypes.NewMerkleRoot([]byte("next")), testClientHeight+5, suite.valSetHash)
|
||||||
Height: testClientHeight + 5,
|
|
||||||
Timestamp: suite.now,
|
|
||||||
Root: commitmenttypes.NewMerkleRoot([]byte("next")),
|
|
||||||
NextValidatorsHash: suite.valSetHash,
|
|
||||||
}
|
|
||||||
|
|
||||||
header := ibctmtypes.CreateTestHeader(testClientID, testClientHeight+5, testClientHeight, suite.header.Time.Add(time.Minute),
|
header := ibctmtypes.CreateTestHeader(testClientID, testClientHeight+5, testClientHeight, suite.header.Time.Add(time.Minute),
|
||||||
suite.valSet, suite.valSet, []tmtypes.PrivValidator{suite.privVal})
|
suite.valSet, suite.valSet, []tmtypes.PrivValidator{suite.privVal})
|
||||||
|
|
|
@ -22,6 +22,10 @@ func RegisterInterfaces(registry codectypes.InterfaceRegistry) {
|
||||||
"cosmos_sdk.ibc.v1.client.ClientState",
|
"cosmos_sdk.ibc.v1.client.ClientState",
|
||||||
(*exported.ClientState)(nil),
|
(*exported.ClientState)(nil),
|
||||||
)
|
)
|
||||||
|
registry.RegisterInterface(
|
||||||
|
"cosmos_sdk.ibc.v1.client.ConsensusState",
|
||||||
|
(*exported.ConsensusState)(nil),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|
|
@ -116,7 +116,7 @@ func (suite *KeeperTestSuite) TestConnOpenTry() {
|
||||||
consState, found := suite.chainA.App.IBCKeeper.ClientKeeper.GetLatestClientConsensusState(suite.chainA.GetContext(), clientA)
|
consState, found := suite.chainA.App.IBCKeeper.ClientKeeper.GetLatestClientConsensusState(suite.chainA.GetContext(), clientA)
|
||||||
suite.Require().True(found)
|
suite.Require().True(found)
|
||||||
|
|
||||||
tmConsState, ok := consState.(ibctmtypes.ConsensusState)
|
tmConsState, ok := consState.(*ibctmtypes.ConsensusState)
|
||||||
suite.Require().True(ok)
|
suite.Require().True(ok)
|
||||||
|
|
||||||
tmConsState.Timestamp = time.Now()
|
tmConsState.Timestamp = time.Now()
|
||||||
|
@ -304,7 +304,7 @@ func (suite *KeeperTestSuite) TestConnOpenAck() {
|
||||||
consState, found := suite.chainB.App.IBCKeeper.ClientKeeper.GetLatestClientConsensusState(suite.chainB.GetContext(), clientB)
|
consState, found := suite.chainB.App.IBCKeeper.ClientKeeper.GetLatestClientConsensusState(suite.chainB.GetContext(), clientB)
|
||||||
suite.Require().True(found)
|
suite.Require().True(found)
|
||||||
|
|
||||||
tmConsState, ok := consState.(ibctmtypes.ConsensusState)
|
tmConsState, ok := consState.(*ibctmtypes.ConsensusState)
|
||||||
suite.Require().True(ok)
|
suite.Require().True(ok)
|
||||||
|
|
||||||
tmConsState.Timestamp = time.Now()
|
tmConsState.Timestamp = time.Now()
|
||||||
|
|
|
@ -22,16 +22,14 @@ type Keeper struct {
|
||||||
types.QueryServer
|
types.QueryServer
|
||||||
|
|
||||||
storeKey sdk.StoreKey
|
storeKey sdk.StoreKey
|
||||||
aminoCdc *codec.Codec // amino codec. TODO: remove after clients have been migrated to proto
|
|
||||||
cdc codec.BinaryMarshaler
|
cdc codec.BinaryMarshaler
|
||||||
clientKeeper types.ClientKeeper
|
clientKeeper types.ClientKeeper
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewKeeper creates a new IBC connection Keeper instance
|
// 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{
|
return Keeper{
|
||||||
storeKey: key,
|
storeKey: key,
|
||||||
aminoCdc: aminoCdc,
|
|
||||||
cdc: cdc,
|
cdc: cdc,
|
||||||
clientKeeper: ck,
|
clientKeeper: ck,
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,7 +31,7 @@ func (k Keeper) VerifyClientConsensusState(
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := clientState.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,
|
connection.GetCounterparty().GetClientID(), consensusHeight, connection.GetCounterparty().GetPrefix(), proof, consensusState,
|
||||||
); err != nil {
|
); err != nil {
|
||||||
return sdkerrors.Wrap(err, "failed consensus state verification")
|
return sdkerrors.Wrap(err, "failed consensus state verification")
|
||||||
|
|
|
@ -48,7 +48,7 @@ func (suite *KeeperTestSuite) TestVerifyClientConsensusState() {
|
||||||
consState, found := suite.chainB.App.IBCKeeper.ClientKeeper.GetLatestClientConsensusState(suite.chainB.GetContext(), clientB)
|
consState, found := suite.chainB.App.IBCKeeper.ClientKeeper.GetLatestClientConsensusState(suite.chainB.GetContext(), clientB)
|
||||||
suite.Require().True(found)
|
suite.Require().True(found)
|
||||||
|
|
||||||
tmConsState, ok := consState.(ibctmtypes.ConsensusState)
|
tmConsState, ok := consState.(*ibctmtypes.ConsensusState)
|
||||||
suite.Require().True(ok)
|
suite.Require().True(ok)
|
||||||
|
|
||||||
tmConsState.Timestamp = time.Now()
|
tmConsState.Timestamp = time.Now()
|
||||||
|
|
|
@ -19,7 +19,7 @@ func RegisterInterfaces(registry codectypes.InterfaceRegistry) {
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
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.
|
// 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
|
// The actual codec used for serialization should be provided to x/ibc/03-connectionl and
|
||||||
|
|
|
@ -29,7 +29,7 @@ func CheckMisbehaviourAndUpdateState(
|
||||||
// cast the interface to specific types before checking for misbehaviour
|
// cast the interface to specific types before checking for misbehaviour
|
||||||
tmClientState, ok := clientState.(*types.ClientState)
|
tmClientState, ok := clientState.(*types.ClientState)
|
||||||
if !ok {
|
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
|
// 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())
|
"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 {
|
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)
|
tmEvidence, ok := misbehaviour.(types.Evidence)
|
||||||
|
@ -60,7 +60,7 @@ func CheckMisbehaviourAndUpdateState(
|
||||||
|
|
||||||
// checkMisbehaviour checks if the evidence provided is a valid light client misbehaviour
|
// checkMisbehaviour checks if the evidence provided is a valid light client misbehaviour
|
||||||
func checkMisbehaviour(
|
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,
|
height uint64, currentTimestamp time.Time, consensusParams *abci.ConsensusParams,
|
||||||
) error {
|
) error {
|
||||||
// calculate the age of the misbehaviour evidence
|
// calculate the age of the misbehaviour evidence
|
||||||
|
|
|
@ -55,7 +55,7 @@ func (suite *TendermintTestSuite) TestCheckMisbehaviour() {
|
||||||
{
|
{
|
||||||
"valid misbehavior evidence",
|
"valid misbehavior evidence",
|
||||||
types.NewClientState(chainID, types.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, height, commitmenttypes.GetSDKSpecs()),
|
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{
|
types.Evidence{
|
||||||
Header1: types.CreateTestHeader(chainID, height, height, suite.now, bothValSet, bothValSet, bothSigners),
|
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),
|
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",
|
"valid misbehavior at height greater than last consensusState",
|
||||||
types.NewClientState(chainID, types.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, height, commitmenttypes.GetSDKSpecs()),
|
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{
|
types.Evidence{
|
||||||
Header1: types.CreateTestHeader(chainID, height, height-1, suite.now, bothValSet, bothValSet, bothSigners),
|
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),
|
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",
|
"consensus state's valset hash different from evidence should still pass",
|
||||||
types.NewClientState(chainID, types.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, height, commitmenttypes.GetSDKSpecs()),
|
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{
|
types.Evidence{
|
||||||
Header1: types.CreateTestHeader(chainID, height, height, suite.now, bothValSet, suite.valSet, bothSigners),
|
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),
|
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",
|
"invalid tendermint client state",
|
||||||
nil,
|
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{
|
types.Evidence{
|
||||||
Header1: types.CreateTestHeader(chainID, height, height, suite.now, bothValSet, bothValSet, bothSigners),
|
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),
|
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",
|
"already frozen client state",
|
||||||
types.ClientState{FrozenHeight: 1},
|
&types.ClientState{FrozenHeight: 1},
|
||||||
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{
|
types.Evidence{
|
||||||
Header1: types.CreateTestHeader(chainID, height, height, suite.now, bothValSet, bothValSet, bothSigners),
|
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),
|
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",
|
"invalid tendermint misbehaviour evidence",
|
||||||
types.NewClientState(chainID, types.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, height, commitmenttypes.GetSDKSpecs()),
|
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,
|
nil,
|
||||||
simapp.DefaultConsensusParams,
|
simapp.DefaultConsensusParams,
|
||||||
height,
|
height,
|
||||||
|
@ -155,7 +155,7 @@ func (suite *TendermintTestSuite) TestCheckMisbehaviour() {
|
||||||
{
|
{
|
||||||
"rejected misbehaviour due to expired age",
|
"rejected misbehaviour due to expired age",
|
||||||
types.NewClientState(chainID, types.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, height, commitmenttypes.GetSDKSpecs()),
|
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{
|
types.Evidence{
|
||||||
Header1: types.CreateTestHeader(chainID, int64(2*height+uint64(simapp.DefaultConsensusParams.Evidence.MaxAgeNumBlocks)), height,
|
Header1: types.CreateTestHeader(chainID, int64(2*height+uint64(simapp.DefaultConsensusParams.Evidence.MaxAgeNumBlocks)), height,
|
||||||
suite.now, bothValSet, bothValSet, bothSigners),
|
suite.now, bothValSet, bothValSet, bothSigners),
|
||||||
|
@ -172,7 +172,7 @@ func (suite *TendermintTestSuite) TestCheckMisbehaviour() {
|
||||||
{
|
{
|
||||||
"provided height > header height",
|
"provided height > header height",
|
||||||
types.NewClientState(chainID, types.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, height, commitmenttypes.GetSDKSpecs()),
|
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{
|
types.Evidence{
|
||||||
Header1: types.CreateTestHeader(chainID, height, height-1, suite.now, bothValSet, bothValSet, bothSigners),
|
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),
|
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",
|
"unbonding period expired",
|
||||||
types.NewClientState(chainID, types.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, height, commitmenttypes.GetSDKSpecs()),
|
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{
|
types.Evidence{
|
||||||
Header1: types.CreateTestHeader(chainID, height, height, suite.now, bothValSet, bothValSet, bothSigners),
|
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),
|
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",
|
"trusted validators is incorrect for given consensus state",
|
||||||
types.NewClientState(chainID, types.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, height, commitmenttypes.GetSDKSpecs()),
|
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{
|
types.Evidence{
|
||||||
Header1: types.CreateTestHeader(chainID, height, height, suite.now, bothValSet, suite.valSet, bothSigners),
|
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),
|
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",
|
"first valset has too much change",
|
||||||
types.NewClientState(chainID, types.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, height, commitmenttypes.GetSDKSpecs()),
|
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{
|
types.Evidence{
|
||||||
Header1: types.CreateTestHeader(chainID, height, height, suite.now, altValSet, bothValSet, altSigners),
|
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),
|
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",
|
"second valset has too much change",
|
||||||
types.NewClientState(chainID, types.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, height, commitmenttypes.GetSDKSpecs()),
|
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{
|
types.Evidence{
|
||||||
Header1: types.CreateTestHeader(chainID, height, height, suite.now, bothValSet, bothValSet, bothSigners),
|
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),
|
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",
|
"both valsets have too much change",
|
||||||
types.NewClientState(chainID, types.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, height, commitmenttypes.GetSDKSpecs()),
|
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{
|
types.Evidence{
|
||||||
Header1: types.CreateTestHeader(chainID, height, height, suite.now, altValSet, bothValSet, altSigners),
|
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),
|
Header2: types.CreateTestHeader(chainID, height, height, suite.now.Add(time.Minute), altValSet, bothValSet, altSigners),
|
||||||
|
|
|
@ -125,7 +125,6 @@ func (cs ClientState) GetProofSpecs() []*ics23.ProofSpec {
|
||||||
func (cs ClientState) VerifyClientConsensusState(
|
func (cs ClientState) VerifyClientConsensusState(
|
||||||
_ sdk.KVStore,
|
_ sdk.KVStore,
|
||||||
cdc codec.BinaryMarshaler,
|
cdc codec.BinaryMarshaler,
|
||||||
aminoCdc *codec.Codec,
|
|
||||||
provingRoot commitmentexported.Root,
|
provingRoot commitmentexported.Root,
|
||||||
height uint64,
|
height uint64,
|
||||||
counterpartyClientIdentifier string,
|
counterpartyClientIdentifier string,
|
||||||
|
@ -145,7 +144,7 @@ func (cs ClientState) VerifyClientConsensusState(
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
bz, err := aminoCdc.MarshalBinaryBare(consensusState)
|
bz, err := codec.MarshalAny(cdc, consensusState)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -404,9 +403,9 @@ func sanitizeVerificationArgs(
|
||||||
return commitmenttypes.MerkleProof{}, sdkerrors.Wrap(clienttypes.ErrInvalidConsensus, "consensus state cannot be empty")
|
return commitmenttypes.MerkleProof{}, sdkerrors.Wrap(clienttypes.ErrInvalidConsensus, "consensus state cannot be empty")
|
||||||
}
|
}
|
||||||
|
|
||||||
_, ok = consensusState.(ConsensusState)
|
_, ok = consensusState.(*ConsensusState)
|
||||||
if !ok {
|
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
|
return merkleProof, nil
|
||||||
|
|
|
@ -149,7 +149,7 @@ func (suite *TendermintTestSuite) TestVerifyClientConsensusState() {
|
||||||
tc := tc
|
tc := tc
|
||||||
|
|
||||||
err := tc.clientState.VerifyClientConsensusState(
|
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 {
|
if tc.expPass {
|
||||||
|
|
|
@ -17,8 +17,8 @@ import (
|
||||||
func NewConsensusState(
|
func NewConsensusState(
|
||||||
timestamp time.Time, root commitmenttypes.MerkleRoot, height uint64,
|
timestamp time.Time, root commitmenttypes.MerkleRoot, height uint64,
|
||||||
nextValsHash tmbytes.HexBytes,
|
nextValsHash tmbytes.HexBytes,
|
||||||
) ConsensusState {
|
) *ConsensusState {
|
||||||
return ConsensusState{
|
return &ConsensusState{
|
||||||
Timestamp: timestamp,
|
Timestamp: timestamp,
|
||||||
Root: root,
|
Root: root,
|
||||||
Height: height,
|
Height: height,
|
||||||
|
|
|
@ -4,18 +4,18 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
clientexported "github.com/cosmos/cosmos-sdk/x/ibc/02-client/exported"
|
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"
|
commitmenttypes "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (suite *TendermintTestSuite) TestConsensusStateValidateBasic() {
|
func (suite *TendermintTestSuite) TestConsensusStateValidateBasic() {
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
msg string
|
msg string
|
||||||
consensusState ibctmtypes.ConsensusState
|
consensusState *types.ConsensusState
|
||||||
expectPass bool
|
expectPass bool
|
||||||
}{
|
}{
|
||||||
{"success",
|
{"success",
|
||||||
ibctmtypes.ConsensusState{
|
&types.ConsensusState{
|
||||||
Timestamp: suite.now,
|
Timestamp: suite.now,
|
||||||
Height: height,
|
Height: height,
|
||||||
Root: commitmenttypes.NewMerkleRoot([]byte("app_hash")),
|
Root: commitmenttypes.NewMerkleRoot([]byte("app_hash")),
|
||||||
|
@ -23,7 +23,7 @@ func (suite *TendermintTestSuite) TestConsensusStateValidateBasic() {
|
||||||
},
|
},
|
||||||
true},
|
true},
|
||||||
{"root is nil",
|
{"root is nil",
|
||||||
ibctmtypes.ConsensusState{
|
&types.ConsensusState{
|
||||||
Timestamp: suite.now,
|
Timestamp: suite.now,
|
||||||
Height: height,
|
Height: height,
|
||||||
Root: commitmenttypes.MerkleRoot{},
|
Root: commitmenttypes.MerkleRoot{},
|
||||||
|
@ -31,7 +31,7 @@ func (suite *TendermintTestSuite) TestConsensusStateValidateBasic() {
|
||||||
},
|
},
|
||||||
false},
|
false},
|
||||||
{"root is empty",
|
{"root is empty",
|
||||||
ibctmtypes.ConsensusState{
|
&types.ConsensusState{
|
||||||
Timestamp: suite.now,
|
Timestamp: suite.now,
|
||||||
Height: height,
|
Height: height,
|
||||||
Root: commitmenttypes.MerkleRoot{},
|
Root: commitmenttypes.MerkleRoot{},
|
||||||
|
@ -39,7 +39,7 @@ func (suite *TendermintTestSuite) TestConsensusStateValidateBasic() {
|
||||||
},
|
},
|
||||||
false},
|
false},
|
||||||
{"nextvalshash is invalid",
|
{"nextvalshash is invalid",
|
||||||
ibctmtypes.ConsensusState{
|
&types.ConsensusState{
|
||||||
Timestamp: suite.now,
|
Timestamp: suite.now,
|
||||||
Height: height,
|
Height: height,
|
||||||
Root: commitmenttypes.NewMerkleRoot([]byte("app_hash")),
|
Root: commitmenttypes.NewMerkleRoot([]byte("app_hash")),
|
||||||
|
@ -48,7 +48,7 @@ func (suite *TendermintTestSuite) TestConsensusStateValidateBasic() {
|
||||||
false},
|
false},
|
||||||
|
|
||||||
{"height is 0",
|
{"height is 0",
|
||||||
ibctmtypes.ConsensusState{
|
&types.ConsensusState{
|
||||||
Timestamp: suite.now,
|
Timestamp: suite.now,
|
||||||
Height: 0,
|
Height: 0,
|
||||||
Root: commitmenttypes.NewMerkleRoot([]byte("app_hash")),
|
Root: commitmenttypes.NewMerkleRoot([]byte("app_hash")),
|
||||||
|
@ -56,7 +56,7 @@ func (suite *TendermintTestSuite) TestConsensusStateValidateBasic() {
|
||||||
},
|
},
|
||||||
false},
|
false},
|
||||||
{"timestamp is zero",
|
{"timestamp is zero",
|
||||||
ibctmtypes.ConsensusState{
|
&types.ConsensusState{
|
||||||
Timestamp: time.Time{},
|
Timestamp: time.Time{},
|
||||||
Height: height,
|
Height: height,
|
||||||
Root: commitmenttypes.NewMerkleRoot([]byte("app_hash")),
|
Root: commitmenttypes.NewMerkleRoot([]byte("app_hash")),
|
||||||
|
|
|
@ -36,8 +36,8 @@ func (h Header) ClientType() clientexported.ClientType {
|
||||||
}
|
}
|
||||||
|
|
||||||
// ConsensusState returns the updated consensus state associated with the header
|
// ConsensusState returns the updated consensus state associated with the header
|
||||||
func (h Header) ConsensusState() ConsensusState {
|
func (h Header) ConsensusState() *ConsensusState {
|
||||||
return ConsensusState{
|
return &ConsensusState{
|
||||||
Height: uint64(h.Height),
|
Height: uint64(h.Height),
|
||||||
Timestamp: h.Time,
|
Timestamp: h.Time,
|
||||||
Root: commitmenttypes.NewMerkleRoot(h.AppHash),
|
Root: commitmenttypes.NewMerkleRoot(h.AppHash),
|
||||||
|
|
|
@ -140,7 +140,7 @@ func (msg MsgCreateClient) GetClientType() string {
|
||||||
func (msg MsgCreateClient) GetConsensusState() clientexported.ConsensusState {
|
func (msg MsgCreateClient) GetConsensusState() clientexported.ConsensusState {
|
||||||
// Construct initial consensus state from provided Header
|
// Construct initial consensus state from provided Header
|
||||||
root := commitmenttypes.NewMerkleRoot(msg.Header.AppHash)
|
root := commitmenttypes.NewMerkleRoot(msg.Header.AppHash)
|
||||||
return ConsensusState{
|
return &ConsensusState{
|
||||||
Timestamp: msg.Header.Time,
|
Timestamp: msg.Header.Time,
|
||||||
Root: root,
|
Root: root,
|
||||||
Height: uint64(msg.Header.Height),
|
Height: uint64(msg.Header.Height),
|
||||||
|
|
|
@ -44,7 +44,7 @@ func CheckValidityAndUpdateState(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
tmConsState, ok := consState.(types.ConsensusState)
|
tmConsState, ok := consState.(*types.ConsensusState)
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, nil, sdkerrors.Wrapf(
|
return nil, nil, sdkerrors.Wrapf(
|
||||||
clienttypes.ErrInvalidConsensus, "expected type %T, got %T", types.ConsensusState{}, consState,
|
clienttypes.ErrInvalidConsensus, "expected type %T, got %T", types.ConsensusState{}, consState,
|
||||||
|
@ -69,7 +69,7 @@ func CheckValidityAndUpdateState(
|
||||||
// checkValidity checks if the Tendermint header is valid.
|
// checkValidity checks if the Tendermint header is valid.
|
||||||
// CONTRACT: consState.Height == header.TrustedHeight
|
// CONTRACT: consState.Height == header.TrustedHeight
|
||||||
func checkValidity(
|
func checkValidity(
|
||||||
clientState *types.ClientState, consState types.ConsensusState,
|
clientState *types.ClientState, consState *types.ConsensusState,
|
||||||
header types.Header, currentTimestamp time.Time,
|
header types.Header, currentTimestamp time.Time,
|
||||||
) error {
|
) error {
|
||||||
// assert that trustedVals is NextValidators of last trusted header
|
// assert that trustedVals is NextValidators of last trusted header
|
||||||
|
@ -140,11 +140,11 @@ func checkValidity(
|
||||||
}
|
}
|
||||||
|
|
||||||
// update the consensus state from a new header
|
// 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 {
|
if uint64(header.Height) > clientState.LatestHeight {
|
||||||
clientState.LatestHeight = uint64(header.Height)
|
clientState.LatestHeight = uint64(header.Height)
|
||||||
}
|
}
|
||||||
consensusState := types.ConsensusState{
|
consensusState := &types.ConsensusState{
|
||||||
Height: uint64(header.Height),
|
Height: uint64(header.Height),
|
||||||
Timestamp: header.Time,
|
Timestamp: header.Time,
|
||||||
Root: commitmenttypes.NewMerkleRoot(header.AppHash),
|
Root: commitmenttypes.NewMerkleRoot(header.AppHash),
|
||||||
|
|
|
@ -14,7 +14,7 @@ import (
|
||||||
func (suite *TendermintTestSuite) TestCheckValidity() {
|
func (suite *TendermintTestSuite) TestCheckValidity() {
|
||||||
var (
|
var (
|
||||||
clientState *types.ClientState
|
clientState *types.ClientState
|
||||||
consensusState types.ConsensusState
|
consensusState *types.ConsensusState
|
||||||
newHeader types.Header
|
newHeader types.Header
|
||||||
currentTime time.Time
|
currentTime time.Time
|
||||||
)
|
)
|
||||||
|
@ -192,7 +192,7 @@ func (suite *TendermintTestSuite) TestCheckValidity() {
|
||||||
// setup test
|
// setup test
|
||||||
tc.setup()
|
tc.setup()
|
||||||
|
|
||||||
expectedConsensus := types.ConsensusState{
|
expectedConsensus := &types.ConsensusState{
|
||||||
Height: uint64(newHeader.Height),
|
Height: uint64(newHeader.Height),
|
||||||
Timestamp: newHeader.Time,
|
Timestamp: newHeader.Time,
|
||||||
Root: commitmenttypes.NewMerkleRoot(newHeader.AppHash),
|
Root: commitmenttypes.NewMerkleRoot(newHeader.AppHash),
|
||||||
|
|
|
@ -75,7 +75,7 @@ func (cs ClientState) GetProofSpecs() []*ics23.ProofSpec {
|
||||||
// VerifyClientConsensusState returns an error since a local host client does not store consensus
|
// VerifyClientConsensusState returns an error since a local host client does not store consensus
|
||||||
// states.
|
// states.
|
||||||
func (cs ClientState) VerifyClientConsensusState(
|
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,
|
uint64, string, uint64, commitmentexported.Prefix, []byte, clientexported.ConsensusState,
|
||||||
) error {
|
) error {
|
||||||
return ErrConsensusStatesNotStored
|
return ErrConsensusStatesNotStored
|
||||||
|
|
|
@ -50,7 +50,7 @@ func (suite *LocalhostTestSuite) TestValidate() {
|
||||||
func (suite *LocalhostTestSuite) TestVerifyClientConsensusState() {
|
func (suite *LocalhostTestSuite) TestVerifyClientConsensusState() {
|
||||||
clientState := types.NewClientState("chainID", 10)
|
clientState := types.NewClientState("chainID", 10)
|
||||||
err := clientState.VerifyClientConsensusState(
|
err := clientState.VerifyClientConsensusState(
|
||||||
nil, nil, nil, nil, 0, "", 0, nil, nil, nil,
|
nil, nil, nil, 0, "", 0, nil, nil, nil,
|
||||||
)
|
)
|
||||||
suite.Require().Error(err)
|
suite.Require().Error(err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,8 +34,8 @@ type Keeper struct {
|
||||||
func NewKeeper(
|
func NewKeeper(
|
||||||
aminoCdc *codec.Codec, cdc codec.BinaryMarshaler, key sdk.StoreKey, stakingKeeper clienttypes.StakingKeeper, scopedKeeper capabilitykeeper.ScopedKeeper,
|
aminoCdc *codec.Codec, cdc codec.BinaryMarshaler, key sdk.StoreKey, stakingKeeper clienttypes.StakingKeeper, scopedKeeper capabilitykeeper.ScopedKeeper,
|
||||||
) *Keeper {
|
) *Keeper {
|
||||||
clientKeeper := clientkeeper.NewKeeper(cdc, aminoCdc, key, stakingKeeper)
|
clientKeeper := clientkeeper.NewKeeper(cdc, key, stakingKeeper)
|
||||||
connectionKeeper := connectionkeeper.NewKeeper(aminoCdc, cdc, key, clientKeeper)
|
connectionKeeper := connectionkeeper.NewKeeper(cdc, key, clientKeeper)
|
||||||
portKeeper := portkeeper.NewKeeper(scopedKeeper)
|
portKeeper := portkeeper.NewKeeper(scopedKeeper)
|
||||||
channelKeeper := channelkeeper.NewKeeper(cdc, key, clientKeeper, connectionKeeper, portKeeper, scopedKeeper)
|
channelKeeper := channelkeeper.NewKeeper(cdc, key, clientKeeper, connectionKeeper, portKeeper, scopedKeeper)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue