From 94155c1a4f8dfae7bb9bfee34e91864479ad0478 Mon Sep 17 00:00:00 2001 From: Shawn Marshall-Spitzbart <44221603+smarshall-spitzbart@users.noreply.github.com> Date: Wed, 5 Oct 2022 12:51:45 -0700 Subject: [PATCH 1/3] large commit --- go.mod | 2 +- .../ccv/consumer/v1/consumer.proto | 4 + .../ccv/provider/v1/provider.proto | 4 + tests/difference/core/driver/setup.go | 3 +- tests/e2e/common_test.go | 4 +- tests/e2e/slashing_test.go | 8 +- testutil/keeper/unit_test_helpers.go | 27 ++-- x/ccv/consumer/keeper/genesis_test.go | 6 +- x/ccv/consumer/keeper/params.go | 11 ++ x/ccv/consumer/keeper/params_test.go | 6 +- x/ccv/consumer/keeper/relay.go | 3 + x/ccv/consumer/types/consumer.pb.go | 143 +++++++++++++----- x/ccv/consumer/types/params.go | 19 ++- x/ccv/provider/keeper/params.go | 17 ++- x/ccv/provider/keeper/params_test.go | 11 +- x/ccv/provider/keeper/proposal_test.go | 27 ++-- x/ccv/provider/keeper/relay.go | 2 + x/ccv/provider/proposal_handler_test.go | 3 +- x/ccv/provider/types/genesis_test.go | 23 ++- x/ccv/provider/types/params.go | 16 +- x/ccv/provider/types/params_test.go | 15 +- x/ccv/provider/types/provider.pb.go | 138 ++++++++++++----- x/ccv/types/shared_params.go | 26 ++++ x/ccv/types/utils.go | 10 -- x/ccv/utils/utils.go | 3 +- 25 files changed, 376 insertions(+), 155 deletions(-) create mode 100644 x/ccv/types/shared_params.go delete mode 100644 x/ccv/types/utils.go 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..dc459cc89c 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,9 @@ message Params { // provider handshake procedure. string distribution_transmission_channel = 3; string provider_fee_pool_addr_str = 4; + // Sent IBC packets will timeout after this duration + google.protobuf.Duration ccv_timeout_period = 5 + [(gogoproto.nullable) = false, (gogoproto.stdduration) = true]; } // 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..25572f47e2 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,9 @@ 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]; } message HandshakeMetadata { diff --git a/tests/difference/core/driver/setup.go b/tests/difference/core/driver/setup.go index 3228c3e802..deb185d599 100644 --- a/tests/difference/core/driver/setup.go +++ b/tests/difference/core/driver/setup.go @@ -476,6 +476,7 @@ func (b *Builder) createConsumerGenesis(tmConfig *ibctesting.TendermintConfig) * 1000, // ignore distribution "", // ignore distribution "", // ignore distribution + ccv.DefaultCCVTimeoutPeriod, ) return consumertypes.NewInitialGenesisState(providerClient, providerConsState, valUpdates, consumertypes.SlashRequests{}, params) } @@ -534,7 +535,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..c329f877d2 100644 --- a/tests/e2e/common_test.go +++ b/tests/e2e/common_test.go @@ -293,7 +293,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 +320,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) 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..20ab72aebd 100644 --- a/testutil/keeper/unit_test_helpers.go +++ b/testutil/keeper/unit_test_helpers.go @@ -29,6 +29,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" + consumertypes "github.com/cosmos/interchain-security/x/ccv/consumer/types" providertypes "github.com/cosmos/interchain-security/x/ccv/provider/types" ) @@ -60,6 +61,7 @@ func NewInMemKeeperParams(t testing.TB) InMemKeeperParams { memStoreKey, paramstypes.ModuleName, ) + // TODO: Find way to use key table from keeper constructor ctx := sdk.NewContext(stateStore, tmproto.Header{}, false, log.NewNopLogger()) return InMemKeeperParams{ @@ -166,25 +168,18 @@ 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) { +// TODO These will be removed and done by constructor of keeper - keyTable := paramstypes.NewKeyTable(paramstypes.NewParamSetPair( - providertypes.KeyTemplateClient, &ibctmtypes.ClientState{}, - func(value interface{}) error { return nil })) - - newSubspace := params.ParamsSubspace.WithKeyTable(keyTable) +// Sets the params subspace key table with params registered for provider +func (params *InMemKeeperParams) SetProviderKeyTable() { + newSubspace := params.ParamsSubspace.WithKeyTable(providertypes.ParamKeyTable()) 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) +// Sets the params subspace key table with params registered for consumer +func (params *InMemKeeperParams) SetConsumerKeyTable() { + newSubspace := params.ParamsSubspace.WithKeyTable(consumertypes.ParamKeyTable()) + params.ParamsSubspace = &newSubspace } // Registers proto interfaces for params.Cdc diff --git a/x/ccv/consumer/keeper/genesis_test.go b/x/ccv/consumer/keeper/genesis_test.go index 4077858303..94b7b81e01 100644 --- a/x/ccv/consumer/keeper/genesis_test.go +++ b/x/ccv/consumer/keeper/genesis_test.go @@ -49,8 +49,8 @@ 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) testCases := []struct { name string @@ -152,7 +152,7 @@ func TestExportGenesis(t *testing.T) { MaturityTime: uint64(time.Now().UnixNano()), } - params := types.NewParams(true, types.DefaultBlocksPerDistributionTransmission, "", "") + params := types.NewParams(true, types.DefaultBlocksPerDistributionTransmission, "", "", ccv.DefaultCCVTimeoutPeriod) // 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..c30bac4a35 100644 --- a/x/ccv/consumer/keeper/params.go +++ b/x/ccv/consumer/keeper/params.go @@ -1,9 +1,12 @@ 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 @@ -13,6 +16,7 @@ func (k Keeper) GetParams(ctx sdk.Context) types.Params { k.GetBlocksPerDistributionTransmission(ctx), k.GetDistributionTransmissionChannel(ctx), k.GetProviderFeePoolAddrStr(ctx), + k.GetCCVTimeoutPeriod(ctx), ) } @@ -57,3 +61,10 @@ 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 ibc packets +func (k Keeper) GetCCVTimeoutPeriod(ctx sdk.Context) time.Duration { + var p time.Duration + k.paramStore.Get(ctx, ccvtypes.KeyCCVTimeoutPeriod, &p) + return p +} diff --git a/x/ccv/consumer/keeper/params_test.go b/x/ccv/consumer/keeper/params_test.go index 0bc043d984..7a9b0dcd94 100644 --- a/x/ccv/consumer/keeper/params_test.go +++ b/x/ccv/consumer/keeper/params_test.go @@ -2,9 +2,11 @@ package keeper_test import ( "testing" + "time" testkeeper "github.com/cosmos/interchain-security/testutil/keeper" "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 +16,12 @@ 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) // 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) 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/types/consumer.pb.go b/x/ccv/consumer/types/consumer.pb.go index f6a55d06c0..f08bf379cc 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,8 @@ 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 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"` } func (m *Params) Reset() { *m = Params{} } @@ -107,6 +113,13 @@ func (m *Params) GetProviderFeePoolAddrStr() string { return "" } +func (m *Params) GetCcvTimeoutPeriod() time.Duration { + if m != nil { + return m.CcvTimeoutPeriod + } + return 0 +} + // LastTransmissionBlockHeight is the last time validator holding // pools were transmitted to the provider chain type LastTransmissionBlockHeight struct { @@ -326,46 +339,49 @@ 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, 0xa9, 0x50, - 0x24, 0xd4, 0xb1, 0x92, 0x8a, 0x4d, 0x77, 0x4d, 0xaa, 0x8a, 0x3f, 0x89, 0xc8, 0xad, 0x58, 0xb0, - 0xb1, 0xc6, 0xe3, 0x5b, 0x67, 0x14, 0x7b, 0xc6, 0xcc, 0x8c, 0x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 0xc0, 0x3c, 0x33, 0x04, 0x00, 0x00, + // 671 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x54, 0xcb, 0x6e, 0xd3, 0x40, + 0x14, 0x8d, 0x9b, 0x36, 0x94, 0x49, 0x41, 0xc8, 0x44, 0x25, 0x2d, 0x92, 0x93, 0x9a, 0x0a, 0x45, + 0x42, 0x1d, 0x2b, 0xa9, 0xd8, 0x74, 0xd7, 0xa4, 0xaa, 0x78, 0x49, 0x04, 0x37, 0x62, 0xc1, 0xc6, + 0x1a, 0x8f, 0xa7, 0xce, 0x28, 0xf6, 0x8c, 0x99, 0x19, 0x1b, 0xfc, 0x17, 0x2c, 0x91, 0xf8, 0x01, + 0x3e, 0x80, 0x8f, 0xa8, 0x58, 0xa0, 0x2e, 0x59, 0x15, 0xd4, 0xfe, 0x01, 0x5f, 0x80, 0xfc, 0x0a, + 0xe1, 0x11, 0x89, 0xdd, 0xbd, 0xba, 0xe7, 0x9c, 0x99, 0x7b, 0xe6, 0xde, 0x01, 0x03, 0xca, 0x14, + 0x11, 0x78, 0x8a, 0x28, 0x73, 0x24, 0xc1, 0xb1, 0xa0, 0x2a, 0xb5, 0x30, 0x4e, 0x2c, 0xcc, 0x99, + 0x8c, 0x43, 0x22, 0xac, 0xa4, 0x3f, 0x8f, 0x61, 0x24, 0xb8, 0xe2, 0xfa, 0xbd, 0x7f, 0x70, 0x20, + 0xc6, 0x09, 0x9c, 0xe3, 0x92, 0xfe, 0xf6, 0xee, 0x32, 0xe1, 0x4c, 0x0f, 0x27, 0x85, 0xd4, 0xf6, + 0x96, 0xcf, 0xb9, 0x1f, 0x10, 0x2b, 0xcf, 0xdc, 0xf8, 0xd4, 0x42, 0x2c, 0x2d, 0x4b, 0xbb, 0x98, + 0xcb, 0x90, 0x4b, 0x4b, 0x2a, 0x34, 0xa3, 0xcc, 0xb7, 0x92, 0xbe, 0x4b, 0x14, 0xea, 0x57, 0x79, + 0x89, 0x6a, 0xf9, 0xdc, 0xe7, 0x79, 0x68, 0x65, 0x51, 0x25, 0x5b, 0x70, 0x9d, 0xa2, 0x50, 0x24, + 0x65, 0xc9, 0xf8, 0xf3, 0x44, 0x2f, 0x16, 0x48, 0x51, 0xce, 0x8a, 0xba, 0xf9, 0x65, 0x05, 0x34, + 0xc6, 0x48, 0xa0, 0x50, 0xea, 0x6d, 0x70, 0x8d, 0x30, 0xe4, 0x06, 0xc4, 0x6b, 0x6b, 0x5d, 0xad, + 0xb7, 0x6e, 0x57, 0xa9, 0xfe, 0x1c, 0xec, 0xba, 0x01, 0xc7, 0x33, 0xe9, 0x44, 0x44, 0x38, 0x1e, + 0x95, 0x4a, 0x50, 0x37, 0xce, 0x54, 0x1c, 0x25, 0x10, 0x93, 0x21, 0x95, 0x92, 0x72, 0xd6, 0x5e, + 0xe9, 0x6a, 0xbd, 0xba, 0xbd, 0x53, 0x60, 0xc7, 0x44, 0x1c, 0x2d, 0x20, 0x27, 0x0b, 0x40, 0xfd, + 0x09, 0xd8, 0x59, 0xaa, 0xe2, 0xe0, 0x29, 0x62, 0x8c, 0x04, 0xed, 0x7a, 0x57, 0xeb, 0x5d, 0xb7, + 0x3b, 0xde, 0x12, 0x91, 0x51, 0x01, 0xd3, 0x0f, 0xc0, 0x76, 0x24, 0x78, 0x42, 0x3d, 0x22, 0x9c, + 0x53, 0x42, 0x9c, 0x88, 0xf3, 0xc0, 0x41, 0x9e, 0x27, 0x1c, 0xa9, 0x44, 0x7b, 0x35, 0x17, 0xd9, + 0xac, 0x10, 0xc7, 0x84, 0x8c, 0x39, 0x0f, 0x0e, 0x3d, 0x4f, 0x9c, 0x28, 0xa1, 0xbf, 0x00, 0x3a, + 0xc6, 0x89, 0xa3, 0x68, 0x48, 0x78, 0xac, 0xb2, 0xee, 0x28, 0xf7, 0xda, 0x6b, 0x5d, 0xad, 0xd7, + 0x1c, 0x6c, 0xc1, 0xc2, 0x3a, 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 0x25, 0x55, 0x3f, 0x06, + 0x80, 0xb2, 0x53, 0x81, 0xb0, 0xaa, 0x26, 0xe9, 0xe6, 0xe0, 0x3e, 0x2c, 0x2f, 0x52, 0x2d, 0x41, + 0xb9, 0x14, 0xf0, 0xf1, 0x1c, 0x39, 0x49, 0x23, 0x62, 0x2f, 0x30, 0x4d, 0x0f, 0xdc, 0x58, 0xbc, + 0x9c, 0xd4, 0x4f, 0xc0, 0xba, 0x28, 0xe3, 0xb6, 0xd6, 0xad, 0xf7, 0x9a, 0x83, 0x3e, 0xfc, 0x8f, + 0x8d, 0x86, 0x8b, 0x2a, 0xc3, 0xd5, 0xec, 0xc5, 0xed, 0xb9, 0xd0, 0x70, 0x72, 0x76, 0x69, 0x68, + 0xe7, 0x97, 0x86, 0xf6, 0xfd, 0xd2, 0xd0, 0xde, 0x5d, 0x19, 0xb5, 0xf3, 0x2b, 0xa3, 0xf6, 0xf5, + 0xca, 0xa8, 0xbd, 0x3a, 0xf0, 0xa9, 0x9a, 0xc6, 0x2e, 0xc4, 0x3c, 0x2c, 0x37, 0xd1, 0xfa, 0x75, + 0xda, 0xde, 0xfc, 0x6b, 0x78, 0xfb, 0xfb, 0xaf, 0xa3, 0xd2, 0x88, 0x48, 0xb7, 0x91, 0x3f, 0xd2, + 0xfe, 0xcf, 0x00, 0x00, 0x00, 0xff, 0xff, 0x68, 0x54, 0x2f, 0x73, 0xa6, 0x04, 0x00, 0x00, } func (m *Params) Marshal() (dAtA []byte, err error) { @@ -388,6 +404,14 @@ func (m *Params) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + n1, err1 := github_com_gogo_protobuf_types.StdDurationMarshalTo(m.CcvTimeoutPeriod, dAtA[i-github_com_gogo_protobuf_types.SizeOfStdDuration(m.CcvTimeoutPeriod):]) + if err1 != nil { + return 0, err1 + } + i -= n1 + i = encodeVarintConsumer(dAtA, i, uint64(n1)) + i-- + dAtA[i] = 0x2a if len(m.ProviderFeePoolAddrStr) > 0 { i -= len(m.ProviderFeePoolAddrStr) copy(dAtA[i:], m.ProviderFeePoolAddrStr) @@ -603,6 +627,8 @@ 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)) return n } @@ -807,6 +833,39 @@ 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 default: iNdEx = preIndex skippy, err := skipConsumer(dAtA[iNdEx:]) diff --git a/x/ccv/consumer/types/params.go b/x/ccv/consumer/types/params.go index 2b6e11ea00..617dce8266 100644 --- a/x/ccv/consumer/types/params.go +++ b/x/ccv/consumer/types/params.go @@ -2,13 +2,21 @@ package types import ( "fmt" + "time" 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 + // Default timeout period is 4 weeks to ensure channel doesn't close on timeout + DefaultCCVTimeoutPeriod = 4 * 7 * 24 * time.Hour +) + +// Reflection based keys for params subspace var ( KeyEnabled = []byte("Enabled") KeyBlocksPerDistributionTransmission = []byte("BlocksPerDistributionTransmission") @@ -23,12 +31,14 @@ 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) Params { return Params{ Enabled: enabled, BlocksPerDistributionTransmission: blocksPerDistributionTransmission, DistributionTransmissionChannel: distributionTransmissionChannel, ProviderFeePoolAddrStr: providerFeePoolAddrStr, + CcvTimeoutPeriod: ccvTimeoutPeriod, } } @@ -39,6 +49,7 @@ func DefaultParams() Params { DefaultBlocksPerDistributionTransmission, "", "", + DefaultCCVTimeoutPeriod, ) } @@ -57,6 +68,8 @@ func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs { p.DistributionTransmissionChannel, validateString), paramtypes.NewParamSetPair(KeyProviderFeePoolAddrStr, p.ProviderFeePoolAddrStr, validateString), + paramtypes.NewParamSetPair(ccvtypes.KeyCCVTimeoutPeriod, + p.CcvTimeoutPeriod, ccvtypes.ValidateCCVTimeoutPeriod), } } diff --git a/x/ccv/provider/keeper/params.go b/x/ccv/provider/keeper/params.go index 3fdf4f895f..0d822e3cef 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,22 @@ 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 +} + // 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), + ) } -// 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..9ad25f678d 100644 --- a/x/ccv/provider/keeper/params_test.go +++ b/x/ccv/provider/keeper/params_test.go @@ -9,24 +9,27 @@ 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) + keeperParams.SetProviderKeyTable() providerKeeper, ctx, ctrl, _ := testkeeper.GetProviderKeeperAndCtx(t, keeperParams) defer ctrl.Finish() + 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) providerKeeper.SetParams(ctx, newParams) params = providerKeeper.GetParams(ctx) require.Equal(t, newParams, params) diff --git a/x/ccv/provider/keeper/proposal_test.go b/x/ccv/provider/keeper/proposal_test.go index 1e309e737b..7580e1670a 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) @@ -576,8 +577,9 @@ func TestPendingConsumerRemovalPropOrder(t *testing.T) { 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,9 @@ func TestMakeConsumerGenesis(t *testing.T) { AllowUpdateAfterExpiry: true, AllowUpdateAfterMisbehaviour: true, }, - ) - providerKeeper, ctx, ctrl, mocks := testkeeper.GetProviderKeeperAndCtx(t, keeperParams) + CcvTimeoutPeriod: ccvtypes.DefaultCCVTimeoutPeriod, + } + providerKeeper.SetParams(ctx, moduleParams) defer ctrl.Finish() // @@ -635,7 +638,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},"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 +650,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 +662,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 +712,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 19938e0284..cd3303bfbb 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..fdda7e5668 100644 --- a/x/ccv/provider/types/genesis_test.go +++ b/x/ccv/provider/types/genesis_test.go @@ -8,6 +8,7 @@ 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" + ccv "github.com/cosmos/interchain-security/x/ccv/types" "github.com/stretchr/testify/require" ) @@ -77,7 +78,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), ), true, }, @@ -92,7 +94,24 @@ 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), + ), + 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), ), false, }, diff --git a/x/ccv/provider/types/params.go b/x/ccv/provider/types/params.go index b121a718a9..0058a2cbe4 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 ( @@ -22,19 +23,21 @@ const ( DefaultMaxClockDrift = 10 * time.Second ) +// Reflection based keys for params subspace var ( KeyTemplateClient = []byte("TemplateClient") ) -// 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) Params { return Params{ - TemplateClient: cs, + TemplateClient: cs, + CcvTimeoutPeriod: ccvTimeoutPeriod, } } @@ -45,13 +48,17 @@ func DefaultParams() Params { return NewParams( ibctmtypes.NewClientState("", ibctmtypes.DefaultTrustLevel, 0, 0, DefaultMaxClockDrift, clienttypes.Height{}, commitmenttypes.GetSDKSpecs(), []string{"upgrade", "upgradedIBCState"}, true, true), + ccvtypes.DefaultCCVTimeoutPeriod, ) } // 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 ccvtypes.ValidateCCVTimeoutPeriod(p.CcvTimeoutPeriod) != nil { + return fmt.Errorf("ccv timeout period is invalid") } return validateTemplateClient(*p.TemplateClient) } @@ -60,6 +67,7 @@ func (p Params) Validate() error { func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs { return paramtypes.ParamSetPairs{ paramtypes.NewParamSetPair(KeyTemplateClient, p.TemplateClient, validateTemplateClient), + paramtypes.NewParamSetPair(ccvtypes.KeyCCVTimeoutPeriod, p.CcvTimeoutPeriod, ccvtypes.ValidateCCVTimeoutPeriod), } } diff --git a/x/ccv/provider/types/params_test.go b/x/ccv/provider/types/params_test.go index f5252327b1..898c2de6b8 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), 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), false}, + {"blank client", types.NewParams(&ibctmtypes.ClientState{}, + 2*7*24*time.Hour), false}, + {"nil client", types.NewParams(nil, 2*7*24*time.Hour), 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), 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..155504d60d 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,8 @@ 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"` } func (m *Params) Reset() { *m = Params{} } @@ -208,6 +211,13 @@ func (m *Params) GetTemplateClient() *types1.ClientState { return nil } +func (m *Params) GetCcvTimeoutPeriod() time.Duration { + if m != nil { + return m.CcvTimeoutPeriod + } + 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 +329,50 @@ 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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b3, 0x79, 0xd0, 0x64, 0x5f, 0x02, 0x1c, 0x0a, 0x91, - 0x4d, 0x28, 0x95, 0xae, 0x87, 0x56, 0x2a, 0x90, 0x6a, 0x36, 0xa5, 0x26, 0x1c, 0x3e, 0x45, 0x9d, - 0xa3, 0x0c, 0xab, 0x74, 0x42, 0x4e, 0x95, 0xfb, 0x08, 0x75, 0xea, 0x9b, 0x40, 0x29, 0x50, 0x9e, - 0x33, 0x58, 0x18, 0x75, 0xc2, 0x19, 0xb0, 0x77, 0x7c, 0x79, 0xdd, 0x73, 0xae, 0xae, 0x7b, 0xce, - 0xaf, 0xeb, 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, + // 688 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x54, 0x3d, 0x73, 0xd4, 0x48, + 0x10, 0x5d, 0x9d, 0xbf, 0x76, 0x67, 0x7d, 0xbe, 0x3b, 0x9d, 0xcb, 0x27, 0xbb, 0xae, 0x76, 0x97, + 0x25, 0x59, 0x8a, 0x42, 0xaa, 0x5d, 0x47, 0x38, 0x5b, 0x9b, 0x02, 0x13, 0x50, 0x2c, 0xb2, 0x49, + 0x48, 0x54, 0xa3, 0x99, 0xb6, 0x34, 0x65, 0x49, 0xa3, 0x9a, 0x19, 0x09, 0x9c, 0x13, 0x10, 0x3a, + 0x74, 0xe8, 0x7f, 0x40, 0xf1, 0x2f, 0x1c, 0x3a, 0x24, 0x02, 0xca, 0xfe, 0x23, 0x94, 0x66, 0x24, + 0xaf, 0xf9, 0x48, 0x08, 0xc8, 0xa6, 0xbb, 0xdf, 0x6b, 0xbd, 0xee, 0xa7, 0x19, 0x34, 0x61, 0x99, + 0x02, 0x41, 0x62, 0xcc, 0xb2, 0x40, 0x02, 0x29, 0x04, 0x53, 0x27, 0x1e, 0x21, 0xa5, 0x97, 0x0b, + 0x5e, 0x32, 0x0a, 0xc2, 0x2b, 0xc7, 0x37, 0x67, 0x37, 0x17, 0x5c, 0x71, 0xfb, 0xee, 0x4f, 0x38, + 0x2e, 0x21, 0xa5, 0x7b, 0x83, 0x2b, 0xc7, 0x5b, 0xeb, 0x11, 0x8f, 0xb8, 0xc6, 0x7b, 0xd5, 0xc9, + 0x50, 0xb7, 0xfa, 0x11, 0xe7, 0x51, 0x02, 0x9e, 0x8e, 0xc2, 0xe2, 0xc8, 0x53, 0x2c, 0x05, 0xa9, + 0x70, 0x9a, 0xd7, 0x80, 0xde, 0xf7, 0x00, 0x5a, 0x08, 0xac, 0x18, 0xcf, 0x9a, 0x06, 0x2c, 0x24, + 0x1e, 0xe1, 0x02, 0x3c, 0x92, 0x30, 0xc8, 0x54, 0x25, 0xcf, 0x9c, 0x6a, 0x80, 0x57, 0x01, 0x12, + 0x16, 0xc5, 0xca, 0xa4, 0xa5, 0xa7, 0x20, 0xa3, 0x20, 0x52, 0x66, 0xc0, 0xf3, 0xc8, 0x10, 0x86, + 0x6f, 0x17, 0x90, 0xb3, 0xc7, 0x33, 0x59, 0xa4, 0x20, 0xa6, 0x94, 0xb2, 0xea, 0x63, 0x33, 0xc1, + 0x73, 0x2e, 0x71, 0x62, 0xaf, 0xa3, 0x25, 0xc5, 0x54, 0x02, 0x8e, 0x35, 0xb0, 0x46, 0x1d, 0xdf, + 0x04, 0xf6, 0x00, 0x75, 0x29, 0x48, 0x22, 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0xb0, 0x30, 0xea, 0xf8, 0xf3, 0xc4, 0xee, 0xe1, 0xc5, 0x55, 0xcf, 0xba, 0xbc, + 0xea, 0x59, 0x5f, 0xae, 0x7a, 0xd6, 0xe9, 0x75, 0xaf, 0x75, 0x79, 0xdd, 0x6b, 0x7d, 0xbc, 0xee, + 0xb5, 0x5e, 0xed, 0x44, 0x4c, 0xc5, 0x45, 0xe8, 0x12, 0x9e, 0x7a, 0x84, 0xcb, 0x94, 0x4b, 0x6f, + 0xfe, 0xea, 0x3c, 0xb8, 0x79, 0xa9, 0xde, 0x7c, 0xfb, 0x56, 0xa9, 0x93, 0x1c, 0x64, 0xb8, 0xac, + 0x77, 0xb2, 0xfd, 0x35, 0x00, 0x00, 0xff, 0xff, 0x94, 0x02, 0x93, 0x09, 0xdc, 0x04, 0x00, 0x00, } func (m *ConsumerAdditionProposal) Marshal() (dAtA []byte, err error) { @@ -520,6 +533,14 @@ func (m *Params) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + 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 +705,8 @@ 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)) return n } @@ -1269,6 +1292,39 @@ 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 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..5cd02e0c25 --- /dev/null +++ b/x/ccv/types/shared_params.go @@ -0,0 +1,26 @@ +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 ValidateCCVTimeoutPeriod(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 +} 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..c6b1fa000a 100644 --- a/x/ccv/utils/utils.go +++ b/x/ccv/utils/utils.go @@ -54,6 +54,7 @@ func SendIBCPacket( channelID string, portID string, packetData []byte, + timeoutPeriod time.Duration, ) error { channel, ok := channelKeeper.GetChannel(ctx, portID, channelID) if !ok { @@ -76,7 +77,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) } From 0ee6c6969e01698ea6ce054089edb02b5c68512d Mon Sep 17 00:00:00 2001 From: Shawn Marshall-Spitzbart <44221603+smarshall-spitzbart@users.noreply.github.com> Date: Wed, 5 Oct 2022 12:54:57 -0700 Subject: [PATCH 2/3] got ridda stuff --- testutil/keeper/unit_test_helpers.go | 17 ----------------- x/ccv/provider/keeper/params_test.go | 3 +-- 2 files changed, 1 insertion(+), 19 deletions(-) diff --git a/testutil/keeper/unit_test_helpers.go b/testutil/keeper/unit_test_helpers.go index 20ab72aebd..203f1750fe 100644 --- a/testutil/keeper/unit_test_helpers.go +++ b/testutil/keeper/unit_test_helpers.go @@ -29,8 +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" - consumertypes "github.com/cosmos/interchain-security/x/ccv/consumer/types" - providertypes "github.com/cosmos/interchain-security/x/ccv/provider/types" ) // Parameters needed to instantiate an in-memory keeper @@ -61,7 +59,6 @@ func NewInMemKeeperParams(t testing.TB) InMemKeeperParams { memStoreKey, paramstypes.ModuleName, ) - // TODO: Find way to use key table from keeper constructor ctx := sdk.NewContext(stateStore, tmproto.Header{}, false, log.NewNopLogger()) return InMemKeeperParams{ @@ -168,20 +165,6 @@ func GetConsumerKeeperAndCtx(t *testing.T, params InMemKeeperParams) ( return NewInMemConsumerKeeper(params, mocks), params.Ctx, ctrl, mocks } -// TODO These will be removed and done by constructor of keeper - -// Sets the params subspace key table with params registered for provider -func (params *InMemKeeperParams) SetProviderKeyTable() { - newSubspace := params.ParamsSubspace.WithKeyTable(providertypes.ParamKeyTable()) - params.ParamsSubspace = &newSubspace -} - -// Sets the params subspace key table with params registered for consumer -func (params *InMemKeeperParams) SetConsumerKeyTable() { - newSubspace := params.ParamsSubspace.WithKeyTable(consumertypes.ParamKeyTable()) - params.ParamsSubspace = &newSubspace -} - // Registers proto interfaces for params.Cdc // // For now, we explicitly force certain unit tests to register sdk crypto interfaces. diff --git a/x/ccv/provider/keeper/params_test.go b/x/ccv/provider/keeper/params_test.go index 9ad25f678d..232cd3c878 100644 --- a/x/ccv/provider/keeper/params_test.go +++ b/x/ccv/provider/keeper/params_test.go @@ -15,14 +15,13 @@ import ( // TestParams tests the getting/setting of provider ccv module params. func TestParams(t *testing.T) { - defaultParams := types.DefaultParams() // Construct an in-mem keeper with registered key table keeperParams := testkeeper.NewInMemKeeperParams(t) - keeperParams.SetProviderKeyTable() 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) From 269e8d7ab6587b3961c700b0fb533012e12046cc Mon Sep 17 00:00:00 2001 From: Shawn Marshall-Spitzbart <44221603+smarshall-spitzbart@users.noreply.github.com> Date: Wed, 5 Oct 2022 12:58:05 -0700 Subject: [PATCH 3/3] Update params.go --- x/ccv/consumer/types/params.go | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/x/ccv/consumer/types/params.go b/x/ccv/consumer/types/params.go index 617dce8266..dc5d7d5432 100644 --- a/x/ccv/consumer/types/params.go +++ b/x/ccv/consumer/types/params.go @@ -11,9 +11,6 @@ import ( const ( // about 2 hr at 7.6 seconds per blocks DefaultBlocksPerDistributionTransmission = 1000 - - // Default timeout period is 4 weeks to ensure channel doesn't close on timeout - DefaultCCVTimeoutPeriod = 4 * 7 * 24 * time.Hour ) // Reflection based keys for params subspace @@ -49,7 +46,7 @@ func DefaultParams() Params { DefaultBlocksPerDistributionTransmission, "", "", - DefaultCCVTimeoutPeriod, + ccvtypes.DefaultCCVTimeoutPeriod, ) }