From a38bd3d8183ab3bcff42e87ba8b08c222d20a4b1 Mon Sep 17 00:00:00 2001 From: stana-ethernal Date: Thu, 28 Nov 2024 12:40:13 +0100 Subject: [PATCH 1/6] added upgrade handler for ics infraction params --- app/upgrades/v22/constants.go | 15 +++++++ app/upgrades/v22/upgrades.go | 65 +++++++++++++++++++++++++++++++ app/upgrades/v22/upgrades_test.go | 47 ++++++++++++++++++++++ go.mod | 3 ++ go.sum | 4 +- 5 files changed, 132 insertions(+), 2 deletions(-) create mode 100644 app/upgrades/v22/constants.go create mode 100644 app/upgrades/v22/upgrades.go create mode 100644 app/upgrades/v22/upgrades_test.go 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= From f5e39a3fd766f14b48e369a55e78d0da26cede0e Mon Sep 17 00:00:00 2001 From: stana-ethernal Date: Mon, 9 Dec 2024 10:31:55 +0100 Subject: [PATCH 2/6] lint fix --- app/upgrades/v22/upgrades.go | 6 +++--- app/upgrades/v22/upgrades_test.go | 12 ++++++------ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/app/upgrades/v22/upgrades.go b/app/upgrades/v22/upgrades.go index 371a9f722d9..bc7a69915f9 100644 --- a/app/upgrades/v22/upgrades.go +++ b/app/upgrades/v22/upgrades.go @@ -41,9 +41,9 @@ func CreateUpgradeHandler( 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 { + activeConsumerIDs := pk.GetAllActiveConsumerIds(ctx) + for _, consumerID := range activeConsumerIDs { + if err := pk.SetInfractionParameters(ctx, consumerID, infractionParameters); err != nil { return err } } diff --git a/app/upgrades/v22/upgrades_test.go b/app/upgrades/v22/upgrades_test.go index 87ba9b86706..a7c4f8400b4 100644 --- a/app/upgrades/v22/upgrades_test.go +++ b/app/upgrades/v22/upgrades_test.go @@ -27,11 +27,11 @@ func TestSetDefaultConsumerInfractionParams(t *testing.T) { pk.SetConsumerChainId(ctx, stoppedConsumerID, "stopped-1") pk.SetConsumerPhase(ctx, stoppedConsumerID, providertypes.CONSUMER_PHASE_STOPPED) - activeConsumerIds := pk.GetAllActiveConsumerIds(ctx) - require.Equal(t, 2, len(activeConsumerIds)) + activeConsumerIDs := pk.GetAllActiveConsumerIds(ctx) + require.Equal(t, 2, len(activeConsumerIDs)) - for _, consumerId := range activeConsumerIds { - _, err := pk.GetInfractionParameters(ctx, consumerId) + for _, consumerID := range activeConsumerIDs { + _, err := pk.GetInfractionParameters(ctx, consumerID) require.Error(t, err) } @@ -39,8 +39,8 @@ func TestSetDefaultConsumerInfractionParams(t *testing.T) { require.NoError(t, err) defaultInfractionParams := v22.DefaultInfractionParams() - for _, consumerId := range activeConsumerIds { - infractionParams, err := pk.GetInfractionParameters(ctx, consumerId) + for _, consumerID := range activeConsumerIDs { + infractionParams, err := pk.GetInfractionParameters(ctx, consumerID) require.NoError(t, err) require.Equal(t, defaultInfractionParams, infractionParams) } From ed836f9eb0d05ccafbd8920dc0cfa5a999fb1317 Mon Sep 17 00:00:00 2001 From: stana-ethernal Date: Mon, 9 Dec 2024 11:01:52 +0100 Subject: [PATCH 3/6] format error --- app/upgrades/v22/upgrades.go | 12 ++++++++---- app/upgrades/v22/upgrades_test.go | 3 ++- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/app/upgrades/v22/upgrades.go b/app/upgrades/v22/upgrades.go index 33a764c9bb4..90814878090 100644 --- a/app/upgrades/v22/upgrades.go +++ b/app/upgrades/v22/upgrades.go @@ -4,13 +4,17 @@ import ( "context" "time" + providerkeeper "github.com/cosmos/interchain-security/v6/x/ccv/provider/keeper" + providertypes "github.com/cosmos/interchain-security/v6/x/ccv/provider/types" + + errorsmod "cosmossdk.io/errors" "cosmossdk.io/math" upgradetypes "cosmossdk.io/x/upgrade/types" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" + "github.com/cosmos/gaia/v22/app/keepers" - providerkeeper "github.com/cosmos/interchain-security/v6/x/ccv/provider/keeper" - providertypes "github.com/cosmos/interchain-security/v6/x/ccv/provider/types" ) // CreateUpgradeHandler returns an upgrade handler for Gaia v22. @@ -25,11 +29,11 @@ func CreateUpgradeHandler( vm, err := mm.RunMigrations(ctx, configurator, vm) if err != nil { - return vm, err + return vm, errorsmod.Wrapf(err, "running module migrations") } if err := SetConsumerInfractionParams(ctx, keepers.ProviderKeeper); err != nil { - return vm, err + return vm, errorsmod.Wrapf(err, "running module migrations") } ctx.Logger().Info("Upgrade v22 complete") diff --git a/app/upgrades/v22/upgrades_test.go b/app/upgrades/v22/upgrades_test.go index 6bd2ee811f8..02607eb1eba 100644 --- a/app/upgrades/v22/upgrades_test.go +++ b/app/upgrades/v22/upgrades_test.go @@ -5,9 +5,10 @@ import ( "github.com/stretchr/testify/require" - v22 "github.com/cosmos/gaia/v22/app/upgrades/v22" testutil "github.com/cosmos/interchain-security/v6/testutil/keeper" providertypes "github.com/cosmos/interchain-security/v6/x/ccv/provider/types" + + v22 "github.com/cosmos/gaia/v22/app/upgrades/v22" ) func TestSetDefaultConsumerInfractionParams(t *testing.T) { From c6106cb59cb80d88933bb309e8857ea1638419a2 Mon Sep 17 00:00:00 2001 From: stana-ethernal Date: Mon, 9 Dec 2024 15:28:46 +0100 Subject: [PATCH 4/6] bump ics version --- go.mod | 13 +++++-------- go.sum | 20 ++++++++++---------- 2 files changed, 15 insertions(+), 18 deletions(-) diff --git a/go.mod b/go.mod index 005211a3b5d..840cf9ced01 100644 --- a/go.mod +++ b/go.mod @@ -30,7 +30,7 @@ require ( github.com/cosmos/ibc-apps/modules/rate-limiting/v8 v8.0.0 github.com/cosmos/ibc-go/modules/capability v1.0.1 github.com/cosmos/ibc-go/v8 v8.5.2 - github.com/cosmos/interchain-security/v6 v6.3.0 + github.com/cosmos/interchain-security/v6 v6.0.0-20241209121224-cabebfa1c816 github.com/google/gofuzz v1.2.0 github.com/gorilla/mux v1.8.1 github.com/ory/dockertest/v3 v3.11.0 @@ -52,7 +52,7 @@ require ( github.com/golang/protobuf v1.5.4 // indirect github.com/grpc-ecosystem/grpc-gateway v1.16.0 google.golang.org/genproto v0.0.0-20240701130421-f6361c86f094 // indirect - google.golang.org/grpc v1.67.1 // indirect + google.golang.org/grpc v1.68.0 // indirect ) require ( @@ -238,9 +238,9 @@ require ( golang.org/x/text v0.19.0 // indirect golang.org/x/time v0.5.0 // indirect google.golang.org/api v0.186.0 // indirect - google.golang.org/genproto/googleapis/api v0.0.0-20240814211410-ddb44dafa142 // indirect - google.golang.org/genproto/googleapis/rpc v0.0.0-20240814211410-ddb44dafa142 // indirect - google.golang.org/protobuf v1.35.1 // indirect + google.golang.org/genproto/googleapis/api v0.0.0-20240903143218-8af14fe29dc1 // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20240903143218-8af14fe29dc1 // indirect + google.golang.org/protobuf v1.35.2 // indirect gopkg.in/ini.v1 v1.67.0 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect @@ -260,9 +260,6 @@ 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 266c9b2f6c0..f82d546bc1d 100644 --- a/go.sum +++ b/go.sum @@ -453,8 +453,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.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/interchain-security/v6 v6.0.0-20241209121224-cabebfa1c816 h1:oQYjNWTqvQuKM9jMSfobd2wBWYkn92DCWVWn+c7aEKE= +github.com/cosmos/interchain-security/v6 v6.0.0-20241209121224-cabebfa1c816/go.mod h1:3BiWAB1SDOjQpz82QekjDVTOaTNYx3AiXk3Il6xT5Co= 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= @@ -1937,10 +1937,10 @@ google.golang.org/genproto v0.0.0-20221014213838-99cd37c6964a/go.mod h1:1vXfmgAz google.golang.org/genproto v0.0.0-20221025140454-527a21cfbd71/go.mod h1:9qHF0xnpdSfF6knlcsnpzUu5y+rpwgbvsyGAZPBMg4s= google.golang.org/genproto v0.0.0-20240701130421-f6361c86f094 h1:6whtk83KtD3FkGrVb2hFXuQ+ZMbCNdakARIn/aHMmG8= google.golang.org/genproto v0.0.0-20240701130421-f6361c86f094/go.mod h1:Zs4wYw8z1zr6RNF4cwYb31mvN/EGaKAdQjNCF3DW6K4= -google.golang.org/genproto/googleapis/api v0.0.0-20240814211410-ddb44dafa142 h1:wKguEg1hsxI2/L3hUYrpo1RVi48K+uTyzKqprwLXsb8= -google.golang.org/genproto/googleapis/api v0.0.0-20240814211410-ddb44dafa142/go.mod h1:d6be+8HhtEtucleCbxpPW9PA9XwISACu8nvpPqF0BVo= -google.golang.org/genproto/googleapis/rpc v0.0.0-20240814211410-ddb44dafa142 h1:e7S5W7MGGLaSu8j3YjdezkZ+m1/Nm0uRVRMEMGk26Xs= -google.golang.org/genproto/googleapis/rpc v0.0.0-20240814211410-ddb44dafa142/go.mod h1:UqMtugtsSgubUsoxbuAoiCXvqvErP7Gf0so0mK9tHxU= +google.golang.org/genproto/googleapis/api v0.0.0-20240903143218-8af14fe29dc1 h1:hjSy6tcFQZ171igDaN5QHOw2n6vx40juYbC/x67CEhc= +google.golang.org/genproto/googleapis/api v0.0.0-20240903143218-8af14fe29dc1/go.mod h1:qpvKtACPCQhAdu3PyQgV4l3LMXZEtft7y8QcarRsp9I= +google.golang.org/genproto/googleapis/rpc v0.0.0-20240903143218-8af14fe29dc1 h1:pPJltXNxVzT4pK9yD8vR9X75DaWYYmLGMsEvBfFQZzQ= +google.golang.org/genproto/googleapis/rpc v0.0.0-20240903143218-8af14fe29dc1/go.mod h1:UqMtugtsSgubUsoxbuAoiCXvqvErP7Gf0so0mK9tHxU= google.golang.org/grpc v1.17.0/go.mod h1:6QZJwpn2B+Zp71q/5VxRsJ6NXXVCE5NRUHRo+f3cWCs= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.20.0/go.mod h1:chYK+tFQF0nDUGJgXMSgLCQk3phJEuONr2DCgLDdAQM= @@ -1982,8 +1982,8 @@ google.golang.org/grpc v1.48.0/go.mod h1:vN9eftEi1UMyUsIF80+uQXhHjbXYbm0uXoFCACu google.golang.org/grpc v1.49.0/go.mod h1:ZgQEeidpAuNRZ8iRrlBKXZQP1ghovWIVhdJRyCDK+GI= google.golang.org/grpc v1.50.0/go.mod h1:ZgQEeidpAuNRZ8iRrlBKXZQP1ghovWIVhdJRyCDK+GI= google.golang.org/grpc v1.50.1/go.mod h1:ZgQEeidpAuNRZ8iRrlBKXZQP1ghovWIVhdJRyCDK+GI= -google.golang.org/grpc v1.67.1 h1:zWnc1Vrcno+lHZCOofnIMvycFcc0QRGIzm9dhnDX68E= -google.golang.org/grpc v1.67.1/go.mod h1:1gLDyUQU7CTLJI90u3nXZ9ekeghjeM7pTDZlqFNg2AA= +google.golang.org/grpc v1.68.0 h1:aHQeeJbo8zAkAa3pRzrVjZlbz6uSfeOXlJNQM0RAbz0= +google.golang.org/grpc v1.68.0/go.mod h1:fmSPC5AsjSBCK54MyHRx48kpOti1/jRfOlwEWywNjWA= google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.1.0/go.mod h1:6Kw0yEErY5E/yWrBtf03jp27GLLJujG4z/JK95pnjjw= google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= @@ -2000,8 +2000,8 @@ google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQ google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= -google.golang.org/protobuf v1.35.1 h1:m3LfL6/Ca+fqnjnlqQXNpFPABW1UD7mjh8KO2mKFytA= -google.golang.org/protobuf v1.35.1/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE= +google.golang.org/protobuf v1.35.2 h1:8Ar7bF+apOIoThw1EdZl0p1oWvMqTHmpA2fRTyZO8io= +google.golang.org/protobuf v1.35.2/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE= gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= From ad71048399a839ed0ecc1dd7297c1c46ce70f746 Mon Sep 17 00:00:00 2001 From: stana-ethernal Date: Wed, 11 Dec 2024 09:04:34 +0100 Subject: [PATCH 5/6] get default infraction parameters from providertypes --- app/upgrades/v22/upgrades.go | 30 ++++++++---------------------- app/upgrades/v22/upgrades_test.go | 21 ++++++++++++++++++--- 2 files changed, 26 insertions(+), 25 deletions(-) diff --git a/app/upgrades/v22/upgrades.go b/app/upgrades/v22/upgrades.go index 90814878090..1852679135d 100644 --- a/app/upgrades/v22/upgrades.go +++ b/app/upgrades/v22/upgrades.go @@ -2,14 +2,11 @@ package v22 import ( "context" - "time" - - providerkeeper "github.com/cosmos/interchain-security/v6/x/ccv/provider/keeper" - providertypes "github.com/cosmos/interchain-security/v6/x/ccv/provider/types" errorsmod "cosmossdk.io/errors" - "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" @@ -32,7 +29,11 @@ func CreateUpgradeHandler( return vm, errorsmod.Wrapf(err, "running module migrations") } - if err := SetConsumerInfractionParams(ctx, keepers.ProviderKeeper); err != nil { + infractionParameters, err := providertypes.DefaultConsumerInfractionParameters(ctx, keepers.SlashingKeeper) + if err != nil { + return vm, errorsmod.Wrapf(err, "running module migrations") + } + if err := SetConsumerInfractionParams(ctx, keepers.ProviderKeeper, infractionParameters); err != nil { return vm, errorsmod.Wrapf(err, "running module migrations") } @@ -41,9 +42,7 @@ func CreateUpgradeHandler( } } -func SetConsumerInfractionParams(ctx sdk.Context, pk providerkeeper.Keeper) error { - infractionParameters := DefaultInfractionParams() - +func SetConsumerInfractionParams(ctx sdk.Context, pk providerkeeper.Keeper, infractionParameters providertypes.InfractionParameters) error { activeConsumerIDs := pk.GetAllActiveConsumerIds(ctx) for _, consumerID := range activeConsumerIDs { if err := pk.SetInfractionParameters(ctx, consumerID, infractionParameters); err != nil { @@ -53,16 +52,3 @@ func SetConsumerInfractionParams(ctx sdk.Context, pk providerkeeper.Keeper) erro 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 index 02607eb1eba..5b8bc2cdecc 100644 --- a/app/upgrades/v22/upgrades_test.go +++ b/app/upgrades/v22/upgrades_test.go @@ -2,7 +2,9 @@ package v22_test import ( "testing" + "time" + "cosmossdk.io/math" "github.com/stretchr/testify/require" testutil "github.com/cosmos/interchain-security/v6/testutil/keeper" @@ -36,13 +38,26 @@ func TestSetDefaultConsumerInfractionParams(t *testing.T) { require.Error(t, err) } - err := v22.SetConsumerInfractionParams(ctx, pk) + testParams := testInfractionParams() + err := v22.SetConsumerInfractionParams(ctx, pk, testParams) 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) + require.Equal(t, testParams, infractionParams) + } +} + +func testInfractionParams() 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 + }, } } From 28b3d4b54807618cdf93479908556e4e6c6fe873 Mon Sep 17 00:00:00 2001 From: stana-ethernal Date: Wed, 11 Dec 2024 10:38:17 +0100 Subject: [PATCH 6/6] lint fix --- app/upgrades/v22/upgrades.go | 5 +++-- app/upgrades/v22/upgrades_test.go | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/app/upgrades/v22/upgrades.go b/app/upgrades/v22/upgrades.go index 1852679135d..34a190c0976 100644 --- a/app/upgrades/v22/upgrades.go +++ b/app/upgrades/v22/upgrades.go @@ -3,11 +3,12 @@ package v22 import ( "context" - errorsmod "cosmossdk.io/errors" - 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" + errorsmod "cosmossdk.io/errors" + upgradetypes "cosmossdk.io/x/upgrade/types" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" diff --git a/app/upgrades/v22/upgrades_test.go b/app/upgrades/v22/upgrades_test.go index 5b8bc2cdecc..1a3ecfe7341 100644 --- a/app/upgrades/v22/upgrades_test.go +++ b/app/upgrades/v22/upgrades_test.go @@ -4,12 +4,13 @@ import ( "testing" "time" - "cosmossdk.io/math" "github.com/stretchr/testify/require" testutil "github.com/cosmos/interchain-security/v6/testutil/keeper" providertypes "github.com/cosmos/interchain-security/v6/x/ccv/provider/types" + "cosmossdk.io/math" + v22 "github.com/cosmos/gaia/v22/app/upgrades/v22" )