diff --git a/x/ccv/provider/migrations/migrator.go b/x/ccv/provider/migrations/migrator.go index 6f5a11f1d3..201380c2e0 100644 --- a/x/ccv/provider/migrations/migrator.go +++ b/x/ccv/provider/migrations/migrator.go @@ -11,6 +11,7 @@ import ( providerkeeper "github.com/cosmos/interchain-security/v6/x/ccv/provider/keeper" v7 "github.com/cosmos/interchain-security/v6/x/ccv/provider/migrations/v7" v8 "github.com/cosmos/interchain-security/v6/x/ccv/provider/migrations/v8" + v9 "github.com/cosmos/interchain-security/v6/x/ccv/provider/migrations/v9" ) // Migrator is a struct for handling in-place store migrations. @@ -96,3 +97,15 @@ func (m Migrator) Migrate7to8(ctx sdktypes.Context) error { return nil } + +// Migrate8to9 migrates x/ccvprovider state from consensus version 8 to 9. +// The migration consists of the following actions: +// - insert infraction parameters for each consumer +func (m Migrator) Migrate8to9(ctx sdktypes.Context) error { + store := ctx.KVStore(m.storeKey) + if err := v9.MigrateConsumerInfractionParams(ctx, store, m.providerKeeper); err != nil { + return err + } + + return nil +} diff --git a/x/ccv/provider/migrations/v9/migrations.go b/x/ccv/provider/migrations/v9/migrations.go new file mode 100644 index 0000000000..df6c7d0057 --- /dev/null +++ b/x/ccv/provider/migrations/v9/migrations.go @@ -0,0 +1,39 @@ +package v9 + +import ( + "time" + + "cosmossdk.io/math" + storetypes "cosmossdk.io/store/types" + + sdk "github.com/cosmos/cosmos-sdk/types" + + providerkeeper "github.com/cosmos/interchain-security/v6/x/ccv/provider/keeper" + providertypes "github.com/cosmos/interchain-security/v6/x/ccv/provider/types" +) + +func MigrateConsumerInfractionParams(ctx sdk.Context, store storetypes.KVStore, pk providerkeeper.Keeper) error { + infractionParameters := defaultInfractionParams() + + activeConsumerIds := pk.GetAllActiveConsumerIds(ctx) + for _, consumerId := range activeConsumerIds { + if err := pk.SetInfractionParameters(ctx, consumerId, infractionParameters); err != nil { + return err + } + } + + return nil +} + +func defaultInfractionParams() providertypes.InfractionParameters { + return providertypes.InfractionParameters{ + DoubleSign: &providertypes.SlashJailParameters{ + JailDuration: time.Duration(1<<63 - 1), // the largest value a time.Duration can hold 9223372036854775807 (approximately 292 years) + SlashFraction: math.LegacyNewDecWithPrec(5, 2), // 0.05 + }, + Downtime: &providertypes.SlashJailParameters{ + JailDuration: 600 * time.Second, + SlashFraction: math.LegacyNewDec(0), // no slashing for downtime on the consumer + }, + } +} diff --git a/x/ccv/provider/migrations/v9/migrations_test.go b/x/ccv/provider/migrations/v9/migrations_test.go new file mode 100644 index 0000000000..21080078b8 --- /dev/null +++ b/x/ccv/provider/migrations/v9/migrations_test.go @@ -0,0 +1,35 @@ +package v9 + +import ( + "testing" + + "github.com/stretchr/testify/require" + + testutil "github.com/cosmos/interchain-security/v6/testutil/keeper" +) + +func TestSetDefaultConsumerInfractionParams(t *testing.T) { + t.Helper() + inMemParams := testutil.NewInMemKeeperParams(t) + k, ctx, ctrl, _ := testutil.GetProviderKeeperAndCtx(t, inMemParams) + defer ctrl.Finish() + + store := ctx.KVStore(inMemParams.StoreKey) + + activeConsumerIds := k.GetAllActiveConsumerIds(ctx) + + for _, consumerId := range activeConsumerIds { + _, err := k.GetInfractionParameters(ctx, consumerId) + require.Error(t, err) + } + + err := MigrateConsumerInfractionParams(ctx, store, k) + require.NoError(t, err) + + defaultInfractionParams := defaultInfractionParams() + for _, consumerId := range activeConsumerIds { + infractionParams, err := k.GetInfractionParameters(ctx, consumerId) + require.NoError(t, err) + require.Equal(t, defaultInfractionParams, infractionParams) + } +} diff --git a/x/ccv/provider/module.go b/x/ccv/provider/module.go index 233d0b36c9..744b17f984 100644 --- a/x/ccv/provider/module.go +++ b/x/ccv/provider/module.go @@ -147,6 +147,10 @@ func (am AppModule) RegisterServices(cfg module.Configurator) { if err := cfg.RegisterMigration(providertypes.ModuleName, 7, migrator.Migrate7to8); err != nil { panic(fmt.Sprintf("failed to register migrator for %s: %s -- from 7 -> 8", providertypes.ModuleName, err)) } + if err := cfg.RegisterMigration(providertypes.ModuleName, 8, migrator.Migrate8to9); err != nil { + panic(fmt.Sprintf("failed to register migrator for %s: %s -- from 8 -> 9", providertypes.ModuleName, err)) + } + } // InitGenesis performs genesis initialization for the provider module. It returns validator updates @@ -168,7 +172,7 @@ func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.Raw } // ConsensusVersion implements AppModule/ConsensusVersion. -func (AppModule) ConsensusVersion() uint64 { return 8 } +func (AppModule) ConsensusVersion() uint64 { return 9 } // BeginBlock implements the AppModule interface func (am AppModule) BeginBlock(ctx context.Context) error {