Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make CCV packet timeout a param #376

Merged
merged 7 commits into from
Oct 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 4 additions & 0 deletions proto/interchain_security/ccv/consumer/v1/consumer.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand Down
4 changes: 4 additions & 0 deletions proto/interchain_security/ccv/provider/v1/provider.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion tests/difference/core/driver/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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{},
Expand Down
4 changes: 2 additions & 2 deletions tests/e2e/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())

Expand All @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions tests/e2e/slashing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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;
Expand Down Expand Up @@ -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)

Expand All @@ -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;
Expand Down
22 changes: 0 additions & 22 deletions testutil/keeper/unit_test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
6 changes: 3 additions & 3 deletions x/ccv/consumer/keeper/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down
11 changes: 11 additions & 0 deletions x/ccv/consumer/keeper/params.go
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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),
)
}

Expand Down Expand Up @@ -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
}
6 changes: 4 additions & 2 deletions x/ccv/consumer/keeper/params_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions x/ccv/consumer/keeper/relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
Loading