From 288928aceacd0d02aab943240eeb17d8c528048b Mon Sep 17 00:00:00 2001 From: Rayden Ge Date: Fri, 13 Dec 2024 06:04:45 +0100 Subject: [PATCH] chore(upgrade): remove historical upgrade handlers (#427) remove historical upgrade handlers and port https://github.com/piplabs/cosmos-sdk/pull/32 change issue: none --- client/app/upgrades.go | 9 +-- client/app/upgrades/v0_12_1/constants.go | 16 ----- client/app/upgrades/v0_12_1/upgrades.go | 76 ------------------------ client/app/upgrades/v0_13_0/constants.go | 16 ----- client/app/upgrades/v0_13_0/upgrades.go | 33 ---------- client/app/upgrades/v0_14_0/constants.go | 16 ----- client/app/upgrades/v0_14_0/upgrades.go | 61 ------------------- go.mod | 2 +- go.sum | 4 +- 9 files changed, 4 insertions(+), 229 deletions(-) delete mode 100644 client/app/upgrades/v0_12_1/constants.go delete mode 100644 client/app/upgrades/v0_12_1/upgrades.go delete mode 100644 client/app/upgrades/v0_13_0/constants.go delete mode 100644 client/app/upgrades/v0_13_0/upgrades.go delete mode 100644 client/app/upgrades/v0_14_0/constants.go delete mode 100644 client/app/upgrades/v0_14_0/upgrades.go diff --git a/client/app/upgrades.go b/client/app/upgrades.go index c6761192..e1bb1088 100644 --- a/client/app/upgrades.go +++ b/client/app/upgrades.go @@ -8,19 +8,12 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/piplabs/story/client/app/upgrades" - "github.com/piplabs/story/client/app/upgrades/v0_12_1" - "github.com/piplabs/story/client/app/upgrades/v0_13_0" - "github.com/piplabs/story/client/app/upgrades/v0_14_0" ) var ( // `Upgrades` defines the upgrade handlers and store loaders for the application. // New upgrades should be added to this slice after they are implemented. - Upgrades = []upgrades.Upgrade{ - v0_12_1.Upgrade, - v0_13_0.Upgrade, - v0_14_0.Upgrade, - } + Upgrades = []upgrades.Upgrade{} // Forks are for hard forks that breaks backward compatibility. Forks = []upgrades.Fork{} ) diff --git a/client/app/upgrades/v0_12_1/constants.go b/client/app/upgrades/v0_12_1/constants.go deleted file mode 100644 index 344f0fde..00000000 --- a/client/app/upgrades/v0_12_1/constants.go +++ /dev/null @@ -1,16 +0,0 @@ -//nolint:revive,stylecheck // version underscores -package v0_12_1 - -import ( - storetypes "cosmossdk.io/store/types" - - "github.com/piplabs/story/client/app/upgrades" -) - -const UpgradeName = "v0.12.1" - -var Upgrade = upgrades.Upgrade{ - UpgradeName: UpgradeName, - CreateUpgradeHandler: CreateUpgradeHandler, - StoreUpgrades: storetypes.StoreUpgrades{}, -} diff --git a/client/app/upgrades/v0_12_1/upgrades.go b/client/app/upgrades/v0_12_1/upgrades.go deleted file mode 100644 index c509a8f9..00000000 --- a/client/app/upgrades/v0_12_1/upgrades.go +++ /dev/null @@ -1,76 +0,0 @@ -//nolint:revive,stylecheck // version underscores -package v0_12_1 - -import ( - "context" - "time" - - upgradetypes "cosmossdk.io/x/upgrade/types" - - "github.com/cosmos/cosmos-sdk/types/module" - - "github.com/piplabs/story/client/app/keepers" - "github.com/piplabs/story/lib/errors" - "github.com/piplabs/story/lib/log" -) - -func CreateUpgradeHandler( - mm *module.Manager, - configurator module.Configurator, - keepers *keepers.Keepers, -) upgradetypes.UpgradeHandler { - return func(ctx context.Context, _ upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) { - log.Info(ctx, "Starting module migrations...") - - vm, err := mm.RunMigrations(ctx, configurator, vm) - if err != nil { - return vm, errors.Wrap(err, "run migrations") - } - - log.Info(ctx, "Decreasing staking periods...") - stakingParams, err := keepers.StakingKeeper.GetParams(ctx) - if err != nil { - return vm, errors.Wrap(err, "failed to get staking params") - } - periods := stakingParams.Periods - - for i := range periods { - if periods[i].PeriodType == 1 { - log.Info(ctx, "Existing short period duration", "Time", periods[i].Duration.String()) - periods[i].Duration = time.Hour * 7 * 24 // one week in hours - } else if periods[i].PeriodType == 2 { - log.Info(ctx, "Existing medium period duration", "Time", periods[i].Duration.String()) - periods[i].Duration = time.Hour * 14 * 24 // two weeks in hours - } else if periods[i].PeriodType == 3 { - log.Info(ctx, "Existing long period duration", "Time", periods[i].Duration.String()) - periods[i].Duration = time.Hour * 21 * 24 // three weeks in hours - } - } - - err = keepers.StakingKeeper.SetParams(ctx, stakingParams) - if err != nil { - return vm, errors.Wrap(err, "failed to set staking params") - } - - log.Info(ctx, "Checking newstaking periods...") - stakingParams, err = keepers.StakingKeeper.GetParams(ctx) - if err != nil { - return vm, errors.Wrap(err, "failed to get staking params") - } - periods = stakingParams.GetPeriods() - - for _, p := range periods { - if p.PeriodType == 1 { - log.Info(ctx, "New short period duration", "Time", p.Duration.String()) - } else if p.PeriodType == 2 { - log.Info(ctx, "New medium period duration", "Time", p.Duration.String()) - } else if p.PeriodType == 3 { - log.Info(ctx, "New long period duration", "Time", p.Duration.String()) - } - } - - log.Info(ctx, "Upgrade v0.12.1 complete") - - return vm, nil - } -} diff --git a/client/app/upgrades/v0_13_0/constants.go b/client/app/upgrades/v0_13_0/constants.go deleted file mode 100644 index bd328169..00000000 --- a/client/app/upgrades/v0_13_0/constants.go +++ /dev/null @@ -1,16 +0,0 @@ -//nolint:revive,stylecheck // version underscores -package v0_13_0 - -import ( - storetypes "cosmossdk.io/store/types" - - "github.com/piplabs/story/client/app/upgrades" -) - -const UpgradeName = "v0.13.0" - -var Upgrade = upgrades.Upgrade{ - UpgradeName: UpgradeName, - CreateUpgradeHandler: CreateUpgradeHandler, - StoreUpgrades: storetypes.StoreUpgrades{}, -} diff --git a/client/app/upgrades/v0_13_0/upgrades.go b/client/app/upgrades/v0_13_0/upgrades.go deleted file mode 100644 index 5363255e..00000000 --- a/client/app/upgrades/v0_13_0/upgrades.go +++ /dev/null @@ -1,33 +0,0 @@ -//nolint:revive,stylecheck // version underscores -package v0_13_0 - -import ( - "context" - - upgradetypes "cosmossdk.io/x/upgrade/types" - - "github.com/cosmos/cosmos-sdk/types/module" - - "github.com/piplabs/story/client/app/keepers" - "github.com/piplabs/story/lib/errors" - "github.com/piplabs/story/lib/log" -) - -func CreateUpgradeHandler( - mm *module.Manager, - configurator module.Configurator, - keepers *keepers.Keepers, -) upgradetypes.UpgradeHandler { - return func(ctx context.Context, _ upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) { - log.Info(ctx, "Starting module migrations...") - - vm, err := mm.RunMigrations(ctx, configurator, vm) - if err != nil { - return vm, errors.Wrap(err, "run migrations") - } - - log.Info(ctx, "Upgrade v0.13.0 complete") - - return vm, nil - } -} diff --git a/client/app/upgrades/v0_14_0/constants.go b/client/app/upgrades/v0_14_0/constants.go deleted file mode 100644 index 30fc6816..00000000 --- a/client/app/upgrades/v0_14_0/constants.go +++ /dev/null @@ -1,16 +0,0 @@ -//nolint:revive,stylecheck // version underscores -package v0_14_0 - -import ( - storetypes "cosmossdk.io/store/types" - - "github.com/piplabs/story/client/app/upgrades" -) - -const UpgradeName = "v0.14.0" - -var Upgrade = upgrades.Upgrade{ - UpgradeName: UpgradeName, - CreateUpgradeHandler: CreateUpgradeHandler, - StoreUpgrades: storetypes.StoreUpgrades{}, -} diff --git a/client/app/upgrades/v0_14_0/upgrades.go b/client/app/upgrades/v0_14_0/upgrades.go deleted file mode 100644 index 59336c2e..00000000 --- a/client/app/upgrades/v0_14_0/upgrades.go +++ /dev/null @@ -1,61 +0,0 @@ -//nolint:revive,stylecheck // version underscores -package v0_14_0 - -import ( - "context" - - upgradetypes "cosmossdk.io/x/upgrade/types" - - "github.com/cosmos/cosmos-sdk/types/module" - - "github.com/piplabs/story/client/app/keepers" - "github.com/piplabs/story/lib/errors" - "github.com/piplabs/story/lib/log" -) - -func CreateUpgradeHandler( - mm *module.Manager, - configurator module.Configurator, - keepers *keepers.Keepers, -) upgradetypes.UpgradeHandler { - return func(ctx context.Context, _ upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) { - log.Info(ctx, "Starting module migrations...") - - vm, err := mm.RunMigrations(ctx, configurator, vm) - if err != nil { - return vm, errors.Wrap(err, "run migrations") - } - - log.Info(ctx, "Getting existing UnbondingID...") - unbondingID, err := keepers.StakingKeeper.GetOldUnbondingID(ctx) - if err != nil { - return vm, errors.Wrap(err, "failed to get existing UnbondingID") - } - log.Info(ctx, "Existing UnbondingID", "UnbondingID", unbondingID) - - log.Info(ctx, "Setting new UnbondingID...") - if err := keepers.StakingKeeper.SetUnbondingID(ctx, unbondingID); err != nil { - return vm, errors.Wrap(err, "failed to set new UnbondingID") - } - - log.Info(ctx, "Getting new UnbondingID...") - newUnbondingID, err := keepers.StakingKeeper.GetUnbondingID(ctx) - if err != nil { - return vm, errors.Wrap(err, "failed to get new UnbondingID") - } - log.Info(ctx, "New UnbondingID", "UnbondingID", newUnbondingID) - - if newUnbondingID != unbondingID { - return vm, errors.New("new UnbondingID does not match existing UnbondingID") - } - - log.Info(ctx, "Removing old UnbondingID...") - if err := keepers.StakingKeeper.RemoveOldUnbondingID(ctx); err != nil { - return vm, errors.Wrap(err, "failed to remove old UnbondingID") - } - - log.Info(ctx, "Upgrade v0.14.0 complete") - - return vm, nil - } -} diff --git a/go.mod b/go.mod index f4c0d09a..e05aafcf 100644 --- a/go.mod +++ b/go.mod @@ -307,7 +307,7 @@ replace ( github.com/cometbft/cometbft v0.38.12 => github.com/cometbft/cometbft v0.38.9 // Direct cosmos-sdk branch link: https://github.com/piplabs/cosmos-sdk/tree/piplabs/v0.50.10, current branch: piplabs/v0.50.10 - github.com/cosmos/cosmos-sdk => github.com/piplabs/cosmos-sdk v0.50.10-piplabs-v0.4 + github.com/cosmos/cosmos-sdk => github.com/piplabs/cosmos-sdk v0.50.10-piplabs-v0.5 // See https://github.com/cosmos/cosmos-sdk/pull/14952 // Also https://github.com/cosmos/cosmos-db/blob/main/go.mod#L11-L12 diff --git a/go.sum b/go.sum index 502a4a61..9331742a 100644 --- a/go.sum +++ b/go.sum @@ -1036,8 +1036,8 @@ github.com/pierrec/lz4 v1.0.2-0.20190131084431-473cd7ce01a1/go.mod h1:3/3N9NVKO0 github.com/pierrec/lz4 v2.0.5+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY= github.com/pingcap/errors v0.11.4 h1:lFuQV/oaUMGcD2tqt+01ROSmJs75VG1ToEOkZIZ4nE4= github.com/pingcap/errors v0.11.4/go.mod h1:Oi8TUi2kEtXXLMJk9l1cGmz20kV3TaQ0usTwv5KuLY8= -github.com/piplabs/cosmos-sdk v0.50.10-piplabs-v0.4 h1:XTPlWC7Uftk4IGlgBgiopXk53fywQNyIoBRv4W1BTFY= -github.com/piplabs/cosmos-sdk v0.50.10-piplabs-v0.4/go.mod h1:6Eesrx3ZE7vxBZWpK++30H+Uc7Q4ahQWCL7JKU/LEdU= +github.com/piplabs/cosmos-sdk v0.50.10-piplabs-v0.5 h1:YuSkplxqggSaKlqMy5OZkU9acHVuv7LhN93q9rFkJQU= +github.com/piplabs/cosmos-sdk v0.50.10-piplabs-v0.5/go.mod h1:6Eesrx3ZE7vxBZWpK++30H+Uc7Q4ahQWCL7JKU/LEdU= github.com/piplabs/cosmos-sdk/x/evidence v0.1.1-piplabs-v0.2 h1:3WnMps6DSyLChQpO29tPVNEFuXIb/RrCyQSSuWNE2o8= github.com/piplabs/cosmos-sdk/x/evidence v0.1.1-piplabs-v0.2/go.mod h1:OIQ4Ax/nK/ED36QTnO4LhTslsR4omyvEAXmJcRw7R/Q= github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c h1:+mdjkGKdHQG3305AYmdv1U2eRNDiU2ErMBj1gwrq8eQ=