diff --git a/go.mod b/go.mod index 2ebb536dbc..2ff5be48a5 100644 --- a/go.mod +++ b/go.mod @@ -30,6 +30,7 @@ require ( ) require ( + github.com/confio/ics23/go v0.7.0 github.com/golang/mock v1.6.0 github.com/oxyno-zeta/gomock-extra-matcher v1.1.0 github.com/regen-network/cosmos-proto v0.3.1 @@ -48,7 +49,6 @@ require ( github.com/cespare/xxhash v1.1.0 // indirect github.com/cespare/xxhash/v2 v2.1.2 // indirect github.com/coinbase/rosetta-sdk-go v0.7.0 // indirect - github.com/confio/ics23/go v0.7.0 // indirect github.com/cosmos/btcutil v1.0.4 // indirect github.com/cosmos/go-bip39 v1.0.0 // indirect github.com/cosmos/iavl v0.17.3 // indirect diff --git a/proto/interchain_security/ccv/consumer/v1/consumer.proto b/proto/interchain_security/ccv/consumer/v1/consumer.proto index 57d0f0fbd3..cdf26277ce 100644 --- a/proto/interchain_security/ccv/consumer/v1/consumer.proto +++ b/proto/interchain_security/ccv/consumer/v1/consumer.proto @@ -9,6 +9,7 @@ import "google/protobuf/any.proto"; import "cosmos/staking/v1beta1/staking.proto"; import "gogoproto/gogo.proto"; import "cosmos_proto/cosmos.proto"; +import "google/protobuf/duration.proto"; // Params defines the parameters for CCV consumer module message Params { @@ -29,6 +30,21 @@ message Params { // provider handshake procedure. string distribution_transmission_channel = 3; string provider_fee_pool_addr_str = 4; + // Sent CCV related IBC packets will timeout after this duration + google.protobuf.Duration ccv_timeout_period = 5 + [(gogoproto.nullable) = false, (gogoproto.stdduration) = true]; + + // Sent transfer related IBC packets will timeout after this duration + google.protobuf.Duration transfer_timeout_period = 6 + [(gogoproto.nullable) = false, (gogoproto.stdduration) = true]; + + // The fraction of tokens allocated to the consumer redistribution address + // during distribution events. The fraction is a string representing a + // decimal number. For example "0.75" would represent 75%. + string consumer_redistribution_fraction = 7; + + // The number of historical info entries to persist in store + int64 num_historical_entries = 8; } // LastTransmissionBlockHeight is the last time validator holding diff --git a/proto/interchain_security/ccv/provider/v1/provider.proto b/proto/interchain_security/ccv/provider/v1/provider.proto index 0c0beb2bb3..eae0f9701d 100644 --- a/proto/interchain_security/ccv/provider/v1/provider.proto +++ b/proto/interchain_security/ccv/provider/v1/provider.proto @@ -6,6 +6,7 @@ option go_package = "github.com/cosmos/interchain-security/x/ccv/provider/types" import "gogoproto/gogo.proto"; import "google/protobuf/timestamp.proto"; +import "google/protobuf/duration.proto"; import "ibc/core/client/v1/client.proto"; import "ibc/lightclients/tendermint/v1/tendermint.proto"; @@ -58,6 +59,11 @@ message ConsumerAdditionProposal { // Params defines the parameters for CCV Provider module message Params { ibc.lightclients.tendermint.v1.ClientState template_client = 1; + // Sent IBC packets will timeout after this duration + google.protobuf.Duration ccv_timeout_period = 2 + [(gogoproto.nullable) = false, (gogoproto.stdduration) = true]; + // TrustingPeriodFraction is used to compute the provider IBC client's TrustingPeriod + int64 trusting_period_fraction = 3; } message HandshakeMetadata { diff --git a/tests/difference/core/driver/setup.go b/tests/difference/core/driver/setup.go index 3228c3e802..2bb5d86a62 100644 --- a/tests/difference/core/driver/setup.go +++ b/tests/difference/core/driver/setup.go @@ -476,6 +476,10 @@ func (b *Builder) createConsumerGenesis(tmConfig *ibctesting.TendermintConfig) * 1000, // ignore distribution "", // ignore distribution "", // ignore distribution + ccv.DefaultCCVTimeoutPeriod, + consumertypes.DefaultTransferTimeoutPeriod, + consumertypes.DefaultConsumerRedistributeFrac, + consumertypes.DefaultNumHistoricalEntries, ) return consumertypes.NewInitialGenesisState(providerClient, providerConsState, valUpdates, consumertypes.SlashRequests{}, params) } @@ -534,7 +538,7 @@ func (b *Builder) doIBCHandshake() { func (b *Builder) sendEmptyVSCPacketToFinishHandshake() { vscID := b.providerKeeper().GetValidatorSetUpdateId(b.providerChain().GetContext()) - timeout := uint64(types.GetTimeoutTimestamp(b.chain(P).CurrentHeader.Time).UnixNano()) + timeout := uint64(b.chain(P).CurrentHeader.Time.Add(ccv.DefaultCCVTimeoutPeriod).UnixNano()) pd := types.NewValidatorSetChangePacketData( []abci.ValidatorUpdate{}, diff --git a/tests/e2e/common_test.go b/tests/e2e/common_test.go index 396aa02ee3..0a3784d5e1 100644 --- a/tests/e2e/common_test.go +++ b/tests/e2e/common_test.go @@ -8,6 +8,7 @@ import ( stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + providertypes "github.com/cosmos/interchain-security/x/ccv/provider/types" ccv "github.com/cosmos/interchain-security/x/ccv/types" "github.com/cosmos/interchain-security/x/ccv/utils" "github.com/stretchr/testify/require" @@ -293,7 +294,7 @@ func (suite *CCVTestSuite) SendEmptyVSCPacket() { providerKeeper := suite.providerChain.App.(*appProvider.App).ProviderKeeper oldBlockTime := suite.providerChain.GetContext().BlockTime() - timeout := uint64(ccv.GetTimeoutTimestamp(oldBlockTime).UnixNano()) + timeout := uint64(oldBlockTime.Add(ccv.DefaultCCVTimeoutPeriod).UnixNano()) valUpdateID := providerKeeper.GetValidatorSetUpdateId(suite.providerChain.GetContext()) @@ -320,7 +321,7 @@ func (suite *CCVTestSuite) SendEmptyVSCPacket() { // Note that it must be called before sending the embedding IBC packet. func (suite *CCVTestSuite) commitSlashPacket(ctx sdk.Context, packetData ccv.SlashPacketData) []byte { oldBlockTime := ctx.BlockTime() - timeout := uint64(ccv.GetTimeoutTimestamp(oldBlockTime).UnixNano()) + timeout := uint64(oldBlockTime.Add(ccv.DefaultCCVTimeoutPeriod).UnixNano()) packet := channeltypes.NewPacket(packetData.GetBytes(), 1, ccv.ConsumerPortID, suite.path.EndpointA.ChannelID, ccv.ProviderPortID, suite.path.EndpointB.ChannelID, clienttypes.Height{}, timeout) @@ -334,7 +335,7 @@ func incrementTimeBy(s *CCVTestSuite, jumpPeriod time.Duration) { consumerUnbondingPeriod, found := s.consumerChain.App.(*appConsumer.App).ConsumerKeeper.GetUnbondingTime(s.consumerChain.GetContext()) s.Require().True(found) split := 1 - if jumpPeriod > consumerUnbondingPeriod/utils.TrustingPeriodFraction { + if jumpPeriod > consumerUnbondingPeriod/providertypes.DefaultTrustingPeriodFraction { // Make sure the clients do not expire split = 4 jumpPeriod = jumpPeriod / 4 @@ -365,7 +366,7 @@ func (suite *CCVTestSuite) CreateCustomClient(endpoint *ibctesting.Endpoint, unb tmConfig, ok := endpoint.ClientConfig.(*ibctesting.TendermintConfig) require.True(endpoint.Chain.T, ok) tmConfig.UnbondingPeriod = unbondingPeriod - tmConfig.TrustingPeriod = unbondingPeriod / utils.TrustingPeriodFraction + tmConfig.TrustingPeriod = unbondingPeriod / providertypes.DefaultTrustingPeriodFraction height := endpoint.Counterparty.Chain.LastHeader.GetHeight().(clienttypes.Height) UpgradePath := []string{"upgrade", "upgradedIBCState"} diff --git a/tests/e2e/democracy_test.go b/tests/e2e/democracy_test.go index 68445c618e..f3de830cf1 100644 --- a/tests/e2e/democracy_test.go +++ b/tests/e2e/democracy_test.go @@ -1,17 +1,13 @@ package e2e_test import ( - "bytes" "fmt" "strconv" "testing" "time" sdk "github.com/cosmos/cosmos-sdk/types" - transfertypes "github.com/cosmos/ibc-go/v3/modules/apps/transfer/types" - clienttypes "github.com/cosmos/ibc-go/v3/modules/core/02-client/types" - channeltypes "github.com/cosmos/ibc-go/v3/modules/core/04-channel/types" ibctesting "github.com/cosmos/ibc-go/v3/testing" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" @@ -22,176 +18,33 @@ import ( "github.com/cosmos/cosmos-sdk/x/params/types/proposal" proposaltypes "github.com/cosmos/cosmos-sdk/x/params/types/proposal" appConsumer "github.com/cosmos/interchain-security/app/consumer-democracy" - appProvider "github.com/cosmos/interchain-security/app/provider" "github.com/cosmos/interchain-security/testutil/simapp" - consumerkeeper "github.com/cosmos/interchain-security/x/ccv/consumer/keeper" consumertypes "github.com/cosmos/interchain-security/x/ccv/consumer/types" - "github.com/cosmos/interchain-security/x/ccv/types" - "github.com/cosmos/interchain-security/x/ccv/utils" - - tmtypes "github.com/tendermint/tendermint/types" "github.com/stretchr/testify/suite" ) -var consumerFraction, _ = sdk.NewDecFromStr(consumerkeeper.ConsumerRedistributeFrac) +var consumerFraction, _ = sdk.NewDecFromStr(consumertypes.DefaultConsumerRedistributeFrac) type ConsumerDemocracyTestSuite struct { suite.Suite - - coordinator *ibctesting.Coordinator - - // testing chains + coordinator *ibctesting.Coordinator providerChain *ibctesting.TestChain consumerChain *ibctesting.TestChain - - path *ibctesting.Path - transferPath *ibctesting.Path -} - -func (s *ConsumerDemocracyTestSuite) SetupTest() { - s.coordinator, s.providerChain, s.consumerChain = simapp.NewProviderConsumerDemocracyCoordinator(s.T()) - - // valsets must match - providerValUpdates := tmtypes.TM2PB.ValidatorUpdates(s.providerChain.Vals) - consumerValUpdates := tmtypes.TM2PB.ValidatorUpdates(s.consumerChain.Vals) - s.Require().True(len(providerValUpdates) == len(consumerValUpdates), "initial valset not matching") - for i := 0; i < len(providerValUpdates); i++ { - addr1 := utils.GetChangePubKeyAddress(providerValUpdates[i]) - addr2 := utils.GetChangePubKeyAddress(consumerValUpdates[i]) - s.Require().True(bytes.Equal(addr1, addr2), "validator mismatch") - } - - // move both chains to the next block - s.providerChain.NextBlock() - s.consumerChain.NextBlock() - - // create consumer client on provider chain and set as consumer client for consumer chainID in provider keeper. - err := s.providerChain.App.(*appProvider.App).ProviderKeeper.CreateConsumerClient( - s.providerCtx(), - s.consumerChain.ChainID, - s.consumerChain.LastHeader.GetHeight().(clienttypes.Height), - false, - ) - s.Require().NoError(err) - - // move provider to next block to commit the state - s.providerChain.NextBlock() - - // initialize the consumer chain with the genesis state stored on the provider - consumerGenesis, found := s.providerChain.App.(*appProvider.App).ProviderKeeper.GetConsumerGenesis( - s.providerCtx(), - s.consumerChain.ChainID, - ) - s.Require().True(found, "consumer genesis not found") - s.consumerChain.App.(*appConsumer.App).ConsumerKeeper.InitGenesis(s.consumerChain.GetContext(), &consumerGenesis) - - // create path for the CCV channel - s.path = ibctesting.NewPath(s.consumerChain, s.providerChain) - - // update CCV path with correct info - // - set provider endpoint's clientID - consumerClient, found := s.providerChain.App.(*appProvider.App).ProviderKeeper.GetConsumerClientId( - s.providerCtx(), - s.consumerChain.ChainID, - ) - s.Require().True(found, "consumer client not found") - s.path.EndpointB.ClientID = consumerClient - // - set consumer endpoint's clientID - providerClient, found := s.consumerChain.App.(*appConsumer.App).ConsumerKeeper.GetProviderClientID(s.consumerChain.GetContext()) - s.Require().True(found, "provider client not found") - s.path.EndpointA.ClientID = providerClient - // - client config - providerUnbondingPeriod := s.providerChain.App.(*appProvider.App).GetStakingKeeper().UnbondingTime(s.providerCtx()) - s.path.EndpointB.ClientConfig.(*ibctesting.TendermintConfig).UnbondingPeriod = providerUnbondingPeriod - s.path.EndpointB.ClientConfig.(*ibctesting.TendermintConfig).TrustingPeriod = providerUnbondingPeriod / utils.TrustingPeriodFraction - consumerUnbondingPeriod := utils.ComputeConsumerUnbondingPeriod(providerUnbondingPeriod) - s.path.EndpointA.ClientConfig.(*ibctesting.TendermintConfig).UnbondingPeriod = consumerUnbondingPeriod - s.path.EndpointA.ClientConfig.(*ibctesting.TendermintConfig).TrustingPeriod = consumerUnbondingPeriod / utils.TrustingPeriodFraction - // - channel config - s.path.EndpointA.ChannelConfig.PortID = types.ConsumerPortID - s.path.EndpointB.ChannelConfig.PortID = types.ProviderPortID - s.path.EndpointA.ChannelConfig.Version = types.Version - s.path.EndpointB.ChannelConfig.Version = types.Version - s.path.EndpointA.ChannelConfig.Order = channeltypes.ORDERED - s.path.EndpointB.ChannelConfig.Order = channeltypes.ORDERED - - // set chains sender account number - // TODO: to be fixed in #151 - err = s.path.EndpointB.Chain.SenderAccount.SetAccountNumber(6) - s.Require().NoError(err) - err = s.path.EndpointA.Chain.SenderAccount.SetAccountNumber(0) - s.Require().NoError(err) - - // create path for the transfer channel - s.transferPath = ibctesting.NewPath(s.consumerChain, s.providerChain) - s.transferPath.EndpointA.ChannelConfig.PortID = transfertypes.PortID - s.transferPath.EndpointB.ChannelConfig.PortID = transfertypes.PortID - s.transferPath.EndpointA.ChannelConfig.Version = transfertypes.Version - s.transferPath.EndpointB.ChannelConfig.Version = transfertypes.Version } -func (s *ConsumerDemocracyTestSuite) SetupCCVChannel() { - s.StartSetupCCVChannel() - s.CompleteSetupCCVChannel() - s.SetupTransferChannel() -} - -func (s *ConsumerDemocracyTestSuite) StartSetupCCVChannel() { - s.coordinator.CreateConnections(s.path) - - err := s.path.EndpointA.ChanOpenInit() - s.Require().NoError(err) - - err = s.path.EndpointB.ChanOpenTry() - s.Require().NoError(err) -} - -func (s *ConsumerDemocracyTestSuite) CompleteSetupCCVChannel() { - err := s.path.EndpointA.ChanOpenAck() - s.Require().NoError(err) - - err = s.path.EndpointB.ChanOpenConfirm() - s.Require().NoError(err) - - // ensure counterparty is up to date - err = s.path.EndpointA.UpdateClient() - s.Require().NoError(err) -} - -func (s *ConsumerDemocracyTestSuite) SetupTransferChannel() { - // transfer path will use the same connection as ccv path - - s.transferPath.EndpointA.ClientID = s.path.EndpointA.ClientID - s.transferPath.EndpointA.ConnectionID = s.path.EndpointA.ConnectionID - s.transferPath.EndpointB.ClientID = s.path.EndpointB.ClientID - s.transferPath.EndpointB.ConnectionID = s.path.EndpointB.ConnectionID - - // CCV channel handshake will automatically initiate transfer channel handshake on ACK - // so transfer channel will be on stage INIT when CompleteSetupCCVChannel returns. - s.transferPath.EndpointA.ChannelID = s.consumerChain.App.(*appConsumer.App). - ConsumerKeeper.GetDistributionTransmissionChannel(s.consumerChain.GetContext()) - - // Complete TRY, ACK, CONFIRM for transfer path - err := s.transferPath.EndpointB.ChanOpenTry() - s.Require().NoError(err) - - err = s.transferPath.EndpointA.ChanOpenAck() - s.Require().NoError(err) - - err = s.transferPath.EndpointB.ChanOpenConfirm() - s.Require().NoError(err) - - // ensure counterparty is up to date - err = s.transferPath.EndpointA.UpdateClient() - s.Require().NoError(err) +// SetupTest sets up in-mem state for the group of tests relevant to ccv with a democracy consumer +// TODO: Make this method more generalizable to be called by any provider/consumer implementation +func (democSuite *ConsumerDemocracyTestSuite) SetupTest() { + democSuite.coordinator, democSuite.providerChain, + democSuite.consumerChain = simapp.NewProviderConsumerDemocracyCoordinator(democSuite.T()) } func TestConsumerDemocracyTestSuite(t *testing.T) { suite.Run(t, new(ConsumerDemocracyTestSuite)) } -func (s *ConsumerDemocracyTestSuite) TestDemocracyRewarsDistribution() { +func (s *ConsumerDemocracyTestSuite) TestDemocracyRewardsDistribution() { s.consumerChain.NextBlock() stakingKeeper := s.consumerChain.App.(*appConsumer.App).StakingKeeper @@ -366,10 +219,6 @@ func getAccountsBalances(ctx sdk.Context, bankKeeper bankkeeper.Keeper, bondDeno return accountsBalances } -func (s *ConsumerDemocracyTestSuite) providerCtx() sdk.Context { - return s.providerChain.GetContext() -} - func (s *ConsumerDemocracyTestSuite) consumerCtx() sdk.Context { return s.consumerChain.GetContext() } diff --git a/tests/e2e/distribution_test.go b/tests/e2e/distribution_test.go index 5eb7b12b77..36313df2fe 100644 --- a/tests/e2e/distribution_test.go +++ b/tests/e2e/distribution_test.go @@ -8,7 +8,6 @@ import ( transfertypes "github.com/cosmos/ibc-go/v3/modules/apps/transfer/types" app "github.com/cosmos/interchain-security/app/consumer" providerApp "github.com/cosmos/interchain-security/app/provider" - consumerkeeper "github.com/cosmos/interchain-security/x/ccv/consumer/keeper" consumertypes "github.com/cosmos/interchain-security/x/ccv/consumer/types" ccv "github.com/cosmos/interchain-security/x/ccv/types" ) @@ -45,7 +44,7 @@ func (s *CCVTestSuite) TestRewardsDistribution() { s.Require().Equal(sdk.NewInt(100).Add(feePoolTokensOld.AmountOf(sdk.DefaultBondDenom)), feePoolTokens.AmountOf(sdk.DefaultBondDenom)) //calculate the reward for consumer and provider chain. Consumer will receive ConsumerRedistributeFrac, the rest is going to provider - frac, err := sdk.NewDecFromStr(consumerkeeper.ConsumerRedistributeFrac) + frac, err := sdk.NewDecFromStr(consumertypes.DefaultConsumerRedistributeFrac) s.Require().NoError(err) consumerExpectedRewards, _ := sdk.NewDecCoinsFromCoins(feePoolTokens...).MulDec(frac).TruncateDecimal() providerExpectedRewards := feePoolTokens.Sub(consumerExpectedRewards) diff --git a/tests/e2e/normal_operations_test.go b/tests/e2e/normal_operations_test.go index 1c90efaf50..9e7501a7b4 100644 --- a/tests/e2e/normal_operations_test.go +++ b/tests/e2e/normal_operations_test.go @@ -3,7 +3,7 @@ package e2e_test import ( "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" appConsumer "github.com/cosmos/interchain-security/app/consumer" - "github.com/cosmos/interchain-security/x/ccv/consumer/types" + consumertypes "github.com/cosmos/interchain-security/x/ccv/consumer/types" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" ) @@ -22,7 +22,7 @@ func (k CCVTestSuite) TestTrackHistoricalInfo() { createVal := func(k CCVTestSuite) { // add new validator to consumer states pk := ed25519.GenPrivKey().PubKey() - cVal, err := types.NewCCValidator(pk.Address(), int64(1), pk) + cVal, err := consumertypes.NewCCValidator(pk.Address(), int64(1), pk) k.Require().NoError(err) consumerKeeper.SetCCValidator(k.consumerChain.GetContext(), cVal) @@ -39,7 +39,7 @@ func (k CCVTestSuite) TestTrackHistoricalInfo() { createVal, createVal, func(k CCVTestSuite) { - newHeight := k.consumerChain.GetContext().BlockHeight() + int64(types.HistoricalEntries) + newHeight := k.consumerChain.GetContext().BlockHeight() + int64(consumertypes.DefaultNumHistoricalEntries) header := tmproto.Header{ ChainID: "HelloChain", Height: newHeight, @@ -71,7 +71,7 @@ func (k CCVTestSuite) TestTrackHistoricalInfo() { expLen: 0, }, { - height: initHeight + int64(types.HistoricalEntries) + 2, + height: initHeight + int64(consumertypes.DefaultNumHistoricalEntries) + 2, found: true, expLen: initValsetLen + 2, }, diff --git a/tests/e2e/setup_test.go b/tests/e2e/setup_test.go index 3fd0522729..44c0c33a11 100644 --- a/tests/e2e/setup_test.go +++ b/tests/e2e/setup_test.go @@ -6,6 +6,7 @@ import ( "bytes" "testing" + providertypes "github.com/cosmos/interchain-security/x/ccv/provider/types" ccv "github.com/cosmos/interchain-security/x/ccv/types" "github.com/cosmos/interchain-security/x/ccv/utils" @@ -95,10 +96,10 @@ func (suite *CCVTestSuite) SetupTest() { // - client config providerUnbondingPeriod := suite.providerChain.App.(*appProvider.App).GetStakingKeeper().UnbondingTime(suite.providerCtx()) suite.path.EndpointB.ClientConfig.(*ibctesting.TendermintConfig).UnbondingPeriod = providerUnbondingPeriod - suite.path.EndpointB.ClientConfig.(*ibctesting.TendermintConfig).TrustingPeriod = providerUnbondingPeriod / utils.TrustingPeriodFraction + suite.path.EndpointB.ClientConfig.(*ibctesting.TendermintConfig).TrustingPeriod = providerUnbondingPeriod / providertypes.DefaultTrustingPeriodFraction consumerUnbondingPeriod := utils.ComputeConsumerUnbondingPeriod(providerUnbondingPeriod) suite.path.EndpointA.ClientConfig.(*ibctesting.TendermintConfig).UnbondingPeriod = consumerUnbondingPeriod - suite.path.EndpointA.ClientConfig.(*ibctesting.TendermintConfig).TrustingPeriod = consumerUnbondingPeriod / utils.TrustingPeriodFraction + suite.path.EndpointA.ClientConfig.(*ibctesting.TendermintConfig).TrustingPeriod = consumerUnbondingPeriod / providertypes.DefaultTrustingPeriodFraction // - channel config suite.path.EndpointA.ChannelConfig.PortID = ccv.ConsumerPortID suite.path.EndpointB.ChannelConfig.PortID = ccv.ProviderPortID diff --git a/tests/e2e/slashing_test.go b/tests/e2e/slashing_test.go index 1e7e5fd6af..fc462ba601 100644 --- a/tests/e2e/slashing_test.go +++ b/tests/e2e/slashing_test.go @@ -64,7 +64,7 @@ func (s *CCVTestSuite) TestSendSlashPacketDowntime() { oldBlockTime := s.consumerCtx().BlockTime() slashFraction := int64(100) packetData := types.NewSlashPacketData(validator, valsetUpdateId, stakingtypes.Downtime) - timeout := uint64(types.GetTimeoutTimestamp(oldBlockTime).UnixNano()) + timeout := uint64(oldBlockTime.Add(ccv.DefaultCCVTimeoutPeriod).UnixNano()) packet := channeltypes.NewPacket(packetData.GetBytes(), 1, ccv.ConsumerPortID, s.path.EndpointA.ChannelID, ccv.ProviderPortID, s.path.EndpointB.ChannelID, clienttypes.Height{}, timeout) @@ -77,7 +77,7 @@ func (s *CCVTestSuite) TestSendSlashPacketDowntime() { // save next VSC packet info oldBlockTime = s.providerCtx().BlockTime() - timeout = uint64(types.GetTimeoutTimestamp(oldBlockTime).UnixNano()) + timeout = uint64(oldBlockTime.Add(ccv.DefaultCCVTimeoutPeriod).UnixNano()) valsetUpdateID := s.providerChain.App.(*appProvider.App).ProviderKeeper.GetValidatorSetUpdateId(s.providerCtx()) // receive the downtime packet on the provider chain; @@ -184,7 +184,7 @@ func (s *CCVTestSuite) TestSendSlashPacketDoubleSign() { oldBlockTime := s.consumerCtx().BlockTime() packetData := types.NewSlashPacketData(validator, valsetUpdateId, stakingtypes.DoubleSign) - timeout := uint64(types.GetTimeoutTimestamp(oldBlockTime).UnixNano()) + timeout := uint64(oldBlockTime.Add(ccv.DefaultCCVTimeoutPeriod).UnixNano()) packet := channeltypes.NewPacket(packetData.GetBytes(), 1, ccv.ConsumerPortID, s.path.EndpointA.ChannelID, ccv.ProviderPortID, s.path.EndpointB.ChannelID, clienttypes.Height{}, timeout) @@ -194,7 +194,7 @@ func (s *CCVTestSuite) TestSendSlashPacketDoubleSign() { // save next VSC packet info oldBlockTime = s.providerCtx().BlockTime() - timeout = uint64(types.GetTimeoutTimestamp(oldBlockTime).UnixNano()) + timeout = uint64(oldBlockTime.Add(ccv.DefaultCCVTimeoutPeriod).UnixNano()) valsetUpdateID := s.providerChain.App.(*appProvider.App).ProviderKeeper.GetValidatorSetUpdateId(s.providerCtx()) // receive the downtime packet on the provider chain; diff --git a/testutil/keeper/unit_test_helpers.go b/testutil/keeper/unit_test_helpers.go index f2aeb2e3ac..203f1750fe 100644 --- a/testutil/keeper/unit_test_helpers.go +++ b/testutil/keeper/unit_test_helpers.go @@ -29,7 +29,6 @@ import ( clienttypes "github.com/cosmos/ibc-go/v3/modules/core/02-client/types" commitmenttypes "github.com/cosmos/ibc-go/v3/modules/core/23-commitment/types" ibctmtypes "github.com/cosmos/ibc-go/v3/modules/light-clients/07-tendermint/types" - providertypes "github.com/cosmos/interchain-security/x/ccv/provider/types" ) // Parameters needed to instantiate an in-memory keeper @@ -166,27 +165,6 @@ func GetConsumerKeeperAndCtx(t *testing.T, params InMemKeeperParams) ( return NewInMemConsumerKeeper(params, mocks), params.Ctx, ctrl, mocks } -// Sets a template client state for a params subspace so that the provider's -// GetTemplateClient method will be satisfied. -func (params *InMemKeeperParams) SetTemplateClientState(customState *ibctmtypes.ClientState) { - - keyTable := paramstypes.NewKeyTable(paramstypes.NewParamSetPair( - providertypes.KeyTemplateClient, &ibctmtypes.ClientState{}, - func(value interface{}) error { return nil })) - - newSubspace := params.ParamsSubspace.WithKeyTable(keyTable) - params.ParamsSubspace = &newSubspace - - // Default template client state if none provided - if customState == nil { - customState = ibctmtypes.NewClientState("", ibctmtypes.DefaultTrustLevel, 0, 0, - time.Second*10, clienttypes.Height{}, commitmenttypes.GetSDKSpecs(), - []string{"upgrade", "upgradedIBCState"}, true, true) - } - - params.ParamsSubspace.Set(params.Ctx, providertypes.KeyTemplateClient, customState) -} - // Registers proto interfaces for params.Cdc // // For now, we explicitly force certain unit tests to register sdk crypto interfaces. diff --git a/x/ccv/consumer/keeper/distribution.go b/x/ccv/consumer/keeper/distribution.go index 1e17ed178d..a118402c77 100644 --- a/x/ccv/consumer/keeper/distribution.go +++ b/x/ccv/consumer/keeper/distribution.go @@ -1,8 +1,6 @@ package keeper import ( - "time" - sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" @@ -14,13 +12,6 @@ import ( ccv "github.com/cosmos/interchain-security/x/ccv/types" ) -const TransferTimeDelay = 1 * 7 * 24 * time.Hour // 1 weeks - -// The fraction of tokens allocated to the consumer redistribution address -// during distribution events. The fraction is a string representing a -// decimal number. For example "0.75" would represent 75%. -const ConsumerRedistributeFrac = "0.75" - // Simple model, send tokens to the fee pool of the provider validator set // reference: cosmos/ibc-go/v3/modules/apps/transfer/keeper/msg_server.go func (k Keeper) DistributeToProviderValidatorSet(ctx sdk.Context) error { @@ -34,7 +25,7 @@ func (k Keeper) DistributeToProviderValidatorSet(ctx sdk.Context) error { fpTokens := k.bankKeeper.GetAllBalances(ctx, consumerFeePoolAddr) // split the fee pool, send the consumer's fraction to the consumer redistribution address - frac, err := sdk.NewDecFromStr(ConsumerRedistributeFrac) + frac, err := sdk.NewDecFromStr(k.GetConsumerRedistributionFrac(ctx)) if err != nil { return err } @@ -76,7 +67,8 @@ func (k Keeper) DistributeToProviderValidatorSet(ctx sdk.Context) error { tstProviderTokens := k.bankKeeper.GetAllBalances(ctx, tstProviderAddr) providerAddr := k.GetProviderFeePoolAddrStr(ctx) timeoutHeight := clienttypes.ZeroHeight() - timeoutTimestamp := uint64(ctx.BlockTime().Add(TransferTimeDelay).UnixNano()) + transferTimeoutPeriod := k.GetTransferTimeoutPeriod(ctx) + timeoutTimestamp := uint64(ctx.BlockTime().Add(transferTimeoutPeriod).UnixNano()) for _, token := range tstProviderTokens { err := k.ibcTransferKeeper.SendTransfer(ctx, transfertypes.PortID, diff --git a/x/ccv/consumer/keeper/genesis_test.go b/x/ccv/consumer/keeper/genesis_test.go index 4077858303..1286f51911 100644 --- a/x/ccv/consumer/keeper/genesis_test.go +++ b/x/ccv/consumer/keeper/genesis_test.go @@ -49,8 +49,16 @@ func TestInitGenesis(t *testing.T) { MaturityTime: uint64(time.Now().UnixNano()), } - // create paramameters for a new chain - params := types.NewParams(true, types.DefaultBlocksPerDistributionTransmission, "", "") + // create parameters for a new chain + params := types.NewParams(true, + types.DefaultBlocksPerDistributionTransmission, + "", + "", + ccv.DefaultCCVTimeoutPeriod, + consumertypes.DefaultTransferTimeoutPeriod, + consumertypes.DefaultConsumerRedistributeFrac, + consumertypes.DefaultNumHistoricalEntries, + ) testCases := []struct { name string @@ -152,7 +160,16 @@ func TestExportGenesis(t *testing.T) { MaturityTime: uint64(time.Now().UnixNano()), } - params := types.NewParams(true, types.DefaultBlocksPerDistributionTransmission, "", "") + params := types.NewParams( + true, + types.DefaultBlocksPerDistributionTransmission, + "", + "", + ccv.DefaultCCVTimeoutPeriod, + consumertypes.DefaultTransferTimeoutPeriod, + consumertypes.DefaultConsumerRedistributeFrac, + consumertypes.DefaultNumHistoricalEntries, + ) // create a single validator pubKey := ed25519.GenPrivKey().PubKey() diff --git a/x/ccv/consumer/keeper/params.go b/x/ccv/consumer/keeper/params.go index e69a66d92b..ae9ec86f0f 100644 --- a/x/ccv/consumer/keeper/params.go +++ b/x/ccv/consumer/keeper/params.go @@ -1,18 +1,25 @@ package keeper import ( + "time" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/interchain-security/x/ccv/consumer/types" + ccvtypes "github.com/cosmos/interchain-security/x/ccv/types" ) -// GetParams returns the paramset for the consumer module +// GetParams returns the params for the consumer ccv module func (k Keeper) GetParams(ctx sdk.Context) types.Params { return types.NewParams( k.GetEnabled(ctx), k.GetBlocksPerDistributionTransmission(ctx), k.GetDistributionTransmissionChannel(ctx), k.GetProviderFeePoolAddrStr(ctx), + k.GetCCVTimeoutPeriod(ctx), + k.GetTransferTimeoutPeriod(ctx), + k.GetConsumerRedistributionFrac(ctx), + k.GetNumHistoricalEntries(ctx), ) } @@ -57,3 +64,29 @@ func (k Keeper) GetProviderFeePoolAddrStr(ctx sdk.Context) string { func (k Keeper) SetProviderFeePoolAddrStr(ctx sdk.Context, addr string) { k.paramStore.Set(ctx, types.KeyProviderFeePoolAddrStr, addr) } + +// GetCCVTimeoutPeriod returns the timeout period for sent ccv related ibc packets +func (k Keeper) GetCCVTimeoutPeriod(ctx sdk.Context) time.Duration { + var p time.Duration + k.paramStore.Get(ctx, ccvtypes.KeyCCVTimeoutPeriod, &p) + return p +} + +// GetTransferTimeoutPeriod returns the timeout period for sent transfer related ibc packets +func (k Keeper) GetTransferTimeoutPeriod(ctx sdk.Context) time.Duration { + var p time.Duration + k.paramStore.Get(ctx, types.KeyTransferTimeoutPeriod, &p) + return p +} + +func (k Keeper) GetConsumerRedistributionFrac(ctx sdk.Context) string { + var str string + k.paramStore.Get(ctx, types.KeyConsumerRedistributionFrac, &str) + return str +} + +func (k Keeper) GetNumHistoricalEntries(ctx sdk.Context) int64 { + var n int64 + k.paramStore.Get(ctx, types.KeyNumHistoricalEntries, &n) + return n +} diff --git a/x/ccv/consumer/keeper/params_test.go b/x/ccv/consumer/keeper/params_test.go index 0bc043d984..722e592495 100644 --- a/x/ccv/consumer/keeper/params_test.go +++ b/x/ccv/consumer/keeper/params_test.go @@ -2,9 +2,12 @@ package keeper_test import ( "testing" + "time" testkeeper "github.com/cosmos/interchain-security/testutil/keeper" "github.com/cosmos/interchain-security/x/ccv/consumer/types" + consumertypes "github.com/cosmos/interchain-security/x/ccv/consumer/types" + ccv "github.com/cosmos/interchain-security/x/ccv/types" "github.com/stretchr/testify/require" ) @@ -14,12 +17,22 @@ func TestParams(t *testing.T) { defer ctrl.Finish() consumerKeeper.SetParams(ctx, types.DefaultParams()) - expParams := types.NewParams(false, 1000, "", "") // these are the default params, IBC suite independently sets enabled=true + expParams := types.NewParams( + false, + 1000, + "", + "", + ccv.DefaultCCVTimeoutPeriod, + consumertypes.DefaultTransferTimeoutPeriod, + consumertypes.DefaultConsumerRedistributeFrac, + consumertypes.DefaultNumHistoricalEntries, + ) // these are the default params, IBC suite independently sets enabled=true params := consumerKeeper.GetParams(ctx) require.Equal(t, expParams, params) - newParams := types.NewParams(false, 1000, "abc", "def") + newParams := types.NewParams( + false, 1000, "abc", "def", 7*24*time.Hour, 25*time.Hour, "0.5", 500) consumerKeeper.SetParams(ctx, newParams) params = consumerKeeper.GetParams(ctx) require.Equal(t, newParams, params) diff --git a/x/ccv/consumer/keeper/relay.go b/x/ccv/consumer/keeper/relay.go index b32ee25d8b..4d5b085937 100644 --- a/x/ccv/consumer/keeper/relay.go +++ b/x/ccv/consumer/keeper/relay.go @@ -108,6 +108,7 @@ func (k Keeper) SendVSCMaturedPackets(ctx sdk.Context) error { channelID, // source channel id ccv.ConsumerPortID, // source port id packetData.GetBytes(), + k.GetParams(ctx).CcvTimeoutPeriod, ) if err != nil { return err @@ -153,6 +154,7 @@ func (k Keeper) SendSlashPacket(ctx sdk.Context, validator abci.Validator, valse channelID, // source channel id ccv.ConsumerPortID, // source port id packetData.GetBytes(), + k.GetParams(ctx).CcvTimeoutPeriod, ) if err != nil { panic(err) @@ -189,6 +191,7 @@ func (k Keeper) SendPendingSlashRequests(ctx sdk.Context) { channelID, // source channel id ccv.ConsumerPortID, // source port id slashReq.Packet.GetBytes(), + k.GetParams(ctx).CcvTimeoutPeriod, ) if err != nil { panic(err) diff --git a/x/ccv/consumer/keeper/validators.go b/x/ccv/consumer/keeper/validators.go index eeb94d5c93..71c67b16a6 100644 --- a/x/ccv/consumer/keeper/validators.go +++ b/x/ccv/consumer/keeper/validators.go @@ -154,7 +154,7 @@ func (k Keeper) DeleteHistoricalInfo(ctx sdk.Context, height int64) { // heights that are below pruning height func (k Keeper) TrackHistoricalInfo(ctx sdk.Context) { - entryNum := types.HistoricalEntries + entryNum := types.DefaultNumHistoricalEntries // Prune store to ensure we only have parameter-defined historical entries. // In most cases, this will involve removing a single historical entry. diff --git a/x/ccv/consumer/types/consumer.pb.go b/x/ccv/consumer/types/consumer.pb.go index f6a55d06c0..0a4ed8a365 100644 --- a/x/ccv/consumer/types/consumer.pb.go +++ b/x/ccv/consumer/types/consumer.pb.go @@ -10,16 +10,20 @@ import ( types1 "github.com/cosmos/interchain-security/x/ccv/types" _ "github.com/gogo/protobuf/gogoproto" proto "github.com/gogo/protobuf/proto" + github_com_gogo_protobuf_types "github.com/gogo/protobuf/types" _ "github.com/regen-network/cosmos-proto" + _ "google.golang.org/protobuf/types/known/durationpb" io "io" math "math" math_bits "math/bits" + time "time" ) // Reference imports to suppress errors if they are not otherwise used. var _ = proto.Marshal var _ = fmt.Errorf var _ = math.Inf +var _ = time.Kitchen // This is a compile-time assertion to ensure that this generated file // is compatible with the proto package it is being compiled against. @@ -29,8 +33,8 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package // Params defines the parameters for CCV consumer module type Params struct { - // TODO: Remove enabled flag and find a better way to setup e2e tests - // See: https://github.com/cosmos/interchain-security/issues/339 + // TODO: Remove enabled flag and find a better way to setup e2e tests + // See: https://github.com/cosmos/interchain-security/issues/339 Enabled bool `protobuf:"varint,1,opt,name=enabled,proto3" json:"enabled,omitempty"` /////////////////////// // Distribution Params @@ -44,6 +48,16 @@ type Params struct { // provider handshake procedure. DistributionTransmissionChannel string `protobuf:"bytes,3,opt,name=distribution_transmission_channel,json=distributionTransmissionChannel,proto3" json:"distribution_transmission_channel,omitempty"` ProviderFeePoolAddrStr string `protobuf:"bytes,4,opt,name=provider_fee_pool_addr_str,json=providerFeePoolAddrStr,proto3" json:"provider_fee_pool_addr_str,omitempty"` + // Sent CCV related IBC packets will timeout after this duration + CcvTimeoutPeriod time.Duration `protobuf:"bytes,5,opt,name=ccv_timeout_period,json=ccvTimeoutPeriod,proto3,stdduration" json:"ccv_timeout_period"` + // Sent transfer related IBC packets will timeout after this duration + TransferTimeoutPeriod time.Duration `protobuf:"bytes,6,opt,name=transfer_timeout_period,json=transferTimeoutPeriod,proto3,stdduration" json:"transfer_timeout_period"` + // The fraction of tokens allocated to the consumer redistribution address + // during distribution events. The fraction is a string representing a + // decimal number. For example "0.75" would represent 75%. + ConsumerRedistributionFraction string `protobuf:"bytes,7,opt,name=consumer_redistribution_fraction,json=consumerRedistributionFraction,proto3" json:"consumer_redistribution_fraction,omitempty"` + // The number of historical info entries to persist in store + NumHistoricalEntries int64 `protobuf:"varint,8,opt,name=num_historical_entries,json=numHistoricalEntries,proto3" json:"num_historical_entries,omitempty"` } func (m *Params) Reset() { *m = Params{} } @@ -107,6 +121,34 @@ func (m *Params) GetProviderFeePoolAddrStr() string { return "" } +func (m *Params) GetCcvTimeoutPeriod() time.Duration { + if m != nil { + return m.CcvTimeoutPeriod + } + return 0 +} + +func (m *Params) GetTransferTimeoutPeriod() time.Duration { + if m != nil { + return m.TransferTimeoutPeriod + } + return 0 +} + +func (m *Params) GetConsumerRedistributionFraction() string { + if m != nil { + return m.ConsumerRedistributionFraction + } + return "" +} + +func (m *Params) GetNumHistoricalEntries() int64 { + if m != nil { + return m.NumHistoricalEntries + } + return 0 +} + // LastTransmissionBlockHeight is the last time validator holding // pools were transmitted to the provider chain type LastTransmissionBlockHeight struct { @@ -326,46 +368,54 @@ func init() { } var fileDescriptor_5b27a82b276e7f93 = []byte{ - // 614 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x54, 0xcd, 0x6e, 0xd3, 0x4c, - 0x14, 0x8d, 0xbf, 0xf4, 0x0b, 0x65, 0x5a, 0x58, 0x98, 0xa8, 0x84, 0x22, 0xa5, 0xa9, 0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 0xd5, 0x5a, 0xd8, 0xbf, 0xbf, 0xb6, 0xbf, 0xdc, 0xd3, 0x0f, 0x7f, 0xfe, 0x02, - 0x74, 0x16, 0x83, 0xf2, 0x3a, 0x45, 0x48, 0x07, 0xbf, 0x02, 0x00, 0x00, 0xff, 0xff, 0x91, 0xef, - 0xc0, 0x3c, 0x33, 0x04, 0x00, 0x00, + // 747 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x54, 0xcd, 0x6e, 0xd3, 0x4a, + 0x14, 0x8e, 0x6f, 0xda, 0x34, 0x77, 0xd2, 0x7b, 0x75, 0xe5, 0x1b, 0x5a, 0xb7, 0x48, 0x4e, 0x1a, + 0x2a, 0x14, 0x09, 0xd5, 0x56, 0x52, 0xd8, 0x74, 0xd7, 0xa4, 0x54, 0xe5, 0x47, 0x22, 0xb8, 0x11, + 0x0b, 0x58, 0x58, 0xe3, 0xf1, 0x24, 0x19, 0xc5, 0x9e, 0x31, 0x33, 0x63, 0x83, 0xdf, 0x82, 0x25, + 0x12, 0x2f, 0x80, 0xc4, 0x96, 0x87, 0xa8, 0x58, 0x75, 0xc9, 0xaa, 0xa0, 0xf6, 0x0d, 0x78, 0x02, + 0xe4, 0xbf, 0x90, 0x14, 0x22, 0x75, 0x77, 0x8e, 0xce, 0xf7, 0x7d, 0x33, 0xe7, 0x17, 0x74, 0x09, + 0x95, 0x98, 0xa3, 0x09, 0x24, 0xd4, 0x16, 0x18, 0x85, 0x9c, 0xc8, 0xd8, 0x44, 0x28, 0x32, 0x11, + 0xa3, 0x22, 0xf4, 0x31, 0x37, 0xa3, 0xce, 0xcc, 0x36, 0x02, 0xce, 0x24, 0x53, 0xef, 0xfc, 0x81, + 0x63, 0x20, 0x14, 0x19, 0x33, 0x5c, 0xd4, 0xd9, 0xde, 0x5d, 0x26, 0x9c, 0xe8, 0xa1, 0x28, 0x93, + 0xda, 0xde, 0x1a, 0x33, 0x36, 0xf6, 0xb0, 0x99, 0x7a, 0x4e, 0x38, 0x32, 0x21, 0x8d, 0xf3, 0xd0, + 0x2e, 0x62, 0xc2, 0x67, 0xc2, 0x14, 0x12, 0x4e, 0x09, 0x1d, 0x9b, 0x51, 0xc7, 0xc1, 0x12, 0x76, + 0x0a, 0x3f, 0x47, 0xd5, 0xc7, 0x6c, 0xcc, 0x52, 0xd3, 0x4c, 0xac, 0x42, 0x36, 0xe3, 0xda, 0x59, + 0x20, 0x73, 0xf2, 0x90, 0x7e, 0xfd, 0x45, 0x37, 0xe4, 0x50, 0x12, 0x46, 0xb3, 0x78, 0xeb, 0xd3, + 0x0a, 0xa8, 0x0c, 0x20, 0x87, 0xbe, 0x50, 0x35, 0xb0, 0x86, 0x29, 0x74, 0x3c, 0xec, 0x6a, 0x4a, + 0x53, 0x69, 0x57, 0xad, 0xc2, 0x55, 0x9f, 0x81, 0x5d, 0xc7, 0x63, 0x68, 0x2a, 0xec, 0x00, 0x73, + 0xdb, 0x25, 0x42, 0x72, 0xe2, 0x84, 0x89, 0x8a, 0x2d, 0x39, 0xa4, 0xc2, 0x27, 0x42, 0x10, 0x46, + 0xb5, 0xbf, 0x9a, 0x4a, 0xbb, 0x6c, 0xed, 0x64, 0xd8, 0x01, 0xe6, 0x47, 0x73, 0xc8, 0xe1, 0x1c, + 0x50, 0x7d, 0x0c, 0x76, 0x96, 0xaa, 0xd8, 0x68, 0x02, 0x29, 0xc5, 0x9e, 0x56, 0x6e, 0x2a, 0xed, + 0xbf, 0xad, 0x86, 0xbb, 0x44, 0xa4, 0x9f, 0xc1, 0xd4, 0x03, 0xb0, 0x1d, 0x70, 0x16, 0x11, 0x17, + 0x73, 0x7b, 0x84, 0xb1, 0x1d, 0x30, 0xe6, 0xd9, 0xd0, 0x75, 0xb9, 0x2d, 0x24, 0xd7, 0x56, 0x52, + 0x91, 0x8d, 0x02, 0x71, 0x8c, 0xf1, 0x80, 0x31, 0xef, 0xd0, 0x75, 0x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f, 0xe9, 0xa5, 0xaf, 0x57, 0x7a, 0xe9, 0xe5, + 0xc1, 0x98, 0xc8, 0x49, 0xe8, 0x18, 0x88, 0xf9, 0xf9, 0x99, 0x31, 0x7f, 0xbd, 0xb6, 0x37, 0xbb, + 0x7b, 0x6f, 0x17, 0x4f, 0xaa, 0x8c, 0x03, 0x2c, 0x9c, 0x4a, 0xda, 0xa4, 0xfd, 0x9f, 0x01, 0x00, + 0x00, 0xff, 0xff, 0x28, 0xec, 0xa0, 0xf9, 0x83, 0x05, 0x00, 0x00, } func (m *Params) Marshal() (dAtA []byte, err error) { @@ -388,6 +438,34 @@ func (m *Params) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if m.NumHistoricalEntries != 0 { + i = encodeVarintConsumer(dAtA, i, uint64(m.NumHistoricalEntries)) + i-- + dAtA[i] = 0x40 + } + if len(m.ConsumerRedistributionFraction) > 0 { + i -= len(m.ConsumerRedistributionFraction) + copy(dAtA[i:], m.ConsumerRedistributionFraction) + i = encodeVarintConsumer(dAtA, i, uint64(len(m.ConsumerRedistributionFraction))) + i-- + dAtA[i] = 0x3a + } + n1, err1 := github_com_gogo_protobuf_types.StdDurationMarshalTo(m.TransferTimeoutPeriod, dAtA[i-github_com_gogo_protobuf_types.SizeOfStdDuration(m.TransferTimeoutPeriod):]) + if err1 != nil { + return 0, err1 + } + i -= n1 + i = encodeVarintConsumer(dAtA, i, uint64(n1)) + i-- + dAtA[i] = 0x32 + n2, err2 := github_com_gogo_protobuf_types.StdDurationMarshalTo(m.CcvTimeoutPeriod, dAtA[i-github_com_gogo_protobuf_types.SizeOfStdDuration(m.CcvTimeoutPeriod):]) + if err2 != nil { + return 0, err2 + } + i -= n2 + i = encodeVarintConsumer(dAtA, i, uint64(n2)) + i-- + dAtA[i] = 0x2a if len(m.ProviderFeePoolAddrStr) > 0 { i -= len(m.ProviderFeePoolAddrStr) copy(dAtA[i:], m.ProviderFeePoolAddrStr) @@ -603,6 +681,17 @@ func (m *Params) Size() (n int) { if l > 0 { n += 1 + l + sovConsumer(uint64(l)) } + l = github_com_gogo_protobuf_types.SizeOfStdDuration(m.CcvTimeoutPeriod) + n += 1 + l + sovConsumer(uint64(l)) + l = github_com_gogo_protobuf_types.SizeOfStdDuration(m.TransferTimeoutPeriod) + n += 1 + l + sovConsumer(uint64(l)) + l = len(m.ConsumerRedistributionFraction) + if l > 0 { + n += 1 + l + sovConsumer(uint64(l)) + } + if m.NumHistoricalEntries != 0 { + n += 1 + sovConsumer(uint64(m.NumHistoricalEntries)) + } return n } @@ -807,6 +896,123 @@ func (m *Params) Unmarshal(dAtA []byte) error { } m.ProviderFeePoolAddrStr = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex + case 5: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field CcvTimeoutPeriod", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowConsumer + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthConsumer + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthConsumer + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := github_com_gogo_protobuf_types.StdDurationUnmarshal(&m.CcvTimeoutPeriod, dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 6: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field TransferTimeoutPeriod", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowConsumer + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthConsumer + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthConsumer + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := github_com_gogo_protobuf_types.StdDurationUnmarshal(&m.TransferTimeoutPeriod, dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 7: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ConsumerRedistributionFraction", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowConsumer + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthConsumer + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthConsumer + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ConsumerRedistributionFraction = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 8: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field NumHistoricalEntries", wireType) + } + m.NumHistoricalEntries = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowConsumer + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.NumHistoricalEntries |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } default: iNdEx = preIndex skippy, err := skipConsumer(dAtA[iNdEx:]) diff --git a/x/ccv/consumer/types/genesis.go b/x/ccv/consumer/types/genesis.go index 0e2a0b2557..a2fdbe38a9 100644 --- a/x/ccv/consumer/types/genesis.go +++ b/x/ccv/consumer/types/genesis.go @@ -62,6 +62,9 @@ func (gs GenesisState) Validate() error { if len(gs.InitialValSet) == 0 { return sdkerrors.Wrap(ccv.ErrInvalidGenesis, "initial validator set is empty") } + if err := gs.Params.Validate(); err != nil { + return err + } if gs.NewChain { if gs.ProviderClientState == nil { diff --git a/x/ccv/consumer/types/keys.go b/x/ccv/consumer/types/keys.go index a94006840a..422cbd1528 100644 --- a/x/ccv/consumer/types/keys.go +++ b/x/ccv/consumer/types/keys.go @@ -19,9 +19,6 @@ const ( // QuerierRoute is the querier route for IBC consumer QuerierRoute = ModuleName - // HistoricalEntries is set to 10000 like the staking module parameter DefaultHistoricalEntries - HistoricalEntries uint32 = 10000 - // ConsumerRedistributeName the root string for the consumer-redistribution account address ConsumerRedistributeName = "cons_redistribute" diff --git a/x/ccv/consumer/types/params.go b/x/ccv/consumer/types/params.go index 2b6e11ea00..13a808cb13 100644 --- a/x/ccv/consumer/types/params.go +++ b/x/ccv/consumer/types/params.go @@ -1,19 +1,39 @@ package types import ( - "fmt" + fmt "fmt" + "time" + sdk "github.com/cosmos/cosmos-sdk/types" paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" + ccvtypes "github.com/cosmos/interchain-security/x/ccv/types" ) -// about 2 hr at 7.6 seconds per blocks -const DefaultBlocksPerDistributionTransmission = 1000 +const ( + // about 2 hr at 7.6 seconds per blocks + DefaultBlocksPerDistributionTransmission = 1000 + // 1 week + DefaultTransferTimeoutPeriod = 1 * 7 * 24 * time.Hour + + // The fraction of tokens allocated to the consumer redistribution address + // during distribution events. The fraction is a string representing a + // decimal number. For example "0.75" would represent 75%. + DefaultConsumerRedistributeFrac = "0.75" + + // Default number of historical info entries to persist in store + DefaultNumHistoricalEntries = 10000 +) + +// Reflection based keys for params subspace var ( KeyEnabled = []byte("Enabled") KeyBlocksPerDistributionTransmission = []byte("BlocksPerDistributionTransmission") KeyDistributionTransmissionChannel = []byte("DistributionTransmissionChannel") KeyProviderFeePoolAddrStr = []byte("ProviderFeePoolAddrStr") + KeyTransferTimeoutPeriod = []byte("TransferTimeoutPeriod") + KeyConsumerRedistributionFrac = []byte("ConsumerRedistributionFraction") + KeyNumHistoricalEntries = []byte("NumHistoricalEntries") ) // ParamKeyTable type declaration for parameters @@ -23,12 +43,19 @@ func ParamKeyTable() paramtypes.KeyTable { // NewParams creates new consumer parameters with provided arguments func NewParams(enabled bool, blocksPerDistributionTransmission int64, - distributionTransmissionChannel, providerFeePoolAddrStr string) Params { + distributionTransmissionChannel, providerFeePoolAddrStr string, + ccvTimeoutPeriod time.Duration, transferTimeoutPeriod time.Duration, + consumerRedistributionFraction string, numHistoricalEntries int64) Params { return Params{ Enabled: enabled, BlocksPerDistributionTransmission: blocksPerDistributionTransmission, DistributionTransmissionChannel: distributionTransmissionChannel, ProviderFeePoolAddrStr: providerFeePoolAddrStr, + CcvTimeoutPeriod: ccvTimeoutPeriod, + TransferTimeoutPeriod: transferTimeoutPeriod, + // TODO: Find a way to make sure fraction is valid, or don't do that here? + ConsumerRedistributionFraction: consumerRedistributionFraction, + NumHistoricalEntries: numHistoricalEntries, } } @@ -39,44 +66,80 @@ func DefaultParams() Params { DefaultBlocksPerDistributionTransmission, "", "", + ccvtypes.DefaultCCVTimeoutPeriod, + DefaultTransferTimeoutPeriod, + DefaultConsumerRedistributeFrac, + DefaultNumHistoricalEntries, ) } // Validate all ccv-consumer module parameters +// TODO: Unit tests similar to provider func (p Params) Validate() error { - return nil -} - -// ParamSetPairs implements params.ParamSet -func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs { - return paramtypes.ParamSetPairs{ - paramtypes.NewParamSetPair(KeyEnabled, p.Enabled, validateBool), - paramtypes.NewParamSetPair(KeyBlocksPerDistributionTransmission, - p.BlocksPerDistributionTransmission, validateInt64), - paramtypes.NewParamSetPair(KeyDistributionTransmissionChannel, - p.DistributionTransmissionChannel, validateString), - paramtypes.NewParamSetPair(KeyProviderFeePoolAddrStr, - p.ProviderFeePoolAddrStr, validateString), + if err := ccvtypes.ValidateBool(p.Enabled); err != nil { + return err } -} - -func validateBool(i interface{}) error { - if _, ok := i.(bool); !ok { - return fmt.Errorf("invalid parameter type: %T", i) + if err := ccvtypes.ValidatePositiveInt64(p.BlocksPerDistributionTransmission); err != nil { + return err + } + // TODO: Is it acceptable if string is empty? Defaults say yes + if err := ccvtypes.ValidateString(p.DistributionTransmissionChannel); err != nil { + return err + } + // TODO: Is it acceptable if string is empty? Defaults say yes + if err := ccvtypes.ValidateString(p.ProviderFeePoolAddrStr); err != nil { + return err + } + if err := ccvtypes.ValidateDuration(p.CcvTimeoutPeriod); err != nil { + return err + } + if err := ccvtypes.ValidateDuration(p.TransferTimeoutPeriod); err != nil { + return err + } + if err := validateConsumerRedistributionFraction(p.ConsumerRedistributionFraction); err != nil { + return err + } + if err := ccvtypes.ValidatePositiveInt64(p.NumHistoricalEntries); err != nil { + return err } return nil } -func validateInt64(i interface{}) error { - if _, ok := i.(int64); !ok { +func validateConsumerRedistributionFraction(i interface{}) error { + str, ok := i.(string) + if !ok { return fmt.Errorf("invalid parameter type: %T", i) } + dec, err := sdk.NewDecFromStr(str) + if err != nil { + return err + } + if !dec.IsPositive() { + return fmt.Errorf("consumer redistribution fraction is not positive") + } + if dec.Sub(sdk.NewDec(1)).IsPositive() { + return fmt.Errorf("consumer redistribution fraction cannot be above 1.0") + } return nil } -func validateString(i interface{}) error { - if _, ok := i.(string); !ok { - return fmt.Errorf("invalid parameter type: %T", i) +// ParamSetPairs implements params.ParamSet +func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs { + return paramtypes.ParamSetPairs{ + paramtypes.NewParamSetPair(KeyEnabled, p.Enabled, ccvtypes.ValidateBool), + paramtypes.NewParamSetPair(KeyBlocksPerDistributionTransmission, + p.BlocksPerDistributionTransmission, ccvtypes.ValidatePositiveInt64), + paramtypes.NewParamSetPair(KeyDistributionTransmissionChannel, + p.DistributionTransmissionChannel, ccvtypes.ValidateString), + paramtypes.NewParamSetPair(KeyProviderFeePoolAddrStr, + p.ProviderFeePoolAddrStr, ccvtypes.ValidateString), + paramtypes.NewParamSetPair(ccvtypes.KeyCCVTimeoutPeriod, + p.CcvTimeoutPeriod, ccvtypes.ValidateDuration), + paramtypes.NewParamSetPair(KeyTransferTimeoutPeriod, + p.TransferTimeoutPeriod, ccvtypes.ValidateDuration), + paramtypes.NewParamSetPair(KeyConsumerRedistributionFrac, + p.ConsumerRedistributionFraction, validateConsumerRedistributionFraction), + paramtypes.NewParamSetPair(KeyNumHistoricalEntries, + p.NumHistoricalEntries, ccvtypes.ValidatePositiveInt64), } - return nil } diff --git a/x/ccv/provider/keeper/params.go b/x/ccv/provider/keeper/params.go index 3fdf4f895f..f3d04cb7e4 100644 --- a/x/ccv/provider/keeper/params.go +++ b/x/ccv/provider/keeper/params.go @@ -1,11 +1,14 @@ package keeper import ( + "time" + sdk "github.com/cosmos/cosmos-sdk/types" ibctmtypes "github.com/cosmos/ibc-go/v3/modules/light-clients/07-tendermint/types" "github.com/cosmos/interchain-security/x/ccv/provider/types" + ccvtypes "github.com/cosmos/interchain-security/x/ccv/types" ) // GetTemplateClient returns the template client for provider proposals @@ -15,12 +18,31 @@ func (k Keeper) GetTemplateClient(ctx sdk.Context) *ibctmtypes.ClientState { return &cs } +// GetCCVTimeoutPeriod returns the timeout period for sent ibc packets +func (k Keeper) GetCCVTimeoutPeriod(ctx sdk.Context) time.Duration { + var p time.Duration + k.paramSpace.Get(ctx, ccvtypes.KeyCCVTimeoutPeriod, &p) + return p +} + +// GetTrustingPeriodFraction returns a TrustingPeriodFraction +// used to compute the provider IBC client's TrustingPeriod as UnbondingPeriod / TrustingPeriodFraction +func (k Keeper) GetTrustingPeriodFraction(ctx sdk.Context) int64 { + var i int64 + k.paramSpace.Get(ctx, types.KeyTrustingPeriodFraction, &i) + return i +} + // GetParams returns the paramset for the provider module func (k Keeper) GetParams(ctx sdk.Context) types.Params { - return types.NewParams(k.GetTemplateClient(ctx)) + return types.NewParams( + k.GetTemplateClient(ctx), + k.GetCCVTimeoutPeriod(ctx), + k.GetTrustingPeriodFraction(ctx), + ) } -// SetParams sets the paramset for the provider module +// SetParams sets the params for the provider module func (k Keeper) SetParams(ctx sdk.Context, params types.Params) { k.paramSpace.SetParamSet(ctx, ¶ms) } diff --git a/x/ccv/provider/keeper/params_test.go b/x/ccv/provider/keeper/params_test.go index 6a8298ad6f..a16d1c1366 100644 --- a/x/ccv/provider/keeper/params_test.go +++ b/x/ccv/provider/keeper/params_test.go @@ -9,24 +9,26 @@ import ( ibctmtypes "github.com/cosmos/ibc-go/v3/modules/light-clients/07-tendermint/types" testkeeper "github.com/cosmos/interchain-security/testutil/keeper" "github.com/cosmos/interchain-security/x/ccv/provider/types" + ccvtypes "github.com/cosmos/interchain-security/x/ccv/types" "github.com/stretchr/testify/require" ) -// TestParams tests the default params of the keeper, and getting/setting new params. +// TestParams tests the getting/setting of provider ccv module params. func TestParams(t *testing.T) { - defaultParams := types.DefaultParams() - // Construct an in-mem keeper with a populated template client state + // Construct an in-mem keeper with registered key table keeperParams := testkeeper.NewInMemKeeperParams(t) - keeperParams.SetTemplateClientState(nil) providerKeeper, ctx, ctrl, _ := testkeeper.GetProviderKeeperAndCtx(t, keeperParams) defer ctrl.Finish() + defaultParams := types.DefaultParams() + providerKeeper.SetParams(ctx, defaultParams) params := providerKeeper.GetParams(ctx) require.Equal(t, defaultParams, params) newParams := types.NewParams(ibctmtypes.NewClientState("", ibctmtypes.DefaultTrustLevel, 0, 0, - time.Second*40, clienttypes.Height{}, commitmenttypes.GetSDKSpecs(), []string{"ibc", "upgradedIBCState"}, true, false)) + time.Second*40, clienttypes.Height{}, commitmenttypes.GetSDKSpecs(), []string{"ibc", "upgradedIBCState"}, true, false), + ccvtypes.DefaultCCVTimeoutPeriod, types.DefaultTrustingPeriodFraction) providerKeeper.SetParams(ctx, newParams) params = providerKeeper.GetParams(ctx) require.Equal(t, newParams, params) diff --git a/x/ccv/provider/keeper/proposal.go b/x/ccv/provider/keeper/proposal.go index d9b346e968..b66aa47812 100644 --- a/x/ccv/provider/keeper/proposal.go +++ b/x/ccv/provider/keeper/proposal.go @@ -60,7 +60,7 @@ func (k Keeper) CreateConsumerClient(ctx sdk.Context, chainID string, initialHei clientState := k.GetTemplateClient(ctx) clientState.ChainId = chainID clientState.LatestHeight = initialHeight - clientState.TrustingPeriod = unbondingPeriod / utils.TrustingPeriodFraction + clientState.TrustingPeriod = unbondingPeriod / time.Duration(k.GetTrustingPeriodFraction(ctx)) clientState.UnbondingPeriod = unbondingPeriod // TODO: Allow for current validators to set different keys @@ -196,7 +196,7 @@ func (k Keeper) MakeConsumerGenesis(ctx sdk.Context) (gen consumertypes.GenesisS clientState := k.GetTemplateClient(ctx) clientState.ChainId = ctx.ChainID() clientState.LatestHeight = height //(+-1???) - clientState.TrustingPeriod = unbondingTime / utils.TrustingPeriodFraction + clientState.TrustingPeriod = unbondingTime / time.Duration(k.GetTrustingPeriodFraction(ctx)) clientState.UnbondingPeriod = unbondingTime consState, err := k.clientKeeper.GetSelfConsensusState(ctx, height) diff --git a/x/ccv/provider/keeper/proposal_test.go b/x/ccv/provider/keeper/proposal_test.go index 1e309e737b..c6a4a03eda 100644 --- a/x/ccv/provider/keeper/proposal_test.go +++ b/x/ccv/provider/keeper/proposal_test.go @@ -19,6 +19,7 @@ import ( providerkeeper "github.com/cosmos/interchain-security/x/ccv/provider/keeper" "github.com/cosmos/interchain-security/x/ccv/provider/types" providertypes "github.com/cosmos/interchain-security/x/ccv/provider/types" + ccvtypes "github.com/cosmos/interchain-security/x/ccv/types" ) // @@ -78,8 +79,8 @@ func TestHandleConsumerAdditionProposal(t *testing.T) { for _, tc := range tests { // Common setup keeperParams := testkeeper.NewInMemKeeperParams(t) - keeperParams.SetTemplateClientState(nil) providerKeeper, ctx, ctrl, mocks := testkeeper.GetProviderKeeperAndCtx(t, keeperParams) + providerKeeper.SetParams(ctx, providertypes.DefaultParams()) ctx = ctx.WithBlockTime(tc.blockTime) if tc.expCreatedClient { @@ -154,8 +155,8 @@ func TestCreateConsumerClient(t *testing.T) { for _, tc := range tests { // Common setup keeperParams := testkeeper.NewInMemKeeperParams(t) - keeperParams.SetTemplateClientState(nil) providerKeeper, ctx, ctrl, mocks := testkeeper.GetProviderKeeperAndCtx(t, keeperParams) + providerKeeper.SetParams(ctx, providertypes.DefaultParams()) // Test specific setup tc.setup(&providerKeeper, ctx, &mocks) @@ -355,8 +356,8 @@ func TestHandleConsumerRemovalProposal(t *testing.T) { // Common setup keeperParams := testkeeper.NewInMemKeeperParams(t) - keeperParams.SetTemplateClientState(nil) providerKeeper, ctx, ctrl, mocks := testkeeper.GetProviderKeeperAndCtx(t, keeperParams) + providerKeeper.SetParams(ctx, providertypes.DefaultParams()) ctx = ctx.WithBlockTime(tc.blockTime) // Mock expectations and setup for stopping the consumer chain, if applicable @@ -431,8 +432,8 @@ func TestStopConsumerChain(t *testing.T) { // Common setup keeperParams := testkeeper.NewInMemKeeperParams(t) - keeperParams.SetTemplateClientState(nil) providerKeeper, ctx, ctrl, mocks := testkeeper.GetProviderKeeperAndCtx(t, keeperParams) + providerKeeper.SetParams(ctx, providertypes.DefaultParams()) // Setup specific to test case tc.setup(ctx, &providerKeeper, mocks) @@ -570,14 +571,15 @@ func TestPendingConsumerRemovalPropOrder(t *testing.T) { } } -// TestMakeConsumerGenesis tests the MakeConsumerGenesis keeper method -// -// Note: the initial intention of this test wasn't very clear, it was migrated with best effort +// TestMakeConsumerGenesis tests the MakeConsumerGenesis keeper method. +// An expected genesis state is hardcoded in json, unmarshaled, and compared +// against an actual consumer genesis state constructed by a provider keeper. func TestMakeConsumerGenesis(t *testing.T) { keeperParams := testkeeper.NewInMemKeeperParams(t) - keeperParams.SetTemplateClientState( - &ibctmtypes.ClientState{ + providerKeeper, ctx, ctrl, mocks := testkeeper.GetProviderKeeperAndCtx(t, keeperParams) + moduleParams := providertypes.Params{ + TemplateClient: &ibctmtypes.ClientState{ TrustLevel: ibctmtypes.DefaultTrustLevel, MaxClockDrift: 10000000000, ProofSpecs: []*_go.ProofSpec{ @@ -621,8 +623,12 @@ func TestMakeConsumerGenesis(t *testing.T) { AllowUpdateAfterExpiry: true, AllowUpdateAfterMisbehaviour: true, }, - ) - providerKeeper, ctx, ctrl, mocks := testkeeper.GetProviderKeeperAndCtx(t, keeperParams) + // Note these are unused provider parameters for this test, and not actually asserted against + // They must be populated with reasonable values to satisfy SetParams though. + CcvTimeoutPeriod: ccvtypes.DefaultCCVTimeoutPeriod, + TrustingPeriodFraction: providertypes.DefaultTrustingPeriodFraction, + } + providerKeeper.SetParams(ctx, moduleParams) defer ctrl.Finish() // @@ -635,7 +641,7 @@ func TestMakeConsumerGenesis(t *testing.T) { actualGenesis, err := providerKeeper.MakeConsumerGenesis(ctx) require.NoError(t, err) - jsonString := `{"params":{"enabled":true, "blocks_per_distribution_transmission":1000, "lock_unbonding_on_timeout": false},"new_chain":true,"provider_client_state":{"chain_id":"testchain1","trust_level":{"numerator":1,"denominator":3},"trusting_period":907200000000000,"unbonding_period":1814400000000000,"max_clock_drift":10000000000,"frozen_height":{},"latest_height":{"revision_height":5},"proof_specs":[{"leaf_spec":{"hash":1,"prehash_value":1,"length":1,"prefix":"AA=="},"inner_spec":{"child_order":[0,1],"child_size":33,"min_prefix_length":4,"max_prefix_length":12,"hash":1}},{"leaf_spec":{"hash":1,"prehash_value":1,"length":1,"prefix":"AA=="},"inner_spec":{"child_order":[0,1],"child_size":32,"min_prefix_length":1,"max_prefix_length":1,"hash":1}}],"upgrade_path":["upgrade","upgradedIBCState"],"allow_update_after_expiry":true,"allow_update_after_misbehaviour":true},"provider_consensus_state":{"timestamp":"2020-01-02T00:00:10Z","root":{"hash":"LpGpeyQVLUo9HpdsgJr12NP2eCICspcULiWa5u9udOA="},"next_validators_hash":"E30CE736441FB9101FADDAF7E578ABBE6DFDB67207112350A9A904D554E1F5BE"},"unbonding_sequences":null,"initial_val_set":[{"pub_key":{"type":"tendermint/PubKeyEd25519","value":"dcASx5/LIKZqagJWN0frOlFtcvz91frYmj/zmoZRWro="},"power":1}]}` + jsonString := `{"params":{"enabled":true, "blocks_per_distribution_transmission":1000, "ccv_timeout_period":2419200000000000, "transfer_timeout_period": 604800000000000, "consumer_redistribution_fraction":"0.75", "num_historical_entries":10000},"new_chain":true,"provider_client_state":{"chain_id":"testchain1","trust_level":{"numerator":1,"denominator":3},"trusting_period":907200000000000,"unbonding_period":1814400000000000,"max_clock_drift":10000000000,"frozen_height":{},"latest_height":{"revision_height":5},"proof_specs":[{"leaf_spec":{"hash":1,"prehash_value":1,"length":1,"prefix":"AA=="},"inner_spec":{"child_order":[0,1],"child_size":33,"min_prefix_length":4,"max_prefix_length":12,"hash":1}},{"leaf_spec":{"hash":1,"prehash_value":1,"length":1,"prefix":"AA=="},"inner_spec":{"child_order":[0,1],"child_size":32,"min_prefix_length":1,"max_prefix_length":1,"hash":1}}],"upgrade_path":["upgrade","upgradedIBCState"],"allow_update_after_expiry":true,"allow_update_after_misbehaviour":true},"provider_consensus_state":{"timestamp":"2020-01-02T00:00:10Z","root":{"hash":"LpGpeyQVLUo9HpdsgJr12NP2eCICspcULiWa5u9udOA="},"next_validators_hash":"E30CE736441FB9101FADDAF7E578ABBE6DFDB67207112350A9A904D554E1F5BE"},"unbonding_sequences":null,"initial_val_set":[{"pub_key":{"type":"tendermint/PubKeyEd25519","value":"dcASx5/LIKZqagJWN0frOlFtcvz91frYmj/zmoZRWro="},"power":1}]}` var expectedGenesis consumertypes.GenesisState err = json.Unmarshal([]byte(jsonString), &expectedGenesis) @@ -647,7 +653,7 @@ func TestMakeConsumerGenesis(t *testing.T) { actualGenesis.ProviderConsensusState = &ibctmtypes.ConsensusState{} expectedGenesis.ProviderConsensusState = &ibctmtypes.ConsensusState{} - require.Equal(t, actualGenesis, expectedGenesis, "consumer chain genesis created incorrectly") + require.Equal(t, expectedGenesis, actualGenesis, "consumer chain genesis created incorrectly") } // TestBeginBlockInit directly tests BeginBlockInit against the spec using helpers defined above. @@ -659,8 +665,8 @@ func TestBeginBlockInit(t *testing.T) { now := time.Now().UTC() keeperParams := testkeeper.NewInMemKeeperParams(t) - keeperParams.SetTemplateClientState(nil) providerKeeper, ctx, ctrl, mocks := testkeeper.GetProviderKeeperAndCtx(t, keeperParams) + providerKeeper.SetParams(ctx, providertypes.DefaultParams()) defer ctrl.Finish() ctx = ctx.WithBlockTime(now) @@ -709,8 +715,8 @@ func TestBeginBlockCCR(t *testing.T) { now := time.Now().UTC() keeperParams := testkeeper.NewInMemKeeperParams(t) - keeperParams.SetTemplateClientState(nil) providerKeeper, ctx, ctrl, mocks := testkeeper.GetProviderKeeperAndCtx(t, keeperParams) + providerKeeper.SetParams(ctx, providertypes.DefaultParams()) defer ctrl.Finish() ctx = ctx.WithBlockTime(now) diff --git a/x/ccv/provider/keeper/relay.go b/x/ccv/provider/keeper/relay.go index b154f9ed13..c40603bbc9 100644 --- a/x/ccv/provider/keeper/relay.go +++ b/x/ccv/provider/keeper/relay.go @@ -147,6 +147,7 @@ func (k Keeper) SendValidatorUpdates(ctx sdk.Context) { channelID, // source channel id ccv.ProviderPortID, // source port id packetData.GetBytes(), + k.GetParams(ctx).CcvTimeoutPeriod, ) if err != nil { panic(fmt.Errorf("packet could not be sent over IBC: %w", err)) @@ -174,6 +175,7 @@ func (k Keeper) SendPendingVSCPackets(ctx sdk.Context, chainID, channelID string channelID, // source channel id ccv.ProviderPortID, // source port id data.GetBytes(), + k.GetParams(ctx).CcvTimeoutPeriod, ) if err != nil { panic(fmt.Errorf("packet could not be sent over IBC: %w", err)) diff --git a/x/ccv/provider/proposal_handler_test.go b/x/ccv/provider/proposal_handler_test.go index 92c806a1ed..c5cd78760f 100644 --- a/x/ccv/provider/proposal_handler_test.go +++ b/x/ccv/provider/proposal_handler_test.go @@ -15,6 +15,7 @@ import ( testkeeper "github.com/cosmos/interchain-security/testutil/keeper" "github.com/cosmos/interchain-security/x/ccv/provider" "github.com/cosmos/interchain-security/x/ccv/provider/types" + providertypes "github.com/cosmos/interchain-security/x/ccv/provider/types" ) // TestConsumerChainProposalHandler tests the highest level handler for proposals concerning both @@ -64,8 +65,8 @@ func TestConsumerChainProposalHandler(t *testing.T) { // Setup keeperParams := testkeeper.NewInMemKeeperParams(t) - keeperParams.SetTemplateClientState(nil) providerKeeper, ctx, ctrl, mocks := testkeeper.GetProviderKeeperAndCtx(t, keeperParams) + providerKeeper.SetParams(ctx, providertypes.DefaultParams()) ctx = ctx.WithBlockTime(tc.blockTime) // Mock expectations depending on expected outcome diff --git a/x/ccv/provider/types/genesis_test.go b/x/ccv/provider/types/genesis_test.go index e1a7556bdc..9960d89409 100644 --- a/x/ccv/provider/types/genesis_test.go +++ b/x/ccv/provider/types/genesis_test.go @@ -8,6 +8,8 @@ import ( commitmenttypes "github.com/cosmos/ibc-go/v3/modules/core/23-commitment/types" ibctmtypes "github.com/cosmos/ibc-go/v3/modules/light-clients/07-tendermint/types" "github.com/cosmos/interchain-security/x/ccv/provider/types" + providertypes "github.com/cosmos/interchain-security/x/ccv/provider/types" + ccv "github.com/cosmos/interchain-security/x/ccv/types" "github.com/stretchr/testify/require" ) @@ -77,7 +79,8 @@ func TestValidateGenesisState(t *testing.T) { nil, nil, types.NewParams(ibctmtypes.NewClientState("", ibctmtypes.DefaultTrustLevel, 0, 0, - time.Second*40, clienttypes.Height{}, commitmenttypes.GetSDKSpecs(), []string{"ibc", "upgradedIBCState"}, true, false)), + time.Second*40, clienttypes.Height{}, commitmenttypes.GetSDKSpecs(), []string{"ibc", "upgradedIBCState"}, true, false), + 2*7*24*time.Hour, 3), ), true, }, @@ -92,7 +95,40 @@ func TestValidateGenesisState(t *testing.T) { nil, nil, types.NewParams(ibctmtypes.NewClientState("", ibctmtypes.DefaultTrustLevel, 0, 0, - 0, clienttypes.Height{}, nil, []string{"ibc", "upgradedIBCState"}, true, false)), + 0, clienttypes.Height{}, nil, []string{"ibc", "upgradedIBCState"}, true, false), + ccv.DefaultCCVTimeoutPeriod, providertypes.DefaultTrustingPeriodFraction), + ), + false, + }, + { + "invalid params, zero ccv timeout", + types.NewGenesisState( + 0, + nil, + []types.ConsumerState{{ChainId: "chainid-1", ChannelId: "channelid"}}, + nil, + nil, + nil, + nil, + types.NewParams(ibctmtypes.NewClientState("", ibctmtypes.DefaultTrustLevel, 0, 0, + time.Second*40, clienttypes.Height{}, commitmenttypes.GetSDKSpecs(), []string{"ibc", "upgradedIBCState"}, true, false), + 0, providertypes.DefaultTrustingPeriodFraction), + ), + false, + }, + { + "invalid params, zero trusted period fraction", + types.NewGenesisState( + 0, + nil, + []types.ConsumerState{{ChainId: "chainid-1", ChannelId: "channelid"}}, + nil, + nil, + nil, + nil, + types.NewParams(ibctmtypes.NewClientState("", ibctmtypes.DefaultTrustLevel, 0, 0, + time.Second*40, clienttypes.Height{}, commitmenttypes.GetSDKSpecs(), []string{"ibc", "upgradedIBCState"}, true, false), + 2*7*24*time.Hour, 0), ), false, }, diff --git a/x/ccv/provider/types/params.go b/x/ccv/provider/types/params.go index b121a718a9..6e958088f2 100644 --- a/x/ccv/provider/types/params.go +++ b/x/ccv/provider/types/params.go @@ -8,6 +8,7 @@ import ( clienttypes "github.com/cosmos/ibc-go/v3/modules/core/02-client/types" commitmenttypes "github.com/cosmos/ibc-go/v3/modules/core/23-commitment/types" ibctmtypes "github.com/cosmos/ibc-go/v3/modules/light-clients/07-tendermint/types" + ccvtypes "github.com/cosmos/interchain-security/x/ccv/types" ) const ( @@ -20,21 +21,30 @@ const ( // DefaultMaxClockDrift defines how much new (untrusted) header's Time can drift into the future. DefaultMaxClockDrift = 10 * time.Second + + // DefaultTrustingPeriodFraction is the default fraction used to compute TrustingPeriod + // as UnbondingPeriod / TrustingPeriodFraction + DefaultTrustingPeriodFraction = 2 ) +// Reflection based keys for params subspace var ( - KeyTemplateClient = []byte("TemplateClient") + KeyTemplateClient = []byte("TemplateClient") + KeyTrustingPeriodFraction = []byte("TrustingPeriodFraction") ) -// ParamKeyTable type declaration for parameters +// ParamKeyTable returns a key table with the necessary registered provider params func ParamKeyTable() paramtypes.KeyTable { return paramtypes.NewKeyTable().RegisterParamSet(&Params{}) } // NewParams creates new provider parameters with provided arguments -func NewParams(cs *ibctmtypes.ClientState) Params { +func NewParams(cs *ibctmtypes.ClientState, ccvTimeoutPeriod time.Duration, + trustingPeriodFraction int64) Params { return Params{ - TemplateClient: cs, + TemplateClient: cs, + CcvTimeoutPeriod: ccvTimeoutPeriod, + TrustingPeriodFraction: trustingPeriodFraction, } } @@ -45,28 +55,41 @@ func DefaultParams() Params { return NewParams( ibctmtypes.NewClientState("", ibctmtypes.DefaultTrustLevel, 0, 0, DefaultMaxClockDrift, clienttypes.Height{}, commitmenttypes.GetSDKSpecs(), []string{"upgrade", "upgradedIBCState"}, true, true), + ccvtypes.DefaultCCVTimeoutPeriod, + DefaultTrustingPeriodFraction, ) } // Validate all ccv-provider module parameters func (p Params) Validate() error { if p.TemplateClient == nil { - return fmt.Errorf("Template client is nil") + return fmt.Errorf("template client is nil") + } + if err := validateTemplateClient(*p.TemplateClient); err != nil { + return err + } + if err := ccvtypes.ValidateDuration(p.CcvTimeoutPeriod); err != nil { + return err + } + if err := ccvtypes.ValidatePositiveInt64(p.TrustingPeriodFraction); err != nil { + return err } - return validateTemplateClient(*p.TemplateClient) + return nil } // ParamSetPairs implements params.ParamSet func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs { return paramtypes.ParamSetPairs{ paramtypes.NewParamSetPair(KeyTemplateClient, p.TemplateClient, validateTemplateClient), + paramtypes.NewParamSetPair(ccvtypes.KeyCCVTimeoutPeriod, p.CcvTimeoutPeriod, ccvtypes.ValidateDuration), + paramtypes.NewParamSetPair(KeyTrustingPeriodFraction, p.TrustingPeriodFraction, ccvtypes.ValidatePositiveInt64), } } func validateTemplateClient(i interface{}) error { cs, ok := i.(ibctmtypes.ClientState) if !ok { - return fmt.Errorf("invalid parameter type: %T", i) + return fmt.Errorf("invalid parameter type: %T, expected: %T", i, ibctmtypes.ClientState{}) } // copy clientstate to prevent changing original pointer diff --git a/x/ccv/provider/types/params_test.go b/x/ccv/provider/types/params_test.go index f5252327b1..385f835567 100644 --- a/x/ccv/provider/types/params_test.go +++ b/x/ccv/provider/types/params_test.go @@ -13,6 +13,7 @@ import ( ) func TestValidateParams(t *testing.T) { + testCases := []struct { name string params types.Params @@ -20,11 +21,17 @@ func TestValidateParams(t *testing.T) { }{ {"default params", types.DefaultParams(), true}, {"custom valid params", types.NewParams(ibctmtypes.NewClientState("", ibctmtypes.DefaultTrustLevel, 0, 0, - time.Second*40, clienttypes.Height{}, commitmenttypes.GetSDKSpecs(), []string{"ibc", "upgradedIBCState"}, true, false)), true}, + time.Second*40, clienttypes.Height{}, commitmenttypes.GetSDKSpecs(), []string{"ibc", "upgradedIBCState"}, true, false), + 2*7*24*time.Hour, 2), true}, {"custom invalid params", types.NewParams(ibctmtypes.NewClientState("", ibctmtypes.DefaultTrustLevel, 0, 0, - 0, clienttypes.Height{}, nil, []string{"ibc", "upgradedIBCState"}, true, false)), false}, - {"blank client", types.NewParams(&ibctmtypes.ClientState{}), false}, - {"nil client", types.NewParams(nil), false}, + 0, clienttypes.Height{}, nil, []string{"ibc", "upgradedIBCState"}, true, false), + 2*7*24*time.Hour, 2), false}, + {"blank client", types.NewParams(&ibctmtypes.ClientState{}, + 2*7*24*time.Hour, 2), false}, + {"nil client", types.NewParams(nil, 2*7*24*time.Hour, 2), false}, + {"0 ccv timeout period", types.NewParams(ibctmtypes.NewClientState("", ibctmtypes.DefaultTrustLevel, 0, 0, + time.Second*40, clienttypes.Height{}, commitmenttypes.GetSDKSpecs(), []string{"ibc", "upgradedIBCState"}, true, false), + 0, 2), false}, } for _, tc := range testCases { diff --git a/x/ccv/provider/types/provider.pb.go b/x/ccv/provider/types/provider.pb.go index df9f5228ab..444f31d909 100644 --- a/x/ccv/provider/types/provider.pb.go +++ b/x/ccv/provider/types/provider.pb.go @@ -10,6 +10,7 @@ import ( _ "github.com/gogo/protobuf/gogoproto" proto "github.com/gogo/protobuf/proto" github_com_gogo_protobuf_types "github.com/gogo/protobuf/types" + _ "google.golang.org/protobuf/types/known/durationpb" _ "google.golang.org/protobuf/types/known/timestamppb" io "io" math "math" @@ -166,6 +167,10 @@ func (m *ConsumerRemovalProposal) GetStopTime() time.Time { // Params defines the parameters for CCV Provider module type Params struct { TemplateClient *types1.ClientState `protobuf:"bytes,1,opt,name=template_client,json=templateClient,proto3" json:"template_client,omitempty"` + // Sent IBC packets will timeout after this duration + CcvTimeoutPeriod time.Duration `protobuf:"bytes,2,opt,name=ccv_timeout_period,json=ccvTimeoutPeriod,proto3,stdduration" json:"ccv_timeout_period"` + // TrustingPeriodFraction is used to compute the provider IBC client's TrustingPeriod + TrustingPeriodFraction int64 `protobuf:"varint,3,opt,name=trusting_period_fraction,json=trustingPeriodFraction,proto3" json:"trusting_period_fraction,omitempty"` } func (m *Params) Reset() { *m = Params{} } @@ -208,6 +213,20 @@ func (m *Params) GetTemplateClient() *types1.ClientState { return nil } +func (m *Params) GetCcvTimeoutPeriod() time.Duration { + if m != nil { + return m.CcvTimeoutPeriod + } + return 0 +} + +func (m *Params) GetTrustingPeriodFraction() int64 { + if m != nil { + return m.TrustingPeriodFraction + } + return 0 +} + type HandshakeMetadata struct { ProviderFeePoolAddr string `protobuf:"bytes,1,opt,name=provider_fee_pool_addr,json=providerFeePoolAddr,proto3" json:"provider_fee_pool_addr,omitempty"` Version string `protobuf:"bytes,2,opt,name=version,proto3" json:"version,omitempty"` @@ -319,47 +338,52 @@ func init() { } var fileDescriptor_f22ec409a72b7b72 = []byte{ - // 638 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x54, 0xbf, 0x6f, 0xd4, 0x30, - 0x14, 0xbe, 0xd0, 0x5f, 0x77, 0xbe, 0x52, 0x44, 0xa8, 0x4a, 0x5a, 0xa1, 0xbb, 0xe3, 0x58, 0x0e, - 0x21, 0x12, 0x5d, 0x3b, 0xd1, 0xed, 0x5a, 0x09, 0xca, 0x80, 0xa8, 0xd2, 0xb2, 0x30, 0x10, 0x39, - 0xf6, 0x6b, 0x62, 0x35, 0xb1, 0x23, 0xdb, 0x09, 0x74, 0x67, 0x60, 0xec, 0xc8, 0xd8, 0xff, 0x80, - 0x7f, 0xa3, 0x63, 0x47, 0x26, 0x40, 0xed, 0x3f, 0x82, 0x62, 0x5f, 0x7a, 0x87, 0xc4, 0xc2, 0xc0, - 0xe6, 0xf7, 0xbd, 0xef, 0x73, 0xde, 0x7b, 0x9f, 0xf3, 0xd0, 0x36, 0xe3, 0x1a, 0x24, 0x49, 0x31, - 0xe3, 0x91, 0x02, 0x52, 0x4a, 0xa6, 0xcf, 0x02, 0x42, 0xaa, 0xa0, 0x90, 0xa2, 0x62, 0x14, 0x64, - 0x50, 0x8d, 0x6f, 0xcf, 0x7e, 0x21, 0x85, 0x16, 0xee, 0x93, 0xbf, 0x68, 0x7c, 0x42, 0x2a, 0xff, - 0x96, 0x57, 0x8d, 0xb7, 0xd6, 0x13, 0x91, 0x08, 0xc3, 0x0f, 0xea, 0x93, 0x95, 0x6e, 0xf5, 0x13, - 0x21, 0x92, 0x0c, 0x02, 0x13, 0xc5, 0xe5, 0x49, 0xa0, 0x59, 0x0e, 0x4a, 0xe3, 0xbc, 0x68, 0x08, - 0x2c, 0x26, 0x01, 0x11, 0x12, 0x02, 0x92, 0x31, 0xe0, 0xba, 0xfe, 0xbc, 0x3d, 0x4d, 0x09, 0x41, - 0x4d, 0xc8, 0x58, 0x92, 0x6a, 0x0b, 0xab, 0x40, 0x03, 0xa7, 0x20, 0x73, 0x66, 0xc9, 0xb3, 0xc8, - 0x0a, 0x86, 0x9f, 0x17, 0x90, 0xb7, 0x2f, 0xb8, 0x2a, 0x73, 0x90, 0x13, 0x4a, 0x99, 0x66, 0x82, - 0x1f, 0x4a, 0x51, 0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b, 0x9e, 0x73, 0x7e, 0xd3, 0x6b, 0x5d, 0xdd, 0xf4, 0x5a, 0xdf, 0x6f, 0x7a, 0xad, 0xf7, - 0xbb, 0x09, 0xd3, 0x69, 0x19, 0xfb, 0x44, 0xe4, 0x01, 0x11, 0x2a, 0x17, 0x2a, 0x98, 0x6d, 0x80, - 0xe7, 0xb7, 0x5b, 0xe3, 0xd3, 0x9f, 0x7b, 0x43, 0x9f, 0x15, 0xa0, 0xe2, 0x65, 0x33, 0xec, 0x9d, - 0xdf, 0x01, 0x00, 0x00, 0xff, 0xff, 0xad, 0x37, 0xb8, 0x76, 0x68, 0x04, 0x00, 0x00, + // 712 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x54, 0xbf, 0x73, 0xd3, 0x30, + 0x14, 0x8e, 0x49, 0x7f, 0x24, 0x4a, 0x29, 0x60, 0x7a, 0xc5, 0xed, 0x71, 0x49, 0x08, 0x4b, 0x38, + 0x0e, 0xfb, 0x92, 0x2e, 0xd0, 0x2d, 0x2d, 0x57, 0xca, 0xc0, 0x11, 0xdc, 0xb2, 0xb0, 0xf8, 0x64, + 0x49, 0xb5, 0x75, 0xb5, 0x2d, 0x9f, 0x24, 0x1b, 0xba, 0x33, 0x30, 0x76, 0xec, 0xd8, 0xff, 0x80, + 0x7f, 0xa3, 0x63, 0x47, 0x26, 0xe0, 0xda, 0x91, 0x7f, 0x82, 0x93, 0x64, 0x37, 0xe5, 0xc7, 0xc2, + 0xc0, 0xa6, 0xf7, 0xde, 0xf7, 0x3d, 0x7f, 0xef, 0x7d, 0x96, 0xc0, 0x98, 0x66, 0x92, 0x70, 0x14, + 0x43, 0x9a, 0x05, 0x82, 0xa0, 0x82, 0x53, 0x79, 0xe4, 0x21, 0x54, 0x7a, 0x39, 0x67, 0x25, 0xc5, + 0x84, 0x7b, 0xe5, 0xe8, 0xea, 0xec, 0xe6, 0x9c, 0x49, 0x66, 0x3f, 0xfc, 0x0b, 0xc7, 0x45, 0xa8, + 0x74, 0xaf, 0x70, 0xe5, 0x68, 0x7d, 0x25, 0x62, 0x11, 0xd3, 0x78, 0x4f, 0x9d, 0x0c, 0x75, 0xbd, + 0x17, 0x31, 0x16, 0x25, 0xc4, 0xd3, 0x51, 0x58, 0x1c, 0x78, 0x92, 0xa6, 0x44, 0x48, 0x98, 0xe6, + 0x15, 0xa0, 0xfb, 0x3b, 0x00, 0x17, 0x1c, 0x4a, 0xca, 0xb2, 0xba, 0x01, 0x0d, 0x91, 0x87, 0x18, + 0x27, 0x1e, 0x4a, 0x28, 0xc9, 0xa4, 0x92, 0x67, 0x4e, 0x15, 0xc0, 0x53, 0x80, 0x84, 0x46, 0xb1, + 0x34, 0x69, 0xe1, 0x49, 0x92, 0x61, 0xc2, 0x53, 0x6a, 0xc0, 0xb3, 0xc8, 0x10, 0x06, 0x1f, 0x9b, + 0xc0, 0xd9, 0x66, 0x99, 0x28, 0x52, 0xc2, 0x27, 0x18, 0x53, 0xf5, 0xb1, 0x29, 0x67, 0x39, 0x13, + 0x30, 0xb1, 0x57, 0xc0, 0xbc, 0xa4, 0x32, 0x21, 0x8e, 0xd5, 0xb7, 0x86, 0x6d, 0xdf, 0x04, 0x76, + 0x1f, 0x74, 0x30, 0x11, 0x88, 0xd3, 0x5c, 0x81, 0x9d, 0x1b, 0xba, 0x76, 0x3d, 0x65, 0xaf, 0x81, + 0x96, 0xd9, 0x0f, 0xc5, 0x4e, 0x53, 0x97, 0x17, 0x75, 0xfc, 0x12, 0xdb, 0x2f, 0xc0, 0x32, 0xcd, + 0xa8, 0xa4, 0x30, 0x09, 0x62, 0xa2, 0x74, 0x3a, 0x73, 0x7d, 0x6b, 0xd8, 0x19, 0xaf, 0xbb, 0x34, + 0x44, 0xae, 0x1a, 0xcd, 0xad, 0x06, 0x2a, 0x47, 0xee, 0xae, 0x46, 0x6c, 0xcd, 0x9d, 0x7d, 0xed, + 0x35, 0xf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, 0xd4, 0x43, 0x4c, 0xa4, 0x4c, 0x78, 0xb3, 0xf7, 0xea, 0xc9, 0xd5, 0x1b, 0xf7, 0xe1, 0xd7, + 0x57, 0x4e, 0x1e, 0xe5, 0x44, 0x84, 0x0b, 0x7a, 0x9b, 0x1b, 0x3f, 0x03, 0x00, 0x00, 0xff, 0xff, + 0xb7, 0x64, 0x3e, 0xb7, 0x16, 0x05, 0x00, 0x00, } func (m *ConsumerAdditionProposal) Marshal() (dAtA []byte, err error) { @@ -520,6 +544,19 @@ func (m *Params) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if m.TrustingPeriodFraction != 0 { + i = encodeVarintProvider(dAtA, i, uint64(m.TrustingPeriodFraction)) + i-- + dAtA[i] = 0x18 + } + n4, err4 := github_com_gogo_protobuf_types.StdDurationMarshalTo(m.CcvTimeoutPeriod, dAtA[i-github_com_gogo_protobuf_types.SizeOfStdDuration(m.CcvTimeoutPeriod):]) + if err4 != nil { + return 0, err4 + } + i -= n4 + i = encodeVarintProvider(dAtA, i, uint64(n4)) + i-- + dAtA[i] = 0x12 if m.TemplateClient != nil { { size, err := m.TemplateClient.MarshalToSizedBuffer(dAtA[:i]) @@ -684,6 +721,11 @@ func (m *Params) Size() (n int) { l = m.TemplateClient.Size() n += 1 + l + sovProvider(uint64(l)) } + l = github_com_gogo_protobuf_types.SizeOfStdDuration(m.CcvTimeoutPeriod) + n += 1 + l + sovProvider(uint64(l)) + if m.TrustingPeriodFraction != 0 { + n += 1 + sovProvider(uint64(m.TrustingPeriodFraction)) + } return n } @@ -1269,6 +1311,58 @@ func (m *Params) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field CcvTimeoutPeriod", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowProvider + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthProvider + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthProvider + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := github_com_gogo_protobuf_types.StdDurationUnmarshal(&m.CcvTimeoutPeriod, dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 3: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field TrustingPeriodFraction", wireType) + } + m.TrustingPeriodFraction = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowProvider + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.TrustingPeriodFraction |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } default: iNdEx = preIndex skippy, err := skipProvider(dAtA[iNdEx:]) diff --git a/x/ccv/types/shared_params.go b/x/ccv/types/shared_params.go new file mode 100644 index 0000000000..f687f8a334 --- /dev/null +++ b/x/ccv/types/shared_params.go @@ -0,0 +1,57 @@ +package types + +import ( + fmt "fmt" + "time" +) + +const ( + // Default timeout period is 4 weeks to ensure channel doesn't close on timeout + DefaultCCVTimeoutPeriod = 4 * 7 * 24 * time.Hour +) + +var ( + KeyCCVTimeoutPeriod = []byte("CcvTimeoutPeriod") +) + +func ValidateDuration(i interface{}) error { + period, ok := i.(time.Duration) + if !ok { + return fmt.Errorf("invalid parameter type: %T", i) + } + if period <= time.Duration(0) { + return fmt.Errorf("ibc timeout period is not positive") + } + return nil +} + +func ValidateBool(i interface{}) error { + if _, ok := i.(bool); !ok { + return fmt.Errorf("invalid parameter type: %T", i) + } + return nil +} + +func ValidateInt64(i interface{}) error { + if _, ok := i.(int64); !ok { + return fmt.Errorf("invalid parameter type: %T", i) + } + return nil +} + +func ValidatePositiveInt64(i interface{}) error { + if err := ValidateInt64(i); err != nil { + return err + } + if i.(int64) <= int64(0) { + return fmt.Errorf("int must be positive") + } + return nil +} + +func ValidateString(i interface{}) error { + if _, ok := i.(string); !ok { + return fmt.Errorf("invalid parameter type: %T", i) + } + return nil +} diff --git a/x/ccv/types/utils.go b/x/ccv/types/utils.go deleted file mode 100644 index 29521da490..0000000000 --- a/x/ccv/types/utils.go +++ /dev/null @@ -1,10 +0,0 @@ -package types - -import "time" - -// TimeDelay is 4 weeks to ensure channel doesn't close on timeout -const TimeDelay = 4 * 7 * 24 * time.Hour - -func GetTimeoutTimestamp(currentTime time.Time) time.Time { - return currentTime.Add(TimeDelay) -} diff --git a/x/ccv/utils/utils.go b/x/ccv/utils/utils.go index 6caed432d6..54a1845e96 100644 --- a/x/ccv/utils/utils.go +++ b/x/ccv/utils/utils.go @@ -13,10 +13,6 @@ import ( abci "github.com/tendermint/tendermint/abci/types" ) -// TrustingPeriodFraction is used to compute the IBC clients TrustingPeriod -// as UnbondingPeriod / TrustingPeriodFraction -const TrustingPeriodFraction = 2 - func AccumulateChanges(currentChanges, newChanges []abci.ValidatorUpdate) []abci.ValidatorUpdate { m := make(map[string]abci.ValidatorUpdate) @@ -54,6 +50,7 @@ func SendIBCPacket( channelID string, portID string, packetData []byte, + timeoutPeriod time.Duration, ) error { channel, ok := channelKeeper.GetChannel(ctx, portID, channelID) if !ok { @@ -76,7 +73,7 @@ func SendIBCPacket( packetData, sequence, portID, channelID, channel.Counterparty.PortId, channel.Counterparty.ChannelId, - clienttypes.Height{}, uint64(ccv.GetTimeoutTimestamp(ctx.BlockTime()).UnixNano()), + clienttypes.Height{}, uint64(ctx.BlockTime().Add(timeoutPeriod).UnixNano()), ) return channelKeeper.SendPacket(ctx, channelCap, packet) }