Skip to content

Commit

Permalink
feat: add v3.1.0 upgrade handler (#827)
Browse files Browse the repository at this point in the history
## Description

This PR adds the upgrade handler for the upcoming `v3.1.0` Desmos version.

Depends-On: #843
Depends-On: #844

---

### 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...

- [x] 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
- [x] targeted the correct branch (see [PR Targeting](https://github.com/desmos-labs/desmos/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/desmos-labs/desmos/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
- [x] 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)
  • Loading branch information
RiccardoM authored May 3, 2022
1 parent 016677d commit bb04410
Show file tree
Hide file tree
Showing 7 changed files with 155 additions and 35 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/on-chain-upgrade.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ jobs:
runs-on: ubuntu-latest
timeout-minutes: 30
env:
GENESIS_DESMOS_VERSION: "v2.3.1"
GENESIS_URL: "https://raw.githubusercontent.com/RiccardoM/desmos-states/master/morpheus-apollo-2-4500000.json"
UPGRADE_NAME: "v3.0.0"
GENESIS_DESMOS_VERSION: "v3.0.0"
GENESIS_URL: "https://raw.githubusercontent.com/RiccardoM/desmos-states/master/morpheus-apollo-2-5274225.json"
UPGRADE_NAME: "v3.1.0"
steps:
- name: Checkout 🛎️
uses: actions/checkout@v3
Expand Down
40 changes: 15 additions & 25 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ import (
"path/filepath"
"strings"

"github.com/desmos-labs/desmos/v3/app/upgrades"
v300 "github.com/desmos-labs/desmos/v3/app/upgrades/v300"
v310 "github.com/desmos-labs/desmos/v3/app/upgrades/v310"

profilesv4 "github.com/desmos-labs/desmos/v3/x/profiles/legacy/v4"

"github.com/desmos-labs/desmos/v3/x/relationships"
Expand Down Expand Up @@ -115,7 +119,6 @@ import (
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"
upgradekeeper "github.com/cosmos/cosmos-sdk/x/upgrade/keeper"

storetypes "github.com/cosmos/cosmos-sdk/store/types"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
crisistypes "github.com/cosmos/cosmos-sdk/x/crisis/types"
distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types"
Expand Down Expand Up @@ -402,7 +405,6 @@ func NewDesmosApp(

app.FeeGrantKeeper = feegrantkeeper.NewKeeper(appCodec, keys[feegrant.StoreKey], app.AccountKeeper)
app.UpgradeKeeper = upgradekeeper.NewKeeper(skipUpgradeHeights, keys[upgradetypes.StoreKey], appCodec, homePath, app.BaseApp)
app.registerUpgradeHandlers()

// register the staking hooks
// NOTE: stakingKeeper above is passed by reference, so that it will contain these hooks
Expand Down Expand Up @@ -716,6 +718,8 @@ func NewDesmosApp(
app.configurator = module.NewConfigurator(app.appCodec, app.MsgServiceRouter(), app.GRPCQueryRouter())
app.mm.RegisterServices(app.configurator)

app.registerUpgradeHandlers()

// add test gRPC service for testing gRPC queries in isolation
testdata.RegisterQueryServer(app.GRPCQueryRouter(), testdata.QueryImpl{})

Expand Down Expand Up @@ -941,38 +945,24 @@ func (app *DesmosApp) RegisterTendermintService(clientCtx client.Context) {
tmservice.RegisterTendermintService(app.BaseApp.GRPCQueryRouter(), clientCtx, app.interfaceRegistry)
}

// registerUpgradeHandlers registers all the upgrade handlers that are supported by the app
func (app *DesmosApp) registerUpgradeHandlers() {
app.UpgradeKeeper.SetUpgradeHandler("v3.0.0", func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
// Set the initial version of the x/relationships module to 1 so that we can migrate to 2
fromVM[relationshipstypes.ModuleName] = 1
app.registerUpgrade(v300.NewUpgrade(app.mm, app.configurator))
app.registerUpgrade(v310.NewUpgrade(app.mm, app.configurator))
}

// Nothing to do here for the x/subspaces module since the InitGenesis will be called
return app.mm.RunMigrations(ctx, app.configurator, fromVM)
})
// registerUpgrade registers the given upgrade to be supported by the app
func (app *DesmosApp) registerUpgrade(upgrade upgrades.Upgrade) {
app.UpgradeKeeper.SetUpgradeHandler(upgrade.Name(), upgrade.Handler())

upgradeInfo, err := app.UpgradeKeeper.ReadUpgradeInfoFromDisk()
if err != nil {
panic(err)
}

if upgradeInfo.Name == "v3.0.0" && !app.UpgradeKeeper.IsSkipHeight(upgradeInfo.Height) {
storeUpgrades := storetypes.StoreUpgrades{
Added: []string{
wasm.StoreKey,
relationshipstypes.StoreKey,
},
// The subspaces key is here because it was already registered (due to an error) inside v2.3.1
// https://github.com/desmos-labs/desmos/blob/v2.3.1/app/app.go#L270
Renamed: []storetypes.StoreRename{
{
OldKey: "subspaces",
NewKey: subspacestypes.StoreKey,
},
},
}

if upgradeInfo.Name == upgrade.Name() && !app.UpgradeKeeper.IsSkipHeight(upgradeInfo.Height) {
// Configure store loader that checks if version == upgradeHeight and applies store upgrades
app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, &storeUpgrades))
app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, upgrade.StoreUpgrades()))
}
}

Expand Down
13 changes: 13 additions & 0 deletions app/upgrades/upgrade.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package upgrades

import (
storetypes "github.com/cosmos/cosmos-sdk/store/types"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
)

// Upgrade represents a generic on-chain upgrade
type Upgrade interface {
Name() string
Handler() upgradetypes.UpgradeHandler
StoreUpgrades() *storetypes.StoreUpgrades
}
66 changes: 66 additions & 0 deletions app/upgrades/v300/upgrade.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package v300

import (
"github.com/CosmWasm/wasmd/x/wasm"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"

"github.com/desmos-labs/desmos/v3/app/upgrades"
relationshipstypes "github.com/desmos-labs/desmos/v3/x/relationships/types"
subspacestypes "github.com/desmos-labs/desmos/v3/x/subspaces/types"
)

var (
_ upgrades.Upgrade = &Upgrade{}
)

// Upgrade represents the v3.0.0 upgrade
type Upgrade struct {
mm *module.Manager
configurator module.Configurator
}

// NewUpgrade returns a new Upgrade instance
func NewUpgrade(mm *module.Manager, configurator module.Configurator) *Upgrade {
return &Upgrade{
mm: mm,
configurator: configurator,
}
}

// Name implements upgrades.Upgrade
func (u *Upgrade) Name() string {
return "v3.0.0"
}

// Handler implements upgrades.Upgrade
func (u *Upgrade) Handler() upgradetypes.UpgradeHandler {
return func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
// Set the initial version of the x/relationships module to 1 so that we can migrate to 2
fromVM[relationshipstypes.ModuleName] = 1

// Nothing to do here for the x/subspaces module since the InitGenesis will be called
return u.mm.RunMigrations(ctx, u.configurator, fromVM)
}
}

// StoreUpgrades implements upgrades.Upgrade
func (u *Upgrade) StoreUpgrades() *storetypes.StoreUpgrades {
return &storetypes.StoreUpgrades{
Added: []string{
wasm.StoreKey,
relationshipstypes.StoreKey,
},

// The subspaces key is here because it was already registered (due to an error) inside v2.3.1
// https://github.com/desmos-labs/desmos/blob/v2.3.1/app/app.go#L270
Renamed: []storetypes.StoreRename{
{
OldKey: "subspaces",
NewKey: subspacestypes.StoreKey,
},
},
}
}
51 changes: 51 additions & 0 deletions app/upgrades/v310/upgrade.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package v310

import (
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"

"github.com/desmos-labs/desmos/v3/app/upgrades"
feestypes "github.com/desmos-labs/desmos/v3/x/fees/types"
)

var (
_ upgrades.Upgrade = &Upgrade{}
)

// Upgrade represents the v3.1.0 upgrade
type Upgrade struct {
mm *module.Manager
configurator module.Configurator
}

// NewUpgrade returns a new Upgrade instance
func NewUpgrade(mm *module.Manager, configurator module.Configurator) *Upgrade {
return &Upgrade{
mm: mm,
configurator: configurator,
}
}

// Name implements upgrades.Upgrade
func (u *Upgrade) Name() string {
return "v3.1.0"
}

// Handler implements upgrades.Upgrade
func (u *Upgrade) Handler() upgradetypes.UpgradeHandler {
return func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
// Nothing to do here for the x/fees module since the InitGenesis will be called
return u.mm.RunMigrations(ctx, u.configurator, fromVM)
}
}

