-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: prepare app for upgrade (#106)
## Description This PR adds an upgrade handler to make sure that the testnet can be upgraded from the current `v1.0.0` version to the new `v1.1.0` version properly. It also includes some code fixes like missing autocli configurations and services registering. To make sure that upgrade goes smoothly, some migration implementations have been added to properly set the params of new modules to default values. Also, the params for the `x/assets` module has been removed as it was empty and not used inside the codebase. <!-- Add a description of the changes that this PR introduces and the files that are the most critical to review. --> --- ### Author Checklist *All items are required. Please add a note to the item if the item is not applicable and please add links to any relevant follow up issues.* I have... - [ ] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] added `!` to the type prefix if API or client breaking change - [ ] targeted the correct branch (see [PR Targeting](https://github.com/milkyway-labs/milkyway/blob/master/CONTRIBUTING.md#pr-targeting)) - [ ] provided a link to the relevant issue or specification - [ ] followed the guidelines for [building modules](https://docs.cosmos.network/v0.44/building-modules/intro.html) - [ ] included the necessary unit and integration [tests](https://github.com/milkyway-labs/milkyway/blob/master/CONTRIBUTING.md#testing) - [ ] added a changelog entry to `CHANGELOG.md` - [ ] included comments for [documenting Go code](https://blog.golang.org/godoc) - [ ] updated the relevant documentation or specification - [ ] reviewed "Files changed" and left comments if necessary - [ ] confirmed all CI checks have passed ### Reviewers Checklist *All items are required. Please add a note if the item is not applicable and please add your handle next to the items reviewed if you only reviewed selected items.* I have... - [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] confirmed `!` in the type prefix if API or client breaking change - [ ] confirmed all author checklist items have been addressed - [ ] reviewed state machine logic - [ ] reviewed API design and naming - [ ] reviewed documentation is accurate - [ ] reviewed tests and test coverage - [ ] manually tested (if applicable) --------- Co-authored-by: Hanjun Kim <hallazzang@gmail.com>
- Loading branch information
1 parent
44aac23
commit 583293d
Showing
29 changed files
with
277 additions
and
1,489 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,10 @@ | ||
package app | ||
|
||
import ( | ||
"context" | ||
|
||
upgradetypes "cosmossdk.io/x/upgrade/types" | ||
"github.com/cosmos/cosmos-sdk/types/module" | ||
v110 "github.com/milkyway-labs/milkyway/app/upgrades/v110" | ||
) | ||
|
||
const upgradeName = "0.2.4" | ||
|
||
// RegisterUpgradeHandlers returns upgrade handlers | ||
func (app *MilkyWayApp) RegisterUpgradeHandlers(cfg module.Configurator) { | ||
app.UpgradeKeeper.SetUpgradeHandler(upgradeName, | ||
func(ctx context.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { | ||
return fromVM, nil | ||
}, | ||
) | ||
func (app *MilkyWayApp) RegisterUpgradeHandlers() { | ||
app.registerUpgrade(v110.NewUpgrade(app.ModuleManager, app.Configurator(), app.appCodec, app.keys, app.RewardsKeeper)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package upgrades | ||
|
||
import ( | ||
storetypes "cosmossdk.io/store/types" | ||
upgradetypes "cosmossdk.io/x/upgrade/types" | ||
) | ||
|
||
// Upgrade represents a generic on-chain upgrade | ||
type Upgrade interface { | ||
Name() string | ||
Handler() upgradetypes.UpgradeHandler | ||
StoreUpgrades() *storetypes.StoreUpgrades | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
package v710 | ||
|
||
import ( | ||
"context" | ||
|
||
storetypes "cosmossdk.io/store/types" | ||
upgradetypes "cosmossdk.io/x/upgrade/types" | ||
"github.com/cosmos/cosmos-sdk/codec" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/cosmos/cosmos-sdk/types/module" | ||
|
||
"github.com/milkyway-labs/milkyway/app/upgrades" | ||
assetstypes "github.com/milkyway-labs/milkyway/x/assets/types" | ||
operatorstypes "github.com/milkyway-labs/milkyway/x/operators/types" | ||
poolstypes "github.com/milkyway-labs/milkyway/x/pools/types" | ||
restakingtypes "github.com/milkyway-labs/milkyway/x/restaking/types" | ||
rewardskeeper "github.com/milkyway-labs/milkyway/x/rewards/keeper" | ||
rewardstypes "github.com/milkyway-labs/milkyway/x/rewards/types" | ||
servicestypes "github.com/milkyway-labs/milkyway/x/services/types" | ||
) | ||
|
||
var ( | ||
_ upgrades.Upgrade = &Upgrade{} | ||
) | ||
|
||
// Upgrade represents the v1.1.0 upgrade | ||
type Upgrade struct { | ||
mm *module.Manager | ||
configurator module.Configurator | ||
|
||
cdc codec.BinaryCodec | ||
keys map[string]*storetypes.KVStoreKey | ||
rewardsKeeper *rewardskeeper.Keeper | ||
} | ||
|
||
// NewUpgrade returns a new Upgrade instance | ||
func NewUpgrade( | ||
mm *module.Manager, | ||
configurator module.Configurator, | ||
cdc codec.BinaryCodec, | ||
keys map[string]*storetypes.KVStoreKey, | ||
rewardsKeeper *rewardskeeper.Keeper, | ||
) *Upgrade { | ||
return &Upgrade{ | ||
mm: mm, | ||
configurator: configurator, | ||
cdc: cdc, | ||
keys: keys, | ||
rewardsKeeper: rewardsKeeper, | ||
} | ||
} | ||
|
||
// Name implements upgrades.Upgrade | ||
func (u *Upgrade) Name() string { | ||
return "v1.1.0" | ||
} | ||
|
||
// Handler implements upgrades.Upgrade | ||
func (u *Upgrade) Handler() upgradetypes.UpgradeHandler { | ||
return func(ctx context.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { | ||
sdkCtx := sdk.UnwrapSDKContext(ctx) | ||
|
||
// Set the operators module params | ||
store := sdkCtx.KVStore(u.keys[operatorstypes.ModuleName]) | ||
operatorsParams := operatorstypes.DefaultParams() | ||
store.Set(operatorstypes.ParamsKey, u.cdc.MustMarshal(&operatorsParams)) | ||
|
||
// Set the pools params | ||
store = sdkCtx.KVStore(u.keys[poolstypes.ModuleName]) | ||
poolsParams := poolstypes.DefaultParams() | ||
store.Set(poolstypes.ParamsKey, u.cdc.MustMarshal(&poolsParams)) | ||
|
||
// Set the restaking params | ||
store = sdkCtx.KVStore(u.keys[restakingtypes.ModuleName]) | ||
restakingParams := restakingtypes.DefaultParams() | ||
store.Set(restakingtypes.ParamsKey, u.cdc.MustMarshal(&restakingParams)) | ||
|
||
// Set the rewards params | ||
if err := u.rewardsKeeper.Params.Set(ctx, rewardstypes.DefaultParams()); err != nil { | ||
return nil, err | ||
} | ||
|
||
// Set the services params | ||
store = sdkCtx.KVStore(u.keys[servicestypes.ModuleName]) | ||
servicesParams := servicestypes.DefaultParams() | ||
store.Set(servicestypes.ParamsKey, u.cdc.MustMarshal(&servicesParams)) | ||
|
||
// Set the module versions | ||
fromVM[assetstypes.ModuleName] = 1 | ||
fromVM[operatorstypes.ModuleName] = 1 | ||
fromVM[poolstypes.ModuleName] = 1 | ||
fromVM[restakingtypes.ModuleName] = 1 | ||
fromVM[rewardstypes.ModuleName] = 1 | ||
fromVM[servicestypes.ModuleName] = 1 | ||
|
||
// This upgrade does not require any migration, so we can simply return the current version map | ||
return u.mm.RunMigrations(ctx, u.configurator, fromVM) | ||
} | ||
} | ||
|
||
// StoreUpgrades implements upgrades.Upgrade | ||
func (u *Upgrade) StoreUpgrades() *storetypes.StoreUpgrades { | ||
return &storetypes.StoreUpgrades{ | ||
Added: []string{ | ||
assetstypes.ModuleName, | ||
operatorstypes.ModuleName, | ||
poolstypes.ModuleName, | ||
restakingtypes.ModuleName, | ||
rewardstypes.ModuleName, | ||
servicestypes.ModuleName, | ||
}, | ||
Renamed: nil, | ||
Deleted: nil, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package storetesting | ||
|
||
import ( | ||
"cosmossdk.io/log" | ||
"cosmossdk.io/store" | ||
"cosmossdk.io/store/metrics" | ||
storetypes "cosmossdk.io/store/types" | ||
tmproto "github.com/cometbft/cometbft/proto/tendermint/types" | ||
dbm "github.com/cosmos/cosmos-db" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
) | ||
|
||
func BuildContext( | ||
keys map[string]*storetypes.KVStoreKey, tKeys map[string]*storetypes.TransientStoreKey, memKeys map[string]*storetypes.MemoryStoreKey, | ||
) sdk.Context { | ||
logger := log.NewNopLogger() | ||
db := dbm.NewMemDB() | ||
cms := store.NewCommitMultiStore(db, logger, metrics.NewNoOpMetrics()) | ||
for _, key := range keys { | ||
cms.MountStoreWithDB(key, storetypes.StoreTypeIAVL, db) | ||
} | ||
for _, tKey := range tKeys { | ||
cms.MountStoreWithDB(tKey, storetypes.StoreTypeTransient, db) | ||
} | ||
for _, memKey := range memKeys { | ||
cms.MountStoreWithDB(memKey, storetypes.StoreTypeMemory, nil) | ||
} | ||
|
||
err := cms.LoadLatestVersion() | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
return sdk.NewContext(cms, tmproto.Header{}, false, logger) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.