Skip to content

Commit

Permalink
fix!: remove supply store key (#883)
Browse files Browse the repository at this point in the history
## Description

This PR removes the `supply` store key that was wrongfully added to the app's store keys and was causing the following error: 
```
panic: cannot delete latest saved version (XXXX)
```

### Bug description 
Previously to `v0.42.0` the Cosmos SDK used a store key named `supply` to store the current supply of the tokens within the `x/supply` module. With `v0.42.0` the `x/supply` module was merged into the `x/bank` module, but the store key was never deleted with any on-chain upgrade. 

With version `v3.1.0` and the introduction of our own `x/supply` module, we wrongfully added a store key named the same way (`supply`) to the app store keys (see [here](7481644#diff-0f1d2976054440336a576d47a44a37b80cdf6701dd9113012bce0e3c425819b7R339)). This caused the application to crash during the loading of the store, as: 

1. the latest saved version of the `supply` store was set to a very old height, and
2. the actual latest block height was a lot higher than that value.

Once this happens, usually the older versions of stores are deleted following the pruning strategy of the node. In this case though the `supply` store should have been deleted entirely, but Cosmos does not allow deleting the latest saved version of a store (unless we use an on-chain upgrade to remove the key). This is what caused the above error.

---

### 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
- [x] 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)
- [x] 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 31, 2022
1 parent 249e286 commit 4e7527d
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
type: fix
module: x/supply
pull_request: 883
description: Removed a wrongfully added supply store key
backward_compatible: false
date: 2022-05-30T13:12:13.631778031Z
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: "v3.0.0"
GENESIS_URL: "https://raw.githubusercontent.com/RiccardoM/desmos-states/master/morpheus-apollo-2-5274225.json"
UPGRADE_NAME: "v3.1.0"
GENESIS_DESMOS_VERSION: "v3.1.0"
GENESIS_URL: "https://raw.githubusercontent.com/RiccardoM/desmos-states/master/morpheus-apollo-2-5782100.json"
UPGRADE_NAME: "v3.2.0"
steps:
- name: Checkout 🛎️
uses: actions/checkout@v3
Expand Down
4 changes: 3 additions & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"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"
v320 "github.com/desmos-labs/desmos/v3/app/upgrades/v320"

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

Expand Down Expand Up @@ -353,7 +354,7 @@ func NewDesmosApp(
// Custom modules
profilestypes.StoreKey, relationshipstypes.StoreKey, subspacestypes.StoreKey,
poststypes.StoreKey,
feestypes.StoreKey, supplytypes.StoreKey,
feestypes.StoreKey,
)
tkeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey)
memKeys := sdk.NewMemoryStoreKeys(capabilitytypes.MemStoreKey)
Expand Down Expand Up @@ -974,6 +975,7 @@ func (app *DesmosApp) RegisterTendermintService(clientCtx client.Context) {
func (app *DesmosApp) registerUpgradeHandlers() {
app.registerUpgrade(v300.NewUpgrade(app.mm, app.configurator))
app.registerUpgrade(v310.NewUpgrade(app.mm, app.configurator))
app.registerUpgrade(v320.NewUpgrade(app.mm, app.configurator))
}

// registerUpgrade registers the given upgrade to be supported by the app
Expand Down
50 changes: 50 additions & 0 deletions app/upgrades/v320/upgrade.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
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"
)

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

// Upgrade represents the v3.2.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.2.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 as this update does not include anything particular
return u.mm.RunMigrations(ctx, u.configurator, fromVM)
}
}

// StoreUpgrades implements upgrades.Upgrade
func (u *Upgrade) StoreUpgrades() *storetypes.StoreUpgrades {
return &storetypes.StoreUpgrades{
Deleted: []string{
"supply", // Remove the supply store key
},
}
}
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:v3.0.0"
image: "desmoslabs/desmos-cosmovisor:v3.1.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:v3.0.0"
image: "desmoslabs/desmos-cosmovisor:v3.1.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:v3.0.0"
image: "desmoslabs/desmos-cosmovisor:v3.1.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:v3.0.0"
image: "desmoslabs/desmos-cosmovisor:v3.1.0"
command: "start --x-crisis-skip-assert-invariants"
ports:
- "26686-26687:26656-26657"
Expand Down
1 change: 0 additions & 1 deletion x/supply/types/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package types
const (
ModuleName = "supply"
RouterKey = ModuleName
StoreKey = ModuleName

QuerierRoute = ModuleName

Expand Down

0 comments on commit 4e7527d

Please sign in to comment.