// StoreUpgrades implements upgrades.Upgrade
func (u *Upgrade) StoreUpgrades() *storetypes.StoreUpgrades {
return &storetypes.StoreUpgrades{
Added: []string{
feestypes.StoreKey,
},
}
}
8 changes: 4 additions & 4 deletions contrib/upgrade_testnet/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ version: '3'
services:
desmosnode0:
container_name: desmosnode0
image: "desmoslabs/desmos-cosmovisor:v2.3.1"
image: "desmoslabs/desmos-cosmovisor:v3.0.0"
command: "start --x-crisis-skip-assert-invariants"
ports:
- "26656-26657:26656-26657"
Expand All @@ -19,7 +19,7 @@ services:

desmosnode1:
container_name: desmosnode1
image: "desmoslabs/desmos-cosmovisor:v2.3.1"
image: "desmoslabs/desmos-cosmovisor:v3.0.0"
command: "start --x-crisis-skip-assert-invariants"
ports:
- "26666-26667:26656-26657"
Expand All @@ -35,7 +35,7 @@ services:

desmosnode2:
container_name: desmosnode2
image: "desmoslabs/desmos-cosmovisor:v2.3.1"
image: "desmoslabs/desmos-cosmovisor:v3.0.0"
command: "start --x-crisis-skip-assert-invariants"
ports:
- "26676-26677:26656-26657"
Expand All @@ -51,7 +51,7 @@ services:

desmosnode3:
container_name: desmosnode3
image: "desmoslabs/desmos-cosmovisor:v2.3.1"
image: "desmoslabs/desmos-cosmovisor:v3.0.0"
command: "start --x-crisis-skip-assert-invariants"
ports:
- "26686-26687:26656-26657"
Expand Down
6 changes: 3 additions & 3 deletions x/profiles/legacy/v5/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import (
// MigrateStore performs in-place store migrations from v5 to v6
// The migration includes:
//
// - add missing application links owner keys
// - remove all chain links that are not valid anymore due to the new rules
// - add missing chain links owner keys
// - add missing application links owner keys to allow reverse searches
// - add missing chain links owner keys to allow reverse searches
// - remove all chain links that are not valid anymore due to the new validation rules
//
func MigrateStore(ctx sdk.Context, storeKey sdk.StoreKey, cdc codec.BinaryCodec, legacyAmino *codec.LegacyAmino) error {
store := ctx.KVStore(storeKey)
Expand Down

0 comments on commit bb04410

Please sign in to comment.