Make clients use proto Height (#7184)

* start using Height in TM client

* fix client tests

* fix client tests

* fix connection tests

* fix rest of tests

* Apply suggestions from code review

Co-authored-by: colin axnér <25233464+colin-axner@users.noreply.github.com>

* fix simple issues

* add and use LTE and GTE methods

* remove TM-specific height semantics from 02-client

* fix lint and build

Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com>
Co-authored-by: colin axnér <25233464+colin-axner@users.noreply.github.com>
This commit is contained in:
Aditya 2020-08-31 13:57:08 -04:00 committed by GitHub
parent fc75d14c88
commit d208d2bed8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
46 changed files with 1615 additions and 1056 deletions

View File

@ -21,3 +21,20 @@ message ClientConsensusStates {
// consensus states associated with the client
repeated google.protobuf.Any consensus_states = 2 [(gogoproto.moretags) = "yaml:\"consensus_states\""];
}
// Height is a monotonically increasing data type
// that can be compared against another Height for the purposes of updating and freezing clients
//
// Normally the EpochHeight is incremented at each height while keeping epoch number the same
// However some consensus algorithms may choose to reset the height in certain conditions
// e.g. hard forks, state-machine breaking changes
// In these cases, the epoch number is incremented so that height continues to be monitonically increasing
// even as the EpochHeight gets reset
message Height {
option (gogoproto.goproto_stringer) = false;
// the epoch that the client is currently on
uint64 epoch_number = 1 [(gogoproto.moretags) = "yaml:\"epoch_number\""];
// the height within the given epoch
uint64 epoch_height = 2 [(gogoproto.moretags) = "yaml:\"epoch_height\""];
}

View File

@ -2,6 +2,7 @@ syntax = "proto3";
package ibc.localhost;
import "gogoproto/gogo.proto";
import "ibc/client/client.proto";
option go_package = "github.com/cosmos/cosmos-sdk/x/ibc/09-localhost/types";
@ -24,5 +25,7 @@ message ClientState {
(gogoproto.moretags) = "yaml:\"chain_id\""
];
// self latest block height
uint64 height = 3;
ibc.client.Height height = 3 [
(gogoproto.nullable) = false
];
}

View File

