diff --git a/app/upgrades/v22/constants.go b/app/upgrades/v22/constants.go new file mode 100644 index 00000000000..0a904e8f159 --- /dev/null +++ b/app/upgrades/v22/constants.go @@ -0,0 +1,15 @@ +package v22 + +import ( + "github.com/cosmos/gaia/v21/app/upgrades" +) + +const ( + // UpgradeName defines the on-chain upgrade name. + UpgradeName = "v22" +) + +var Upgrade = upgrades.Upgrade{ + UpgradeName: UpgradeName, + CreateUpgradeHandler: CreateUpgradeHandler, +} diff --git a/app/upgrades/v22/upgrades.go b/app/upgrades/v22/upgrades.go new file mode 100644 index 00000000000..371a9f722d9 --- /dev/null +++ b/app/upgrades/v22/upgrades.go @@ -0,0 +1,65 @@ +package v22 + +import ( + "context" + "time" + + "cosmossdk.io/math" + upgradetypes "cosmossdk.io/x/upgrade/types" + providerkeeper "github.com/cosmos/interchain-security/v6/x/ccv/provider/keeper" + providertypes "github.com/cosmos/interchain-security/v6/x/ccv/provider/types" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/module" + + "github.com/cosmos/gaia/v21/app/keepers" +) + +func CreateUpgradeHandler( + mm *module.Manager, + configurator module.Configurator, + keepers *keepers.AppKeepers, +) upgradetypes.UpgradeHandler { + return func(c context.Context, plan upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) { + ctx := sdk.UnwrapSDKContext(c) + ctx.Logger().Info("Starting module migrations...") + + vm, err := mm.RunMigrations(ctx, configurator, vm) + if err != nil { + return vm, err + } + + if err := SetConsumerInfractionParams(ctx, keepers.ProviderKeeper); err != nil { + return vm, err + } + + ctx.Logger().Info("Upgrade v22 complete") + return vm, nil + } +} + +func SetConsumerInfractionParams(ctx sdk.Context, 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/app/upgrades/v22/upgrades_test.go b/app/upgrades/v22/upgrades_test.go new file mode 100644 index 00000000000..87ba9b86706 --- /dev/null +++ b/app/upgrades/v22/upgrades_test.go @@ -0,0 +1,47 @@ +package v22_test + +import ( + "testing" + + "github.com/stretchr/testify/require" + + v22 "github.com/cosmos/gaia/v21/app/upgrades/v22" + testutil "github.com/cosmos/interchain-security/v6/testutil/keeper" + providertypes "github.com/cosmos/interchain-security/v6/x/ccv/provider/types" +) + +func TestSetDefaultConsumerInfractionParams(t *testing.T) { + t.Helper() + inMemParams := testutil.NewInMemKeeperParams(t) + pk, ctx, ctrl, _ := testutil.GetProviderKeeperAndCtx(t, inMemParams) + defer ctrl.Finish() + + // Add consumer chains + initConsumerID := pk.FetchAndIncrementConsumerId(ctx) + pk.SetConsumerChainId(ctx, initConsumerID, "init-1") + pk.SetConsumerPhase(ctx, initConsumerID, providertypes.CONSUMER_PHASE_INITIALIZED) + launchedConsumerID := pk.FetchAndIncrementConsumerId(ctx) + pk.SetConsumerChainId(ctx, launchedConsumerID, "launched-1") + pk.SetConsumerPhase(ctx, launchedConsumerID, providertypes.CONSUMER_PHASE_LAUNCHED) + stoppedConsumerID := pk.FetchAndIncrementConsumerId(ctx) + pk.SetConsumerChainId(ctx, stoppedConsumerID, "stopped-1") + pk.SetConsumerPhase(ctx, stoppedConsumerID, providertypes.CONSUMER_PHASE_STOPPED) + + activeConsumerIds := pk.GetAllActiveConsumerIds(ctx) + require.Equal(t, 2, len(activeConsumerIds)) + + for _, consumerId := range activeConsumerIds { + _, err := pk.GetInfractionParameters(ctx, consumerId) + require.Error(t, err) + } + + err := v22.SetConsumerInfractionParams(ctx, pk) + require.NoError(t, err) + + defaultInfractionParams := v22.DefaultInfractionParams() + for _, consumerId := range activeConsumerIds { + infractionParams, err := pk.GetInfractionParameters(ctx, consumerId) + require.NoError(t, err) + require.Equal(t, defaultInfractionParams, infractionParams) + } +} diff --git a/go.mod b/go.mod index c5c27720a66..e81c776fde3 100644 --- a/go.mod +++ b/go.mod @@ -253,6 +253,9 @@ replace ( // Use special SDK v0.50.x release with support for both ICS and LSM github.com/cosmos/cosmos-sdk => github.com/cosmos/cosmos-sdk v0.50.10-lsm + // todo:remove this after ics version is updated + github.com/cosmos/interchain-security/v6 => github.com/cosmos/interchain-security/v6 v6.0.0-20241128093443-3f7df3506d1a + // TODO: remove it: https://github.com/cosmos/cosmos-sdk/issues/13134 github.com/dgrijalva/jwt-go => github.com/golang-jwt/jwt/v4 v4.4.2 diff --git a/go.sum b/go.sum index fa52cfc2b33..f9634902593 100644 --- a/go.sum +++ b/go.sum @@ -444,8 +444,8 @@ github.com/cosmos/ibc-go/v8 v8.5.2 h1:27s9oeD2AxLQF3e9BQsYt9doONyZ7FwZi/qkBv6Sdk github.com/cosmos/ibc-go/v8 v8.5.2/go.mod h1:P5hkAvq0Qbg0h18uLxDVA9q1kOJ0l36htMsskiNwXbo= github.com/cosmos/ics23/go v0.11.0 h1:jk5skjT0TqX5e5QJbEnwXIS2yI2vnmLOgpQPeM5RtnU= github.com/cosmos/ics23/go v0.11.0/go.mod h1:A8OjxPE67hHST4Icw94hOxxFEJMBG031xIGF/JHNIY0= -github.com/cosmos/interchain-security/v6 v6.3.0 h1:AIsfxLUDtUGVfaqJ1WPwnYIOT5AxoSO58469iw9vNH4= -github.com/cosmos/interchain-security/v6 v6.3.0/go.mod h1:6DSiV2w+DuPkxP1KGFtaxpiwf8Xt2iusj8O53KCx96Q= +github.com/cosmos/interchain-security/v6 v6.0.0-20241128093443-3f7df3506d1a h1:JQfqLMR0XBF40kRkMzqISVDH86frYyZ/X6xAzRwvDbw= +github.com/cosmos/interchain-security/v6 v6.0.0-20241128093443-3f7df3506d1a/go.mod h1:6DSiV2w+DuPkxP1KGFtaxpiwf8Xt2iusj8O53KCx96Q= github.com/cosmos/keyring v1.2.0 h1:8C1lBP9xhImmIabyXW4c3vFjjLiBdGCmfLUfeZlV1Yo= github.com/cosmos/keyring v1.2.0/go.mod h1:fc+wB5KTk9wQ9sDx0kFXB3A0MaeGHM9AwRStKOQ5vOA= github.com/cosmos/ledger-cosmos-go v0.13.3 h1:7ehuBGuyIytsXbd4MP43mLeoN2LTOEnk5nvue4rK+yM=