diff --git a/x/ibc/02-client/keeper/client_test.go b/x/ibc/02-client/keeper/client_test.go index fcc780d74..f20447cbd 100644 --- a/x/ibc/02-client/keeper/client_test.go +++ b/x/ibc/02-client/keeper/client_test.go @@ -5,6 +5,7 @@ import ( "fmt" "time" + lite "github.com/tendermint/tendermint/lite2" tmtypes "github.com/tendermint/tendermint/types" "github.com/cosmos/cosmos-sdk/x/ibc/02-client/exported" @@ -37,12 +38,12 @@ func (suite *KeeperTestSuite) TestCreateClient() { i := i if tc.expPanic { suite.Require().Panics(func() { - clientState, err := ibctmtypes.Initialize(tc.clientID, trustingPeriod, ubdPeriod, maxClockDrift, suite.header) + clientState, err := ibctmtypes.Initialize(tc.clientID, lite.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, suite.header) suite.Require().NoError(err, "err on client state initialization") suite.keeper.CreateClient(suite.ctx, clientState, suite.consensusState) }, "Msg %d didn't panic: %s", i, tc.msg) } else { - clientState, err := ibctmtypes.Initialize(tc.clientID, trustingPeriod, ubdPeriod, maxClockDrift, suite.header) + clientState, err := ibctmtypes.Initialize(tc.clientID, lite.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, suite.header) if tc.expPass { suite.Require().NoError(err, "errored on initialization") suite.Require().NotNil(clientState, "valid test case %d failed: %s", i, tc.msg) @@ -79,7 +80,7 @@ func (suite *KeeperTestSuite) TestUpdateClientTendermint() { expPass bool }{ {"valid update", func() error { - clientState, err := ibctmtypes.Initialize(testClientID, trustingPeriod, ubdPeriod, maxClockDrift, suite.header) + clientState, err := ibctmtypes.Initialize(testClientID, lite.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, suite.header) if err != nil { return err } @@ -113,7 +114,7 @@ func (suite *KeeperTestSuite) TestUpdateClientTendermint() { return nil }, false}, {"invalid header", func() error { - clientState, err := ibctmtypes.Initialize(testClientID, trustingPeriod, ubdPeriod, maxClockDrift, suite.header) + clientState, err := ibctmtypes.Initialize(testClientID, lite.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, suite.header) if err != nil { return err } @@ -228,7 +229,7 @@ func (suite *KeeperTestSuite) TestCheckMisbehaviourAndUpdateState() { }, func() error { suite.consensusState.ValidatorSet = bothValSet - clientState, err := ibctmtypes.Initialize(testClientID, trustingPeriod, ubdPeriod, maxClockDrift, suite.header) + clientState, err := ibctmtypes.Initialize(testClientID, lite.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, suite.header) if err != nil { return err } @@ -248,7 +249,7 @@ func (suite *KeeperTestSuite) TestCheckMisbehaviourAndUpdateState() { }, func() error { suite.consensusState.ValidatorSet = bothValSet - clientState, err := ibctmtypes.Initialize(testClientID, trustingPeriod, ubdPeriod, maxClockDrift, suite.header) + clientState, err := ibctmtypes.Initialize(testClientID, lite.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, suite.header) if err != nil { return err } @@ -303,7 +304,7 @@ func (suite *KeeperTestSuite) TestCheckMisbehaviourAndUpdateState() { ClientID: testClientID, }, func() error { - clientState, err := ibctmtypes.Initialize(testClientID, trustingPeriod, ubdPeriod, maxClockDrift, suite.header) + clientState, err := ibctmtypes.Initialize(testClientID, lite.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, suite.header) if err != nil { return err } diff --git a/x/ibc/02-client/keeper/keeper_test.go b/x/ibc/02-client/keeper/keeper_test.go index deb7b45b5..a959c7df3 100644 --- a/x/ibc/02-client/keeper/keeper_test.go +++ b/x/ibc/02-client/keeper/keeper_test.go @@ -8,6 +8,7 @@ import ( "github.com/stretchr/testify/suite" abci "github.com/tendermint/tendermint/abci/types" + lite "github.com/tendermint/tendermint/lite2" tmtypes "github.com/tendermint/tendermint/types" "github.com/cosmos/cosmos-sdk/codec" @@ -89,7 +90,7 @@ func TestKeeperTestSuite(t *testing.T) { } func (suite *KeeperTestSuite) TestSetClientState() { - clientState := ibctmtypes.NewClientState(testClientID, trustingPeriod, ubdPeriod, maxClockDrift, ibctmtypes.Header{}) + clientState := ibctmtypes.NewClientState(testClientID, lite.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, ibctmtypes.Header{}) suite.keeper.SetClientState(suite.ctx, clientState) retrievedState, found := suite.keeper.GetClientState(suite.ctx, testClientID) @@ -120,9 +121,9 @@ func (suite *KeeperTestSuite) TestSetClientConsensusState() { func (suite KeeperTestSuite) TestGetAllClients() { expClients := []exported.ClientState{ - ibctmtypes.NewClientState(testClientID2, trustingPeriod, ubdPeriod, maxClockDrift, ibctmtypes.Header{}), - ibctmtypes.NewClientState(testClientID3, trustingPeriod, ubdPeriod, maxClockDrift, ibctmtypes.Header{}), - ibctmtypes.NewClientState(testClientID, trustingPeriod, ubdPeriod, maxClockDrift, ibctmtypes.Header{}), + ibctmtypes.NewClientState(testClientID2, lite.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, ibctmtypes.Header{}), + ibctmtypes.NewClientState(testClientID3, lite.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, ibctmtypes.Header{}), + ibctmtypes.NewClientState(testClientID, lite.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, ibctmtypes.Header{}), } for i := range expClients { @@ -167,7 +168,7 @@ func (suite KeeperTestSuite) TestGetConsensusState() { func (suite KeeperTestSuite) TestConsensusStateHelpers() { // initial setup - clientState, err := ibctmtypes.Initialize(testClientID, trustingPeriod, ubdPeriod, maxClockDrift, suite.header) + clientState, err := ibctmtypes.Initialize(testClientID, lite.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, suite.header) suite.Require().NoError(err) suite.keeper.SetClientState(suite.ctx, clientState) diff --git a/x/ibc/02-client/types/genesis_test.go b/x/ibc/02-client/types/genesis_test.go index 53d32fecb..4d494b199 100644 --- a/x/ibc/02-client/types/genesis_test.go +++ b/x/ibc/02-client/types/genesis_test.go @@ -6,6 +6,7 @@ import ( "github.com/stretchr/testify/require" + lite "github.com/tendermint/tendermint/lite2" tmtypes "github.com/tendermint/tendermint/types" "github.com/cosmos/cosmos-sdk/x/ibc/02-client/exported" @@ -49,7 +50,7 @@ func TestValidateGenesis(t *testing.T) { name: "valid genesis", genState: types.NewGenesisState( []exported.ClientState{ - ibctmtypes.NewClientState(clientID, trustingPeriod, ubdPeriod, maxClockDrift, header), + ibctmtypes.NewClientState(clientID, lite.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, header), localhosttypes.NewClientState("chaindID", 10), }, []types.ClientConsensusStates{ @@ -70,7 +71,7 @@ func TestValidateGenesis(t *testing.T) { name: "invalid client", genState: types.NewGenesisState( []exported.ClientState{ - ibctmtypes.NewClientState(clientID, trustingPeriod, ubdPeriod, maxClockDrift, header), + ibctmtypes.NewClientState(clientID, lite.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, header), localhosttypes.NewClientState("chaindID", 0), }, nil, @@ -82,7 +83,7 @@ func TestValidateGenesis(t *testing.T) { name: "invalid consensus state", genState: types.NewGenesisState( []exported.ClientState{ - ibctmtypes.NewClientState(clientID, trustingPeriod, ubdPeriod, maxClockDrift, header), + ibctmtypes.NewClientState(clientID, lite.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, header), localhosttypes.NewClientState("chaindID", 10), }, []types.ClientConsensusStates{ @@ -103,7 +104,7 @@ func TestValidateGenesis(t *testing.T) { name: "invalid consensus state", genState: types.NewGenesisState( []exported.ClientState{ - ibctmtypes.NewClientState(clientID, trustingPeriod, ubdPeriod, maxClockDrift, header), + ibctmtypes.NewClientState(clientID, lite.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, header), localhosttypes.NewClientState("chaindID", 10), }, []types.ClientConsensusStates{ diff --git a/x/ibc/03-connection/keeper/keeper_test.go b/x/ibc/03-connection/keeper/keeper_test.go index 2284209e0..6bfc88382 100644 --- a/x/ibc/03-connection/keeper/keeper_test.go +++ b/x/ibc/03-connection/keeper/keeper_test.go @@ -8,6 +8,7 @@ import ( "github.com/stretchr/testify/suite" abci "github.com/tendermint/tendermint/abci/types" + lite "github.com/tendermint/tendermint/lite2" tmtypes "github.com/tendermint/tendermint/types" "github.com/cosmos/cosmos-sdk/codec" @@ -128,9 +129,9 @@ func (suite KeeperTestSuite) TestGetAllConnections() { func (suite KeeperTestSuite) TestGetAllClientConnectionPaths() { clients := []clientexported.ClientState{ - ibctmtypes.NewClientState(testClientIDA, trustingPeriod, ubdPeriod, maxClockDrift, ibctmtypes.Header{}), - ibctmtypes.NewClientState(testClientIDB, trustingPeriod, ubdPeriod, maxClockDrift, ibctmtypes.Header{}), - ibctmtypes.NewClientState(testClientID3, trustingPeriod, ubdPeriod, maxClockDrift, ibctmtypes.Header{}), + ibctmtypes.NewClientState(testClientIDA, lite.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, ibctmtypes.Header{}), + ibctmtypes.NewClientState(testClientIDB, lite.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, ibctmtypes.Header{}), + ibctmtypes.NewClientState(testClientID3, lite.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, ibctmtypes.Header{}), } for i := range clients { @@ -260,7 +261,7 @@ func (chain *TestChain) CreateClient(client *TestChain) error { ctxTarget := chain.GetContext() // create client - clientState, err := ibctmtypes.Initialize(client.ClientID, trustingPeriod, ubdPeriod, maxClockDrift, client.Header) + clientState, err := ibctmtypes.Initialize(client.ClientID, lite.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, client.Header) if err != nil { return err } @@ -336,7 +337,7 @@ func (chain *TestChain) updateClient(client *TestChain) { ctxTarget, client.ClientID, client.Header.GetHeight(), consensusState, ) chain.App.IBCKeeper.ClientKeeper.SetClientState( - ctxTarget, ibctmtypes.NewClientState(client.ClientID, trustingPeriod, ubdPeriod, maxClockDrift, client.Header), + ctxTarget, ibctmtypes.NewClientState(client.ClientID, lite.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, client.Header), ) // _, _, err := simapp.SignCheckDeliver( diff --git a/x/ibc/04-channel/keeper/keeper_test.go b/x/ibc/04-channel/keeper/keeper_test.go index 63f777ae5..fd9a5ce5c 100644 --- a/x/ibc/04-channel/keeper/keeper_test.go +++ b/x/ibc/04-channel/keeper/keeper_test.go @@ -9,6 +9,7 @@ import ( "github.com/stretchr/testify/suite" abci "github.com/tendermint/tendermint/abci/types" + lite "github.com/tendermint/tendermint/lite2" tmtypes "github.com/tendermint/tendermint/types" "github.com/cosmos/cosmos-sdk/codec" @@ -316,7 +317,7 @@ func (chain *TestChain) CreateClient(client *TestChain) error { ctxTarget := chain.GetContext() // create client - clientState, err := ibctmtypes.Initialize(client.ClientID, trustingPeriod, ubdPeriod, maxClockDrift, client.Header) + clientState, err := ibctmtypes.Initialize(client.ClientID, lite.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, client.Header) if err != nil { return err } @@ -384,7 +385,7 @@ func (chain *TestChain) updateClient(client *TestChain) { ctxTarget, client.ClientID, client.Header.GetHeight(), consensusState, ) chain.App.IBCKeeper.ClientKeeper.SetClientState( - ctxTarget, ibctmtypes.NewClientState(client.ClientID, trustingPeriod, ubdPeriod, maxClockDrift, client.Header), + ctxTarget, ibctmtypes.NewClientState(client.ClientID, lite.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, client.Header), ) // _, _, err := simapp.SignCheckDeliver( diff --git a/x/ibc/07-tendermint/client/cli/tx.go b/x/ibc/07-tendermint/client/cli/tx.go index 8cb780505..dad457164 100644 --- a/x/ibc/07-tendermint/client/cli/tx.go +++ b/x/ibc/07-tendermint/client/cli/tx.go @@ -4,12 +4,17 @@ import ( "bufio" "fmt" "io/ioutil" + "strconv" "strings" "time" "github.com/pkg/errors" "github.com/spf13/cobra" + "github.com/spf13/viper" + + tmmath "github.com/tendermint/tendermint/libs/math" + lite "github.com/tendermint/tendermint/lite2" "github.com/cosmos/cosmos-sdk/client/context" "github.com/cosmos/cosmos-sdk/client/flags" @@ -22,19 +27,17 @@ import ( ibctmtypes "github.com/cosmos/cosmos-sdk/x/ibc/07-tendermint/types" ) +const flagTrustLevel = "trust-level" + // GetCmdCreateClient defines the command to create a new IBC Client as defined // in https://github.com/cosmos/ics/tree/master/spec/ics-002-client-semantics#create func GetCmdCreateClient(cdc *codec.Codec) *cobra.Command { cmd := &cobra.Command{ - Use: "create [client-id] [path/to/consensus_state.json] [trusting_period] [unbonding_period] [max_clock_drift]", - Short: "create new client with a consensus state", - Long: strings.TrimSpace(fmt.Sprintf(`create new client with a specified identifier and consensus state: - -Example: -$ %s tx ibc client create [client-id] [path/to/consensus_state.json] [trusting_period] [unbonding_period] [max_clock_drift] --from node0 --home ../node0/cli --chain-id $CID - `, version.ClientName), - ), - Args: cobra.ExactArgs(5), + Use: "create [client-id] [path/to/consensus_state.json] [trusting_period] [unbonding_period] [max_clock_drift]", + Short: "create new tendermint client", + Long: "create new tendermint client. Trust level can be a fraction (eg: '1/3') or 'default'", + Example: fmt.Sprintf("%s tx ibc client create [client-id] [path/to/consensus_state.json] [trusting_period] [unbonding_period] [max_clock_drift] --trust-level default --from node0 --home ../node0/cli --chain-id $CID", version.ClientName), + Args: cobra.ExactArgs(6), RunE: func(cmd *cobra.Command, args []string) error { inBuf := bufio.NewReader(cmd.InOrStdin()) txBldr := authtypes.NewTxBuilderFromCLI(inBuf).WithTxEncoder(authclient.GetTxEncoder(cdc)) @@ -54,23 +57,39 @@ $ %s tx ibc client create [client-id] [path/to/consensus_state.json] [trusting_p } } - trustingPeriod, err := time.ParseDuration(args[2]) + var ( + trustLevel tmmath.Fraction + err error + ) + + lvl := viper.GetString(flagTrustLevel) + + if lvl == "default" { + trustLevel = lite.DefaultTrustLevel + } else { + trustLevel, err = parseFraction(args[2]) + if err != nil { + return err + } + } + + trustingPeriod, err := time.ParseDuration(args[3]) if err != nil { return err } - ubdPeriod, err := time.ParseDuration(args[3]) + ubdPeriod, err := time.ParseDuration(args[4]) if err != nil { return err } - maxClockDrift, err := time.ParseDuration(args[4]) + maxClockDrift, err := time.ParseDuration(args[5]) if err != nil { return err } msg := ibctmtypes.NewMsgCreateClient( - clientID, header, trustingPeriod, ubdPeriod, maxClockDrift, cliCtx.GetFromAddress(), + clientID, header, trustLevel, trustingPeriod, ubdPeriod, maxClockDrift, cliCtx.GetFromAddress(), ) if err := msg.ValidateBasic(); err != nil { @@ -80,7 +99,7 @@ $ %s tx ibc client create [client-id] [path/to/consensus_state.json] [trusting_p return authclient.GenerateOrBroadcastMsgs(cliCtx, txBldr, []sdk.Msg{msg}) }, } - + cmd.Flags().String(flagTrustLevel, "default", "light client trust level fraction for header updates") return cmd } @@ -170,3 +189,25 @@ $ %s tx ibc client misbehaviour [path/to/evidence.json] --from node0 --home ../n return cmd } + +func parseFraction(fraction string) (tmmath.Fraction, error) { + fr := strings.Split(fraction, "/") + if len(fr) != 2 || fr[0] == fraction { + return tmmath.Fraction{}, fmt.Errorf("fraction must have format 'numerator/denominator' got %s", fraction) + } + + numerator, err := strconv.ParseInt(fr[0], 10, 64) + if err != nil { + return tmmath.Fraction{}, fmt.Errorf("invalid trust-level numerator: %w", err) + } + + denominator, err := strconv.ParseInt(fr[1], 10, 64) + if err != nil { + return tmmath.Fraction{}, fmt.Errorf("invalid trust-level denominator: %w", err) + } + + return tmmath.Fraction{ + Numerator: numerator, + Denominator: denominator, + }, nil +} diff --git a/x/ibc/07-tendermint/client/rest/rest.go b/x/ibc/07-tendermint/client/rest/rest.go index afe1efda4..bac3487d4 100644 --- a/x/ibc/07-tendermint/client/rest/rest.go +++ b/x/ibc/07-tendermint/client/rest/rest.go @@ -5,6 +5,8 @@ import ( "github.com/gorilla/mux" + tmmath "github.com/tendermint/tendermint/libs/math" + "github.com/cosmos/cosmos-sdk/client/context" "github.com/cosmos/cosmos-sdk/types/rest" evidenceexported "github.com/cosmos/cosmos-sdk/x/evidence/exported" @@ -27,7 +29,8 @@ type CreateClientReq struct { BaseReq rest.BaseReq `json:"base_req" yaml:"base_req"` ClientID string `json:"client_id" yaml:"client_id"` ChainID string `json:"chain_id" yaml:"chain_id"` - Header ibctmtypes.Header `json:"consensus_state" yaml:"consensus_state"` + Header ibctmtypes.Header `json:"header" yaml:"header"` + TrustLevel tmmath.Fraction `json:"trust_level" yaml:"trust_level"` TrustingPeriod time.Duration `json:"trusting_period" yaml:"trusting_period"` UnbondingPeriod time.Duration `json:"unbonding_period" yaml:"unbonding_period"` MaxClockDrift time.Duration `json:"max_clock_drift" yaml:"max_clock_drift"` diff --git a/x/ibc/07-tendermint/client/rest/tx.go b/x/ibc/07-tendermint/client/rest/tx.go index 1e2458d5d..b0646a887 100644 --- a/x/ibc/07-tendermint/client/rest/tx.go +++ b/x/ibc/07-tendermint/client/rest/tx.go @@ -17,7 +17,7 @@ import ( func registerTxRoutes(cliCtx context.CLIContext, r *mux.Router) { r.HandleFunc("/ibc/clients/tendermint", createClientHandlerFn(cliCtx)).Methods("POST") r.HandleFunc(fmt.Sprintf("/ibc/clients/{%s}/update", RestClientID), updateClientHandlerFn(cliCtx)).Methods("POST") - r.HandleFunc("/ibc/clients/{%s}/misbehaviour", submitMisbehaviourHandlerFn(cliCtx)).Methods("POST") + r.HandleFunc(fmt.Sprintf("/ibc/clients/{%s}/misbehaviour", RestClientID), submitMisbehaviourHandlerFn(cliCtx)).Methods("POST") } // createClientHandlerFn implements a create client handler @@ -50,8 +50,7 @@ func createClientHandlerFn(cliCtx context.CLIContext) http.HandlerFunc { // create the message msg := ibctmtypes.NewMsgCreateClient( - req.ClientID, - req.Header, + req.ClientID, req.Header, req.TrustLevel, req.TrustingPeriod, req.UnbondingPeriod, req.MaxClockDrift, fromAddr, ) diff --git a/x/ibc/07-tendermint/misbehaviour_test.go b/x/ibc/07-tendermint/misbehaviour_test.go index 1965a7f30..d2237f266 100644 --- a/x/ibc/07-tendermint/misbehaviour_test.go +++ b/x/ibc/07-tendermint/misbehaviour_test.go @@ -5,6 +5,7 @@ import ( "time" "github.com/tendermint/tendermint/crypto/tmhash" + lite "github.com/tendermint/tendermint/lite2" tmtypes "github.com/tendermint/tendermint/types" tendermint "github.com/cosmos/cosmos-sdk/x/ibc/07-tendermint" @@ -48,7 +49,7 @@ func (suite *TendermintTestSuite) TestCheckMisbehaviour() { }{ { "valid misbehavior evidence", - ibctmtypes.NewClientState(chainID, trustingPeriod, ubdPeriod, maxClockDrift, suite.header), + ibctmtypes.NewClientState(chainID, lite.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, suite.header), ibctmtypes.ConsensusState{Timestamp: suite.now, Root: commitmenttypes.NewMerkleRoot(tmhash.Sum([]byte("app_hash"))), ValidatorSet: bothValSet}, ibctmtypes.Evidence{ Header1: ibctmtypes.CreateTestHeader(chainID, height, suite.now, bothValSet, bothSigners), @@ -61,7 +62,7 @@ func (suite *TendermintTestSuite) TestCheckMisbehaviour() { }, { "valid misbehavior at height greater than last consensusState", - ibctmtypes.NewClientState(chainID, trustingPeriod, ubdPeriod, maxClockDrift, suite.header), + ibctmtypes.NewClientState(chainID, lite.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, suite.header), ibctmtypes.ConsensusState{Timestamp: suite.now, Height: height - 1, Root: commitmenttypes.NewMerkleRoot(tmhash.Sum([]byte("app_hash"))), ValidatorSet: bothValSet}, ibctmtypes.Evidence{ Header1: ibctmtypes.CreateTestHeader(chainID, height, suite.now, bothValSet, bothSigners), @@ -74,7 +75,7 @@ func (suite *TendermintTestSuite) TestCheckMisbehaviour() { }, { "consensus state's valset hash different from evidence should still pass", - ibctmtypes.NewClientState(chainID, trustingPeriod, ubdPeriod, maxClockDrift, suite.header), + ibctmtypes.NewClientState(chainID, lite.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, suite.header), ibctmtypes.ConsensusState{Timestamp: suite.now, Height: height - 1, Root: commitmenttypes.NewMerkleRoot(tmhash.Sum([]byte("app_hash"))), ValidatorSet: suite.valSet}, ibctmtypes.Evidence{ Header1: ibctmtypes.CreateTestHeader(chainID, height, suite.now, bothValSet, bothSigners), @@ -87,7 +88,7 @@ func (suite *TendermintTestSuite) TestCheckMisbehaviour() { }, { "first valset has too much change", - ibctmtypes.NewClientState(chainID, trustingPeriod, ubdPeriod, maxClockDrift, suite.header), + ibctmtypes.NewClientState(chainID, lite.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, suite.header), ibctmtypes.ConsensusState{Timestamp: suite.now, Root: commitmenttypes.NewMerkleRoot(tmhash.Sum([]byte("app_hash"))), ValidatorSet: bothValSet}, ibctmtypes.Evidence{ Header1: ibctmtypes.CreateTestHeader(chainID, height, suite.now, altValSet, altSigners), @@ -100,7 +101,7 @@ func (suite *TendermintTestSuite) TestCheckMisbehaviour() { }, { "second valset has too much change", - ibctmtypes.NewClientState(chainID, trustingPeriod, ubdPeriod, maxClockDrift, suite.header), + ibctmtypes.NewClientState(chainID, lite.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, suite.header), ibctmtypes.ConsensusState{Timestamp: suite.now, Root: commitmenttypes.NewMerkleRoot(tmhash.Sum([]byte("app_hash"))), ValidatorSet: bothValSet}, ibctmtypes.Evidence{ Header1: ibctmtypes.CreateTestHeader(chainID, height, suite.now, bothValSet, bothSigners), @@ -113,7 +114,7 @@ func (suite *TendermintTestSuite) TestCheckMisbehaviour() { }, { "both valsets have too much change", - ibctmtypes.NewClientState(chainID, trustingPeriod, ubdPeriod, maxClockDrift, suite.header), + ibctmtypes.NewClientState(chainID, lite.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, suite.header), ibctmtypes.ConsensusState{Timestamp: suite.now, Root: commitmenttypes.NewMerkleRoot(tmhash.Sum([]byte("app_hash"))), ValidatorSet: bothValSet}, ibctmtypes.Evidence{ Header1: ibctmtypes.CreateTestHeader(chainID, height, suite.now, altValSet, altSigners), diff --git a/x/ibc/07-tendermint/types/client_state.go b/x/ibc/07-tendermint/types/client_state.go index 43fdbf93a..1a153c41e 100644 --- a/x/ibc/07-tendermint/types/client_state.go +++ b/x/ibc/07-tendermint/types/client_state.go @@ -18,6 +18,8 @@ import ( commitmenttypes "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/types" host "github.com/cosmos/cosmos-sdk/x/ibc/24-host" ibctypes "github.com/cosmos/cosmos-sdk/x/ibc/types" + tmmath "github.com/tendermint/tendermint/libs/math" + lite "github.com/tendermint/tendermint/lite2" ) var _ clientexported.ClientState = ClientState{} @@ -28,6 +30,8 @@ type ClientState struct { // Client ID ID string `json:"id" yaml:"id"` + TrustLevel tmmath.Fraction `json:"trust_level" yaml:"trust_level"` + // Duration of the period since the LastestTimestamp during which the // submitted headers are valid for upgrade TrustingPeriod time.Duration `json:"trusting_period" yaml:"trusting_period"` @@ -49,31 +53,37 @@ type ClientState struct { // InitializeFromMsg creates a tendermint client state from a CreateClientMsg func InitializeFromMsg(msg MsgCreateClient) (ClientState, error) { return Initialize( - msg.GetClientID(), msg.TrustingPeriod, msg.UnbondingPeriod, msg.MaxClockDrift, msg.Header, + msg.GetClientID(), msg.TrustLevel, + msg.TrustingPeriod, msg.UnbondingPeriod, msg.MaxClockDrift, + msg.Header, ) } // Initialize creates a client state and validates its contents, checking that // the provided consensus state is from the same client type. func Initialize( - id string, trustingPeriod, ubdPeriod, maxClockDrift time.Duration, header Header, + id string, trustLevel tmmath.Fraction, + trustingPeriod, ubdPeriod, maxClockDrift time.Duration, + header Header, ) (ClientState, error) { if trustingPeriod >= ubdPeriod { return ClientState{}, errors.New("trusting period should be < unbonding period") } - clientState := NewClientState(id, trustingPeriod, ubdPeriod, maxClockDrift, header) + clientState := NewClientState(id, trustLevel, trustingPeriod, ubdPeriod, maxClockDrift, header) return clientState, nil } // NewClientState creates a new ClientState instance func NewClientState( - id string, trustingPeriod, ubdPeriod, maxClockDrift time.Duration, header Header, + id string, trustLevel tmmath.Fraction, + trustingPeriod, ubdPeriod, maxClockDrift time.Duration, + header Header, ) ClientState { - return ClientState{ ID: id, + TrustLevel: trustLevel, TrustingPeriod: trustingPeriod, UnbondingPeriod: ubdPeriod, MaxClockDrift: maxClockDrift, @@ -120,6 +130,9 @@ func (cs ClientState) Validate() error { if err := host.DefaultClientIdentifierValidator(cs.ID); err != nil { return err } + if err := lite.ValidateTrustLevel(cs.TrustLevel); err != nil { + return err + } if cs.TrustingPeriod == 0 { return errors.New("trusting period cannot be zero") } diff --git a/x/ibc/07-tendermint/types/client_state_test.go b/x/ibc/07-tendermint/types/client_state_test.go index aafe47b0e..a7fd79503 100644 --- a/x/ibc/07-tendermint/types/client_state_test.go +++ b/x/ibc/07-tendermint/types/client_state_test.go @@ -7,6 +7,8 @@ import ( ibctmtypes "github.com/cosmos/cosmos-sdk/x/ibc/07-tendermint/types" commitmenttypes "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/types" ibctypes "github.com/cosmos/cosmos-sdk/x/ibc/types" + tmmath "github.com/tendermint/tendermint/libs/math" + lite "github.com/tendermint/tendermint/lite2" ) const ( @@ -25,32 +27,37 @@ func (suite *TendermintTestSuite) TestValidate() { }{ { name: "valid client", - clientState: ibctmtypes.NewClientState(testClientID, trustingPeriod, ubdPeriod, maxClockDrift, suite.header), + clientState: ibctmtypes.NewClientState(testClientID, lite.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, suite.header), expPass: true, }, { name: "invalid client id", - clientState: ibctmtypes.NewClientState("testClientID", trustingPeriod, ubdPeriod, maxClockDrift, suite.header), + clientState: ibctmtypes.NewClientState("testClientID", lite.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, suite.header), + expPass: false, + }, + { + name: "invalid trust level", + clientState: ibctmtypes.NewClientState(testClientID, tmmath.Fraction{Numerator: 0, Denominator: 1}, trustingPeriod, ubdPeriod, maxClockDrift, suite.header), expPass: false, }, { name: "invalid trusting period", - clientState: ibctmtypes.NewClientState(testClientID, 0, ubdPeriod, maxClockDrift, suite.header), + clientState: ibctmtypes.NewClientState(testClientID, lite.DefaultTrustLevel, 0, ubdPeriod, maxClockDrift, suite.header), expPass: false, }, { name: "invalid unbonding period", - clientState: ibctmtypes.NewClientState(testClientID, trustingPeriod, 0, maxClockDrift, suite.header), + clientState: ibctmtypes.NewClientState(testClientID, lite.DefaultTrustLevel, trustingPeriod, 0, maxClockDrift, suite.header), expPass: false, }, { name: "invalid max clock drift", - clientState: ibctmtypes.NewClientState(testClientID, trustingPeriod, ubdPeriod, 0, suite.header), + clientState: ibctmtypes.NewClientState(testClientID, lite.DefaultTrustLevel, trustingPeriod, ubdPeriod, 0, suite.header), expPass: false, }, { name: "invalid header", - clientState: ibctmtypes.NewClientState(testClientID, trustingPeriod, ubdPeriod, maxClockDrift, ibctmtypes.Header{}), + clientState: ibctmtypes.NewClientState(testClientID, lite.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, ibctmtypes.Header{}), expPass: false, }, } @@ -86,7 +93,7 @@ func (suite *TendermintTestSuite) TestVerifyClientConsensusState() { // }, { name: "ApplyPrefix failed", - clientState: ibctmtypes.NewClientState(chainID, trustingPeriod, ubdPeriod, maxClockDrift, suite.header), + clientState: ibctmtypes.NewClientState(chainID, lite.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, suite.header), consensusState: ibctmtypes.ConsensusState{ Root: commitmenttypes.NewMerkleRoot(suite.header.AppHash), }, @@ -95,7 +102,7 @@ func (suite *TendermintTestSuite) TestVerifyClientConsensusState() { }, { name: "latest client height < height", - clientState: ibctmtypes.NewClientState(chainID, trustingPeriod, ubdPeriod, maxClockDrift, suite.header), + clientState: ibctmtypes.NewClientState(chainID, lite.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, suite.header), consensusState: ibctmtypes.ConsensusState{ Root: commitmenttypes.NewMerkleRoot(suite.header.AppHash), }, @@ -113,7 +120,7 @@ func (suite *TendermintTestSuite) TestVerifyClientConsensusState() { }, { name: "proof verification failed", - clientState: ibctmtypes.NewClientState(chainID, trustingPeriod, ubdPeriod, maxClockDrift, suite.header), + clientState: ibctmtypes.NewClientState(chainID, lite.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, suite.header), consensusState: ibctmtypes.ConsensusState{ Root: commitmenttypes.NewMerkleRoot(suite.header.AppHash), ValidatorSet: suite.valSet, @@ -165,7 +172,7 @@ func (suite *TendermintTestSuite) TestVerifyConnectionState() { // }, { name: "ApplyPrefix failed", - clientState: ibctmtypes.NewClientState(chainID, trustingPeriod, ubdPeriod, maxClockDrift, suite.header), + clientState: ibctmtypes.NewClientState(chainID, lite.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, suite.header), connection: conn, consensusState: ibctmtypes.ConsensusState{ Root: commitmenttypes.NewMerkleRoot(suite.header.AppHash), @@ -175,7 +182,7 @@ func (suite *TendermintTestSuite) TestVerifyConnectionState() { }, { name: "latest client height < height", - clientState: ibctmtypes.NewClientState(chainID, trustingPeriod, ubdPeriod, maxClockDrift, suite.header), + clientState: ibctmtypes.NewClientState(chainID, lite.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, suite.header), connection: conn, consensusState: ibctmtypes.ConsensusState{ Root: commitmenttypes.NewMerkleRoot(suite.header.AppHash), @@ -195,7 +202,7 @@ func (suite *TendermintTestSuite) TestVerifyConnectionState() { }, { name: "proof verification failed", - clientState: ibctmtypes.NewClientState(chainID, trustingPeriod, ubdPeriod, maxClockDrift, suite.header), + clientState: ibctmtypes.NewClientState(chainID, lite.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, suite.header), connection: conn, consensusState: ibctmtypes.ConsensusState{ Root: commitmenttypes.NewMerkleRoot(suite.header.AppHash), @@ -248,7 +255,7 @@ func (suite *TendermintTestSuite) TestVerifyChannelState() { // }, { name: "ApplyPrefix failed", - clientState: ibctmtypes.NewClientState(chainID, trustingPeriod, ubdPeriod, maxClockDrift, suite.header), + clientState: ibctmtypes.NewClientState(chainID, lite.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, suite.header), channel: ch, consensusState: ibctmtypes.ConsensusState{ Root: commitmenttypes.NewMerkleRoot(suite.header.AppHash), @@ -258,7 +265,7 @@ func (suite *TendermintTestSuite) TestVerifyChannelState() { }, { name: "latest client height < height", - clientState: ibctmtypes.NewClientState(chainID, trustingPeriod, ubdPeriod, maxClockDrift, suite.header), + clientState: ibctmtypes.NewClientState(chainID, lite.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, suite.header), channel: ch, consensusState: ibctmtypes.ConsensusState{ Root: commitmenttypes.NewMerkleRoot(suite.header.AppHash), @@ -278,7 +285,7 @@ func (suite *TendermintTestSuite) TestVerifyChannelState() { }, { name: "proof verification failed", - clientState: ibctmtypes.NewClientState(chainID, trustingPeriod, ubdPeriod, maxClockDrift, suite.header), + clientState: ibctmtypes.NewClientState(chainID, lite.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, suite.header), channel: ch, consensusState: ibctmtypes.ConsensusState{ Root: commitmenttypes.NewMerkleRoot(suite.header.AppHash), @@ -328,7 +335,7 @@ func (suite *TendermintTestSuite) TestVerifyPacketCommitment() { // }, { name: "ApplyPrefix failed", - clientState: ibctmtypes.NewClientState(chainID, trustingPeriod, ubdPeriod, maxClockDrift, suite.header), + clientState: ibctmtypes.NewClientState(chainID, lite.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, suite.header), commitment: []byte{}, consensusState: ibctmtypes.ConsensusState{ Root: commitmenttypes.NewMerkleRoot(suite.header.AppHash), @@ -338,7 +345,7 @@ func (suite *TendermintTestSuite) TestVerifyPacketCommitment() { }, { name: "latest client height < height", - clientState: ibctmtypes.NewClientState(chainID, trustingPeriod, ubdPeriod, maxClockDrift, suite.header), + clientState: ibctmtypes.NewClientState(chainID, lite.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, suite.header), commitment: []byte{}, consensusState: ibctmtypes.ConsensusState{ Root: commitmenttypes.NewMerkleRoot(suite.header.AppHash), @@ -358,7 +365,7 @@ func (suite *TendermintTestSuite) TestVerifyPacketCommitment() { }, { name: "proof verification failed", - clientState: ibctmtypes.NewClientState(chainID, trustingPeriod, ubdPeriod, maxClockDrift, suite.header), + clientState: ibctmtypes.NewClientState(chainID, lite.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, suite.header), commitment: []byte{}, consensusState: ibctmtypes.ConsensusState{ Root: commitmenttypes.NewMerkleRoot(suite.header.AppHash), @@ -408,7 +415,7 @@ func (suite *TendermintTestSuite) TestVerifyPacketAcknowledgement() { // }, { name: "ApplyPrefix failed", - clientState: ibctmtypes.NewClientState(chainID, trustingPeriod, ubdPeriod, maxClockDrift, suite.header), + clientState: ibctmtypes.NewClientState(chainID, lite.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, suite.header), ack: []byte{}, consensusState: ibctmtypes.ConsensusState{ Root: commitmenttypes.NewMerkleRoot(suite.header.AppHash), @@ -418,7 +425,7 @@ func (suite *TendermintTestSuite) TestVerifyPacketAcknowledgement() { }, { name: "latest client height < height", - clientState: ibctmtypes.NewClientState(chainID, trustingPeriod, ubdPeriod, maxClockDrift, suite.header), + clientState: ibctmtypes.NewClientState(chainID, lite.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, suite.header), ack: []byte{}, consensusState: ibctmtypes.ConsensusState{ Root: commitmenttypes.NewMerkleRoot(suite.header.AppHash), @@ -438,7 +445,7 @@ func (suite *TendermintTestSuite) TestVerifyPacketAcknowledgement() { }, { name: "proof verification failed", - clientState: ibctmtypes.NewClientState(chainID, trustingPeriod, ubdPeriod, maxClockDrift, suite.header), + clientState: ibctmtypes.NewClientState(chainID, lite.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, suite.header), ack: []byte{}, consensusState: ibctmtypes.ConsensusState{ Root: commitmenttypes.NewMerkleRoot(suite.header.AppHash), @@ -487,7 +494,7 @@ func (suite *TendermintTestSuite) TestVerifyPacketAcknowledgementAbsence() { // }, { name: "ApplyPrefix failed", - clientState: ibctmtypes.NewClientState(chainID, trustingPeriod, ubdPeriod, maxClockDrift, suite.header), + clientState: ibctmtypes.NewClientState(chainID, lite.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, suite.header), consensusState: ibctmtypes.ConsensusState{ Root: commitmenttypes.NewMerkleRoot(suite.header.AppHash), }, @@ -496,7 +503,7 @@ func (suite *TendermintTestSuite) TestVerifyPacketAcknowledgementAbsence() { }, { name: "latest client height < height", - clientState: ibctmtypes.NewClientState(chainID, trustingPeriod, ubdPeriod, maxClockDrift, suite.header), + clientState: ibctmtypes.NewClientState(chainID, lite.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, suite.header), consensusState: ibctmtypes.ConsensusState{ Root: commitmenttypes.NewMerkleRoot(suite.header.AppHash), }, @@ -514,7 +521,7 @@ func (suite *TendermintTestSuite) TestVerifyPacketAcknowledgementAbsence() { }, { name: "proof verification failed", - clientState: ibctmtypes.NewClientState(chainID, trustingPeriod, ubdPeriod, maxClockDrift, suite.header), + clientState: ibctmtypes.NewClientState(chainID, lite.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, suite.header), consensusState: ibctmtypes.ConsensusState{ Root: commitmenttypes.NewMerkleRoot(suite.header.AppHash), ValidatorSet: suite.valSet, @@ -562,7 +569,7 @@ func (suite *TendermintTestSuite) TestVerifyNextSeqRecv() { // }, { name: "ApplyPrefix failed", - clientState: ibctmtypes.NewClientState(chainID, trustingPeriod, ubdPeriod, maxClockDrift, suite.header), + clientState: ibctmtypes.NewClientState(chainID, lite.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, suite.header), consensusState: ibctmtypes.ConsensusState{ Root: commitmenttypes.NewMerkleRoot(suite.header.AppHash), }, @@ -571,7 +578,7 @@ func (suite *TendermintTestSuite) TestVerifyNextSeqRecv() { }, { name: "latest client height < height", - clientState: ibctmtypes.NewClientState(chainID, trustingPeriod, ubdPeriod, maxClockDrift, suite.header), + clientState: ibctmtypes.NewClientState(chainID, lite.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, suite.header), consensusState: ibctmtypes.ConsensusState{ Root: commitmenttypes.NewMerkleRoot(suite.header.AppHash), }, @@ -589,7 +596,7 @@ func (suite *TendermintTestSuite) TestVerifyNextSeqRecv() { }, { name: "proof verification failed", - clientState: ibctmtypes.NewClientState(chainID, trustingPeriod, ubdPeriod, maxClockDrift, suite.header), + clientState: ibctmtypes.NewClientState(chainID, lite.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, suite.header), consensusState: ibctmtypes.ConsensusState{ Root: commitmenttypes.NewMerkleRoot(suite.header.AppHash), ValidatorSet: suite.valSet, diff --git a/x/ibc/07-tendermint/types/msgs.go b/x/ibc/07-tendermint/types/msgs.go index 0095ba5b9..6234c676d 100644 --- a/x/ibc/07-tendermint/types/msgs.go +++ b/x/ibc/07-tendermint/types/msgs.go @@ -3,6 +3,9 @@ package types import ( "time" + tmmath "github.com/tendermint/tendermint/libs/math" + lite "github.com/tendermint/tendermint/lite2" + sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" evidenceexported "github.com/cosmos/cosmos-sdk/x/evidence/exported" @@ -28,23 +31,25 @@ var ( // MsgCreateClient defines a message to create an IBC client type MsgCreateClient struct { - ClientID string `json:"client_id" yaml:"client_id"` - Header Header `json:"header" yaml:"header"` - TrustingPeriod time.Duration `json:"trusting_period" yaml:"trusting_period"` - UnbondingPeriod time.Duration `json:"unbonding_period" yaml:"unbonding_period"` - MaxClockDrift time.Duration `json:"max_clock_drift" yaml:"max_clock_drift"` - Signer sdk.AccAddress `json:"address" yaml:"address"` + ClientID string `json:"client_id" yaml:"client_id"` + Header Header `json:"header" yaml:"header"` + TrustLevel tmmath.Fraction `json:"trust_level" yaml:"trust_level"` + TrustingPeriod time.Duration `json:"trusting_period" yaml:"trusting_period"` + UnbondingPeriod time.Duration `json:"unbonding_period" yaml:"unbonding_period"` + MaxClockDrift time.Duration `json:"max_clock_drift" yaml:"max_clock_drift"` + Signer sdk.AccAddress `json:"address" yaml:"address"` } // NewMsgCreateClient creates a new MsgCreateClient instance func NewMsgCreateClient( - id string, header Header, + id string, header Header, trustLevel tmmath.Fraction, trustingPeriod, unbondingPeriod, maxClockDrift time.Duration, signer sdk.AccAddress, ) MsgCreateClient { return MsgCreateClient{ ClientID: id, Header: header, + TrustLevel: trustLevel, TrustingPeriod: trustingPeriod, UnbondingPeriod: unbondingPeriod, MaxClockDrift: maxClockDrift, @@ -67,6 +72,9 @@ func (msg MsgCreateClient) ValidateBasic() error { if msg.TrustingPeriod == 0 { return sdkerrors.Wrap(ErrInvalidTrustingPeriod, "duration cannot be 0") } + if err := lite.ValidateTrustLevel(msg.TrustLevel); err != nil { + return err + } if msg.UnbondingPeriod == 0 { return sdkerrors.Wrap(ErrInvalidUnbondingPeriod, "duration cannot be 0") } diff --git a/x/ibc/07-tendermint/types/msgs_test.go b/x/ibc/07-tendermint/types/msgs_test.go index 3fdf89795..cac3d6fa3 100644 --- a/x/ibc/07-tendermint/types/msgs_test.go +++ b/x/ibc/07-tendermint/types/msgs_test.go @@ -2,6 +2,9 @@ package types_test import ( "github.com/tendermint/tendermint/crypto/secp256k1" + "github.com/tendermint/tendermint/libs/math" + lite "github.com/tendermint/tendermint/lite2" + tmtypes "github.com/tendermint/tendermint/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/ibc/02-client/exported" @@ -11,18 +14,22 @@ import ( func (suite *TendermintTestSuite) TestMsgCreateClientValidateBasic() { privKey := secp256k1.GenPrivKey() signer := sdk.AccAddress(privKey.PubKey().Address()) + invalidHeader := ibctmtypes.CreateTestHeader(suite.header.ChainID, height, suite.now, suite.valSet, []tmtypes.PrivValidator{suite.privVal}) + invalidHeader.ValidatorSet = nil cases := []struct { msg ibctmtypes.MsgCreateClient expPass bool errMsg string }{ - {ibctmtypes.NewMsgCreateClient(exported.ClientTypeTendermint, suite.header, trustingPeriod, ubdPeriod, maxClockDrift, signer), true, "success msg should pass"}, - {ibctmtypes.NewMsgCreateClient("BADCHAIN", suite.header, trustingPeriod, ubdPeriod, maxClockDrift, signer), false, "invalid client id passed"}, - {ibctmtypes.NewMsgCreateClient(exported.ClientTypeTendermint, suite.header, 0, ubdPeriod, maxClockDrift, signer), false, "zero trusting period passed"}, - {ibctmtypes.NewMsgCreateClient(exported.ClientTypeTendermint, suite.header, trustingPeriod, 0, maxClockDrift, signer), false, "zero unbonding period passed"}, - {ibctmtypes.NewMsgCreateClient(exported.ClientTypeTendermint, suite.header, trustingPeriod, ubdPeriod, maxClockDrift, nil), false, "Empty address passed"}, - {ibctmtypes.NewMsgCreateClient(exported.ClientTypeTendermint, ibctmtypes.Header{}, trustingPeriod, ubdPeriod, maxClockDrift, signer), false, "nil header"}, + {ibctmtypes.NewMsgCreateClient(exported.ClientTypeTendermint, suite.header, lite.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, signer), true, "success msg should pass"}, + {ibctmtypes.NewMsgCreateClient("BADCHAIN", suite.header, lite.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, signer), false, "invalid client id passed"}, + {ibctmtypes.NewMsgCreateClient(exported.ClientTypeTendermint, suite.header, math.Fraction{Numerator: 0, Denominator: 1}, trustingPeriod, ubdPeriod, maxClockDrift, signer), false, "invalid trust level"}, + {ibctmtypes.NewMsgCreateClient(exported.ClientTypeTendermint, suite.header, lite.DefaultTrustLevel, 0, ubdPeriod, maxClockDrift, signer), false, "zero trusting period passed"}, + {ibctmtypes.NewMsgCreateClient(exported.ClientTypeTendermint, suite.header, lite.DefaultTrustLevel, trustingPeriod, 0, maxClockDrift, signer), false, "zero unbonding period passed"}, + {ibctmtypes.NewMsgCreateClient(exported.ClientTypeTendermint, suite.header, lite.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, nil), false, "Empty address passed"}, + {ibctmtypes.NewMsgCreateClient(exported.ClientTypeTendermint, ibctmtypes.Header{}, lite.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, signer), false, "nil header"}, + {ibctmtypes.NewMsgCreateClient(exported.ClientTypeTendermint, invalidHeader, lite.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, signer), false, "invalid header"}, } for i, tc := range cases { diff --git a/x/ibc/07-tendermint/update.go b/x/ibc/07-tendermint/update.go index cee63ee6d..414d4bc07 100644 --- a/x/ibc/07-tendermint/update.go +++ b/x/ibc/07-tendermint/update.go @@ -88,7 +88,7 @@ func checkValidity( err := lite.Verify( clientState.GetChainID(), &clientState.LastHeader.SignedHeader, clientState.LastHeader.ValidatorSet, &header.SignedHeader, header.ValidatorSet, - clientState.TrustingPeriod, currentTimestamp, clientState.MaxClockDrift, lite.DefaultTrustLevel, + clientState.TrustingPeriod, currentTimestamp, clientState.MaxClockDrift, clientState.TrustLevel, ) if err != nil { return sdkerrors.Wrap(clienttypes.ErrInvalidHeader, err.Error()) diff --git a/x/ibc/07-tendermint/update_test.go b/x/ibc/07-tendermint/update_test.go index 38dd55e03..57cf3741e 100644 --- a/x/ibc/07-tendermint/update_test.go +++ b/x/ibc/07-tendermint/update_test.go @@ -4,6 +4,7 @@ import ( "bytes" "time" + lite "github.com/tendermint/tendermint/lite2" tmtypes "github.com/tendermint/tendermint/types" tendermint "github.com/cosmos/cosmos-sdk/x/ibc/07-tendermint" @@ -53,7 +54,7 @@ func (suite *TendermintTestSuite) TestCheckValidity() { { name: "successful update with next height and same validator set", setup: func() { - clientState = ibctmtypes.NewClientState(chainID, trustingPeriod, ubdPeriod, maxClockDrift, suite.header) + clientState = ibctmtypes.NewClientState(chainID, lite.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, suite.header) newHeader = ibctmtypes.CreateTestHeader(chainID, height+1, suite.headerTime, suite.valSet, signers) currentTime = suite.now }, @@ -62,7 +63,7 @@ func (suite *TendermintTestSuite) TestCheckValidity() { { name: "successful update with future height and different validator set", setup: func() { - clientState = ibctmtypes.NewClientState(chainID, trustingPeriod, ubdPeriod, maxClockDrift, suite.header) + clientState = ibctmtypes.NewClientState(chainID, lite.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, suite.header) newHeader = ibctmtypes.CreateTestHeader(chainID, height+5, suite.headerTime, bothValSet, bothSigners) currentTime = suite.now }, @@ -71,7 +72,7 @@ func (suite *TendermintTestSuite) TestCheckValidity() { { name: "unsuccessful update with next height: update header mismatches nextValSetHash", setup: func() { - clientState = ibctmtypes.NewClientState(chainID, trustingPeriod, ubdPeriod, maxClockDrift, suite.header) + clientState = ibctmtypes.NewClientState(chainID, lite.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, suite.header) newHeader = ibctmtypes.CreateTestHeader(chainID, height+1, suite.headerTime, bothValSet, bothSigners) currentTime = suite.now }, @@ -80,7 +81,7 @@ func (suite *TendermintTestSuite) TestCheckValidity() { { name: "unsuccessful update with future height: too much change in validator set", setup: func() { - clientState = ibctmtypes.NewClientState(chainID, trustingPeriod, ubdPeriod, maxClockDrift, suite.header) + clientState = ibctmtypes.NewClientState(chainID, lite.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, suite.header) newHeader = ibctmtypes.CreateTestHeader(chainID, height+5, suite.headerTime, altValSet, altSigners) currentTime = suite.now }, @@ -89,7 +90,7 @@ func (suite *TendermintTestSuite) TestCheckValidity() { { name: "unsuccessful update: trusting period has passed since last client timestamp", setup: func() { - clientState = ibctmtypes.NewClientState(chainID, trustingPeriod, ubdPeriod, maxClockDrift, suite.header) + clientState = ibctmtypes.NewClientState(chainID, lite.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, suite.header) newHeader = ibctmtypes.CreateTestHeader(chainID, height+1, suite.headerTime, suite.valSet, signers) // make current time pass trusting period from last timestamp on clientstate currentTime = suite.now.Add(ubdPeriod) @@ -99,7 +100,7 @@ func (suite *TendermintTestSuite) TestCheckValidity() { { name: "unsuccessful update: header timestamp is past current timestamp", setup: func() { - clientState = ibctmtypes.NewClientState(chainID, trustingPeriod, ubdPeriod, maxClockDrift, suite.header) + clientState = ibctmtypes.NewClientState(chainID, lite.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, suite.header) newHeader = ibctmtypes.CreateTestHeader(chainID, height+1, suite.now.Add(time.Minute), suite.valSet, signers) currentTime = suite.now }, @@ -108,7 +109,7 @@ func (suite *TendermintTestSuite) TestCheckValidity() { { name: "unsuccessful update: header timestamp is not past last client timestamp", setup: func() { - clientState = ibctmtypes.NewClientState(chainID, trustingPeriod, ubdPeriod, maxClockDrift, suite.header) + clientState = ibctmtypes.NewClientState(chainID, lite.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, suite.header) newHeader = ibctmtypes.CreateTestHeader(chainID, height+1, suite.clientTime, suite.valSet, signers) currentTime = suite.now }, @@ -117,7 +118,7 @@ func (suite *TendermintTestSuite) TestCheckValidity() { { name: "header basic validation failed", setup: func() { - clientState = ibctmtypes.NewClientState(chainID, trustingPeriod, ubdPeriod, maxClockDrift, suite.header) + clientState = ibctmtypes.NewClientState(chainID, lite.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, suite.header) newHeader = ibctmtypes.CreateTestHeader(chainID, height+1, suite.headerTime, suite.valSet, signers) // cause new header to fail validatebasic by changing commit height to mismatch header height newHeader.SignedHeader.Commit.Height = height - 1 @@ -128,7 +129,7 @@ func (suite *TendermintTestSuite) TestCheckValidity() { { name: "header height < latest client height", setup: func() { - clientState = ibctmtypes.NewClientState(chainID, trustingPeriod, ubdPeriod, maxClockDrift, suite.header) + clientState = ibctmtypes.NewClientState(chainID, lite.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, suite.header) // Make new header at height less than latest client state newHeader = ibctmtypes.CreateTestHeader(chainID, height-1, suite.headerTime, suite.valSet, signers) currentTime = suite.now diff --git a/x/ibc/20-transfer/handler_test.go b/x/ibc/20-transfer/handler_test.go index 0839d0c35..647cc9b4d 100644 --- a/x/ibc/20-transfer/handler_test.go +++ b/x/ibc/20-transfer/handler_test.go @@ -8,6 +8,7 @@ import ( "github.com/stretchr/testify/suite" abci "github.com/tendermint/tendermint/abci/types" + lite "github.com/tendermint/tendermint/lite2" tmtypes "github.com/tendermint/tendermint/types" "github.com/cosmos/cosmos-sdk/codec" @@ -188,7 +189,7 @@ func (chain *TestChain) CreateClient(client *TestChain) error { ctxTarget := chain.GetContext() // create client - clientState, err := ibctmtypes.Initialize(client.ClientID, trustingPeriod, ubdPeriod, maxClockDrift, client.Header) + clientState, err := ibctmtypes.Initialize(client.ClientID, lite.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, client.Header) if err != nil { return err } @@ -257,7 +258,7 @@ func (chain *TestChain) updateClient(client *TestChain) { ctxTarget, client.ClientID, uint64(client.Header.SignedHeader.Header.Height), consensusState, ) chain.App.IBCKeeper.ClientKeeper.SetClientState( - ctxTarget, ibctmtypes.NewClientState(client.ClientID, trustingPeriod, ubdPeriod, maxClockDrift, client.Header), + ctxTarget, ibctmtypes.NewClientState(client.ClientID, lite.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, client.Header), ) // _, _, err := simapp.SignCheckDeliver( diff --git a/x/ibc/20-transfer/keeper/keeper_test.go b/x/ibc/20-transfer/keeper/keeper_test.go index bbc8d8b9b..8b0653d04 100644 --- a/x/ibc/20-transfer/keeper/keeper_test.go +++ b/x/ibc/20-transfer/keeper/keeper_test.go @@ -8,6 +8,7 @@ import ( "github.com/stretchr/testify/suite" abci "github.com/tendermint/tendermint/abci/types" "github.com/tendermint/tendermint/crypto" + lite "github.com/tendermint/tendermint/lite2" tmtypes "github.com/tendermint/tendermint/types" "github.com/cosmos/cosmos-sdk/codec" @@ -164,7 +165,7 @@ func (chain *TestChain) CreateClient(client *TestChain) error { ctxTarget := chain.GetContext() // create client - clientState, err := ibctmtypes.Initialize(client.ClientID, trustingPeriod, ubdPeriod, maxClockDrift, client.Header) + clientState, err := ibctmtypes.Initialize(client.ClientID, lite.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, client.Header) if err != nil { return err } @@ -233,7 +234,7 @@ func (chain *TestChain) updateClient(client *TestChain) { ctxTarget, client.ClientID, client.Header.GetHeight(), consensusState, ) chain.App.IBCKeeper.ClientKeeper.SetClientState( - ctxTarget, ibctmtypes.NewClientState(client.ClientID, trustingPeriod, ubdPeriod, maxClockDrift, client.Header), + ctxTarget, ibctmtypes.NewClientState(client.ClientID, lite.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, client.Header), ) // _, _, err := simapp.SignCheckDeliver( diff --git a/x/ibc/ante/ante_test.go b/x/ibc/ante/ante_test.go index cfb02bf4c..11cf8047e 100644 --- a/x/ibc/ante/ante_test.go +++ b/x/ibc/ante/ante_test.go @@ -7,6 +7,7 @@ import ( "github.com/stretchr/testify/suite" abci "github.com/tendermint/tendermint/abci/types" + lite "github.com/tendermint/tendermint/lite2" tmtypes "github.com/tendermint/tendermint/types" "github.com/cosmos/cosmos-sdk/codec" @@ -239,7 +240,7 @@ func (chain *TestChain) CreateClient(client *TestChain) error { ctxTarget := chain.GetContext() // create client - clientState, err := ibctmtypes.Initialize(client.ClientID, trustingPeriod, ubdPeriod, maxClockDrift, client.Header) + clientState, err := ibctmtypes.Initialize(client.ClientID, lite.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, client.Header) if err != nil { return err } @@ -307,7 +308,7 @@ func (chain *TestChain) updateClient(client *TestChain) { ctxTarget, client.ClientID, uint64(client.Header.Height-1), consensusState, ) chain.App.IBCKeeper.ClientKeeper.SetClientState( - ctxTarget, ibctmtypes.NewClientState(client.ClientID, trustingPeriod, ubdPeriod, maxClockDrift, client.Header), + ctxTarget, ibctmtypes.NewClientState(client.ClientID, lite.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, client.Header), ) // _, _, err := simapp.SignCheckDeliver( diff --git a/x/ibc/genesis_test.go b/x/ibc/genesis_test.go index fcb0b441a..14022c725 100644 --- a/x/ibc/genesis_test.go +++ b/x/ibc/genesis_test.go @@ -10,6 +10,7 @@ import ( localhosttypes "github.com/cosmos/cosmos-sdk/x/ibc/09-localhost/types" commitmenttypes "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/types" ibctypes "github.com/cosmos/cosmos-sdk/x/ibc/types" + lite "github.com/tendermint/tendermint/lite2" ) func (suite *IBCTestSuite) TestValidateGenesis() { @@ -28,7 +29,7 @@ func (suite *IBCTestSuite) TestValidateGenesis() { genState: ibc.GenesisState{ ClientGenesis: client.NewGenesisState( []exported.ClientState{ - ibctmtypes.NewClientState(clientID, trustingPeriod, ubdPeriod, maxClockDrift, suite.header), + ibctmtypes.NewClientState(clientID, lite.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, suite.header), localhosttypes.NewClientState("chaindID", 10), }, []client.ConsensusStates{ @@ -81,7 +82,7 @@ func (suite *IBCTestSuite) TestValidateGenesis() { genState: ibc.GenesisState{ ClientGenesis: client.NewGenesisState( []exported.ClientState{ - ibctmtypes.NewClientState(clientID, trustingPeriod, ubdPeriod, maxClockDrift, suite.header), + ibctmtypes.NewClientState(clientID, lite.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, suite.header), localhosttypes.NewClientState("chaindID", 0), }, nil,