@ -8,6 +8,7 @@ import "tendermint/types/types.proto";
import "confio/proofs.proto";
import "google/protobuf/duration.proto";
import "google/protobuf/timestamp.proto";
import "ibc/client/client.proto";
import "ibc/commitment/commitment.proto";
import "gogoproto/gogo.proto";
@ -41,9 +42,15 @@ message ClientState {
(gogoproto.moretags) = "yaml:\"max_clock_drift\""
];
// Block height when the client was frozen due to a misbehaviour
uint64 frozen_height = 6 [(gogoproto.moretags) = "yaml:\"frozen_height\""];
ibc.client.Height frozen_height = 6 [
(gogoproto.nullable) = false,
(gogoproto.moretags) = "yaml:\"frozen_height\""
];
// Latest height the client was updated to
uint64 latest_height = 7 [(gogoproto.moretags) = "yaml:\"latest_height\""];
ibc.client.Height latest_height = 7 [
(gogoproto.nullable) = false,
(gogoproto.moretags) = "yaml:\"latest_height\""
];
// Proof specifications used in verifying counterparty state
repeated ics23.ProofSpec proof_specs = 8
[(gogoproto.moretags) = "yaml:\"proof_specs\""];
@ -60,7 +67,9 @@ message ConsensusState {
// commitment root (i.e app hash)
ibc.commitment.MerkleRoot root = 2 [(gogoproto.nullable) = false];
// height at which the consensus state was stored.
uint64 height = 3;
ibc.client.Height height = 3 [
(gogoproto.nullable) = false
];
bytes next_validators_hash = 4 [
(gogoproto.casttype) =
"github.com/tendermint/tendermint/libs/bytes.HexBytes",
@ -106,7 +115,10 @@ message Header {
.tendermint.types.ValidatorSet validator_set = 2
[(gogoproto.moretags) = "yaml:\"validator_set\""];
uint64 trusted_height = 3 [(gogoproto.moretags) = "yaml:\"trusted_height\""];
ibc.client.Height trusted_height = 3 [
(gogoproto.nullable) = false,
(gogoproto.moretags) = "yaml:\"trusted_height\""
];
.tendermint.types.ValidatorSet trusted_validators = 4
[(gogoproto.moretags) = "yaml:\"trusted_validators\""];
}

View File

@ -182,6 +182,17 @@ type MsgSubmitMisbehaviour interface {
GetMisbehaviour() Misbehaviour
}
// Height is a wrapper interface over clienttypes.Height
// all clients must use the concrete implementation in types
type Height interface {
IsZero() bool
LT(Height) bool
LTE(Height) bool
EQ(Height) bool
GT(Height) bool
GTE(Height) bool
}
// ClientType defines the type of the consensus algorithm
type ClientType byte

View File

@ -43,7 +43,11 @@ func InitGenesis(ctx sdk.Context, k keeper.Keeper, gs types.GenesisState) {
}
// client id is always "localhost"
clientState := localhosttypes.NewClientState(ctx.ChainID(), ctx.BlockHeight())
// Hardcode 0 as epoch number for now
// TODO: Retrieve epoch from chain-id
clientState := localhosttypes.NewClientState(
ctx.ChainID(), types.NewHeight(0, uint64(ctx.BlockHeight())),
)
_, err := k.CreateClient(ctx, exported.ClientTypeLocalHost, clientState, nil)
if err != nil {

View File

@ -22,7 +22,8 @@ func HandleMsgCreateClient(ctx sdk.Context, k keeper.Keeper, msg exported.MsgCre
// localhost is a special case that must initialize client state
// from context and not from msg
case *localhosttypes.MsgCreateClient:
clientState = localhosttypes.NewClientState(ctx.ChainID(), ctx.BlockHeight())
selfHeight := types.NewHeight(0, uint64(ctx.BlockHeight()))
clientState = localhosttypes.NewClientState(ctx.ChainID(), selfHeight)
// Localhost consensus height is chain's blockheight
consensusHeight = uint64(ctx.BlockHeight())
default:

View File

@ -7,6 +7,7 @@ import (
tmtypes "github.com/tendermint/tendermint/types"
"github.com/cosmos/cosmos-sdk/x/ibc/02-client/exported"
"github.com/cosmos/cosmos-sdk/x/ibc/02-client/types"
ibctmtypes "github.com/cosmos/cosmos-sdk/x/ibc/07-tendermint/types"
localhosttypes "github.com/cosmos/cosmos-sdk/x/ibc/09-localhost/types"
commitmenttypes "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/types"
@ -80,14 +81,15 @@ 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
incrementedClientHeight := testClientHeight.Increment()
intermediateConsState := &ibctmtypes.ConsensusState{
Height: testClientHeight + 1,
Height: incrementedClientHeight,
Timestamp: suite.now.Add(time.Minute),
NextValidatorsHash: suite.valSetHash,
}
suite.keeper.SetClientConsensusState(suite.ctx, testClientID, testClientHeight+1, intermediateConsState)
suite.keeper.SetClientConsensusState(suite.ctx, testClientID, incrementedClientHeight.EpochHeight, intermediateConsState)
clientState.LatestHeight = testClientHeight + 1
clientState.LatestHeight = incrementedClientHeight
suite.keeper.SetClientState(suite.ctx, testClientID, clientState)
updateHeader = createFutureUpdateFn(suite)
@ -100,7 +102,7 @@ func (suite *KeeperTestSuite) TestUpdateClientTendermint() {
// store previous consensus state
prevConsState := &ibctmtypes.ConsensusState{
Height: 1,
Height: types.NewHeight(0, 1),
Timestamp: suite.past,
NextValidatorsHash: suite.valSetHash,
}
@ -108,7 +110,7 @@ func (suite *KeeperTestSuite) TestUpdateClientTendermint() {
// store intermediate consensus state to check that trustedHeight does not need to be hightest consensus state before header height
intermediateConsState := &ibctmtypes.ConsensusState{
Height: 2,
Height: types.NewHeight(0, 2),
Timestamp: suite.past.Add(time.Minute),
NextValidatorsHash: suite.valSetHash,
}
@ -145,7 +147,7 @@ func (suite *KeeperTestSuite) TestUpdateClientTendermint() {
return nil
}, false},
{"frozen client before update", func() error {
clientState = &ibctmtypes.ClientState{FrozenHeight: 1, LatestHeight: testClientHeight}
clientState = &ibctmtypes.ClientState{FrozenHeight: types.NewHeight(0, 1), LatestHeight: testClientHeight}
suite.keeper.SetClientState(suite.ctx, testClientID, clientState)
suite.keeper.SetClientType(suite.ctx, testClientID, exported.Tendermint)
updateHeader = createFutureUpdateFn(suite)
@ -154,13 +156,13 @@ func (suite *KeeperTestSuite) TestUpdateClientTendermint() {
}, false},
{"valid past update before client was frozen", func() error {
clientState = ibctmtypes.NewClientState(testChainID, ibctmtypes.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, testClientHeight, commitmenttypes.GetSDKSpecs())
clientState.FrozenHeight = testClientHeight - 1
clientState.FrozenHeight = types.NewHeight(0, testClientHeight.EpochHeight-1)
_, err := suite.keeper.CreateClient(suite.ctx, testClientID, clientState, suite.consensusState)
suite.Require().NoError(err)
// store previous consensus state
prevConsState := &ibctmtypes.ConsensusState{
Height: 1,
Height: types.NewHeight(0, 1),
Timestamp: suite.past,
NextValidatorsHash: suite.valSetHash,
}
@ -198,7 +200,7 @@ func (suite *KeeperTestSuite) TestUpdateClientTendermint() {
suite.Require().NoError(err, err)
expConsensusState := &ibctmtypes.ConsensusState{
Height: updateHeader.GetHeight(),
Height: types.NewHeight(0, updateHeader.GetHeight()),
Timestamp: updateHeader.GetTime(),
Root: commitmenttypes.NewMerkleRoot(updateHeader.Header.GetAppHash()),
NextValidatorsHash: updateHeader.Header.NextValidatorsHash,
@ -231,7 +233,7 @@ func (suite *KeeperTestSuite) TestUpdateClientTendermint() {
}
func (suite *KeeperTestSuite) TestUpdateClientLocalhost() {
var localhostClient exported.ClientState = localhosttypes.NewClientState(suite.header.Header.GetChainID(), suite.ctx.BlockHeight())
var localhostClient exported.ClientState = localhosttypes.NewClientState(suite.header.Header.GetChainID(), types.NewHeight(0, uint64(suite.ctx.BlockHeight())))
suite.ctx = suite.ctx.WithBlockHeight(suite.ctx.BlockHeight() + 1)
@ -274,8 +276,8 @@ func (suite *KeeperTestSuite) TestCheckMisbehaviourAndUpdateState() {
{
"trusting period misbehavior should pass",
&ibctmtypes.Misbehaviour{
Header1: ibctmtypes.CreateTestHeader(testChainID, testClientHeight, testClientHeight, altTime, bothValSet, bothValSet, bothSigners),
Header2: ibctmtypes.CreateTestHeader(testChainID, testClientHeight, testClientHeight, suite.ctx.BlockTime(), bothValSet, bothValSet, bothSigners),
Header1: ibctmtypes.CreateTestHeader(testChainID, height, height, altTime, bothValSet, bothValSet, bothSigners),
Header2: ibctmtypes.CreateTestHeader(testChainID, height, height, suite.ctx.BlockTime(), bothValSet, bothValSet, bothSigners),
ChainId: testChainID,
ClientId: testClientID,
},
@ -291,8 +293,8 @@ func (suite *KeeperTestSuite) TestCheckMisbehaviourAndUpdateState() {
{
"misbehavior at later height should pass",
&ibctmtypes.Misbehaviour{
Header1: ibctmtypes.CreateTestHeader(testChainID, testClientHeight+5, testClientHeight, altTime, bothValSet, valSet, bothSigners),
Header2: ibctmtypes.CreateTestHeader(testChainID, testClientHeight+5, testClientHeight, suite.ctx.BlockTime(), bothValSet, valSet, bothSigners),
Header1: ibctmtypes.CreateTestHeader(testChainID, height+5, height, altTime, bothValSet, valSet, bothSigners),
Header2: ibctmtypes.CreateTestHeader(testChainID, height+5, height, suite.ctx.BlockTime(), bothValSet, valSet, bothSigners),
ChainId: testChainID,
ClientId: testClientID,
},
@ -303,13 +305,13 @@ func (suite *KeeperTestSuite) TestCheckMisbehaviourAndUpdateState() {
// store intermediate consensus state to check that trustedHeight does not need to be highest consensus state before header height
intermediateConsState := &ibctmtypes.ConsensusState{
Height: testClientHeight + 3,
Height: types.NewHeight(0, height+3),
Timestamp: suite.now.Add(time.Minute),
NextValidatorsHash: suite.valSetHash,
}
suite.keeper.SetClientConsensusState(suite.ctx, testClientID, testClientHeight+3, intermediateConsState)
suite.keeper.SetClientConsensusState(suite.ctx, testClientID, height+3, intermediateConsState)
clientState.LatestHeight = testClientHeight + 3
clientState.LatestHeight = types.NewHeight(0, height+3)
suite.keeper.SetClientState(suite.ctx, testClientID, clientState)
return err
@ -319,8 +321,8 @@ func (suite *KeeperTestSuite) TestCheckMisbehaviourAndUpdateState() {
{
"misbehavior at later height with different trusted heights should pass",
&ibctmtypes.Misbehaviour{
Header1: ibctmtypes.CreateTestHeader(testChainID, testClientHeight+5, testClientHeight, altTime, bothValSet, valSet, bothSigners),
Header2: ibctmtypes.CreateTestHeader(testChainID, testClientHeight+5, testClientHeight+3, suite.ctx.BlockTime(), bothValSet, bothValSet, bothSigners),
Header1: ibctmtypes.CreateTestHeader(testChainID, height+5, height, altTime, bothValSet, valSet, bothSigners),
Header2: ibctmtypes.CreateTestHeader(testChainID, height+5, height+3, suite.ctx.BlockTime(), bothValSet, bothValSet, bothSigners),
ChainId: testChainID,
ClientId: testClientID,
},
@ -331,13 +333,13 @@ func (suite *KeeperTestSuite) TestCheckMisbehaviourAndUpdateState() {
// store trusted consensus state for Header2
intermediateConsState := &ibctmtypes.ConsensusState{
Height: testClientHeight + 3,
Height: types.NewHeight(0, height+3),
Timestamp: suite.now.Add(time.Minute),
NextValidatorsHash: bothValsHash,
}
suite.keeper.SetClientConsensusState(suite.ctx, testClientID, testClientHeight+3, intermediateConsState)
suite.keeper.SetClientConsensusState(suite.ctx, testClientID, height+3, intermediateConsState)
clientState.LatestHeight = testClientHeight + 3
clientState.LatestHeight = types.NewHeight(0, height+3)
suite.keeper.SetClientState(suite.ctx, testClientID, clientState)
return err
@ -347,8 +349,8 @@ func (suite *KeeperTestSuite) TestCheckMisbehaviourAndUpdateState() {
{
"misbehaviour fails validatebasic",
&ibctmtypes.Misbehaviour{
Header1: ibctmtypes.CreateTestHeader(testChainID, testClientHeight+1, testClientHeight, altTime, bothValSet, bothValSet, bothSigners),
Header2: ibctmtypes.CreateTestHeader(testChainID, testClientHeight, testClientHeight, suite.ctx.BlockTime(), bothValSet, bothValSet, bothSigners),
Header1: ibctmtypes.CreateTestHeader(testChainID, height+1, height, altTime, bothValSet, bothValSet, bothSigners),
Header2: ibctmtypes.CreateTestHeader(testChainID, height, height, suite.ctx.BlockTime(), bothValSet, bothValSet, bothSigners),
ChainId: testChainID,
ClientId: testClientID,
},
@ -364,8 +366,8 @@ func (suite *KeeperTestSuite) TestCheckMisbehaviourAndUpdateState() {
{
"trusted ConsensusState1 not found",
&ibctmtypes.Misbehaviour{
Header1: ibctmtypes.CreateTestHeader(testChainID, testClientHeight+5, testClientHeight+3, altTime, bothValSet, bothValSet, bothSigners),
Header2: ibctmtypes.CreateTestHeader(testChainID, testClientHeight+5, testClientHeight, suite.ctx.BlockTime(), bothValSet, valSet, bothSigners),
Header1: ibctmtypes.CreateTestHeader(testChainID, height+5, height+3, altTime, bothValSet, bothValSet, bothSigners),
Header2: ibctmtypes.CreateTestHeader(testChainID, height+5, height, suite.ctx.BlockTime(), bothValSet, valSet, bothSigners),
ChainId: testChainID,
ClientId: testClientID,
},
@ -381,8 +383,8 @@ func (suite *KeeperTestSuite) TestCheckMisbehaviourAndUpdateState() {
{
"trusted ConsensusState2 not found",
&ibctmtypes.Misbehaviour{
Header1: ibctmtypes.CreateTestHeader(testChainID, testClientHeight+5, testClientHeight, altTime, bothValSet, valSet, bothSigners),
Header2: ibctmtypes.CreateTestHeader(testChainID, testClientHeight+5, testClientHeight+3, suite.ctx.BlockTime(), bothValSet, bothValSet, bothSigners),
Header1: ibctmtypes.CreateTestHeader(testChainID, height+5, height, altTime, bothValSet, valSet, bothSigners),
Header2: ibctmtypes.CreateTestHeader(testChainID, height+5, height+3, suite.ctx.BlockTime(), bothValSet, bothValSet, bothSigners),
ChainId: testChainID,
ClientId: testClientID,
},
@ -405,8 +407,8 @@ func (suite *KeeperTestSuite) TestCheckMisbehaviourAndUpdateState() {
{
"client already frozen at earlier height",
&ibctmtypes.Misbehaviour{
Header1: ibctmtypes.CreateTestHeader(testChainID, testClientHeight, testClientHeight, altTime, bothValSet, bothValSet, bothSigners),
Header2: ibctmtypes.CreateTestHeader(testChainID, testClientHeight, testClientHeight, suite.ctx.BlockTime(), bothValSet, bothValSet, bothSigners),
Header1: ibctmtypes.CreateTestHeader(testChainID, height, height, altTime, bothValSet, bothValSet, bothSigners),
Header2: ibctmtypes.CreateTestHeader(testChainID, height, height, suite.ctx.BlockTime(), bothValSet, bothValSet, bothSigners),
ChainId: testChainID,
ClientId: testClientID,
},
@ -415,7 +417,7 @@ func (suite *KeeperTestSuite) TestCheckMisbehaviourAndUpdateState() {
clientState := ibctmtypes.NewClientState(testChainID, ibctmtypes.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, testClientHeight, commitmenttypes.GetSDKSpecs())
_, err := suite.keeper.CreateClient(suite.ctx, testClientID, clientState, suite.consensusState)
clientState.FrozenHeight = 1
clientState.FrozenHeight = types.NewHeight(0, 1)
suite.keeper.SetClientState(suite.ctx, testClientID, clientState)
return err
@ -426,8 +428,8 @@ func (suite *KeeperTestSuite) TestCheckMisbehaviourAndUpdateState() {
{
"misbehaviour check failed",
&ibctmtypes.Misbehaviour{
Header1: ibctmtypes.CreateTestHeader(testChainID, testClientHeight, testClientHeight, altTime, bothValSet, bothValSet, bothSigners),
Header2: ibctmtypes.CreateTestHeader(testChainID, testClientHeight, testClientHeight, suite.ctx.BlockTime(), altValSet, bothValSet, altSigners),
Header1: ibctmtypes.CreateTestHeader(testChainID, height, height, altTime, bothValSet, bothValSet, bothSigners),
Header2: ibctmtypes.CreateTestHeader(testChainID, height, height, suite.ctx.BlockTime(), altValSet, bothValSet, altSigners),
ChainId: testChainID,
ClientId: testClientID,
},

View File

@ -42,7 +42,7 @@ func (suite *KeeperTestSuite) TestQueryClientState() {
{
"success",
func() {
clientState := ibctmtypes.NewClientState(testChainID, ibctmtypes.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, 0, commitmenttypes.GetSDKSpecs())
clientState := ibctmtypes.NewClientState(testChainID, ibctmtypes.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, types.Height{}, commitmenttypes.GetSDKSpecs())
suite.keeper.SetClientState(suite.ctx, testClientID, clientState)
var err error
@ -209,7 +209,7 @@ func (suite *KeeperTestSuite) TestQueryConsensusState() {
func() {
clientState := ibctmtypes.NewClientState(testChainID, ibctmtypes.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, testClientHeight, commitmenttypes.GetSDKSpecs())
cs := ibctmtypes.NewConsensusState(
suite.consensusState.Timestamp, commitmenttypes.NewMerkleRoot([]byte("hash1")), suite.consensusState.GetHeight(), nil,
suite.consensusState.Timestamp, commitmenttypes.NewMerkleRoot([]byte("hash1")), suite.consensusState.Height, nil,
)
suite.keeper.SetClientState(suite.ctx, testClientID, clientState)
suite.keeper.SetClientConsensusState(suite.ctx, testClientID, suite.consensusState.GetHeight(), cs)
@ -229,9 +229,9 @@ func (suite *KeeperTestSuite) TestQueryConsensusState() {
"success with height",
func() {
cs := ibctmtypes.NewConsensusState(
suite.consensusState.Timestamp, commitmenttypes.NewMerkleRoot([]byte("hash1")), suite.consensusState.GetHeight(), nil,
suite.consensusState.Timestamp, commitmenttypes.NewMerkleRoot([]byte("hash1")), suite.consensusState.Height, nil,
)
suite.keeper.SetClientConsensusState(suite.ctx, testClientID, testClientHeight, cs)
suite.keeper.SetClientConsensusState(suite.ctx, testClientID, height, cs)
var err error
expConsensusState, err = types.PackConsensusState(cs)
@ -239,7 +239,7 @@ func (suite *KeeperTestSuite) TestQueryConsensusState() {
req = &types.QueryConsensusStateRequest{
ClientId: testClientID,
Height: testClientHeight,
Height: height,
}
},
true,
@ -311,14 +311,14 @@ func (suite *KeeperTestSuite) TestQueryConsensusStates() {
"success",
func() {
cs := ibctmtypes.NewConsensusState(
suite.consensusState.Timestamp, commitmenttypes.NewMerkleRoot([]byte("hash1")), suite.consensusState.GetHeight(), nil,
suite.consensusState.Timestamp, commitmenttypes.NewMerkleRoot([]byte("hash1")), suite.consensusState.Height, nil,
)
cs2 := ibctmtypes.NewConsensusState(
suite.consensusState.Timestamp.Add(time.Second), commitmenttypes.NewMerkleRoot([]byte("hash2")), suite.consensusState.GetHeight(), nil,
suite.consensusState.Timestamp.Add(time.Second), commitmenttypes.NewMerkleRoot([]byte("hash2")), suite.consensusState.Height, nil,
)
suite.keeper.SetClientConsensusState(suite.ctx, testClientID, testClientHeight, cs)
suite.keeper.SetClientConsensusState(suite.ctx, testClientID, testClientHeight+1, cs2)
suite.keeper.SetClientConsensusState(suite.ctx, testClientID, height, cs)
suite.keeper.SetClientConsensusState(suite.ctx, testClientID, height+1, cs2)
any, err := types.PackConsensusState(cs)
suite.Require().NoError(err)

View File

@ -185,6 +185,7 @@ func (k Keeper) GetClientConsensusStateLTE(ctx sdk.Context, clientID string, max
// GetSelfConsensusState introspects the (self) past historical info at a given height
// and returns the expected consensus state at that height.
// TODO: Replace height with *clienttypes.Height once interfaces change
func (k Keeper) GetSelfConsensusState(ctx sdk.Context, height uint64) (exported.ConsensusState, bool) {
histInfo, found := k.stakingKeeper.GetHistoricalInfo(ctx, int64(height))
if !found {
@ -192,7 +193,7 @@ func (k Keeper) GetSelfConsensusState(ctx sdk.Context, height uint64) (exported.
}
consensusState := &ibctmtypes.ConsensusState{
Height: height,
Height: types.NewHeight(0, height),
Timestamp: histInfo.Header.Time,
Root: commitmenttypes.NewMerkleRoot(histInfo.Header.GetAppHash()),
NextValidatorsHash: histInfo.Header.NextValidatorsHash,
@ -218,7 +219,10 @@ func (k Keeper) ValidateSelfClient(ctx sdk.Context, clientState exported.ClientS
ctx.ChainID(), tmClient.ChainId)
}
if tmClient.LatestHeight > uint64(ctx.BlockHeight()) {
// For now, assume epoch number is zero
// TODO: Retrieve epoch number from chain-id
selfHeight := types.NewHeight(0, uint64(ctx.BlockHeight()))
if tmClient.LatestHeight.GT(selfHeight) {
return sdkerrors.Wrapf(types.ErrInvalidClient, "client has LatestHeight %d greater than chain height %d",
tmClient.LatestHeight, ctx.BlockHeight())
}

View File

@ -32,13 +32,15 @@ const (
testClientID2 = "ethbridge"
testClientID3 = "ethermint"
testClientHeight = 5
height = 5
trustingPeriod time.Duration = time.Hour * 24 * 7 * 2
ubdPeriod time.Duration = time.Hour * 24 * 7 * 3
maxClockDrift time.Duration = time.Second * 10
)
var testClientHeight = types.NewHeight(0, 5)
type KeeperTestSuite struct {
suite.Suite
@ -74,7 +76,7 @@ func (suite *KeeperTestSuite) SetupTest() {
app := simapp.Setup(isCheckTx)
suite.cdc = app.AppCodec()
suite.ctx = app.BaseApp.NewContext(isCheckTx, tmproto.Header{Height: testClientHeight, ChainID: testClientID, Time: now2})
suite.ctx = app.BaseApp.NewContext(isCheckTx, tmproto.Header{Height: height, ChainID: testClientID, Time: now2})
suite.keeper = &app.IBCKeeper.ClientKeeper
suite.privVal = tmtypes.NewMockPV()
@ -84,7 +86,7 @@ func (suite *KeeperTestSuite) SetupTest() {
validator := tmtypes.NewValidator(pubKey, 1)
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.header = ibctmtypes.CreateTestHeader(testChainID, height, height-1, now2, suite.valSet, suite.valSet, []tmtypes.PrivValidator{suite.privVal})
suite.consensusState = ibctmtypes.NewConsensusState(suite.now, commitmenttypes.NewMerkleRoot([]byte("hash")), testClientHeight, suite.valSetHash)
var validators stakingtypes.Validators
@ -110,7 +112,7 @@ func TestKeeperTestSuite(t *testing.T) {
}
func (suite *KeeperTestSuite) TestSetClientState() {
clientState := ibctmtypes.NewClientState(testChainID, ibctmtypes.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, 0, commitmenttypes.GetSDKSpecs())
clientState := ibctmtypes.NewClientState(testChainID, ibctmtypes.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, types.Height{}, commitmenttypes.GetSDKSpecs())
suite.keeper.SetClientState(suite.ctx, testClientID, clientState)
retrievedState, found := suite.keeper.GetClientState(suite.ctx, testClientID)
@ -127,9 +129,9 @@ func (suite *KeeperTestSuite) TestSetClientType() {
}
func (suite *KeeperTestSuite) TestSetClientConsensusState() {
suite.keeper.SetClientConsensusState(suite.ctx, testClientID, testClientHeight, suite.consensusState)
suite.keeper.SetClientConsensusState(suite.ctx, testClientID, height, suite.consensusState)
retrievedConsState, found := suite.keeper.GetClientConsensusState(suite.ctx, testClientID, testClientHeight)
retrievedConsState, found := suite.keeper.GetClientConsensusState(suite.ctx, testClientID, height)
suite.Require().True(found, "GetConsensusState failed")
tmConsState, ok := retrievedConsState.(*ibctmtypes.ConsensusState)
@ -145,7 +147,7 @@ func (suite *KeeperTestSuite) TestValidateSelfClient() {
}{
{
"success",
ibctmtypes.NewClientState(testChainID, ibctmtypes.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, uint64(testClientHeight), commitmenttypes.GetSDKSpecs()),
ibctmtypes.NewClientState(testChainID, ibctmtypes.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, testClientHeight, commitmenttypes.GetSDKSpecs()),
true,
},
{
@ -155,43 +157,43 @@ func (suite *KeeperTestSuite) TestValidateSelfClient() {
},
{
"frozen client",
&ibctmtypes.ClientState{testChainID, ibctmtypes.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, uint64(testClientHeight), uint64(testClientHeight), commitmenttypes.GetSDKSpecs()},
&ibctmtypes.ClientState{testChainID, ibctmtypes.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, testClientHeight, testClientHeight, commitmenttypes.GetSDKSpecs()},
false,
},
{
"incorrect chainID",
ibctmtypes.NewClientState("gaiatestnet", ibctmtypes.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, uint64(testClientHeight), commitmenttypes.GetSDKSpecs()),
ibctmtypes.NewClientState("gaiatestnet", ibctmtypes.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, testClientHeight, commitmenttypes.GetSDKSpecs()),
false,
},
{
"invalid client height",
ibctmtypes.NewClientState(testChainID, ibctmtypes.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, uint64(testClientHeight)+10, commitmenttypes.GetSDKSpecs()),
ibctmtypes.NewClientState(testChainID, ibctmtypes.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, types.NewHeight(0, testClientHeight.EpochHeight+10), commitmenttypes.GetSDKSpecs()),
false,
},
{
"invalid proof specs",
ibctmtypes.NewClientState(testChainID, ibctmtypes.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, uint64(testClientHeight), nil),
ibctmtypes.NewClientState(testChainID, ibctmtypes.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, testClientHeight, nil),
false,
},
{
"invalid trust level",
ibctmtypes.NewClientState(testChainID, ibctmtypes.Fraction{0, 1}, trustingPeriod, ubdPeriod, maxClockDrift, uint64(testClientHeight), commitmenttypes.GetSDKSpecs()),
ibctmtypes.NewClientState(testChainID, ibctmtypes.Fraction{0, 1}, trustingPeriod, ubdPeriod, maxClockDrift, testClientHeight, commitmenttypes.GetSDKSpecs()),
false,
},
{
"invalid unbonding period",
ibctmtypes.NewClientState(testChainID, ibctmtypes.DefaultTrustLevel, trustingPeriod, ubdPeriod+10, maxClockDrift, uint64(testClientHeight), commitmenttypes.GetSDKSpecs()),
ibctmtypes.NewClientState(testChainID, ibctmtypes.DefaultTrustLevel, trustingPeriod, ubdPeriod+10, maxClockDrift, testClientHeight, commitmenttypes.GetSDKSpecs()),
false,
},
{
"invalid trusting period",
ibctmtypes.NewClientState(testChainID, ibctmtypes.DefaultTrustLevel, ubdPeriod+10, ubdPeriod, maxClockDrift, uint64(testClientHeight), commitmenttypes.GetSDKSpecs()),
ibctmtypes.NewClientState(testChainID, ibctmtypes.DefaultTrustLevel, ubdPeriod+10, ubdPeriod, maxClockDrift, testClientHeight, commitmenttypes.GetSDKSpecs()),
false,
},
}
ctx := suite.ctx.WithChainID(testChainID)
ctx = ctx.WithBlockHeight(testClientHeight)
ctx = ctx.WithBlockHeight(height)
for _, tc := range testCases {
err := suite.keeper.ValidateSelfClient(ctx, tc.clientState)
@ -208,9 +210,9 @@ func (suite KeeperTestSuite) TestGetAllClients() {
testClientID2, testClientID3, testClientID,
}
expClients := []exported.ClientState{
ibctmtypes.NewClientState(testChainID, ibctmtypes.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, 0, commitmenttypes.GetSDKSpecs()),
ibctmtypes.NewClientState(testChainID, ibctmtypes.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, 0, commitmenttypes.GetSDKSpecs()),
ibctmtypes.NewClientState(testChainID, ibctmtypes.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, 0, commitmenttypes.GetSDKSpecs()),
ibctmtypes.NewClientState(testChainID, ibctmtypes.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, types.Height{}, commitmenttypes.GetSDKSpecs()),
ibctmtypes.NewClientState(testChainID, ibctmtypes.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, types.Height{}, commitmenttypes.GetSDKSpecs()),
ibctmtypes.NewClientState(testChainID, ibctmtypes.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, types.Height{}, commitmenttypes.GetSDKSpecs()),
}
for i := range expClients {
@ -232,9 +234,9 @@ func (suite KeeperTestSuite) TestGetAllGenesisClients() {
testClientID2, testClientID3, testClientID,
}
expClients := []exported.ClientState{
ibctmtypes.NewClientState(testChainID, ibctmtypes.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, 0, commitmenttypes.GetSDKSpecs()),
ibctmtypes.NewClientState(testChainID, ibctmtypes.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, 0, commitmenttypes.GetSDKSpecs()),
ibctmtypes.NewClientState(testChainID, ibctmtypes.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, 0, commitmenttypes.GetSDKSpecs()),
ibctmtypes.NewClientState(testChainID, ibctmtypes.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, types.Height{}, commitmenttypes.GetSDKSpecs()),
ibctmtypes.NewClientState(testChainID, ibctmtypes.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, types.Height{}, commitmenttypes.GetSDKSpecs()),
ibctmtypes.NewClientState(testChainID, ibctmtypes.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, types.Height{}, commitmenttypes.GetSDKSpecs()),
}
expGenClients := make([]types.IdentifiedClientState, len(expClients))
@ -285,16 +287,16 @@ func (suite KeeperTestSuite) TestConsensusStateHelpers() {
clientState := ibctmtypes.NewClientState(testChainID, ibctmtypes.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, testClientHeight, commitmenttypes.GetSDKSpecs())
suite.keeper.SetClientState(suite.ctx, testClientID, clientState)
suite.keeper.SetClientConsensusState(suite.ctx, testClientID, testClientHeight, suite.consensusState)
suite.keeper.SetClientConsensusState(suite.ctx, testClientID, height, suite.consensusState)
nextState := ibctmtypes.NewConsensusState(suite.now, commitmenttypes.NewMerkleRoot([]byte("next")), testClientHeight+5, suite.valSetHash)
nextState := ibctmtypes.NewConsensusState(suite.now, commitmenttypes.NewMerkleRoot([]byte("next")), types.NewHeight(0, height+5), suite.valSetHash)
header := ibctmtypes.CreateTestHeader(testClientID, testClientHeight+5, testClientHeight, suite.header.Header.Time.Add(time.Minute),
header := ibctmtypes.CreateTestHeader(testClientID, height+5, height, suite.header.Header.Time.Add(time.Minute),
suite.valSet, suite.valSet, []tmtypes.PrivValidator{suite.privVal})
// mock update functionality
clientState.LatestHeight = header.GetHeight()
suite.keeper.SetClientConsensusState(suite.ctx, testClientID, testClientHeight+5, nextState)
clientState.LatestHeight = types.NewHeight(0, header.GetHeight())
suite.keeper.SetClientConsensusState(suite.ctx, testClientID, height+5, nextState)
suite.keeper.SetClientState(suite.ctx, testClientID, clientState)
latest, ok := suite.keeper.GetLatestClientConsensusState(suite.ctx, testClientID)
@ -302,24 +304,24 @@ func (suite KeeperTestSuite) TestConsensusStateHelpers() {
suite.Require().Equal(nextState, latest, "Latest client not returned correctly")
// Should return existing consensusState at latestClientHeight
lte, ok := suite.keeper.GetClientConsensusStateLTE(suite.ctx, testClientID, testClientHeight+3)
lte, ok := suite.keeper.GetClientConsensusStateLTE(suite.ctx, testClientID, height+3)
suite.Require().True(ok)
suite.Require().Equal(suite.consensusState, lte, "LTE helper function did not return latest client state below height: %d", testClientHeight+3)
suite.Require().Equal(suite.consensusState, lte, "LTE helper function did not return latest client state below height: %d", height+3)
}
func (suite KeeperTestSuite) TestGetAllConsensusStates() {
expConsensus := []exported.ConsensusState{
ibctmtypes.NewConsensusState(
suite.consensusState.Timestamp, commitmenttypes.NewMerkleRoot([]byte("hash")), suite.consensusState.GetHeight(), nil,
suite.consensusState.Timestamp, commitmenttypes.NewMerkleRoot([]byte("hash")), suite.consensusState.Height, nil,
),
ibctmtypes.NewConsensusState(
suite.consensusState.Timestamp.Add(time.Minute), commitmenttypes.NewMerkleRoot([]byte("app_hash")), suite.consensusState.GetHeight()+1, nil,
suite.consensusState.Timestamp.Add(time.Minute), commitmenttypes.NewMerkleRoot([]byte("app_hash")), suite.consensusState.Height.Increment(), nil,
),
}
expConsensus2 := []exported.ConsensusState{
ibctmtypes.NewConsensusState(
suite.consensusState.Timestamp.Add(2*time.Minute), commitmenttypes.NewMerkleRoot([]byte("app_hash_2")), suite.consensusState.GetHeight()+2, nil,
suite.consensusState.Timestamp.Add(2*time.Minute), commitmenttypes.NewMerkleRoot([]byte("app_hash_2")), types.NewHeight(0, suite.consensusState.GetHeight()+2), nil,
),
}

View File

@ -11,6 +11,7 @@ import (
"github.com/cosmos/cosmos-sdk/types/kv"
"github.com/cosmos/cosmos-sdk/x/ibc/02-client/exported"
"github.com/cosmos/cosmos-sdk/x/ibc/02-client/simulation"
"github.com/cosmos/cosmos-sdk/x/ibc/02-client/types"
ibctmtypes "github.com/cosmos/cosmos-sdk/x/ibc/07-tendermint/types"
host "github.com/cosmos/cosmos-sdk/x/ibc/24-host"
)
@ -20,11 +21,11 @@ func TestDecodeStore(t *testing.T) {
clientID := "clientidone"
clientState := &ibctmtypes.ClientState{
FrozenHeight: 10,
FrozenHeight: types.NewHeight(0, 10),
}
consState := &ibctmtypes.ConsensusState{
Height: 10,
Height: types.NewHeight(0, 10),
Timestamp: time.Now().UTC(),
}

View File

@ -134,15 +134,77 @@ func (m *ClientConsensusStates) GetConsensusStates() []*types.Any {
return nil
}
// Height is a monotonically increasing data type
// that can be compared against another Height for the purposes of updating and freezing clients
//
// Normally the EpochHeight is incremented at each height while keeping epoch number the same
// However some consensus algorithms may choose to reset the height in certain conditions
// e.g. hard forks, state-machine breaking changes
// In these cases, the epoch number is incremented so that height continues to be monitonically increasing
// even as the EpochHeight gets reset
type Height struct {
// the epoch that the client is currently on
EpochNumber uint64 `protobuf:"varint,1,opt,name=epoch_number,json=epochNumber,proto3" json:"epoch_number,omitempty" yaml:"epoch_number"`
// the height within the given epoch
EpochHeight uint64 `protobuf:"varint,2,opt,name=epoch_height,json=epochHeight,proto3" json:"epoch_height,omitempty" yaml:"epoch_height"`
}
func (m *Height) Reset() { *m = Height{} }
func (*Height) ProtoMessage() {}
func (*Height) Descriptor() ([]byte, []int) {
return fileDescriptor_226f80e576f20abd, []int{2}
}
func (m *Height) XXX_Unmarshal(b []byte) error {
return m.Unmarshal(b)
}
func (m *Height) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
if deterministic {
return xxx_messageInfo_Height.Marshal(b, m, deterministic)
} else {
b = b[:cap(b)]
n, err := m.MarshalToSizedBuffer(b)
if err != nil {
return nil, err
}
return b[:n], nil
}
}
func (m *Height) XXX_Merge(src proto.Message) {
xxx_messageInfo_Height.Merge(m, src)
}
func (m *Height) XXX_Size() int {
return m.Size()
}
func (m *Height) XXX_DiscardUnknown() {
xxx_messageInfo_Height.DiscardUnknown(m)
}
var xxx_messageInfo_Height proto.InternalMessageInfo
func (m *Height) GetEpochNumber() uint64 {
if m != nil {
return m.EpochNumber
}
return 0
}
func (m *Height) GetEpochHeight() uint64 {
if m != nil {
return m.EpochHeight
}
return 0
}
func init() {
proto.RegisterType((*IdentifiedClientState)(nil), "ibc.client.IdentifiedClientState")
proto.RegisterType((*ClientConsensusStates)(nil), "ibc.client.ClientConsensusStates")
proto.RegisterType((*Height)(nil), "ibc.client.Height")
}
func init() { proto.RegisterFile("ibc/client/client.proto", fileDescriptor_226f80e576f20abd) }
var fileDescriptor_226f80e576f20abd = []byte{
// 314 bytes of a gzipped FileDescriptorProto
// 378 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x12, 0xcf, 0x4c, 0x4a, 0xd6,
0x4f, 0xce, 0xc9, 0x4c, 0xcd, 0x2b, 0x81, 0x52, 0x7a, 0x05, 0x45, 0xf9, 0x25, 0xf9, 0x42, 0x5c,
0x99, 0x49, 0xc9, 0x7a, 0x10, 0x11, 0x29, 0x91, 0xf4, 0xfc, 0xf4, 0x7c, 0xb0, 0xb0, 0x3e, 0x88,
@ -157,12 +219,16 @@ var fileDescriptor_226f80e576f20abd = []byte{
0xc8, 0x25, 0x0a, 0x71, 0x94, 0x73, 0x7e, 0x5e, 0x71, 0x6a, 0x5e, 0x71, 0x69, 0x31, 0x58, 0xa2,
0x98, 0x1c, 0xe7, 0xc5, 0x70, 0x09, 0x24, 0xc3, 0x4c, 0x81, 0xd8, 0x56, 0x2c, 0xc1, 0xa4, 0xc0,
0x8c, 0xd3, 0x89, 0xd2, 0x9f, 0xee, 0xc9, 0x8b, 0x43, 0xcd, 0x43, 0xd3, 0xa7, 0x14, 0xc4, 0x9f,
0x8c, 0xea, 0x20, 0x27, 0x9f, 0x13, 0x8f, 0xe4, 0x18, 0x2f, 0x3c, 0x92, 0x63, 0x7c, 0xf0, 0x48,
0x8e, 0x71, 0xc2, 0x63, 0x39, 0x86, 0x0b, 0x8f, 0xe5, 0x18, 0x6e, 0x3c, 0x96, 0x63, 0x88, 0x32,
0x4a, 0xcf, 0x2c, 0xc9, 0x28, 0x4d, 0xd2, 0x4b, 0xce, 0xcf, 0xd5, 0x4f, 0xce, 0x2f, 0xce, 0xcd,
0x2f, 0x86, 0x52, 0xba, 0xc5, 0x29, 0xd9, 0xfa, 0x15, 0xfa, 0xa0, 0x88, 0x35, 0x30, 0xd2, 0x85,
0xc6, 0x6d, 0x49, 0x65, 0x41, 0x6a, 0x71, 0x12, 0x1b, 0xd8, 0x25, 0xc6, 0x80, 0x00, 0x00, 0x00,
0xff, 0xff, 0x38, 0x45, 0x52, 0x5c, 0xf6, 0x01, 0x00, 0x00,
0x8c, 0xea, 0x20, 0xa5, 0x36, 0x46, 0x2e, 0x36, 0x8f, 0xd4, 0xcc, 0xf4, 0x8c, 0x12, 0x21, 0x2b,
0x2e, 0x9e, 0xd4, 0x82, 0xfc, 0xe4, 0x8c, 0xf8, 0xbc, 0xd2, 0xdc, 0xa4, 0xd4, 0x22, 0xb0, 0xf3,
0x58, 0x90, 0x7d, 0x8c, 0x2c, 0xab, 0x14, 0xc4, 0x0d, 0xe6, 0xfa, 0x81, 0x79, 0x08, 0xbd, 0x19,
0x60, 0xb3, 0xc0, 0x61, 0x88, 0x45, 0x2f, 0x44, 0x16, 0xa6, 0x17, 0x62, 0xaf, 0x15, 0xcb, 0x8c,
0x05, 0xf2, 0x0c, 0x4e, 0x3e, 0x27, 0x1e, 0xc9, 0x31, 0x5e, 0x78, 0x24, 0xc7, 0xf8, 0xe0, 0x91,
0x1c, 0xe3, 0x84, 0xc7, 0x72, 0x0c, 0x17, 0x1e, 0xcb, 0x31, 0xdc, 0x78, 0x2c, 0xc7, 0x10, 0x65,
0x94, 0x9e, 0x59, 0x92, 0x51, 0x9a, 0xa4, 0x97, 0x9c, 0x9f, 0xab, 0x9f, 0x9c, 0x5f, 0x9c, 0x9b,
0x5f, 0x0c, 0xa5, 0x74, 0x8b, 0x53, 0xb2, 0xf5, 0x2b, 0xf4, 0x41, 0x29, 0xcc, 0xc0, 0x48, 0x17,
0x9a, 0xc8, 0x4a, 0x2a, 0x0b, 0x52, 0x8b, 0x93, 0xd8, 0xc0, 0x41, 0x62, 0x0c, 0x08, 0x00, 0x00,
0xff, 0xff, 0x55, 0xfb, 0xf5, 0xfb, 0x7f, 0x02, 0x00, 0x00,
}
func (m *IdentifiedClientState) Marshal() (dAtA []byte, err error) {
@ -251,6 +317,39 @@ func (m *ClientConsensusStates) MarshalToSizedBuffer(dAtA []byte) (int, error) {
return len(dAtA) - i, nil
}
func (m *Height) Marshal() (dAtA []byte, err error) {
size := m.Size()
dAtA = make([]byte, size)
n, err := m.MarshalToSizedBuffer(dAtA[:size])
if err != nil {
return nil, err
}
return dAtA[:n], nil
}
func (m *Height) MarshalTo(dAtA []byte) (int, error) {
size := m.Size()
return m.MarshalToSizedBuffer(dAtA[:size])
}
func (m *Height) MarshalToSizedBuffer(dAtA []byte) (int, error) {
i := len(dAtA)
_ = i
var l int
_ = l
if m.EpochHeight != 0 {
i = encodeVarintClient(dAtA, i, uint64(m.EpochHeight))
i--
dAtA[i] = 0x10
}
if m.EpochNumber != 0 {
i = encodeVarintClient(dAtA, i, uint64(m.EpochNumber))
i--
dAtA[i] = 0x8
}
return len(dAtA) - i, nil
}
func encodeVarintClient(dAtA []byte, offset int, v uint64) int {
offset -= sovClient(v)
base := offset
@ -298,6 +397,21 @@ func (m *ClientConsensusStates) Size() (n int) {
return n
}
func (m *Height) Size() (n int) {
if m == nil {
return 0
}
var l int
_ = l
if m.EpochNumber != 0 {
n += 1 + sovClient(uint64(m.EpochNumber))
}
if m.EpochHeight != 0 {
n += 1 + sovClient(uint64(m.EpochHeight))
}
return n
}
func sovClient(x uint64) (n int) {
return (math_bits.Len64(x|1) + 6) / 7
}
@ -544,6 +658,97 @@ func (m *ClientConsensusStates) Unmarshal(dAtA []byte) error {
}
return nil
}
func (m *Height) Unmarshal(dAtA []byte) error {
l := len(dAtA)
iNdEx := 0
for iNdEx < l {
preIndex := iNdEx
var wire uint64
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowClient
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
wire |= uint64(b&0x7F) << shift
if b < 0x80 {
break
}
}
fieldNum := int32(wire >> 3)
wireType := int(wire & 0x7)
if wireType == 4 {
return fmt.Errorf("proto: Height: wiretype end group for non-group")
}
if fieldNum <= 0 {
return fmt.Errorf("proto: Height: illegal tag %d (wire type %d)", fieldNum, wire)
}
switch fieldNum {
case 1:
if wireType != 0 {
return fmt.Errorf("proto: wrong wireType = %d for field EpochNumber", wireType)
}
m.EpochNumber = 0
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowClient
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
m.EpochNumber |= uint64(b&0x7F) << shift
if b < 0x80 {
break
}
}
case 2:
if wireType != 0 {
return fmt.Errorf("proto: wrong wireType = %d for field EpochHeight", wireType)
}
m.EpochHeight = 0
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowClient
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
m.EpochHeight |= uint64(b&0x7F) << shift
if b < 0x80 {
break
}
}
default:
iNdEx = preIndex
skippy, err := skipClient(dAtA[iNdEx:])
if err != nil {
return err
}
if skippy < 0 {
return ErrInvalidLengthClient
}
if (iNdEx + skippy) < 0 {
return ErrInvalidLengthClient
}
if (iNdEx + skippy) > l {
return io.ErrUnexpectedEOF
}
iNdEx += skippy
}
}
if iNdEx > l {
return io.ErrUnexpectedEOF
}
return nil
}
func skipClient(dAtA []byte) (n int, err error) {
l := len(dAtA)
iNdEx := 0

View File

@ -12,7 +12,7 @@ import (
)
func TestPackClientState(t *testing.T) {
clientState := localhosttypes.NewClientState(chainID, height)
clientState := localhosttypes.NewClientState(chainID, clientHeight)
clientAny, err := types.PackClientState(clientState)
require.NoError(t, err, "pack clientstate should not return error")
@ -27,7 +27,7 @@ func TestPackClientState(t *testing.T) {
}
func TestPackConsensusState(t *testing.T) {
consensusState := ibctmtypes.NewConsensusState(time.Now(), commitmenttypes.NewMerkleRoot([]byte("root")), height, []byte("nextvalshash"))
consensusState := ibctmtypes.NewConsensusState(time.Now(), commitmenttypes.NewMerkleRoot([]byte("root")), clientHeight, []byte("nextvalshash"))
consensusAny, err := types.PackConsensusState(consensusState)
require.NoError(t, err, "pack consensusstate should not return error")

View File

@ -22,6 +22,8 @@ const (
height = 10
)
var clientHeight = types.NewHeight(0, 10)
func TestValidateGenesis(t *testing.T) {
privVal := tmtypes.NewMockPV()
pubKey, err := privVal.GetPubKey()
@ -49,10 +51,10 @@ func TestValidateGenesis(t *testing.T) {
genState: types.NewGenesisState(
[]types.IdentifiedClientState{
types.NewIdentifiedClientState(
clientID, ibctmtypes.NewClientState(chainID, ibctesting.DefaultTrustLevel, ibctesting.TrustingPeriod, ibctesting.UnbondingPeriod, ibctesting.MaxClockDrift, height, commitmenttypes.GetSDKSpecs()),
clientID, ibctmtypes.NewClientState(chainID, ibctesting.DefaultTrustLevel, ibctesting.TrustingPeriod, ibctesting.UnbondingPeriod, ibctesting.MaxClockDrift, clientHeight, commitmenttypes.GetSDKSpecs()),
),
types.NewIdentifiedClientState(
exported.ClientTypeLocalHost, localhosttypes.NewClientState("chainID", 10),
exported.ClientTypeLocalHost, localhosttypes.NewClientState("chainID", clientHeight),
),
},
[]types.ClientConsensusStates{
@ -60,7 +62,7 @@ func TestValidateGenesis(t *testing.T) {
clientID,
[]exported.ConsensusState{
ibctmtypes.NewConsensusState(
header.GetTime(), commitmenttypes.NewMerkleRoot(header.Header.GetAppHash()), header.GetHeight(), header.Header.NextValidatorsHash,
header.GetTime(), commitmenttypes.NewMerkleRoot(header.Header.GetAppHash()), types.NewHeight(0, header.GetHeight()), header.Header.NextValidatorsHash,
),
},
),
@ -74,10 +76,10 @@ func TestValidateGenesis(t *testing.T) {
genState: types.NewGenesisState(
[]types.IdentifiedClientState{
types.NewIdentifiedClientState(
"/~@$*", ibctmtypes.NewClientState(chainID, ibctmtypes.DefaultTrustLevel, ibctesting.TrustingPeriod, ibctesting.UnbondingPeriod, ibctesting.MaxClockDrift, height, commitmenttypes.GetSDKSpecs()),
"/~@$*", ibctmtypes.NewClientState(chainID, ibctmtypes.DefaultTrustLevel, ibctesting.TrustingPeriod, ibctesting.UnbondingPeriod, ibctesting.MaxClockDrift, clientHeight, commitmenttypes.GetSDKSpecs()),
),
types.NewIdentifiedClientState(
exported.ClientTypeLocalHost, localhosttypes.NewClientState("chainID", 10),
exported.ClientTypeLocalHost, localhosttypes.NewClientState("chainID", clientHeight),
),
},
[]types.ClientConsensusStates{
@ -85,7 +87,7 @@ func TestValidateGenesis(t *testing.T) {
clientID,
[]exported.ConsensusState{
ibctmtypes.NewConsensusState(
header.GetTime(), commitmenttypes.NewMerkleRoot(header.Header.GetAppHash()), header.GetHeight(), header.Header.NextValidatorsHash,
header.GetTime(), commitmenttypes.NewMerkleRoot(header.Header.GetAppHash()), types.NewHeight(0, header.GetHeight()), header.Header.NextValidatorsHash,
),
},
),
@ -99,9 +101,9 @@ func TestValidateGenesis(t *testing.T) {
genState: types.NewGenesisState(
[]types.IdentifiedClientState{
types.NewIdentifiedClientState(
clientID, ibctmtypes.NewClientState(chainID, ibctmtypes.DefaultTrustLevel, ibctesting.TrustingPeriod, ibctesting.UnbondingPeriod, ibctesting.MaxClockDrift, height, commitmenttypes.GetSDKSpecs()),
clientID, ibctmtypes.NewClientState(chainID, ibctmtypes.DefaultTrustLevel, ibctesting.TrustingPeriod, ibctesting.UnbondingPeriod, ibctesting.MaxClockDrift, clientHeight, commitmenttypes.GetSDKSpecs()),
),
types.NewIdentifiedClientState(exported.ClientTypeLocalHost, localhosttypes.NewClientState("chaindID", 0)),
types.NewIdentifiedClientState(exported.ClientTypeLocalHost, localhosttypes.NewClientState("chaindID", types.Height{})),
},
nil,
true,
@ -113,10 +115,10 @@ func TestValidateGenesis(t *testing.T) {
genState: types.NewGenesisState(
[]types.IdentifiedClientState{
types.NewIdentifiedClientState(
clientID, ibctmtypes.NewClientState(chainID, ibctmtypes.DefaultTrustLevel, ibctesting.TrustingPeriod, ibctesting.UnbondingPeriod, ibctesting.MaxClockDrift, height, commitmenttypes.GetSDKSpecs()),
clientID, ibctmtypes.NewClientState(chainID, ibctmtypes.DefaultTrustLevel, ibctesting.TrustingPeriod, ibctesting.UnbondingPeriod, ibctesting.MaxClockDrift, clientHeight, commitmenttypes.GetSDKSpecs()),
),
types.NewIdentifiedClientState(
exported.ClientTypeLocalHost, localhosttypes.NewClientState("chaindID", 10),
exported.ClientTypeLocalHost, localhosttypes.NewClientState("chaindID", clientHeight),
),
},
[]types.ClientConsensusStates{
@ -124,7 +126,7 @@ func TestValidateGenesis(t *testing.T) {
"(CLIENTID2)",
[]exported.ConsensusState{
ibctmtypes.NewConsensusState(
header.GetTime(), commitmenttypes.NewMerkleRoot(header.Header.GetAppHash()), 0, header.Header.NextValidatorsHash,
header.GetTime(), commitmenttypes.NewMerkleRoot(header.Header.GetAppHash()), types.Height{}, header.Header.NextValidatorsHash,
),
},
),
@ -138,10 +140,10 @@ func TestValidateGenesis(t *testing.T) {
genState: types.NewGenesisState(
[]types.IdentifiedClientState{
types.NewIdentifiedClientState(
clientID, ibctmtypes.NewClientState(chainID, ibctmtypes.DefaultTrustLevel, ibctesting.TrustingPeriod, ibctesting.UnbondingPeriod, ibctesting.MaxClockDrift, height, commitmenttypes.GetSDKSpecs()),
clientID, ibctmtypes.NewClientState(chainID, ibctmtypes.DefaultTrustLevel, ibctesting.TrustingPeriod, ibctesting.UnbondingPeriod, ibctesting.MaxClockDrift, clientHeight, commitmenttypes.GetSDKSpecs()),
),
types.NewIdentifiedClientState(
exported.ClientTypeLocalHost, localhosttypes.NewClientState("chaindID", 10),
exported.ClientTypeLocalHost, localhosttypes.NewClientState("chaindID", clientHeight),
),
},
[]types.ClientConsensusStates{
@ -149,7 +151,7 @@ func TestValidateGenesis(t *testing.T) {
clientID,
[]exported.ConsensusState{
ibctmtypes.NewConsensusState(
header.GetTime(), commitmenttypes.NewMerkleRoot(header.Header.GetAppHash()), 0, header.Header.NextValidatorsHash,
header.GetTime(), commitmenttypes.NewMerkleRoot(header.Header.GetAppHash()), types.Height{}, header.Header.NextValidatorsHash,
),
},
),

View File

@ -0,0 +1,99 @@
package types
import (
"fmt"
"github.com/cosmos/cosmos-sdk/x/ibc/02-client/exported"
)
var _ exported.Height = (*Height)(nil)
// NewHeight is a constructor for the IBC height type
func NewHeight(epochNumber, epochHeight uint64) Height {
return Height{
EpochNumber: epochNumber,
EpochHeight: epochHeight,
}
}
/// Compare implements a method to compare two heights. When comparing two heights a, b
// we can call a.Compare(b) which will return
// -1 if a < b
// 0 if a = b
// 1 if a > b
//
// It first compares based on epoch numbers, whichever has the higher epoch number is the higher height
// If epoch number is the same, then the epoch height is compared
func (h Height) Compare(other exported.Height) int64 {
height, ok := other.(Height)
if !ok {
panic(fmt.Sprintf("cannot compare against invalid height type: %T. expected height type: %T", other, h))
}
var cmp int64
if h.EpochNumber != height.EpochNumber {
cmp = int64(h.EpochNumber) - int64(height.EpochNumber)
} else {
cmp = int64(h.EpochHeight) - int64(height.EpochHeight)
}
if cmp < 0 {
return -1
} else if cmp > 0 {
return 1
}
return 0
}
// LT Helper comparison function returns true if h < other
func (h Height) LT(other exported.Height) bool {
return h.Compare(other) == -1
}
// LTE Helper comparison function returns true if h <= other
func (h Height) LTE(other exported.Height) bool {
cmp := h.Compare(other)
return cmp <= 0
}
// GT Helper comparison function returns true if h > other
func (h Height) GT(other exported.Height) bool {
return h.Compare(other) == 1
}
// GTE Helper comparison function returns true if h >= other
func (h Height) GTE(other exported.Height) bool {
cmp := h.Compare(other)
return cmp >= 0
}
// EQ Helper comparison function returns true if h == other
func (h Height) EQ(other exported.Height) bool {
return h.Compare(other) == 0
}
// String returns a string representation of Height
func (h Height) String() string {
return fmt.Sprintf("epoch-%d-height-%d", h.EpochNumber, h.EpochHeight)
}
// Decrement will return a decremented height from the given height. If this is not possible,
// an error is returned
// Decrement will return a new height with the EpochHeight decremented
// If the EpochHeight is already at lowest value (1), then false success flag is returend
func (h Height) Decrement() (decremented Height, success bool) {
if h.EpochHeight == 0 {
return Height{}, false
}
return NewHeight(h.EpochNumber, h.EpochHeight-1), true
}
// Increment will return an incremented height from the given height.
// Increment will return a height with the same epoch number but an
// incremented epoch height
func (h Height) Increment() Height {
return NewHeight(h.EpochNumber, h.EpochHeight+1)
}
// IsZero returns true if height epoch and epoch-height are both 0
func (h Height) IsZero() bool {
return h.EpochNumber == 0 && h.EpochHeight == 0
}

View File

@ -0,0 +1,55 @@
package types_test
import (
"testing"
"github.com/cosmos/cosmos-sdk/x/ibc/02-client/types"
"github.com/stretchr/testify/require"
)
func TestCompareHeights(t *testing.T) {
testCases := []struct {
name string
height1 types.Height
height2 types.Height
compareSign int64
}{
{"epoch number 1 is lesser", types.NewHeight(1, 3), types.NewHeight(3, 4), -1},
{"epoch number 1 is greater", types.NewHeight(7, 5), types.NewHeight(4, 5), 1},
{"epoch height 1 is lesser", types.NewHeight(3, 4), types.NewHeight(3, 9), -1},
{"epoch height 1 is greater", types.NewHeight(3, 8), types.NewHeight(3, 3), 1},
{"height is equal", types.NewHeight(4, 4), types.NewHeight(4, 4), 0},
}
for i, tc := range testCases {
compare := tc.height1.Compare(tc.height2)
switch tc.compareSign {
case -1:
require.True(t, compare == -1, "case %d: %s should return negative value on comparison, got: %d",
i, tc.name, compare)
case 0:
require.True(t, compare == 0, "case %d: %s should return zero on comparison, got: %d",
i, tc.name, compare)
case 1:
require.True(t, compare == 1, "case %d: %s should return positive value on comparison, got: %d",
i, tc.name, compare)
}
}
}
func TestDecrement(t *testing.T) {
validDecrement := types.NewHeight(3, 3)
expected := types.NewHeight(3, 2)
actual, success := validDecrement.Decrement()
require.Equal(t, expected, actual, "decrementing %s did not return expected height: %s. got %s",
validDecrement, expected, actual)
require.True(t, success, "decrement failed unexpectedly")
invalidDecrement := types.NewHeight(3, 0)
actual, success = invalidDecrement.Decrement()
require.Equal(t, types.Height{}, actual, "invalid decrement returned non-zero height: %s", actual)
require.False(t, success, "invalid decrement passed")
}

View File

@ -155,7 +155,7 @@ func (suite *KeeperTestSuite) TestConnOpenTry() {
// modify counterparty client without setting in store so it still passes validate but fails proof verification
tmClient, ok := counterpartyClient.(*ibctmtypes.ClientState)
suite.Require().True(ok)
tmClient.LatestHeight++
tmClient.LatestHeight = tmClient.LatestHeight.Increment()
}, false},
{"consensus state verification failed", func() {
clientA, clientB = suite.coordinator.SetupClients(suite.chainA, suite.chainB, clientexported.Tendermint)
@ -171,7 +171,7 @@ func (suite *KeeperTestSuite) TestConnOpenTry() {
suite.Require().True(ok)
tmConsState.Timestamp = time.Now()
suite.chainA.App.IBCKeeper.ClientKeeper.SetClientConsensusState(suite.chainA.GetContext(), clientA, tmConsState.Height, tmConsState)
suite.chainA.App.IBCKeeper.ClientKeeper.SetClientConsensusState(suite.chainA.GetContext(), clientA, tmConsState.GetHeight(), tmConsState)
_, _, err := suite.coordinator.ConnOpenInit(suite.chainA, suite.chainB, clientA, clientB)
suite.Require().NoError(err)
@ -413,7 +413,7 @@ func (suite *KeeperTestSuite) TestConnOpenAck() {
// modify counterparty client without setting in store so it still passes validate but fails proof verification
tmClient, ok := counterpartyClient.(*ibctmtypes.ClientState)
suite.Require().True(ok)
tmClient.LatestHeight++
tmClient.LatestHeight = tmClient.LatestHeight.Increment()
err = suite.coordinator.ConnOpenTry(suite.chainB, suite.chainA, connB, connA)
suite.Require().NoError(err)
@ -434,7 +434,7 @@ func (suite *KeeperTestSuite) TestConnOpenAck() {
suite.Require().True(ok)
tmConsState.Timestamp = time.Now()
suite.chainB.App.IBCKeeper.ClientKeeper.SetClientConsensusState(suite.chainB.GetContext(), clientB, tmConsState.Height, tmConsState)
suite.chainB.App.IBCKeeper.ClientKeeper.SetClientConsensusState(suite.chainB.GetContext(), clientB, tmConsState.GetHeight(), tmConsState)
err = suite.coordinator.ConnOpenTry(suite.chainB, suite.chainA, connB, connA)
suite.Require().NoError(err)

View File

@ -103,7 +103,7 @@ func (suite *KeeperTestSuite) TestVerifyClientConsensusState() {
suite.Require().True(ok)
tmConsState.Timestamp = time.Now()
suite.chainB.App.IBCKeeper.ClientKeeper.SetClientConsensusState(suite.chainB.GetContext(), clientB, tmConsState.Height, tmConsState)
suite.chainB.App.IBCKeeper.ClientKeeper.SetClientConsensusState(suite.chainB.GetContext(), clientB, tmConsState.GetHeight(), tmConsState)
suite.coordinator.CommitBlock(suite.chainB)
}, false},

View File

@ -5,6 +5,7 @@ import (
"github.com/stretchr/testify/require"
clienttypes "github.com/cosmos/cosmos-sdk/x/ibc/02-client/types"
"github.com/cosmos/cosmos-sdk/x/ibc/03-connection/types"
commitmenttypes "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/types"
ibctesting "github.com/cosmos/cosmos-sdk/x/ibc/testing"
@ -16,7 +17,7 @@ var (
clientID = "clientidone"
connectionID2 = "connectionidtwo"
clientID2 = "clientidtwo"
clientHeight = uint64(6)
clientHeight = clienttypes.NewHeight(0, 6)
)
func TestConnectionValidateBasic(t *testing.T) {

View File

@ -119,7 +119,7 @@ func (suite *MsgTestSuite) TestNewMsgConnectionOpenTry() {
// invalidClientState fails validateBasic
invalidClient := ibctmtypes.NewClientState(
chainID, ibctmtypes.DefaultTrustLevel, ibctesting.TrustingPeriod, ibctesting.UnbondingPeriod, ibctesting.MaxClockDrift, 0, commitmenttypes.GetSDKSpecs(),
chainID, ibctmtypes.DefaultTrustLevel, ibctesting.TrustingPeriod, ibctesting.UnbondingPeriod, ibctesting.MaxClockDrift, clienttypes.Height{}, commitmenttypes.GetSDKSpecs(),
)
testMsgs := []*types.MsgConnectionOpenTry{
@ -190,7 +190,7 @@ func (suite *MsgTestSuite) TestNewMsgConnectionOpenAck() {
// invalidClientState fails validateBasic
invalidClient := ibctmtypes.NewClientState(
chainID, ibctmtypes.DefaultTrustLevel, ibctesting.TrustingPeriod, ibctesting.UnbondingPeriod, ibctesting.MaxClockDrift, 0, commitmenttypes.GetSDKSpecs(),
chainID, ibctmtypes.DefaultTrustLevel, ibctesting.TrustingPeriod, ibctesting.UnbondingPeriod, ibctesting.MaxClockDrift, clienttypes.Height{}, commitmenttypes.GetSDKSpecs(),
)
testMsgs := []*types.MsgConnectionOpenAck{

View File

@ -27,7 +27,7 @@ var _ clientexported.ClientState = (*ClientState)(nil)
func NewClientState(
chainID string, trustLevel Fraction,
trustingPeriod, ubdPeriod, maxClockDrift time.Duration,
latestHeight uint64, specs []*ics23.ProofSpec,
latestHeight clienttypes.Height, specs []*ics23.ProofSpec,
) *ClientState {
return &ClientState{
ChainId: chainID,
@ -36,7 +36,7 @@ func NewClientState(
UnbondingPeriod: ubdPeriod,
MaxClockDrift: maxClockDrift,
LatestHeight: latestHeight,
FrozenHeight: 0,
FrozenHeight: clienttypes.Height{},
ProofSpecs: specs,
}
}
@ -52,19 +52,21 @@ func (cs ClientState) ClientType() clientexported.ClientType {
}
// GetLatestHeight returns latest block height.
// TODO: return clienttypes.Height once interface has changed
func (cs ClientState) GetLatestHeight() uint64 {
return cs.LatestHeight
return cs.LatestHeight.EpochHeight
}
// IsFrozen returns true if the frozen height has been set.
func (cs ClientState) IsFrozen() bool {
return cs.FrozenHeight != 0
return !cs.FrozenHeight.IsZero()
}
// FrozenHeight returns the height at which client is frozen
// GetFrozenHeight returns the height at which client is frozen
// NOTE: FrozenHeight is 0 if client is unfrozen
// TODO: return clienttypes.Height once interface has changed
func (cs ClientState) GetFrozenHeight() uint64 {
return cs.FrozenHeight
return cs.FrozenHeight.EpochHeight
}
// Validate performs a basic validation of the client state fields.
@ -84,8 +86,8 @@ func (cs ClientState) Validate() error {
if cs.MaxClockDrift == 0 {
return sdkerrors.Wrap(ErrInvalidMaxClockDrift, "max clock drift cannot be zero")
}
if cs.LatestHeight == 0 {
return sdkerrors.Wrap(ErrInvalidHeaderHeight, "tendermint height cannot be zero")
if cs.LatestHeight.EpochHeight == 0 {
return sdkerrors.Wrapf(ErrInvalidHeaderHeight, "tendermint epoch height cannot be zero")
}
if cs.TrustingPeriod >= cs.UnbondingPeriod {
return sdkerrors.Wrapf(
@ -413,7 +415,7 @@ func produceVerificationArgs(
)
}
if cs.IsFrozen() && cs.FrozenHeight <= height {
if cs.IsFrozen() && !cs.FrozenHeight.GT(clienttypes.NewHeight(0, height)) {
return commitmenttypes.MerkleProof{}, nil, clienttypes.ErrClientFrozen
}

View File

@ -4,6 +4,7 @@ import (
ics23 "github.com/confio/ics23/go"
clientexported "github.com/cosmos/cosmos-sdk/x/ibc/02-client/exported"
clienttypes "github.com/cosmos/cosmos-sdk/x/ibc/02-client/types"
channeltypes "github.com/cosmos/cosmos-sdk/x/ibc/04-channel/types"
"github.com/cosmos/cosmos-sdk/x/ibc/07-tendermint/types"
commitmenttypes "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/types"
@ -61,7 +62,7 @@ func (suite *TendermintTestSuite) TestValidate() {
},
{
name: "invalid height",
clientState: types.NewClientState(chainID, types.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, 0, commitmenttypes.GetSDKSpecs()),
clientState: types.NewClientState(chainID, types.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, clienttypes.Height{}, commitmenttypes.GetSDKSpecs()),
expPass: false,
},
{
@ -130,7 +131,7 @@ func (suite *TendermintTestSuite) TestVerifyClientConsensusState() {
},
{
name: "client is frozen",
clientState: &types.ClientState{LatestHeight: height, FrozenHeight: height - 1},
clientState: &types.ClientState{LatestHeight: height, FrozenHeight: clienttypes.NewHeight(height.EpochNumber, height.EpochHeight-1)},
consensusState: types.ConsensusState{
Root: commitmenttypes.NewMerkleRoot(suite.header.Header.GetAppHash()),
},
@ -154,7 +155,7 @@ func (suite *TendermintTestSuite) TestVerifyClientConsensusState() {
tc := tc
err := tc.clientState.VerifyClientConsensusState(
nil, suite.cdc, tc.consensusState.Root, height, "chainA", tc.consensusState.GetHeight(), tc.prefix, tc.proof, tc.consensusState,
nil, suite.cdc, tc.consensusState.Root, height.EpochHeight, "chainA", tc.consensusState.GetHeight(), tc.prefix, tc.proof, tc.consensusState,
)
if tc.expPass {
@ -190,12 +191,12 @@ func (suite *TendermintTestSuite) TestVerifyConnectionState() {
},
{
"latest client height < height", func() {
proofHeight = clientState.LatestHeight + 1
proofHeight = clientState.LatestHeight.EpochHeight + 1
}, false,
},
{
"client is frozen", func() {
clientState.FrozenHeight = 1
clientState.FrozenHeight = clienttypes.NewHeight(0, 1)
}, false,
},
{
@ -268,12 +269,12 @@ func (suite *TendermintTestSuite) TestVerifyChannelState() {
},
{
"latest client height < height", func() {
proofHeight = clientState.LatestHeight + 1
proofHeight = clientState.LatestHeight.EpochHeight + 1
}, false,
},
{
"client is frozen", func() {
clientState.FrozenHeight = 1
clientState.FrozenHeight = clienttypes.NewHeight(0, 1)
}, false,
},
{
@ -347,12 +348,12 @@ func (suite *TendermintTestSuite) TestVerifyPacketCommitment() {
},
{
"latest client height < height", func() {
proofHeight = clientState.LatestHeight + 1
proofHeight = clientState.LatestHeight.EpochHeight + 1
}, false,
},
{
"client is frozen", func() {
clientState.FrozenHeight = 1
clientState.FrozenHeight = clienttypes.NewHeight(0, 1)
}, false,
},
{
@ -429,12 +430,12 @@ func (suite *TendermintTestSuite) TestVerifyPacketAcknowledgement() {
},
{
"latest client height < height", func() {
proofHeight = clientState.LatestHeight + 1
proofHeight = clientState.LatestHeight.EpochHeight + 1
}, false,
},
{
"client is frozen", func() {
clientState.FrozenHeight = 1
clientState.FrozenHeight = clienttypes.NewHeight(0, 1)
}, false,
},
{
@ -517,12 +518,12 @@ func (suite *TendermintTestSuite) TestVerifyPacketAcknowledgementAbsence() {
},
{
"latest client height < height", func() {
proofHeight = clientState.LatestHeight + 1
proofHeight = clientState.LatestHeight.EpochHeight + 1
}, false,
},
{
"client is frozen", func() {
clientState.FrozenHeight = 1
clientState.FrozenHeight = clienttypes.NewHeight(0, 1)
}, false,
},
{
@ -604,12 +605,12 @@ func (suite *TendermintTestSuite) TestVerifyNextSeqRecv() {
},
{
"latest client height < height", func() {
proofHeight = clientState.LatestHeight + 1
proofHeight = clientState.LatestHeight.EpochHeight + 1
}, false,
},
{
"client is frozen", func() {
clientState.FrozenHeight = 1
clientState.FrozenHeight = clienttypes.NewHeight(0, 1)
}, false,
},
{

View File

@ -15,7 +15,7 @@ import (
// NewConsensusState creates a new ConsensusState instance.
func NewConsensusState(
timestamp time.Time, root commitmenttypes.MerkleRoot, height uint64,
timestamp time.Time, root commitmenttypes.MerkleRoot, height clienttypes.Height,
nextValsHash tmbytes.HexBytes,
) *ConsensusState {
return &ConsensusState{
@ -38,7 +38,7 @@ func (cs ConsensusState) GetRoot() commitmentexported.Root {
// GetHeight returns the height for the specific consensus state
func (cs ConsensusState) GetHeight() uint64 {
return cs.Height
return cs.Height.EpochHeight
}
// GetTimestamp returns block time in nanoseconds at which the consensus state was stored
@ -54,8 +54,8 @@ func (cs ConsensusState) ValidateBasic() error {
if err := tmtypes.ValidateHash(cs.NextValidatorsHash); err != nil {
return sdkerrors.Wrap(err, "next validators hash is invalid")
}
if cs.Height == 0 {
return sdkerrors.Wrap(clienttypes.ErrInvalidConsensus, "height cannot be 0")
if cs.Height.EpochHeight == 0 {
return sdkerrors.Wrapf(clienttypes.ErrInvalidConsensus, "tendermint epoch height cannot be zero")
}
if cs.Timestamp.IsZero() {
return sdkerrors.Wrap(clienttypes.ErrInvalidConsensus, "timestamp cannot be zero Unix time")

View File

@ -4,6 +4,7 @@ import (
"time"
clientexported "github.com/cosmos/cosmos-sdk/x/ibc/02-client/exported"
clienttypes "github.com/cosmos/cosmos-sdk/x/ibc/02-client/types"
"github.com/cosmos/cosmos-sdk/x/ibc/07-tendermint/types"
commitmenttypes "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/types"
)
@ -50,7 +51,7 @@ func (suite *TendermintTestSuite) TestConsensusStateValidateBasic() {
{"height is 0",
&types.ConsensusState{
Timestamp: suite.now,
Height: 0,
Height: clienttypes.NewHeight(0, 0),
Root: commitmenttypes.NewMerkleRoot([]byte("app_hash")),
NextValidatorsHash: suite.valsHash,
},

View File

@ -22,7 +22,7 @@ func (h Header) ClientType() clientexported.ClientType {
// ConsensusState returns the updated consensus state associated with the header
func (h Header) ConsensusState() *ConsensusState {
return &ConsensusState{
Height: h.GetHeight(),
Height: clienttypes.NewHeight(0, h.GetHeight()),
Timestamp: h.GetTime(),
Root: commitmenttypes.NewMerkleRoot(h.Header.GetAppHash()),
NextValidatorsHash: h.Header.NextValidatorsHash,
@ -33,6 +33,7 @@ func (h Header) ConsensusState() *ConsensusState {
// header is nil.
//
// NOTE: also referred as `sequence`
// TODO: return clienttypes.Height once interface changes
func (h Header) GetHeight() uint64 {
if h.Header == nil {
return 0
@ -71,9 +72,10 @@ func (h Header) ValidateBasic(chainID string) error {
// TrustedHeight is less than Header for updates
// and less than or equal to Header for misbehaviour
if h.TrustedHeight > h.GetHeight() {
height := clienttypes.NewHeight(0, h.GetHeight())
if h.TrustedHeight.GT(height) {
return sdkerrors.Wrapf(ErrInvalidHeaderHeight, "TrustedHeight %d must be less than or equal to header height %d",
h.TrustedHeight, h.GetHeight())
h.TrustedHeight, height)
}
if h.ValidatorSet == nil {

View File

@ -4,6 +4,7 @@ import (
"time"
clientexported "github.com/cosmos/cosmos-sdk/x/ibc/02-client/exported"
clienttypes "github.com/cosmos/cosmos-sdk/x/ibc/02-client/types"
"github.com/cosmos/cosmos-sdk/x/ibc/07-tendermint/types"
)
@ -45,7 +46,7 @@ func (suite *TendermintTestSuite) TestHeaderValidateBasic() {
chainID = "chainid"
}, false},
{"trusted height is greater than header height", func() {
header.TrustedHeight = header.GetHeight() + 1
header.TrustedHeight = clienttypes.NewHeight(0, header.GetHeight()+1)
}, false},
{"validator set nil", func() {
header.ValidatorSet = nil

View File

@ -73,11 +73,11 @@ func (misbehaviour Misbehaviour) ValidateBasic() error {
if misbehaviour.Header2 == nil {
return sdkerrors.Wrap(ErrInvalidHeader, "misbehaviour Header2 cannot be nil")
}
if misbehaviour.Header1.TrustedHeight == 0 {
return sdkerrors.Wrap(ErrInvalidHeaderHeight, "misbehaviour Header1 must have non-zero trusted height")
if misbehaviour.Header1.TrustedHeight.EpochHeight == 0 {
return sdkerrors.Wrapf(ErrInvalidHeaderHeight, "misbehaviour Header1 cannot have zero epoch height")
}
if misbehaviour.Header2.TrustedHeight == 0 {
return sdkerrors.Wrap(ErrInvalidHeaderHeight, "misbehaviour Header2 must have non-zero trusted height")
if misbehaviour.Header2.TrustedHeight.EpochHeight == 0 {
return sdkerrors.Wrapf(ErrInvalidHeaderHeight, "misbehaviour Header2 cannot have zero epoch height")
}
if misbehaviour.Header1.TrustedValidators == nil {
return sdkerrors.Wrap(ErrInvalidValidatorSet, "trusted validator set in Header1 cannot be empty")

View File

@ -25,38 +25,38 @@ func (cs ClientState) CheckMisbehaviourAndUpdateState(
clientStore sdk.KVStore,
misbehaviour clientexported.Misbehaviour,
) (clientexported.ClientState, error) {
// If client is already frozen at earlier height than misbehaviour, return with error
if cs.IsFrozen() && cs.FrozenHeight <= misbehaviour.GetHeight() {
return nil, sdkerrors.Wrapf(clienttypes.ErrInvalidMisbehaviour,
"client is already frozen at earlier height %d than misbehaviour height %d", cs.FrozenHeight, misbehaviour.GetHeight())
}
tmEvidence, ok := misbehaviour.(*Misbehaviour)
tmMisbehaviour, ok := misbehaviour.(*Misbehaviour)
if !ok {
return nil, sdkerrors.Wrapf(clienttypes.ErrInvalidClientType, "expected type %T, got %T", misbehaviour, &Misbehaviour{})
}
// If client is already frozen at earlier height than misbehaviour, return with error
height := clienttypes.NewHeight(0, misbehaviour.GetHeight())
if cs.IsFrozen() && cs.FrozenHeight.LTE(height) {
return nil, sdkerrors.Wrapf(clienttypes.ErrInvalidMisbehaviour,
"client is already frozen at earlier height %d than misbehaviour height %d", cs.FrozenHeight, misbehaviour.GetHeight())
}
// Retrieve trusted consensus states for each Header in misbehaviour
// and unmarshal from clientStore
// Get consensus bytes from clientStore
tmConsensusState1, err := GetConsensusState(clientStore, cdc, tmEvidence.Header1.TrustedHeight)
tmConsensusState1, err := GetConsensusState(clientStore, cdc, tmMisbehaviour.Header1.TrustedHeight.EpochHeight)
if err != nil {
return nil, sdkerrors.Wrapf(err, "could not get trusted consensus state from clientStore for Header1 at TrustedHeight: %d", tmEvidence.Header1.TrustedHeight)
return nil, sdkerrors.Wrapf(err, "could not get trusted consensus state from clientStore for Header1 at TrustedHeight: %d", tmMisbehaviour.Header1.TrustedHeight)
}
// Get consensus bytes from clientStore
tmConsensusState2, err := GetConsensusState(clientStore, cdc, tmEvidence.Header2.TrustedHeight)
tmConsensusState2, err := GetConsensusState(clientStore, cdc, tmMisbehaviour.Header2.TrustedHeight.EpochHeight)
if err != nil {
return nil, sdkerrors.Wrapf(err, "could not get trusted consensus state from clientStore for Header2 at TrustedHeight: %d", tmEvidence.Header2.TrustedHeight)
return nil, sdkerrors.Wrapf(err, "could not get trusted consensus state from clientStore for Header2 at TrustedHeight: %d", tmMisbehaviour.Header2.TrustedHeight)
}
// calculate the age of the misbehaviour
infractionHeight := tmEvidence.GetHeight()
infractionTime := tmEvidence.GetTime()
infractionHeight := tmMisbehaviour.GetHeight()
infractionTime := tmMisbehaviour.GetTime()
ageDuration := ctx.BlockTime().Sub(infractionTime)
ageBlocks := int64(cs.LatestHeight - infractionHeight)
ageBlocks := int64(cs.LatestHeight.EpochHeight - infractionHeight)
// TODO: Retrieve consensusparams from client state and not context
// Issue #6516: https://github.com/cosmos/cosmos-sdk/issues/6516
@ -86,17 +86,18 @@ func (cs ClientState) CheckMisbehaviourAndUpdateState(
// misbehaviour.ValidateBasic by the client keeper and msg.ValidateBasic
// by the base application.
if err := checkMisbehaviourHeader(
&cs, tmConsensusState1, tmEvidence.Header1, ctx.BlockTime(),
&cs, tmConsensusState1, tmMisbehaviour.Header1, ctx.BlockTime(),
); err != nil {
return nil, sdkerrors.Wrap(err, "verifying Header1 in Misbehaviour failed")
}
if err := checkMisbehaviourHeader(
&cs, tmConsensusState2, tmEvidence.Header2, ctx.BlockTime(),
&cs, tmConsensusState2, tmMisbehaviour.Header2, ctx.BlockTime(),
); err != nil {
return nil, sdkerrors.Wrap(err, "verifying Header2 in Misbehaviour failed")
}
cs.FrozenHeight = tmEvidence.GetHeight()
frozenHeight := clienttypes.NewHeight(0, tmMisbehaviour.GetHeight())
cs.FrozenHeight = frozenHeight
return &cs, nil
}

View File

@ -9,6 +9,7 @@ import (
"github.com/cosmos/cosmos-sdk/simapp"
clientexported "github.com/cosmos/cosmos-sdk/x/ibc/02-client/exported"
clienttypes "github.com/cosmos/cosmos-sdk/x/ibc/02-client/types"
"github.com/cosmos/cosmos-sdk/x/ibc/07-tendermint/types"
commitmenttypes "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/types"
)
@ -33,6 +34,10 @@ func (suite *TendermintTestSuite) TestCheckMisbehaviourAndUpdateState() {
altSigners := []tmtypes.PrivValidator{altPrivVal}
epochHeight := int64(height.EpochHeight)
heightMinus1 := clienttypes.NewHeight(height.EpochNumber, height.EpochHeight-1)
heightMinus3 := clienttypes.NewHeight(height.EpochNumber, height.EpochHeight-3)
testCases := []struct {
name string
clientState clientexported.ClientState
@ -48,8 +53,8 @@ func (suite *TendermintTestSuite) TestCheckMisbehaviourAndUpdateState() {
types.NewConsensusState(suite.now, commitmenttypes.NewMerkleRoot(tmhash.Sum([]byte("app_hash"))), height, bothValsHash),
types.NewConsensusState(suite.now, commitmenttypes.NewMerkleRoot(tmhash.Sum([]byte("app_hash"))), height, bothValsHash),
&types.Misbehaviour{
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),
Header1: types.CreateTestHeader(chainID, epochHeight, epochHeight, suite.now, bothValSet, bothValSet, bothSigners),
Header2: types.CreateTestHeader(chainID, epochHeight, epochHeight, suite.now.Add(time.Minute), bothValSet, bothValSet, bothSigners),
ChainId: chainID,
ClientId: chainID,
},
@ -59,11 +64,11 @@ func (suite *TendermintTestSuite) TestCheckMisbehaviourAndUpdateState() {
{
"valid misbehavior at height greater than last consensusState",
types.NewClientState(chainID, types.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, height, commitmenttypes.GetSDKSpecs()),
types.NewConsensusState(suite.now, commitmenttypes.NewMerkleRoot(tmhash.Sum([]byte("app_hash"))), height-1, bothValsHash),
types.NewConsensusState(suite.now, commitmenttypes.NewMerkleRoot(tmhash.Sum([]byte("app_hash"))), height-1, bothValsHash),
types.NewConsensusState(suite.now, commitmenttypes.NewMerkleRoot(tmhash.Sum([]byte("app_hash"))), heightMinus1, bothValsHash),
types.NewConsensusState(suite.now, commitmenttypes.NewMerkleRoot(tmhash.Sum([]byte("app_hash"))), heightMinus1, bothValsHash),
&types.Misbehaviour{
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),
Header1: types.CreateTestHeader(chainID, epochHeight, epochHeight-1, suite.now, bothValSet, bothValSet, bothSigners),
Header2: types.CreateTestHeader(chainID, epochHeight, epochHeight-1, suite.now.Add(time.Minute), bothValSet, bothValSet, bothSigners),
ChainId: chainID,
ClientId: chainID,
},
@ -73,11 +78,11 @@ func (suite *TendermintTestSuite) TestCheckMisbehaviourAndUpdateState() {
{
"valid misbehavior misbehaviour with different trusted heights",
types.NewClientState(chainID, types.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, height, commitmenttypes.GetSDKSpecs()),
types.NewConsensusState(suite.now, commitmenttypes.NewMerkleRoot(tmhash.Sum([]byte("app_hash"))), height-1, bothValsHash),
types.NewConsensusState(suite.now, commitmenttypes.NewMerkleRoot(tmhash.Sum([]byte("app_hash"))), height-3, suite.valsHash),
types.NewConsensusState(suite.now, commitmenttypes.NewMerkleRoot(tmhash.Sum([]byte("app_hash"))), heightMinus1, bothValsHash),
types.NewConsensusState(suite.now, commitmenttypes.NewMerkleRoot(tmhash.Sum([]byte("app_hash"))), heightMinus3, suite.valsHash),
&types.Misbehaviour{
Header1: types.CreateTestHeader(chainID, height, height-1, suite.now, bothValSet, bothValSet, bothSigners),
Header2: types.CreateTestHeader(chainID, height, height-3, suite.now.Add(time.Minute), bothValSet, suite.valSet, bothSigners),
Header1: types.CreateTestHeader(chainID, epochHeight, epochHeight-1, suite.now, bothValSet, bothValSet, bothSigners),
Header2: types.CreateTestHeader(chainID, epochHeight, epochHeight-3, suite.now.Add(time.Minute), bothValSet, suite.valSet, bothSigners),
ChainId: chainID,
ClientId: chainID,
},
@ -90,8 +95,8 @@ func (suite *TendermintTestSuite) TestCheckMisbehaviourAndUpdateState() {
types.NewConsensusState(suite.now, commitmenttypes.NewMerkleRoot(tmhash.Sum([]byte("app_hash"))), height, suite.valsHash),
types.NewConsensusState(suite.now, commitmenttypes.NewMerkleRoot(tmhash.Sum([]byte("app_hash"))), height, suite.valsHash),
&types.Misbehaviour{
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),
Header1: types.CreateTestHeader(chainID, epochHeight, epochHeight, suite.now, bothValSet, suite.valSet, bothSigners),
Header2: types.CreateTestHeader(chainID, epochHeight, epochHeight, suite.now.Add(time.Minute), bothValSet, suite.valSet, bothSigners),
ChainId: chainID,
ClientId: chainID,
},
@ -101,11 +106,11 @@ func (suite *TendermintTestSuite) TestCheckMisbehaviourAndUpdateState() {
{
"invalid misbehavior misbehaviour with trusted height different from trusted consensus state",
types.NewClientState(chainID, types.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, height, commitmenttypes.GetSDKSpecs()),
types.NewConsensusState(suite.now, commitmenttypes.NewMerkleRoot(tmhash.Sum([]byte("app_hash"))), height-1, bothValsHash),
types.NewConsensusState(suite.now, commitmenttypes.NewMerkleRoot(tmhash.Sum([]byte("app_hash"))), height-3, suite.valsHash),
types.NewConsensusState(suite.now, commitmenttypes.NewMerkleRoot(tmhash.Sum([]byte("app_hash"))), heightMinus1, bothValsHash),
types.NewConsensusState(suite.now, commitmenttypes.NewMerkleRoot(tmhash.Sum([]byte("app_hash"))), heightMinus3, suite.valsHash),
&types.Misbehaviour{
Header1: types.CreateTestHeader(chainID, height, height-1, suite.now, bothValSet, bothValSet, bothSigners),
Header2: types.CreateTestHeader(chainID, height, height, suite.now.Add(time.Minute), bothValSet, suite.valSet, bothSigners),
Header1: types.CreateTestHeader(chainID, epochHeight, epochHeight-1, suite.now, bothValSet, bothValSet, bothSigners),
Header2: types.CreateTestHeader(chainID, epochHeight, epochHeight, suite.now.Add(time.Minute), bothValSet, suite.valSet, bothSigners),
ChainId: chainID,
ClientId: chainID,
},
@ -115,11 +120,11 @@ func (suite *TendermintTestSuite) TestCheckMisbehaviourAndUpdateState() {
{
"invalid misbehavior misbehaviour with trusted validators different from trusted consensus state",
types.NewClientState(chainID, types.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, height, commitmenttypes.GetSDKSpecs()),
types.NewConsensusState(suite.now, commitmenttypes.NewMerkleRoot(tmhash.Sum([]byte("app_hash"))), height-1, bothValsHash),
types.NewConsensusState(suite.now, commitmenttypes.NewMerkleRoot(tmhash.Sum([]byte("app_hash"))), height-3, suite.valsHash),
types.NewConsensusState(suite.now, commitmenttypes.NewMerkleRoot(tmhash.Sum([]byte("app_hash"))), heightMinus1, bothValsHash),
types.NewConsensusState(suite.now, commitmenttypes.NewMerkleRoot(tmhash.Sum([]byte("app_hash"))), heightMinus3, suite.valsHash),
&types.Misbehaviour{
Header1: types.CreateTestHeader(chainID, height, height-1, suite.now, bothValSet, bothValSet, bothSigners),
Header2: types.CreateTestHeader(chainID, height, height-3, suite.now.Add(time.Minute), bothValSet, bothValSet, bothSigners),
Header1: types.CreateTestHeader(chainID, epochHeight, epochHeight-1, suite.now, bothValSet, bothValSet, bothSigners),
Header2: types.CreateTestHeader(chainID, epochHeight, epochHeight-3, suite.now.Add(time.Minute), bothValSet, bothValSet, bothSigners),
ChainId: chainID,
ClientId: chainID,
},
@ -128,12 +133,12 @@ func (suite *TendermintTestSuite) TestCheckMisbehaviourAndUpdateState() {
},
{
"already frozen client state",
types.ClientState{FrozenHeight: 1},
types.ClientState{FrozenHeight: clienttypes.NewHeight(0, 1)},
types.NewConsensusState(suite.now, commitmenttypes.NewMerkleRoot(tmhash.Sum([]byte("app_hash"))), height, bothValsHash),
types.NewConsensusState(suite.now, commitmenttypes.NewMerkleRoot(tmhash.Sum([]byte("app_hash"))), height, bothValsHash),
&types.Misbehaviour{
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),
Header1: types.CreateTestHeader(chainID, epochHeight, epochHeight, suite.now, bothValSet, bothValSet, bothSigners),
Header2: types.CreateTestHeader(chainID, epochHeight, epochHeight, suite.now.Add(time.Minute), bothValSet, bothValSet, bothSigners),
ChainId: chainID,
ClientId: chainID,
},
@ -146,8 +151,8 @@ func (suite *TendermintTestSuite) TestCheckMisbehaviourAndUpdateState() {
nil, // consensus state for trusted height - 1 does not exist in store
types.NewConsensusState(suite.now, commitmenttypes.NewMerkleRoot(tmhash.Sum([]byte("app_hash"))), height, bothValsHash),
&types.Misbehaviour{
Header1: types.CreateTestHeader(chainID, height, height-1, suite.now, bothValSet, bothValSet, bothSigners),
Header2: types.CreateTestHeader(chainID, height, height, suite.now.Add(time.Minute), bothValSet, bothValSet, bothSigners),
Header1: types.CreateTestHeader(chainID, epochHeight, epochHeight-1, suite.now, bothValSet, bothValSet, bothSigners),
Header2: types.CreateTestHeader(chainID, epochHeight, epochHeight, suite.now.Add(time.Minute), bothValSet, bothValSet, bothSigners),
ChainId: chainID,
ClientId: chainID,
},
@ -155,7 +160,7 @@ func (suite *TendermintTestSuite) TestCheckMisbehaviourAndUpdateState() {
false,
},
{
"invalid tendermint misbehaviour misbehaviour",
"invalid tendermint misbehaviour",
types.NewClientState(chainID, types.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, height, commitmenttypes.GetSDKSpecs()),
types.NewConsensusState(suite.now, commitmenttypes.NewMerkleRoot(tmhash.Sum([]byte("app_hash"))), height, bothValsHash),
types.NewConsensusState(suite.now, commitmenttypes.NewMerkleRoot(tmhash.Sum([]byte("app_hash"))), height, bothValsHash),
@ -169,8 +174,8 @@ func (suite *TendermintTestSuite) TestCheckMisbehaviourAndUpdateState() {
types.NewConsensusState(suite.now, commitmenttypes.NewMerkleRoot(tmhash.Sum([]byte("app_hash"))), height, bothValsHash),
types.NewConsensusState(suite.now, commitmenttypes.NewMerkleRoot(tmhash.Sum([]byte("app_hash"))), height, bothValsHash),
&types.Misbehaviour{
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),
Header1: types.CreateTestHeader(chainID, epochHeight, epochHeight, suite.now, bothValSet, bothValSet, bothSigners),
Header2: types.CreateTestHeader(chainID, epochHeight, epochHeight, suite.now.Add(time.Minute), bothValSet, bothValSet, bothSigners),
ChainId: chainID,
ClientId: chainID,
},
@ -179,12 +184,12 @@ func (suite *TendermintTestSuite) TestCheckMisbehaviourAndUpdateState() {
},
{
"rejected misbehaviour due to expired block duration",
types.NewClientState(chainID, types.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, uint64(height+simapp.DefaultConsensusParams.Evidence.MaxAgeNumBlocks+1), commitmenttypes.GetSDKSpecs()),
types.NewClientState(chainID, types.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, clienttypes.NewHeight(0, uint64(epochHeight+simapp.DefaultConsensusParams.Evidence.MaxAgeNumBlocks+1)), commitmenttypes.GetSDKSpecs()),
types.NewConsensusState(suite.now, commitmenttypes.NewMerkleRoot(tmhash.Sum([]byte("app_hash"))), height, bothValsHash),
types.NewConsensusState(suite.now, commitmenttypes.NewMerkleRoot(tmhash.Sum([]byte("app_hash"))), height, bothValsHash),
&types.Misbehaviour{
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),
Header1: types.CreateTestHeader(chainID, epochHeight, epochHeight, suite.now, bothValSet, bothValSet, bothSigners),
Header2: types.CreateTestHeader(chainID, epochHeight, epochHeight, suite.now.Add(time.Minute), bothValSet, bothValSet, bothSigners),
ChainId: chainID,
ClientId: chainID,
},
@ -197,8 +202,8 @@ func (suite *TendermintTestSuite) TestCheckMisbehaviourAndUpdateState() {
types.NewConsensusState(suite.now, commitmenttypes.NewMerkleRoot(tmhash.Sum([]byte("app_hash"))), height, bothValsHash),
types.NewConsensusState(suite.now, commitmenttypes.NewMerkleRoot(tmhash.Sum([]byte("app_hash"))), height, bothValsHash),
&types.Misbehaviour{
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),
Header1: types.CreateTestHeader(chainID, epochHeight, epochHeight-1, suite.now, bothValSet, bothValSet, bothSigners),
Header2: types.CreateTestHeader(chainID, epochHeight, epochHeight-1, suite.now.Add(time.Minute), bothValSet, bothValSet, bothSigners),
ChainId: chainID,
ClientId: chainID,
},
@ -208,11 +213,11 @@ func (suite *TendermintTestSuite) TestCheckMisbehaviourAndUpdateState() {
{
"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"))), heightMinus1, bothValsHash),
types.NewConsensusState(suite.now, commitmenttypes.NewMerkleRoot(tmhash.Sum([]byte("app_hash"))), height, bothValsHash),
&types.Misbehaviour{
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),
Header1: types.CreateTestHeader(chainID, epochHeight, epochHeight-1, suite.now, bothValSet, bothValSet, bothSigners),
Header2: types.CreateTestHeader(chainID, epochHeight, epochHeight, suite.now.Add(time.Minute), bothValSet, bothValSet, bothSigners),
ChainId: chainID,
ClientId: chainID,
},
@ -225,8 +230,8 @@ func (suite *TendermintTestSuite) TestCheckMisbehaviourAndUpdateState() {
types.NewConsensusState(suite.now, commitmenttypes.NewMerkleRoot(tmhash.Sum([]byte("app_hash"))), height, bothValsHash),
types.NewConsensusState(suite.now, commitmenttypes.NewMerkleRoot(tmhash.Sum([]byte("app_hash"))), height, bothValsHash),
&types.Misbehaviour{
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),
Header1: types.CreateTestHeader(chainID, epochHeight, epochHeight, suite.now, bothValSet, suite.valSet, bothSigners),
Header2: types.CreateTestHeader(chainID, epochHeight, epochHeight, suite.now.Add(time.Minute), bothValSet, suite.valSet, bothSigners),
ChainId: chainID,
ClientId: chainID,
},
@ -239,8 +244,8 @@ func (suite *TendermintTestSuite) TestCheckMisbehaviourAndUpdateState() {
types.NewConsensusState(suite.now, commitmenttypes.NewMerkleRoot(tmhash.Sum([]byte("app_hash"))), height, bothValsHash),
types.NewConsensusState(suite.now, commitmenttypes.NewMerkleRoot(tmhash.Sum([]byte("app_hash"))), height, bothValsHash),
&types.Misbehaviour{
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),
Header1: types.CreateTestHeader(chainID, epochHeight, epochHeight, suite.now, altValSet, bothValSet, altSigners),
Header2: types.CreateTestHeader(chainID, epochHeight, epochHeight, suite.now.Add(time.Minute), bothValSet, bothValSet, bothSigners),
ChainId: chainID,
ClientId: chainID,
},
@ -253,8 +258,8 @@ func (suite *TendermintTestSuite) TestCheckMisbehaviourAndUpdateState() {
types.NewConsensusState(suite.now, commitmenttypes.NewMerkleRoot(tmhash.Sum([]byte("app_hash"))), height, bothValsHash),
types.NewConsensusState(suite.now, commitmenttypes.NewMerkleRoot(tmhash.Sum([]byte("app_hash"))), height, bothValsHash),
&types.Misbehaviour{
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),
Header1: types.CreateTestHeader(chainID, epochHeight, epochHeight, suite.now, bothValSet, bothValSet, bothSigners),
Header2: types.CreateTestHeader(chainID, epochHeight, epochHeight, suite.now.Add(time.Minute), altValSet, bothValSet, altSigners),
ChainId: chainID,
ClientId: chainID,
},
@ -267,8 +272,8 @@ func (suite *TendermintTestSuite) TestCheckMisbehaviourAndUpdateState() {
types.NewConsensusState(suite.now, commitmenttypes.NewMerkleRoot(tmhash.Sum([]byte("app_hash"))), height, bothValsHash),
types.NewConsensusState(suite.now, commitmenttypes.NewMerkleRoot(tmhash.Sum([]byte("app_hash"))), height, bothValsHash),
&types.Misbehaviour{
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),
Header1: types.CreateTestHeader(chainID, epochHeight, epochHeight, suite.now, altValSet, bothValSet, altSigners),
Header2: types.CreateTestHeader(chainID, epochHeight, epochHeight, suite.now.Add(time.Minute), altValSet, bothValSet, altSigners),
ChainId: chainID,
ClientId: chainID,
},

View File

@ -13,17 +13,18 @@ import (
func (suite *TendermintTestSuite) TestMisbehaviour() {
signers := []tmtypes.PrivValidator{suite.privVal}
epochHeight := int64(height.EpochHeight)
misbehaviour := &types.Misbehaviour{
Header1: suite.header,
Header2: types.CreateTestHeader(chainID, height, height-1, suite.now, suite.valSet, suite.valSet, signers),
Header2: types.CreateTestHeader(chainID, epochHeight, epochHeight-1, suite.now, suite.valSet, suite.valSet, signers),
ChainId: chainID,
ClientId: clientID,
}
suite.Require().Equal(clientexported.Tendermint, misbehaviour.ClientType())
suite.Require().Equal(clientID, misbehaviour.GetClientID())
suite.Require().Equal(uint64(height), misbehaviour.GetHeight())
suite.Require().Equal(height.EpochHeight, misbehaviour.GetHeight())
}
func (suite *TendermintTestSuite) TestMisbehaviourValidateBasic() {
@ -31,7 +32,9 @@ func (suite *TendermintTestSuite) TestMisbehaviourValidateBasic() {
altPubKey, err := altPrivVal.GetPubKey()
suite.Require().NoError(err)
altVal := tmtypes.NewValidator(altPubKey, height)
epochHeight := int64(height.EpochHeight)
altVal := tmtypes.NewValidator(altPubKey, epochHeight)
// Create bothValSet with both suite validator and altVal
bothValSet := tmtypes.NewValidatorSet(append(suite.valSet.Validators, altVal))
@ -56,7 +59,7 @@ func (suite *TendermintTestSuite) TestMisbehaviourValidateBasic() {
"valid misbehaviour",
&types.Misbehaviour{
Header1: suite.header,
Header2: types.CreateTestHeader(chainID, height, height-1, suite.now.Add(time.Minute), suite.valSet, suite.valSet, signers),
Header2: types.CreateTestHeader(chainID, epochHeight, epochHeight-1, suite.now.Add(time.Minute), suite.valSet, suite.valSet, signers),
ChainId: chainID,
ClientId: clientID,
},
@ -79,7 +82,7 @@ func (suite *TendermintTestSuite) TestMisbehaviourValidateBasic() {
"valid misbehaviour with different trusted headers",
&types.Misbehaviour{
Header1: suite.header,
Header2: types.CreateTestHeader(chainID, height, height-3, suite.now.Add(time.Minute), suite.valSet, bothValSet, signers),
Header2: types.CreateTestHeader(chainID, epochHeight, epochHeight-3, suite.now.Add(time.Minute), suite.valSet, bothValSet, signers),
ChainId: chainID,
ClientId: clientID,
},
@ -89,7 +92,7 @@ func (suite *TendermintTestSuite) TestMisbehaviourValidateBasic() {
{
"trusted height is 0 in Header1",
&types.Misbehaviour{
Header1: types.CreateTestHeader(chainID, height, 0, suite.now.Add(time.Minute), suite.valSet, suite.valSet, signers),
Header1: types.CreateTestHeader(chainID, epochHeight, 0, suite.now.Add(time.Minute), suite.valSet, suite.valSet, signers),
Header2: suite.header,
ChainId: chainID,
ClientId: clientID,
@ -101,7 +104,7 @@ func (suite *TendermintTestSuite) TestMisbehaviourValidateBasic() {
"trusted height is 0 in Header2",
&types.Misbehaviour{
Header1: suite.header,
Header2: types.CreateTestHeader(chainID, height, 0, suite.now.Add(time.Minute), suite.valSet, suite.valSet, signers),
Header2: types.CreateTestHeader(chainID, epochHeight, 0, suite.now.Add(time.Minute), suite.valSet, suite.valSet, signers),
ChainId: chainID,
ClientId: clientID,
},
@ -111,7 +114,7 @@ func (suite *TendermintTestSuite) TestMisbehaviourValidateBasic() {
{
"trusted valset is nil in Header1",
&types.Misbehaviour{
Header1: types.CreateTestHeader(chainID, height, height-1, suite.now.Add(time.Minute), suite.valSet, nil, signers),
Header1: types.CreateTestHeader(chainID, epochHeight, epochHeight-1, suite.now.Add(time.Minute), suite.valSet, nil, signers),
Header2: suite.header,
ChainId: chainID,
ClientId: clientID,
@ -123,7 +126,7 @@ func (suite *TendermintTestSuite) TestMisbehaviourValidateBasic() {
"trusted valset is nil in Header2",
&types.Misbehaviour{
Header1: suite.header,
Header2: types.CreateTestHeader(chainID, height, height-1, suite.now.Add(time.Minute), suite.valSet, nil, signers),
Header2: types.CreateTestHeader(chainID, epochHeight, epochHeight-1, suite.now.Add(time.Minute), suite.valSet, nil, signers),
ChainId: chainID,
ClientId: clientID,
},
@ -134,7 +137,7 @@ func (suite *TendermintTestSuite) TestMisbehaviourValidateBasic() {
"invalid client ID ",
&types.Misbehaviour{
Header1: suite.header,
Header2: types.CreateTestHeader(chainID, height, height-1, suite.now, suite.valSet, suite.valSet, signers),
Header2: types.CreateTestHeader(chainID, epochHeight, epochHeight-1, suite.now, suite.valSet, suite.valSet, signers),
ChainId: chainID,
ClientId: "GAIA",
},
@ -145,7 +148,7 @@ func (suite *TendermintTestSuite) TestMisbehaviourValidateBasic() {
"wrong chainID on header1",
&types.Misbehaviour{
Header1: suite.header,
Header2: types.CreateTestHeader("ethermint", height, height-1, suite.now, suite.valSet, suite.valSet, signers),
Header2: types.CreateTestHeader("ethermint", epochHeight, epochHeight-1, suite.now, suite.valSet, suite.valSet, signers),
ChainId: "ethermint",
ClientId: clientID,
},
@ -156,7 +159,7 @@ func (suite *TendermintTestSuite) TestMisbehaviourValidateBasic() {
"wrong chainID on header2",
&types.Misbehaviour{
Header1: suite.header,
Header2: types.CreateTestHeader("ethermint", height, height-1, suite.now, suite.valSet, suite.valSet, signers),
Header2: types.CreateTestHeader("ethermint", epochHeight, epochHeight-1, suite.now, suite.valSet, suite.valSet, signers),
ChainId: chainID,
ClientId: clientID,
},
@ -188,7 +191,7 @@ func (suite *TendermintTestSuite) TestMisbehaviourValidateBasic() {
{
"header 1 doesn't have 2/3 majority",
&types.Misbehaviour{
Header1: types.CreateTestHeader(chainID, height, height-1, suite.now, bothValSet, suite.valSet, bothSigners),
Header1: types.CreateTestHeader(chainID, epochHeight, epochHeight-1, suite.now, bothValSet, suite.valSet, bothSigners),
Header2: suite.header,
ChainId: chainID,
ClientId: clientID,
@ -211,7 +214,7 @@ func (suite *TendermintTestSuite) TestMisbehaviourValidateBasic() {
"header 2 doesn't have 2/3 majority",
&types.Misbehaviour{
Header1: suite.header,
Header2: types.CreateTestHeader(chainID, height, height-1, suite.now, bothValSet, suite.valSet, bothSigners),
Header2: types.CreateTestHeader(chainID, epochHeight, epochHeight-1, suite.now, bothValSet, suite.valSet, bothSigners),
ChainId: chainID,
ClientId: clientID,
},
@ -233,7 +236,7 @@ func (suite *TendermintTestSuite) TestMisbehaviourValidateBasic() {
"validators sign off on wrong commit",
&types.Misbehaviour{
Header1: suite.header,
Header2: types.CreateTestHeader(chainID, height, height-1, suite.now, bothValSet, suite.valSet, bothSigners),
Header2: types.CreateTestHeader(chainID, epochHeight, epochHeight-1, suite.now, bothValSet, suite.valSet, bothSigners),
ChainId: chainID,
ClientId: clientID,
},

View File

@ -10,6 +10,7 @@ import (
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
evidencetypes "github.com/cosmos/cosmos-sdk/x/evidence/types"
clientexported "github.com/cosmos/cosmos-sdk/x/ibc/02-client/exported"
clienttypes "github.com/cosmos/cosmos-sdk/x/ibc/02-client/types"
commitmenttypes "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/types"
host "github.com/cosmos/cosmos-sdk/x/ibc/24-host"
)
@ -113,10 +114,12 @@ func (msg MsgCreateClient) GetClientType() string {
func (msg MsgCreateClient) GetConsensusState() clientexported.ConsensusState {
// Construct initial consensus state from provided Header
root := commitmenttypes.NewMerkleRoot(msg.Header.Header.GetAppHash())
// NOTE: Using 0 for epoch number for now
// TODO: Use clienttypes.Height in Header once Header.GetHeight returns *clienttypes.Height
return &ConsensusState{
Timestamp: msg.Header.GetTime(),
Root: root,
Height: msg.Header.GetHeight(),
Height: clienttypes.NewHeight(0, msg.Header.GetHeight()),
NextValidatorsHash: msg.Header.Header.NextValidatorsHash,
}
}
@ -125,7 +128,7 @@ func (msg MsgCreateClient) GetConsensusState() clientexported.ConsensusState {
func (msg MsgCreateClient) InitializeClientState() clientexported.ClientState {
return NewClientState(msg.Header.Header.GetChainID(), msg.TrustLevel,
msg.TrustingPeriod, msg.UnbondingPeriod, msg.MaxClockDrift,
msg.Header.GetHeight(), msg.ProofSpecs,
clienttypes.NewHeight(0, msg.Header.GetHeight()), msg.ProofSpecs,
)
}

View File

@ -15,7 +15,7 @@ import (
func (suite *TendermintTestSuite) TestMsgCreateClientValidateBasic() {
privKey := secp256k1.GenPrivKey()
signer := sdk.AccAddress(privKey.PubKey().Address())
invalidHeader := types.CreateTestHeader(suite.header.Header.GetChainID(), height, 0, suite.now, suite.valSet, nil, []tmtypes.PrivValidator{suite.privVal})
invalidHeader := types.CreateTestHeader(suite.header.Header.GetChainID(), int64(height.EpochHeight), 0, suite.now, suite.valSet, nil, []tmtypes.PrivValidator{suite.privVal})
invalidHeader.ValidatorSet = nil
cases := []struct {

View File

@ -7,14 +7,15 @@ import (
fmt "fmt"
_go "github.com/confio/ics23/go"
github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types"
types "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/types"
types "github.com/cosmos/cosmos-sdk/x/ibc/02-client/types"
types1 "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/types"
_ "github.com/gogo/protobuf/gogoproto"
proto "github.com/gogo/protobuf/proto"
github_com_gogo_protobuf_types "github.com/gogo/protobuf/types"
_ "github.com/golang/protobuf/ptypes/duration"
_ "github.com/golang/protobuf/ptypes/timestamp"
github_com_tendermint_tendermint_libs_bytes "github.com/tendermint/tendermint/libs/bytes"
types1 "github.com/tendermint/tendermint/proto/tendermint/types"
types2 "github.com/tendermint/tendermint/proto/tendermint/types"
io "io"
math "math"
math_bits "math/bits"
@ -46,9 +47,9 @@ type ClientState struct {
// defines how much new (untrusted) header's Time can drift into the future.
MaxClockDrift time.Duration `protobuf:"bytes,5,opt,name=max_clock_drift,json=maxClockDrift,proto3,stdduration" json:"max_clock_drift" yaml:"max_clock_drift"`
// Block height when the client was frozen due to a misbehaviour
FrozenHeight uint64 `protobuf:"varint,6,opt,name=frozen_height,json=frozenHeight,proto3" json:"frozen_height,omitempty" yaml:"frozen_height"`
FrozenHeight types.Height `protobuf:"bytes,6,opt,name=frozen_height,json=frozenHeight,proto3" json:"frozen_height" yaml:"frozen_height"`
// Latest height the client was updated to
LatestHeight uint64 `protobuf:"varint,7,opt,name=latest_height,json=latestHeight,proto3" json:"latest_height,omitempty" yaml:"latest_height"`
LatestHeight types.Height `protobuf:"bytes,7,opt,name=latest_height,json=latestHeight,proto3" json:"latest_height" yaml:"latest_height"`
// Proof specifications used in verifying counterparty state
ProofSpecs []*_go.ProofSpec `protobuf:"bytes,8,rep,name=proof_specs,json=proofSpecs,proto3" json:"proof_specs,omitempty" yaml:"proof_specs"`
}
@ -92,9 +93,9 @@ type ConsensusState struct {
// was stored.
Timestamp time.Time `protobuf:"bytes,1,opt,name=timestamp,proto3,stdtime" json:"timestamp"`
// commitment root (i.e app hash)
Root types.MerkleRoot `protobuf:"bytes,2,opt,name=root,proto3" json:"root"`
Root types1.MerkleRoot `protobuf:"bytes,2,opt,name=root,proto3" json:"root"`
// height at which the consensus state was stored.
Height uint64 `protobuf:"varint,3,opt,name=height,proto3" json:"height,omitempty"`
Height types.Height `protobuf:"bytes,3,opt,name=height,proto3" json:"height"`
NextValidatorsHash github_com_tendermint_tendermint_libs_bytes.HexBytes `protobuf:"bytes,4,opt,name=next_validators_hash,json=nextValidatorsHash,proto3,casttype=github.com/tendermint/tendermint/libs/bytes.HexBytes" json:"next_validators_hash,omitempty" yaml:"next_validators_hash"`
}
@ -185,10 +186,10 @@ var xxx_messageInfo_Misbehaviour proto.InternalMessageInfo
// hash to TrustedConsensusState.NextValidatorsHash since that is the last
// trusted validator set at the TrustedHeight.
type Header struct {
*types1.SignedHeader `protobuf:"bytes,1,opt,name=signed_header,json=signedHeader,proto3,embedded=signed_header" json:"signed_header,omitempty" yaml:"signed_header"`
ValidatorSet *types1.ValidatorSet `protobuf:"bytes,2,opt,name=validator_set,json=validatorSet,proto3" json:"validator_set,omitempty" yaml:"validator_set"`
TrustedHeight uint64 `protobuf:"varint,3,opt,name=trusted_height,json=trustedHeight,proto3" json:"trusted_height,omitempty" yaml:"trusted_height"`
TrustedValidators *types1.ValidatorSet `protobuf:"bytes,4,opt,name=trusted_validators,json=trustedValidators,proto3" json:"trusted_validators,omitempty" yaml:"trusted_validators"`
*types2.SignedHeader `protobuf:"bytes,1,opt,name=signed_header,json=signedHeader,proto3,embedded=signed_header" json:"signed_header,omitempty" yaml:"signed_header"`
ValidatorSet *types2.ValidatorSet `protobuf:"bytes,2,opt,name=validator_set,json=validatorSet,proto3" json:"validator_set,omitempty" yaml:"validator_set"`
TrustedHeight types.Height `protobuf:"bytes,3,opt,name=trusted_height,json=trustedHeight,proto3" json:"trusted_height" yaml:"trusted_height"`
TrustedValidators *types2.ValidatorSet `protobuf:"bytes,4,opt,name=trusted_validators,json=trustedValidators,proto3" json:"trusted_validators,omitempty" yaml:"trusted_validators"`
}
func (m *Header) Reset() { *m = Header{} }
@ -224,21 +225,21 @@ func (m *Header) XXX_DiscardUnknown() {
var xxx_messageInfo_Header proto.InternalMessageInfo
func (m *Header) GetValidatorSet() *types1.ValidatorSet {
func (m *Header) GetValidatorSet() *types2.ValidatorSet {
if m != nil {
return m.ValidatorSet
}
return nil
}
func (m *Header) GetTrustedHeight() uint64 {
func (m *Header) GetTrustedHeight() types.Height {
if m != nil {
return m.TrustedHeight
}
return 0
return types.Height{}
}
func (m *Header) GetTrustedValidators() *types1.ValidatorSet {
func (m *Header) GetTrustedValidators() *types2.ValidatorSet {
if m != nil {
return m.TrustedValidators
}
@ -438,75 +439,76 @@ func init() {
func init() { proto.RegisterFile("ibc/tendermint/tendermint.proto", fileDescriptor_76a953d5a747dd66) }
var fileDescriptor_76a953d5a747dd66 = []byte{
// 1088 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xbc, 0x56, 0x4f, 0x4f, 0xe3, 0x46,
0x14, 0xc7, 0x21, 0x84, 0x30, 0x09, 0x7f, 0xea, 0xa5, 0x34, 0xb0, 0x34, 0x8e, 0xdc, 0x0b, 0x17,
0x9c, 0x92, 0x5d, 0xb5, 0x12, 0x52, 0xa5, 0x5d, 0xb3, 0xaa, 0xa0, 0x2a, 0x12, 0x1d, 0xba, 0xad,
0x54, 0xa9, 0xb2, 0x1c, 0x7b, 0x92, 0x8c, 0xb0, 0x3d, 0x91, 0x67, 0x82, 0xa0, 0x9f, 0x60, 0x7b,
0xdb, 0xe3, 0x1e, 0xbb, 0xdf, 0xa0, 0x87, 0x7e, 0x85, 0x4a, 0x7b, 0xe4, 0xd8, 0x93, 0x5b, 0xc1,
0x37, 0xc8, 0x91, 0x53, 0xe5, 0x99, 0xb1, 0x3d, 0x09, 0x68, 0xb7, 0x5d, 0xb1, 0x5c, 0x60, 0xde,
0x9f, 0xdf, 0x7b, 0x33, 0x2f, 0xbf, 0xf7, 0x9e, 0x81, 0x81, 0xbb, 0x5e, 0x9b, 0xa1, 0xc8, 0x47,
0x71, 0x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0x8b, 0xb6, 0xf2, 0xf7, 0x45, 0x5b,
0x79, 0x71, 0xd9, 0x9e, 0x3a, 0xbf, 0x6c, 0x4f, 0xfd, 0x79, 0xd9, 0x9e, 0xfa, 0xee, 0xe3, 0xb7,
0xd2, 0x9e, 0x76, 0xd2, 0xef, 0xf3, 0xc7, 0x9f, 0x6c, 0x4e, 0xfe, 0xcf, 0xe0, 0xd4, 0x78, 0xba,
0x3e, 0xf9, 0x27, 0x00, 0x00, 0xff, 0xff, 0xe8, 0xb0, 0x57, 0x1e, 0xa1, 0x0c, 0x00, 0x00,
}
func (m *ClientState) Marshal() (dAtA []byte, err error) {
@ -543,39 +545,49 @@ func (m *ClientState) MarshalToSizedBuffer(dAtA []byte) (int, error) {
dAtA[i] = 0x42
}
}
if m.LatestHeight != 0 {
i = encodeVarintTendermint(dAtA, i, uint64(m.LatestHeight))
i--
dAtA[i] = 0x38
{
size, err := m.LatestHeight.MarshalToSizedBuffer(dAtA[:i])
if err != nil {
return 0, err
}
i -= size
i = encodeVarintTendermint(dAtA, i, uint64(size))
}
if m.FrozenHeight != 0 {
i = encodeVarintTendermint(dAtA, i, uint64(m.FrozenHeight))
i--
dAtA[i] = 0x30
}
n1, err1 := github_com_gogo_protobuf_types.StdDurationMarshalTo(m.MaxClockDrift, dAtA[i-github_com_gogo_protobuf_types.SizeOfStdDuration(m.MaxClockDrift):])
if err1 != nil {
return 0, err1
}
i -= n1
i = encodeVarintTendermint(dAtA, i, uint64(n1))
i--
dAtA[i] = 0x2a
n2, err2 := github_com_gogo_protobuf_types.StdDurationMarshalTo(m.UnbondingPeriod, dAtA[i-github_com_gogo_protobuf_types.SizeOfStdDuration(m.UnbondingPeriod):])
if err2 != nil {
return 0, err2
dAtA[i] = 0x3a
{
size, err := m.FrozenHeight.MarshalToSizedBuffer(dAtA[:i])
if err != nil {
return 0, err
}
i -= size
i = encodeVarintTendermint(dAtA, i, uint64(size))
}
i -= n2
i = encodeVarintTendermint(dAtA, i, uint64(n2))
i--
dAtA[i] = 0x22
n3, err3 := github_com_gogo_protobuf_types.StdDurationMarshalTo(m.TrustingPeriod, dAtA[i-github_com_gogo_protobuf_types.SizeOfStdDuration(m.TrustingPeriod):])
dAtA[i] = 0x32
n3, err3 := github_com_gogo_protobuf_types.StdDurationMarshalTo(m.MaxClockDrift, dAtA[i-github_com_gogo_protobuf_types.SizeOfStdDuration(m.MaxClockDrift):])
if err3 != nil {
return 0, err3
}
i -= n3
i = encodeVarintTendermint(dAtA, i, uint64(n3))
i--
dAtA[i] = 0x2a
n4, err4 := github_com_gogo_protobuf_types.StdDurationMarshalTo(m.UnbondingPeriod, dAtA[i-github_com_gogo_protobuf_types.SizeOfStdDuration(m.UnbondingPeriod):])
if err4 != nil {
return 0, err4
}
i -= n4
i = encodeVarintTendermint(dAtA, i, uint64(n4))
i--
dAtA[i] = 0x22
n5, err5 := github_com_gogo_protobuf_types.StdDurationMarshalTo(m.TrustingPeriod, dAtA[i-github_com_gogo_protobuf_types.SizeOfStdDuration(m.TrustingPeriod):])
if err5 != nil {
return 0, err5
}
i -= n5
i = encodeVarintTendermint(dAtA, i, uint64(n5))
i--
dAtA[i] = 0x1a
{
size, err := m.TrustLevel.MarshalToSizedBuffer(dAtA[:i])
@ -624,11 +636,16 @@ func (m *ConsensusState) MarshalToSizedBuffer(dAtA []byte) (int, error) {
i--
dAtA[i] = 0x22
}
if m.Height != 0 {
i = encodeVarintTendermint(dAtA, i, uint64(m.Height))
i--
dAtA[i] = 0x18
{
size, err := m.Height.MarshalToSizedBuffer(dAtA[:i])
if err != nil {
return 0, err
}
i -= size
i = encodeVarintTendermint(dAtA, i, uint64(size))
}
i--
dAtA[i] = 0x1a
{
size, err := m.Root.MarshalToSizedBuffer(dAtA[:i])
if err != nil {
@ -639,12 +656,12 @@ func (m *ConsensusState) MarshalToSizedBuffer(dAtA []byte) (int, error) {
}
i--
dAtA[i] = 0x12
n6, err6 := github_com_gogo_protobuf_types.StdTimeMarshalTo(m.Timestamp, dAtA[i-github_com_gogo_protobuf_types.SizeOfStdTime(m.Timestamp):])
if err6 != nil {
return 0, err6
n9, err9 := github_com_gogo_protobuf_types.StdTimeMarshalTo(m.Timestamp, dAtA[i-github_com_gogo_protobuf_types.SizeOfStdTime(m.Timestamp):])
if err9 != nil {
return 0, err9
}
i -= n6
i = encodeVarintTendermint(dAtA, i, uint64(n6))
i -= n9
i = encodeVarintTendermint(dAtA, i, uint64(n9))
i--
dAtA[i] = 0xa
return len(dAtA) - i, nil
@ -743,11 +760,16 @@ func (m *Header) MarshalToSizedBuffer(dAtA []byte) (int, error) {
i--
dAtA[i] = 0x22
}
if m.TrustedHeight != 0 {
i = encodeVarintTendermint(dAtA, i, uint64(m.TrustedHeight))
i--
dAtA[i] = 0x18
{
size, err := m.TrustedHeight.MarshalToSizedBuffer(dAtA[:i])
if err != nil {
return 0, err
}
i -= size
i = encodeVarintTendermint(dAtA, i, uint64(size))
}
i--
dAtA[i] = 0x1a
if m.ValidatorSet != nil {
{
size, err := m.ValidatorSet.MarshalToSizedBuffer(dAtA[:i])
@ -849,28 +871,28 @@ func (m *MsgCreateClient) MarshalToSizedBuffer(dAtA []byte) (int, error) {
i--
dAtA[i] = 0x3a
}
n12, err12 := github_com_gogo_protobuf_types.StdDurationMarshalTo(m.MaxClockDrift, dAtA[i-github_com_gogo_protobuf_types.SizeOfStdDuration(m.MaxClockDrift):])
if err12 != nil {
return 0, err12
n16, err16 := github_com_gogo_protobuf_types.StdDurationMarshalTo(m.MaxClockDrift, dAtA[i-github_com_gogo_protobuf_types.SizeOfStdDuration(m.MaxClockDrift):])
if err16 != nil {
return 0, err16
}
i -= n12
i = encodeVarintTendermint(dAtA, i, uint64(n12))
i -= n16
i = encodeVarintTendermint(dAtA, i, uint64(n16))
i--
dAtA[i] = 0x32
n13, err13 := github_com_gogo_protobuf_types.StdDurationMarshalTo(m.UnbondingPeriod, dAtA[i-github_com_gogo_protobuf_types.SizeOfStdDuration(m.UnbondingPeriod):])
if err13 != nil {
return 0, err13
n17, err17 := github_com_gogo_protobuf_types.StdDurationMarshalTo(m.UnbondingPeriod, dAtA[i-github_com_gogo_protobuf_types.SizeOfStdDuration(m.UnbondingPeriod):])
if err17 != nil {
return 0, err17
}
i -= n13
i = encodeVarintTendermint(dAtA, i, uint64(n13))
i -= n17
i = encodeVarintTendermint(dAtA, i, uint64(n17))
i--
dAtA[i] = 0x2a
n14, err14 := github_com_gogo_protobuf_types.StdDurationMarshalTo(m.TrustingPeriod, dAtA[i-github_com_gogo_protobuf_types.SizeOfStdDuration(m.TrustingPeriod):])
if err14 != nil {
return 0, err14
n18, err18 := github_com_gogo_protobuf_types.StdDurationMarshalTo(m.TrustingPeriod, dAtA[i-github_com_gogo_protobuf_types.SizeOfStdDuration(m.TrustingPeriod):])
if err18 != nil {
return 0, err18
}
i -= n14
i = encodeVarintTendermint(dAtA, i, uint64(n14))
i -= n18
i = encodeVarintTendermint(dAtA, i, uint64(n18))
i--
dAtA[i] = 0x22
{
@ -1025,12 +1047,10 @@ func (m *ClientState) Size() (n int) {
n += 1 + l + sovTendermint(uint64(l))
l = github_com_gogo_protobuf_types.SizeOfStdDuration(m.MaxClockDrift)
n += 1 + l + sovTendermint(uint64(l))
if m.FrozenHeight != 0 {
n += 1 + sovTendermint(uint64(m.FrozenHeight))
}
if m.LatestHeight != 0 {
n += 1 + sovTendermint(uint64(m.LatestHeight))
}
l = m.FrozenHeight.Size()
n += 1 + l + sovTendermint(uint64(l))
l = m.LatestHeight.Size()
n += 1 + l + sovTendermint(uint64(l))
if len(m.ProofSpecs) > 0 {
for _, e := range m.ProofSpecs {
l = e.Size()
@ -1050,9 +1070,8 @@ func (m *ConsensusState) Size() (n int) {
n += 1 + l + sovTendermint(uint64(l))
l = m.Root.Size()
n += 1 + l + sovTendermint(uint64(l))
if m.Height != 0 {
n += 1 + sovTendermint(uint64(m.Height))
}
l = m.Height.Size()
n += 1 + l + sovTendermint(uint64(l))
l = len(m.NextValidatorsHash)
if l > 0 {
n += 1 + l + sovTendermint(uint64(l))
@ -1099,9 +1118,8 @@ func (m *Header) Size() (n int) {
l = m.ValidatorSet.Size()
n += 1 + l + sovTendermint(uint64(l))
}
if m.TrustedHeight != 0 {
n += 1 + sovTendermint(uint64(m.TrustedHeight))
}
l = m.TrustedHeight.Size()
n += 1 + l + sovTendermint(uint64(l))
if m.TrustedValidators != nil {
l = m.TrustedValidators.Size()
n += 1 + l + sovTendermint(uint64(l))
@ -1397,10 +1415,10 @@ func (m *ClientState) Unmarshal(dAtA []byte) error {
}
iNdEx = postIndex
case 6:
if wireType != 0 {
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field FrozenHeight", wireType)
}
m.FrozenHeight = 0
var msglen int
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowTendermint
@ -1410,16 +1428,30 @@ func (m *ClientState) Unmarshal(dAtA []byte) error {
}
b := dAtA[iNdEx]
iNdEx++
m.FrozenHeight |= uint64(b&0x7F) << shift
msglen |= int(b&0x7F) << shift
if b < 0x80 {
break
}
}
if msglen < 0 {
return ErrInvalidLengthTendermint
}
postIndex := iNdEx + msglen
if postIndex < 0 {
return ErrInvalidLengthTendermint
}
if postIndex > l {
return io.ErrUnexpectedEOF
}
if err := m.FrozenHeight.Unmarshal(dAtA[iNdEx:postIndex]); err != nil {
return err
}
iNdEx = postIndex
case 7:
if wireType != 0 {
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field LatestHeight", wireType)
}
m.LatestHeight = 0
var msglen int
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowTendermint
@ -1429,11 +1461,25 @@ func (m *ClientState) Unmarshal(dAtA []byte) error {
}
b := dAtA[iNdEx]
iNdEx++
m.LatestHeight |= uint64(b&0x7F) << shift
msglen |= int(b&0x7F) << shift
if b < 0x80 {
break
}
}
if msglen < 0 {
return ErrInvalidLengthTendermint
}
postIndex := iNdEx + msglen
if postIndex < 0 {
return ErrInvalidLengthTendermint
}
if postIndex > l {
return io.ErrUnexpectedEOF
}
if err := m.LatestHeight.Unmarshal(dAtA[iNdEx:postIndex]); err != nil {
return err
}
iNdEx = postIndex
case 8:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field ProofSpecs", wireType)
@ -1588,10 +1634,10 @@ func (m *ConsensusState) Unmarshal(dAtA []byte) error {
}
iNdEx = postIndex
case 3:
if wireType != 0 {
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field Height", wireType)
}
m.Height = 0
var msglen int
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowTendermint
@ -1601,11 +1647,25 @@ func (m *ConsensusState) Unmarshal(dAtA []byte) error {
}
b := dAtA[iNdEx]
iNdEx++
m.Height |= uint64(b&0x7F) << shift
msglen |= int(b&0x7F) << shift
if b < 0x80 {
break
}
}
if msglen < 0 {
return ErrInvalidLengthTendermint
}
postIndex := iNdEx + msglen
if postIndex < 0 {
return ErrInvalidLengthTendermint
}
if postIndex > l {
return io.ErrUnexpectedEOF
}
if err := m.Height.Unmarshal(dAtA[iNdEx:postIndex]); err != nil {
return err
}
iNdEx = postIndex
case 4:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field NextValidatorsHash", wireType)
@ -1912,7 +1972,7 @@ func (m *Header) Unmarshal(dAtA []byte) error {
return io.ErrUnexpectedEOF
}
if m.SignedHeader == nil {
m.SignedHeader = &types1.SignedHeader{}
m.SignedHeader = &types2.SignedHeader{}
}
if err := m.SignedHeader.Unmarshal(dAtA[iNdEx:postIndex]); err != nil {
return err
@ -1948,17 +2008,17 @@ func (m *Header) Unmarshal(dAtA []byte) error {
return io.ErrUnexpectedEOF
}
if m.ValidatorSet == nil {
m.ValidatorSet = &types1.ValidatorSet{}
m.ValidatorSet = &types2.ValidatorSet{}
}
if err := m.ValidatorSet.Unmarshal(dAtA[iNdEx:postIndex]); err != nil {
return err
}
iNdEx = postIndex
case 3:
if wireType != 0 {
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field TrustedHeight", wireType)
}
m.TrustedHeight = 0
var msglen int
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowTendermint
@ -1968,11 +2028,25 @@ func (m *Header) Unmarshal(dAtA []byte) error {
}
b := dAtA[iNdEx]
iNdEx++
m.TrustedHeight |= uint64(b&0x7F) << shift
msglen |= int(b&0x7F) << shift
if b < 0x80 {
break
}
}
if msglen < 0 {
return ErrInvalidLengthTendermint
}
postIndex := iNdEx + msglen
if postIndex < 0 {
return ErrInvalidLengthTendermint
}
if postIndex > l {
return io.ErrUnexpectedEOF
}
if err := m.TrustedHeight.Unmarshal(dAtA[iNdEx:postIndex]); err != nil {
return err
}
iNdEx = postIndex
case 4:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field TrustedValidators", wireType)
@ -2003,7 +2077,7 @@ func (m *Header) Unmarshal(dAtA []byte) error {
return io.ErrUnexpectedEOF
}
if m.TrustedValidators == nil {
m.TrustedValidators = &types1.ValidatorSet{}
m.TrustedValidators = &types2.ValidatorSet{}
}
if err := m.TrustedValidators.Unmarshal(dAtA[iNdEx:postIndex]); err != nil {
return err

View File

@ -12,6 +12,7 @@ import (
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/simapp"
sdk "github.com/cosmos/cosmos-sdk/types"
clienttypes "github.com/cosmos/cosmos-sdk/x/ibc/02-client/types"
ibctmtypes "github.com/cosmos/cosmos-sdk/x/ibc/07-tendermint/types"
ibctesting "github.com/cosmos/cosmos-sdk/x/ibc/testing"
)
@ -19,12 +20,13 @@ import (
const (
chainID = "gaia"
clientID = "gaiamainnet"
height = 4
trustingPeriod time.Duration = time.Hour * 24 * 7 * 2
ubdPeriod time.Duration = time.Hour * 24 * 7 * 3
maxClockDrift time.Duration = time.Second * 10
)
var height = clienttypes.NewHeight(0, 4)
type TendermintTestSuite struct {
suite.Suite
@ -69,10 +71,12 @@ func (suite *TendermintTestSuite) SetupTest() {
pubKey, err := suite.privVal.GetPubKey()
suite.Require().NoError(err)
epochHeight := int64(height.EpochHeight)
val := tmtypes.NewValidator(pubKey, 10)
suite.valSet = tmtypes.NewValidatorSet([]*tmtypes.Validator{val})
suite.valsHash = suite.valSet.Hash()
suite.header = ibctmtypes.CreateTestHeader(chainID, height, height-1, suite.now, suite.valSet, suite.valSet, []tmtypes.PrivValidator{suite.privVal})
suite.header = ibctmtypes.CreateTestHeader(chainID, epochHeight, epochHeight-1, suite.now, suite.valSet, suite.valSet, []tmtypes.PrivValidator{suite.privVal})
suite.ctx = app.BaseApp.NewContext(checkTx, tmproto.Header{Height: 1, Time: suite.now})
}

View File

@ -4,6 +4,7 @@ import (
"bytes"
"time"
clienttypes "github.com/cosmos/cosmos-sdk/x/ibc/02-client/types"
"github.com/tendermint/tendermint/crypto/tmhash"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
"github.com/tendermint/tendermint/proto/tendermint/version"
@ -75,7 +76,7 @@ func CreateTestHeader(chainID string, height, trustedHeight int64, timestamp tim
return &Header{
SignedHeader: &signedHeader,
ValidatorSet: valSet,
TrustedHeight: uint64(trustedHeight),
TrustedHeight: clienttypes.NewHeight(0, uint64(trustedHeight)),
TrustedValidators: trustedVals,
}
}

View File

@ -46,7 +46,7 @@ func (cs ClientState) CheckHeaderAndUpdateState(
}
// Get consensus bytes from clientStore
tmConsState, err := GetConsensusState(clientStore, cdc, tmHeader.TrustedHeight)
tmConsState, err := GetConsensusState(clientStore, cdc, tmHeader.TrustedHeight.EpochHeight)
if err != nil {
return nil, nil, sdkerrors.Wrapf(
err, "could not get consensus state from clientstore at TrustedHeight: %d", tmHeader.TrustedHeight,
@ -63,7 +63,7 @@ func (cs ClientState) CheckHeaderAndUpdateState(
// checkTrustedHeader checks that consensus state matches trusted fields of Header
func checkTrustedHeader(header *Header, consState *ConsensusState) error {
if header.TrustedHeight != consState.Height {
if !header.TrustedHeight.EQ(consState.Height) {
return sdkerrors.Wrapf(
ErrInvalidHeaderHeight,
"trusted header height %d does not match consensus state height %d",
@ -115,7 +115,8 @@ func checkValidity(
}
// assert header height is newer than consensus state
if header.GetHeight() <= consState.Height {
height := clienttypes.NewHeight(0, header.GetHeight())
if height.LTE(consState.Height) {
return sdkerrors.Wrapf(
clienttypes.ErrInvalidHeader,
"header height ≤ consensus state height (%d ≤ %d)", header.GetHeight(), consState.Height,
@ -125,7 +126,7 @@ func checkValidity(
// Construct a trusted header using the fields in consensus state
// Only Height, Time, and NextValidatorsHash are necessary for verification
trustedHeader := tmtypes.Header{
Height: int64(consState.Height),
Height: int64(consState.Height.EpochHeight),
Time: consState.Timestamp,
NextValidatorsHash: consState.NextValidatorsHash,
}
@ -151,11 +152,12 @@ func checkValidity(
// update the consensus state from a new header
func update(clientState *ClientState, header *Header) (*ClientState, *ConsensusState) {
if header.GetHeight() > clientState.LatestHeight {
clientState.LatestHeight = header.GetHeight()
height := clienttypes.NewHeight(0, header.GetHeight())
if height.GT(clientState.LatestHeight) {
clientState.LatestHeight = height
}
consensusState := &ConsensusState{
Height: header.GetHeight(),
Height: height,
Timestamp: header.GetTime(),
Root: commitmenttypes.NewMerkleRoot(header.Header.GetAppHash()),
NextValidatorsHash: header.Header.NextValidatorsHash,

View File

@ -5,6 +5,7 @@ import (
tmtypes "github.com/tendermint/tendermint/types"
clienttypes "github.com/cosmos/cosmos-sdk/x/ibc/02-client/types"
types "github.com/cosmos/cosmos-sdk/x/ibc/07-tendermint/types"
commitmenttypes "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/types"
)
@ -22,7 +23,11 @@ func (suite *TendermintTestSuite) TestCheckHeaderAndUpdateState() {
altPubKey, err := altPrivVal.GetPubKey()
suite.Require().NoError(err)
altVal := tmtypes.NewValidator(altPubKey, height)
epochHeight := int64(height.EpochHeight)
heightMinus3 := clienttypes.NewHeight(height.EpochNumber, height.EpochHeight-3)
heightPlus5 := clienttypes.NewHeight(height.EpochNumber, height.EpochHeight+5)
altVal := tmtypes.NewValidator(altPubKey, epochHeight)
// Create bothValSet with both suite validator and altVal. Would be valid update
bothValSet := tmtypes.NewValidatorSet(append(suite.valSet.Validators, altVal))
@ -47,7 +52,7 @@ func (suite *TendermintTestSuite) TestCheckHeaderAndUpdateState() {
setup: func() {
clientState = types.NewClientState(chainID, types.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, height, commitmenttypes.GetSDKSpecs())
consensusState = types.NewConsensusState(suite.clientTime, commitmenttypes.NewMerkleRoot(suite.header.Header.GetAppHash()), height, suite.valsHash)
newHeader = types.CreateTestHeader(chainID, height+1, height, suite.headerTime, suite.valSet, suite.valSet, signers)
newHeader = types.CreateTestHeader(chainID, epochHeight+1, epochHeight, suite.headerTime, suite.valSet, suite.valSet, signers)
currentTime = suite.now
},
expPass: true,
@ -57,7 +62,7 @@ func (suite *TendermintTestSuite) TestCheckHeaderAndUpdateState() {
setup: func() {
clientState = types.NewClientState(chainID, types.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, height, commitmenttypes.GetSDKSpecs())
consensusState = types.NewConsensusState(suite.clientTime, commitmenttypes.NewMerkleRoot(suite.header.Header.GetAppHash()), height, suite.valsHash)
newHeader = types.CreateTestHeader(chainID, height+5, height, suite.headerTime, bothValSet, suite.valSet, bothSigners)
newHeader = types.CreateTestHeader(chainID, epochHeight+5, epochHeight, suite.headerTime, bothValSet, suite.valSet, bothSigners)
currentTime = suite.now
},
expPass: true,
@ -67,7 +72,7 @@ func (suite *TendermintTestSuite) TestCheckHeaderAndUpdateState() {
setup: func() {
clientState = types.NewClientState(chainID, types.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, height, commitmenttypes.GetSDKSpecs())
consensusState = types.NewConsensusState(suite.clientTime, commitmenttypes.NewMerkleRoot(suite.header.Header.GetAppHash()), height, bothValSet.Hash())
newHeader = types.CreateTestHeader(chainID, height+1, height, suite.headerTime, bothValSet, bothValSet, bothSigners)
newHeader = types.CreateTestHeader(chainID, epochHeight+1, epochHeight, suite.headerTime, bothValSet, bothValSet, bothSigners)
currentTime = suite.now
},
expPass: true,
@ -76,8 +81,8 @@ func (suite *TendermintTestSuite) TestCheckHeaderAndUpdateState() {
name: "successful update for a previous height",
setup: func() {
clientState = types.NewClientState(chainID, types.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, height, commitmenttypes.GetSDKSpecs())
consensusState = types.NewConsensusState(suite.clientTime, commitmenttypes.NewMerkleRoot(suite.header.Header.GetAppHash()), height-3, suite.valsHash)
newHeader = types.CreateTestHeader(chainID, height-1, height-3, suite.headerTime, bothValSet, suite.valSet, bothSigners)
consensusState = types.NewConsensusState(suite.clientTime, commitmenttypes.NewMerkleRoot(suite.header.Header.GetAppHash()), heightMinus3, suite.valsHash)
newHeader = types.CreateTestHeader(chainID, epochHeight-1, epochHeight-3, suite.headerTime, bothValSet, suite.valSet, bothSigners)
currentTime = suite.now
},
expPass: true,
@ -87,7 +92,7 @@ func (suite *TendermintTestSuite) TestCheckHeaderAndUpdateState() {
setup: func() {
clientState = types.NewClientState(chainID, types.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, height, commitmenttypes.GetSDKSpecs())
consensusState = types.NewConsensusState(suite.clientTime, commitmenttypes.NewMerkleRoot(suite.header.Header.GetAppHash()), height, suite.valsHash)
newHeader = types.CreateTestHeader(chainID, height+1, height, suite.headerTime, bothValSet, suite.valSet, bothSigners)
newHeader = types.CreateTestHeader(chainID, epochHeight+1, epochHeight, suite.headerTime, bothValSet, suite.valSet, bothSigners)
currentTime = suite.now
},
expPass: false,
@ -97,7 +102,7 @@ func (suite *TendermintTestSuite) TestCheckHeaderAndUpdateState() {
setup: func() {
clientState = types.NewClientState(chainID, types.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, height, commitmenttypes.GetSDKSpecs())
consensusState = types.NewConsensusState(suite.clientTime, commitmenttypes.NewMerkleRoot(suite.header.Header.GetAppHash()), height, bothValSet.Hash())
newHeader = types.CreateTestHeader(chainID, height+1, height, suite.headerTime, suite.valSet, bothValSet, signers)
newHeader = types.CreateTestHeader(chainID, epochHeight+1, epochHeight, suite.headerTime, suite.valSet, bothValSet, signers)
currentTime = suite.now
},
expPass: false,
@ -107,7 +112,7 @@ func (suite *TendermintTestSuite) TestCheckHeaderAndUpdateState() {
setup: func() {
clientState = types.NewClientState(chainID, types.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, height, commitmenttypes.GetSDKSpecs())
consensusState = types.NewConsensusState(suite.clientTime, commitmenttypes.NewMerkleRoot(suite.header.Header.GetAppHash()), height, suite.valsHash)
newHeader = types.CreateTestHeader(chainID, height+5, height, suite.headerTime, altValSet, suite.valSet, altSigners)
newHeader = types.CreateTestHeader(chainID, epochHeight+5, epochHeight, suite.headerTime, altValSet, suite.valSet, altSigners)
currentTime = suite.now
},
expPass: false,
@ -117,7 +122,7 @@ func (suite *TendermintTestSuite) TestCheckHeaderAndUpdateState() {
setup: func() {
clientState = types.NewClientState(chainID, types.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, height, commitmenttypes.GetSDKSpecs())
consensusState = types.NewConsensusState(suite.clientTime, commitmenttypes.NewMerkleRoot(suite.header.Header.GetAppHash()), height, suite.valsHash)
newHeader = types.CreateTestHeader(chainID, height+5, height, suite.headerTime, bothValSet, bothValSet, bothSigners)
newHeader = types.CreateTestHeader(chainID, epochHeight+5, epochHeight, suite.headerTime, bothValSet, bothValSet, bothSigners)
currentTime = suite.now
},
expPass: false,
@ -127,7 +132,7 @@ func (suite *TendermintTestSuite) TestCheckHeaderAndUpdateState() {
setup: func() {
clientState = types.NewClientState(chainID, types.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, height, commitmenttypes.GetSDKSpecs())
consensusState = types.NewConsensusState(suite.clientTime, commitmenttypes.NewMerkleRoot(suite.header.Header.GetAppHash()), height, suite.valsHash)
newHeader = types.CreateTestHeader(chainID, height+1, height, suite.headerTime, suite.valSet, suite.valSet, signers)
newHeader = types.CreateTestHeader(chainID, epochHeight+1, epochHeight, suite.headerTime, suite.valSet, suite.valSet, signers)
// make current time pass trusting period from last timestamp on clientstate
currentTime = suite.now.Add(trustingPeriod)
},
@ -138,7 +143,7 @@ func (suite *TendermintTestSuite) TestCheckHeaderAndUpdateState() {
setup: func() {
clientState = types.NewClientState(chainID, types.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, height, commitmenttypes.GetSDKSpecs())
consensusState = types.NewConsensusState(suite.clientTime, commitmenttypes.NewMerkleRoot(suite.header.Header.GetAppHash()), height, suite.valsHash)
newHeader = types.CreateTestHeader(chainID, height+1, height, suite.now.Add(time.Minute), suite.valSet, suite.valSet, signers)
newHeader = types.CreateTestHeader(chainID, epochHeight+1, epochHeight, suite.now.Add(time.Minute), suite.valSet, suite.valSet, signers)
currentTime = suite.now
},
expPass: false,
@ -148,7 +153,7 @@ func (suite *TendermintTestSuite) TestCheckHeaderAndUpdateState() {
setup: func() {
clientState = types.NewClientState(chainID, types.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, height, commitmenttypes.GetSDKSpecs())
consensusState = types.NewConsensusState(suite.clientTime, commitmenttypes.NewMerkleRoot(suite.header.Header.GetAppHash()), height, suite.valsHash)
newHeader = types.CreateTestHeader(chainID, height+1, height, suite.clientTime, suite.valSet, suite.valSet, signers)
newHeader = types.CreateTestHeader(chainID, epochHeight+1, epochHeight, suite.clientTime, suite.valSet, suite.valSet, signers)
currentTime = suite.now
},
expPass: false,
@ -158,9 +163,9 @@ func (suite *TendermintTestSuite) TestCheckHeaderAndUpdateState() {
setup: func() {
clientState = types.NewClientState(chainID, types.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, height, commitmenttypes.GetSDKSpecs())
consensusState = types.NewConsensusState(suite.clientTime, commitmenttypes.NewMerkleRoot(suite.header.Header.GetAppHash()), height, suite.valsHash)
newHeader = types.CreateTestHeader(chainID, height+1, height, suite.headerTime, suite.valSet, suite.valSet, signers)
newHeader = types.CreateTestHeader(chainID, epochHeight+1, epochHeight, suite.headerTime, suite.valSet, suite.valSet, signers)
// cause new header to fail validatebasic by changing commit height to mismatch header height
newHeader.SignedHeader.Commit.Height = height - 1
newHeader.SignedHeader.Commit.Height = epochHeight - 1
currentTime = suite.now
},
expPass: false,
@ -168,10 +173,10 @@ func (suite *TendermintTestSuite) TestCheckHeaderAndUpdateState() {
{
name: "header height < consensus height",
setup: func() {
clientState = types.NewClientState(chainID, types.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, height+5, commitmenttypes.GetSDKSpecs())
clientState = types.NewClientState(chainID, types.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, heightPlus5, commitmenttypes.GetSDKSpecs())
consensusState = types.NewConsensusState(suite.clientTime, commitmenttypes.NewMerkleRoot(suite.header.Header.GetAppHash()), height, suite.valsHash)
// Make new header at height less than latest client state
newHeader = types.CreateTestHeader(chainID, height-1, height, suite.headerTime, suite.valSet, suite.valSet, signers)
newHeader = types.CreateTestHeader(chainID, epochHeight-1, epochHeight, suite.headerTime, suite.valSet, suite.valSet, signers)
currentTime = suite.now
},
expPass: false,
@ -189,8 +194,9 @@ func (suite *TendermintTestSuite) TestCheckHeaderAndUpdateState() {
// Set trusted consensus state in client store
suite.chainA.App.IBCKeeper.ClientKeeper.SetClientConsensusState(ctx, clientID, consensusState.GetHeight(), consensusState)
height := clienttypes.NewHeight(0, newHeader.GetHeight())
expectedConsensus := &types.ConsensusState{
Height: uint64(newHeader.GetHeight()),
Height: height,
Timestamp: newHeader.GetTime(),
Root: commitmenttypes.NewMerkleRoot(newHeader.Header.GetAppHash()),
NextValidatorsHash: newHeader.Header.NextValidatorsHash,
@ -207,12 +213,13 @@ func (suite *TendermintTestSuite) TestCheckHeaderAndUpdateState() {
suite.Require().NoError(err, "valid test case %d failed: %s", i, tc.name)
// Determine if clientState should be updated or not
if uint64(newHeader.GetHeight()) > clientState.LatestHeight {
// TODO: check the entire Height struct once GetLatestHeight returns clienttypes.Height
if height.GT(clientState.LatestHeight) {
// Header Height is greater than clientState latest Height, clientState should be updated with header.GetHeight()
suite.Require().Equal(uint64(newHeader.GetHeight()), newClientState.GetLatestHeight(), "clientstate height did not update")
suite.Require().Equal(height.EpochHeight, newClientState.GetLatestHeight(), "clientstate height did not update")
} else {
// Update will add past consensus state, clientState should not be updated at all
suite.Require().Equal(clientState.LatestHeight, newClientState.GetLatestHeight(), "client state height updated for past header")
suite.Require().Equal(clientState.LatestHeight.EpochHeight, newClientState.GetLatestHeight(), "client state height updated for past header")
}
suite.Require().Equal(expectedConsensus, consensusState, "valid test case %d failed: %s", i, tc.name)

View File

@ -24,10 +24,10 @@ import (
var _ clientexported.ClientState = (*ClientState)(nil)
// NewClientState creates a new ClientState instance
func NewClientState(chainID string, height int64) *ClientState {
func NewClientState(chainID string, height clienttypes.Height) *ClientState {
return &ClientState{
ChainId: chainID,
Height: uint64(height),
Height: height,
}
}
@ -43,7 +43,7 @@ func (cs ClientState) ClientType() clientexported.ClientType {
// GetLatestHeight returns the latest height stored.
func (cs ClientState) GetLatestHeight() uint64 {
return cs.Height
return cs.Height.EpochHeight
}
// IsFrozen returns false.
@ -61,8 +61,8 @@ func (cs ClientState) Validate() error {
if strings.TrimSpace(cs.ChainId) == "" {
return sdkerrors.Wrap(sdkerrors.ErrInvalidChainID, "chain id cannot be blank")
}
if cs.Height <= 0 {
return sdkerrors.Wrapf(sdkerrors.ErrInvalidHeight, "height must be positive: %d", cs.Height)
if cs.Height.EpochHeight == 0 {
return sdkerrors.Wrapf(sdkerrors.ErrInvalidHeight, "local epoch height cannot be zero")
}
return nil
}
@ -76,9 +76,11 @@ func (cs ClientState) GetProofSpecs() []*ics23.ProofSpec {
func (cs ClientState) CheckHeaderAndUpdateState(
ctx sdk.Context, _ codec.BinaryMarshaler, _ sdk.KVStore, _ clientexported.Header,
) (clientexported.ClientState, clientexported.ConsensusState, error) {
// 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).
ctx.BlockHeight(),
clienttypes.NewHeight(0, uint64(ctx.BlockHeight())),
), nil, nil
}

View File

@ -25,17 +25,17 @@ func (suite *LocalhostTestSuite) TestValidate() {
}{
{
name: "valid client",
clientState: types.NewClientState("chainID", 10),
clientState: types.NewClientState("chainID", clienttypes.NewHeight(3, 10)),
expPass: true,
},
{
name: "invalid chain id",
clientState: types.NewClientState(" ", 10),
clientState: types.NewClientState(" ", clienttypes.NewHeight(3, 10)),
expPass: false,
},
{
name: "invalid height",
clientState: types.NewClientState("chainID", 0),
clientState: types.NewClientState("chainID", clienttypes.Height{}),
expPass: false,
},
}
@ -51,8 +51,8 @@ func (suite *LocalhostTestSuite) TestValidate() {
}
func (suite *LocalhostTestSuite) TestVerifyClientState() {
clientState := types.NewClientState("chainID", 10)
invalidClient := types.NewClientState("chainID", 12)
clientState := types.NewClientState("chainID", clientHeight)
invalidClient := types.NewClientState("chainID", clienttypes.NewHeight(0, 12))
testCases := []struct {
name string
@ -112,7 +112,7 @@ func (suite *LocalhostTestSuite) TestVerifyClientState() {
}
func (suite *LocalhostTestSuite) TestVerifyClientConsensusState() {
clientState := types.NewClientState("chainID", 10)
clientState := types.NewClientState("chainID", clientHeight)
err := clientState.VerifyClientConsensusState(
nil, nil, nil, 0, "", 0, nil, nil, nil,
)
@ -133,7 +133,7 @@ func (suite *LocalhostTestSuite) TestVerifyConnectionState() {
}{
{
name: "proof verification success",
clientState: types.NewClientState("chainID", 10),
clientState: types.NewClientState("chainID", clientHeight),
malleate: func() {
bz, err := suite.cdc.MarshalBinaryBare(&conn1)
suite.Require().NoError(err)
@ -144,14 +144,14 @@ func (suite *LocalhostTestSuite) TestVerifyConnectionState() {
},
{
name: "proof verification failed: connection not stored",
clientState: types.NewClientState("chainID", 10),
clientState: types.NewClientState("chainID", clientHeight),
malleate: func() {},
connection: conn1,
expPass: false,
},
{
name: "proof verification failed: unmarshal error",
clientState: types.NewClientState("chainID", 10),
clientState: types.NewClientState("chainID", clientHeight),
malleate: func() {
suite.store.Set(host.KeyConnection(testConnectionID), []byte("connection"))
},
@ -160,7 +160,7 @@ func (suite *LocalhostTestSuite) TestVerifyConnectionState() {
},
{
name: "proof verification failed: different connection stored",
clientState: types.NewClientState("chainID", 10),
clientState: types.NewClientState("chainID", clientHeight),
malleate: func() {
bz, err := suite.cdc.MarshalBinaryBare(&conn2)
suite.Require().NoError(err)
@ -205,7 +205,7 @@ func (suite *LocalhostTestSuite) TestVerifyChannelState() {
}{
{
name: "proof verification success",
clientState: types.NewClientState("chainID", 10),
clientState: types.NewClientState("chainID", clientHeight),
malleate: func() {
bz, err := suite.cdc.MarshalBinaryBare(&ch1)
suite.Require().NoError(err)
@ -216,14 +216,14 @@ func (suite *LocalhostTestSuite) TestVerifyChannelState() {
},
{
name: "proof verification failed: channel not stored",
clientState: types.NewClientState("chainID", 10),
clientState: types.NewClientState("chainID", clientHeight),
malleate: func() {},
channel: ch1,
expPass: false,
},
{
name: "proof verification failed: unmarshal failed",
clientState: types.NewClientState("chainID", 10),
clientState: types.NewClientState("chainID", clientHeight),
malleate: func() {
suite.store.Set(host.KeyChannel(testPortID, testChannelID), []byte("channel"))
@ -233,7 +233,7 @@ func (suite *LocalhostTestSuite) TestVerifyChannelState() {
},
{
name: "proof verification failed: different channel stored",
clientState: types.NewClientState("chainID", 10),
clientState: types.NewClientState("chainID", clientHeight),
malleate: func() {
bz, err := suite.cdc.MarshalBinaryBare(&ch2)
suite.Require().NoError(err)
@ -275,7 +275,7 @@ func (suite *LocalhostTestSuite) TestVerifyPacketCommitment() {
}{
{
name: "proof verification success",
clientState: types.NewClientState("chainID", 10),
clientState: types.NewClientState("chainID", clientHeight),
malleate: func() {
suite.store.Set(
host.KeyPacketCommitment(testPortID, testChannelID, testSequence), []byte("commitment"),
@ -286,7 +286,7 @@ func (suite *LocalhostTestSuite) TestVerifyPacketCommitment() {
},
{
name: "proof verification failed: different commitment stored",
clientState: types.NewClientState("chainID", 10),
clientState: types.NewClientState("chainID", clientHeight),
malleate: func() {
suite.store.Set(
host.KeyPacketCommitment(testPortID, testChannelID, testSequence), []byte("different"),
@ -297,7 +297,7 @@ func (suite *LocalhostTestSuite) TestVerifyPacketCommitment() {
},
{
name: "proof verification failed: no commitment stored",
clientState: types.NewClientState("chainID", 10),
clientState: types.NewClientState("chainID", clientHeight),
malleate: func() {},
commitment: []byte{},
expPass: false,
@ -334,7 +334,7 @@ func (suite *LocalhostTestSuite) TestVerifyPacketAcknowledgement() {
}{
{
name: "proof verification success",
clientState: types.NewClientState("chainID", 10),
clientState: types.NewClientState("chainID", clientHeight),
malleate: func() {
suite.store.Set(
host.KeyPacketAcknowledgement(testPortID, testChannelID, testSequence), []byte("acknowledgement"),
@ -345,7 +345,7 @@ func (suite *LocalhostTestSuite) TestVerifyPacketAcknowledgement() {
},
{
name: "proof verification failed: different ack stored",
clientState: types.NewClientState("chainID", 10),
clientState: types.NewClientState("chainID", clientHeight),
malleate: func() {
suite.store.Set(
host.KeyPacketAcknowledgement(testPortID, testChannelID, testSequence), []byte("different"),
@ -356,7 +356,7 @@ func (suite *LocalhostTestSuite) TestVerifyPacketAcknowledgement() {
},
{
name: "proof verification failed: no commitment stored",
clientState: types.NewClientState("chainID", 10),
clientState: types.NewClientState("chainID", clientHeight),
malleate: func() {},
ack: []byte{},
expPass: false,
@ -384,7 +384,7 @@ func (suite *LocalhostTestSuite) TestVerifyPacketAcknowledgement() {
}
func (suite *LocalhostTestSuite) TestVerifyPacketAcknowledgementAbsence() {
clientState := types.NewClientState("chainID", 10)
clientState := types.NewClientState("chainID", clientHeight)
err := clientState.VerifyPacketAcknowledgementAbsence(
suite.store, suite.cdc, height, nil, nil, testPortID, testChannelID, testSequence,
@ -412,7 +412,7 @@ func (suite *LocalhostTestSuite) TestVerifyNextSeqRecv() {
}{
{
name: "proof verification success",
clientState: types.NewClientState("chainID", 10),
clientState: types.NewClientState("chainID", clientHeight),
malleate: func() {
suite.store.Set(
host.KeyNextSequenceRecv(testPortID, testChannelID),
@ -424,7 +424,7 @@ func (suite *LocalhostTestSuite) TestVerifyNextSeqRecv() {
},
{
name: "proof verification failed: different nextSeqRecv stored",
clientState: types.NewClientState("chainID", 10),
clientState: types.NewClientState("chainID", clientHeight),
malleate: func() {
suite.store.Set(
host.KeyNextSequenceRecv(testPortID, testChannelID),
@ -436,7 +436,7 @@ func (suite *LocalhostTestSuite) TestVerifyNextSeqRecv() {
},
{
name: "proof verification failed: no nextSeqRecv stored",
clientState: types.NewClientState("chainID", 10),
clientState: types.NewClientState("chainID", clientHeight),
malleate: func() {},
nextSeqRecv: nextSeqRecv,
expPass: false,

View File

@ -6,6 +6,7 @@ package types
import (
fmt "fmt"
github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types"
types "github.com/cosmos/cosmos-sdk/x/ibc/02-client/types"
_ "github.com/gogo/protobuf/gogoproto"
proto "github.com/gogo/protobuf/proto"
io "io"
@ -70,7 +71,7 @@ type ClientState struct {
// self chain ID
ChainId string `protobuf:"bytes,2,opt,name=chain_id,json=chainId,proto3" json:"chain_id,omitempty" yaml:"chain_id"`
// self latest block height
Height uint64 `protobuf:"varint,3,opt,name=height,proto3" json:"height,omitempty"`
Height types.Height `protobuf:"bytes,3,opt,name=height,proto3" json:"height"`
}
func (m *ClientState) Reset() { *m = ClientState{} }
@ -114,26 +115,27 @@ func init() {
func init() { proto.RegisterFile("ibc/localhost/localhost.proto", fileDescriptor_6a04d924e6f8a88e) }
var fileDescriptor_6a04d924e6f8a88e = []byte{
// 289 bytes of a gzipped FileDescriptorProto
// 317 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0xcd, 0x4c, 0x4a, 0xd6,
0xcf, 0xc9, 0x4f, 0x4e, 0xcc, 0xc9, 0xc8, 0x2f, 0x2e, 0x41, 0xb0, 0xf4, 0x0a, 0x8a, 0xf2,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 0x49, 0x2c, 0x49, 0x15, 0xe2, 0xe3, 0x62, 0xca, 0x4c, 0x01, 0x1b, 0xce, 0x19,
0xc4, 0x94, 0x99, 0x22, 0xa4, 0xc7, 0xc5, 0x91, 0x9c, 0x91, 0x98, 0x99, 0x17, 0x9f, 0x99, 0x22,
0xc1, 0x04, 0x12, 0x75, 0x12, 0xfe, 0x74, 0x4f, 0x9e, 0xbf, 0x32, 0x31, 0x37, 0xc7, 0x4a, 0x09,
0x26, 0xa3, 0x14, 0xc4, 0x0e, 0x66, 0x7a, 0xa6, 0x08, 0x19, 0x70, 0xb1, 0x65, 0xa4, 0x66, 0xa6,
0x67, 0x94, 0x48, 0x30, 0x2b, 0x30, 0x6a, 0x70, 0x1b, 0x09, 0xe9, 0x81, 0x82, 0x00, 0xea, 0x2d,
0x0f, 0xb0, 0x8c, 0x13, 0xcb, 0x89, 0x7b, 0xf2, 0x0c, 0x41, 0x50, 0x75, 0x10, 0x77, 0x38, 0xf9,
0x9f, 0x78, 0x24, 0xc7, 0x78, 0xe1, 0x91, 0x1c, 0xe3, 0x83, 0x47, 0x72, 0x8c, 0x13, 0x1e, 0xcb,
0x31, 0x5c, 0x78, 0x2c, 0xc7, 0x70, 0xe3, 0xb1, 0x1c, 0x43, 0x94, 0x29, 0x5e, 0xef, 0x55, 0xe8,
0x83, 0x42, 0xcf, 0xc0, 0x52, 0x17, 0x11, 0x09, 0x60, 0x1f, 0x27, 0xb1, 0x81, 0xc3, 0xd0, 0x18,
0x10, 0x00, 0x00, 0xff, 0xff, 0x8d, 0x4e, 0x4d, 0x60, 0xa2, 0x01, 0x00, 0x00,
}
func (m *MsgCreateClient) Marshal() (dAtA []byte, err error) {
@ -186,11 +188,16 @@ func (m *ClientState) MarshalToSizedBuffer(dAtA []byte) (int, error) {
_ = i
var l int
_ = l
if m.Height != 0 {
i = encodeVarintLocalhost(dAtA, i, uint64(m.Height))
i--
dAtA[i] = 0x18
{
size, err := m.Height.MarshalToSizedBuffer(dAtA[:i])
if err != nil {
return 0, err
}
i -= size
i = encodeVarintLocalhost(dAtA, i, uint64(size))
}
i--
dAtA[i] = 0x1a
if len(m.ChainId) > 0 {
i -= len(m.ChainId)
copy(dAtA[i:], m.ChainId)
@ -246,9 +253,8 @@ func (m *ClientState) Size() (n int) {
if l > 0 {
n += 1 + l + sovLocalhost(uint64(l))
}
if m.Height != 0 {
n += 1 + sovLocalhost(uint64(m.Height))
}
l = m.Height.Size()
n += 1 + l + sovLocalhost(uint64(l))
return n
}
@ -439,10 +445,10 @@ func (m *ClientState) Unmarshal(dAtA []byte) error {
m.ChainId = string(dAtA[iNdEx:postIndex])
iNdEx = postIndex
case 3:
if wireType != 0 {
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field Height", wireType)
}
m.Height = 0
var msglen int
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowLocalhost
@ -452,11 +458,25 @@ func (m *ClientState) Unmarshal(dAtA []byte) error {
}
b := dAtA[iNdEx]
iNdEx++
m.Height |= uint64(b&0x7F) << shift
msglen |= int(b&0x7F) << shift
if b < 0x80 {
break
}
}
if msglen < 0 {
return ErrInvalidLengthLocalhost
}
postIndex := iNdEx + msglen
if postIndex < 0 {
return ErrInvalidLengthLocalhost
}
if postIndex > l {
return io.ErrUnexpectedEOF
}
if err := m.Height.Unmarshal(dAtA[iNdEx:postIndex]); err != nil {
return err
}
iNdEx = postIndex
default:
iNdEx = preIndex
skippy, err := skipLocalhost(dAtA[iNdEx:])

View File

@ -10,12 +10,17 @@ import (
"github.com/cosmos/cosmos-sdk/simapp"
sdk "github.com/cosmos/cosmos-sdk/types"
clientexported "github.com/cosmos/cosmos-sdk/x/ibc/02-client/exported"
clienttypes "github.com/cosmos/cosmos-sdk/x/ibc/02-client/types"
)
const (
height = 4
)
var (
clientHeight = clienttypes.NewHeight(0, 10)
)
type LocalhostTestSuite struct {
suite.Suite

View File

@ -37,10 +37,10 @@ func (suite *IBCTestSuite) TestValidateGenesis() {
ClientGenesis: clienttypes.NewGenesisState(
[]clienttypes.IdentifiedClientState{
clienttypes.NewIdentifiedClientState(
clientID, ibctmtypes.NewClientState(chainID, ibctmtypes.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, height, commitmenttypes.GetSDKSpecs()),
clientID, ibctmtypes.NewClientState(chainID, ibctmtypes.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, clientHeight, commitmenttypes.GetSDKSpecs()),
),
clienttypes.NewIdentifiedClientState(
clientexported.ClientTypeLocalHost, localhosttypes.NewClientState("chaindID", 10),
clientexported.ClientTypeLocalHost, localhosttypes.NewClientState("chaindID", clientHeight),
),
},
[]clienttypes.ClientConsensusStates{
@ -48,7 +48,7 @@ func (suite *IBCTestSuite) TestValidateGenesis() {
clientID,
[]clientexported.ConsensusState{
ibctmtypes.NewConsensusState(
suite.header.GetTime(), commitmenttypes.NewMerkleRoot(suite.header.Header.AppHash), suite.header.GetHeight(), suite.header.Header.NextValidatorsHash,
suite.header.GetTime(), commitmenttypes.NewMerkleRoot(suite.header.Header.AppHash), clienttypes.NewHeight(0, suite.header.GetHeight()), suite.header.Header.NextValidatorsHash,
),
},
),
@ -97,10 +97,10 @@ func (suite *IBCTestSuite) TestValidateGenesis() {
ClientGenesis: clienttypes.NewGenesisState(
[]clienttypes.IdentifiedClientState{
clienttypes.NewIdentifiedClientState(
clientID, ibctmtypes.NewClientState(chainID, ibctmtypes.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, height, commitmenttypes.GetSDKSpecs()),
clientID, ibctmtypes.NewClientState(chainID, ibctmtypes.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, clientHeight, commitmenttypes.GetSDKSpecs()),
),
clienttypes.NewIdentifiedClientState(
clientexported.ClientTypeLocalHost, localhosttypes.NewClientState("(chaindID)", 0),
clientexported.ClientTypeLocalHost, localhosttypes.NewClientState("(chaindID)", clienttypes.Height{}),
),
},
nil,
@ -166,10 +166,10 @@ func (suite *IBCTestSuite) TestInitGenesis() {
ClientGenesis: clienttypes.NewGenesisState(
[]clienttypes.IdentifiedClientState{
clienttypes.NewIdentifiedClientState(
clientID, ibctmtypes.NewClientState(chainID, ibctmtypes.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, height, commitmenttypes.GetSDKSpecs()),
clientID, ibctmtypes.NewClientState(chainID, ibctmtypes.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, clientHeight, commitmenttypes.GetSDKSpecs()),
),
clienttypes.NewIdentifiedClientState(
clientexported.ClientTypeLocalHost, localhosttypes.NewClientState("chaindID", 10),
clientexported.ClientTypeLocalHost, localhosttypes.NewClientState("chaindID", clientHeight),
),
},
[]clienttypes.ClientConsensusStates{
@ -177,7 +177,7 @@ func (suite *IBCTestSuite) TestInitGenesis() {
clientID,
[]clientexported.ConsensusState{
ibctmtypes.NewConsensusState(
suite.header.GetTime(), commitmenttypes.NewMerkleRoot(suite.header.Header.AppHash), suite.header.GetHeight(), suite.header.Header.NextValidatorsHash,
suite.header.GetTime(), commitmenttypes.NewMerkleRoot(suite.header.Header.AppHash), clienttypes.NewHeight(0, suite.header.GetHeight()), suite.header.Header.NextValidatorsHash,
),
},
),

View File

@ -10,6 +10,7 @@ import (
"github.com/cosmos/cosmos-sdk/simapp"
sdk "github.com/cosmos/cosmos-sdk/types"
clienttypes "github.com/cosmos/cosmos-sdk/x/ibc/02-client/types"
channeltypes "github.com/cosmos/cosmos-sdk/x/ibc/04-channel/types"
ibctmtypes "github.com/cosmos/cosmos-sdk/x/ibc/07-tendermint/types"
)
@ -38,6 +39,8 @@ const (
maxClockDrift time.Duration = time.Second * 10
)
var clientHeight = clienttypes.NewHeight(0, 10)
type IBCTestSuite struct {
suite.Suite

View File

@ -8,6 +8,7 @@ import (
"github.com/cosmos/cosmos-sdk/simapp"
"github.com/cosmos/cosmos-sdk/types/kv"
clienttypes "github.com/cosmos/cosmos-sdk/x/ibc/02-client/types"
connectiontypes "github.com/cosmos/cosmos-sdk/x/ibc/03-connection/types"
channeltypes "github.com/cosmos/cosmos-sdk/x/ibc/04-channel/types"
ibctmtypes "github.com/cosmos/cosmos-sdk/x/ibc/07-tendermint/types"
@ -25,7 +26,7 @@ func TestDecodeStore(t *testing.T) {
portID := "portidone"
clientState := &ibctmtypes.ClientState{
FrozenHeight: 10,
FrozenHeight: clienttypes.NewHeight(0, 10),
}
connection := connectiontypes.ConnectionEnd{
ClientId: "clientidone",

View File

@ -25,6 +25,7 @@ import (
capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types"
ibctransfertypes "github.com/cosmos/cosmos-sdk/x/ibc-transfer/types"
clientexported "github.com/cosmos/cosmos-sdk/x/ibc/02-client/exported"
clienttypes "github.com/cosmos/cosmos-sdk/x/ibc/02-client/types"
connectiontypes "github.com/cosmos/cosmos-sdk/x/ibc/03-connection/types"
channelexported "github.com/cosmos/cosmos-sdk/x/ibc/04-channel/exported"
channeltypes "github.com/cosmos/cosmos-sdk/x/ibc/04-channel/types"
@ -409,7 +410,9 @@ func (chain *TestChain) UpdateTMClient(counterparty *TestChain, clientID string)
}
}
// inject trusted fields into last header
header.TrustedHeight = trustedHeight
// for now assume epoch number is 0
// TODO: use clienttypes.Height once Header.GetHeight is updated
header.TrustedHeight = clienttypes.NewHeight(0, trustedHeight)
trustedVals, err := tmTrustedVals.ToProto()
if err != nil {

File diff suppressed because it is too large Load Diff