Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ecocredit module migration #805

Merged
merged 8 commits into from
Feb 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
go.sum
- uses: golangci/golangci-lint-action@master
with:
version: v1.28
version: v1.44
args: --timeout 10m
github-token: ${{ secrets.github_token }}
if: env.GIT_DIFF
6 changes: 0 additions & 6 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ import (
ibc "github.com/cosmos/ibc-go/v2/modules/core"
ibcclient "github.com/cosmos/ibc-go/v2/modules/core/02-client"
ibcclienttypes "github.com/cosmos/ibc-go/v2/modules/core/02-client/types"
ibcconnectiontypes "github.com/cosmos/ibc-go/v2/modules/core/03-connection/types"
porttypes "github.com/cosmos/ibc-go/v2/modules/core/05-port/types"
ibchost "github.com/cosmos/ibc-go/v2/modules/core/24-host"
ibckeeper "github.com/cosmos/ibc-go/v2/modules/core/keeper"
Expand Down Expand Up @@ -503,11 +502,6 @@ func NewRegenApp(logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest
// note replicate if you do not need to test core IBC or light clients.
app.ScopedIBCMockKeeper = scopedIBCMockKeeper

app.AddPatch(3126912, func(ctx sdk.Context) error {
app.IBCKeeper.ConnectionKeeper.SetParams(ctx, ibcconnectiontypes.DefaultParams())
return nil
})

return app
}

Expand Down
68 changes: 13 additions & 55 deletions app/stable_appconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,23 @@
package app

import (
"encoding/json"
"fmt"

"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/codec/types"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/cosmos/cosmos-sdk/x/auth"
"github.com/cosmos/cosmos-sdk/x/authz"
distrclient "github.com/cosmos/cosmos-sdk/x/distribution/client"
"github.com/cosmos/cosmos-sdk/x/feegrant"
"github.com/cosmos/cosmos-sdk/x/gov"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
paramsclient "github.com/cosmos/cosmos-sdk/x/params/client"
paramskeeper "github.com/cosmos/cosmos-sdk/x/params/keeper"
upgradeclient "github.com/cosmos/cosmos-sdk/x/upgrade/client"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
abci "github.com/tendermint/tendermint/abci/types"

"github.com/regen-network/regen-ledger/types/module/server"
ecocredittypes "github.com/regen-network/regen-ledger/x/ecocredit"
"github.com/regen-network/regen-ledger/x/ecocredit"
)

func setCustomModuleBasics() []module.AppModuleBasic {
Expand All @@ -49,60 +44,23 @@ func setCustomKVStoreKeys() []string {
}

func (app *RegenApp) registerUpgradeHandlers() {

// This is the upgrade plan name we used in the gov proposal.
upgradeName := "v2.0-upgrade"
app.UpgradeKeeper.SetUpgradeHandler(upgradeName, func(ctx sdk.Context, plan upgradetypes.Plan, _ module.VersionMap) (module.VersionMap, error) {
robert-zaremba marked this conversation as resolved.
Show resolved Hide resolved
// 1st-time running in-store migrations, using 1 as fromVersion to
// avoid running InitGenesis.
// Explicitly skipping x/auth migrations. It is already patched in regen-ledger v1.0.
fromVM := map[string]uint64{
"auth": auth.AppModule{}.ConsensusVersion(),
"bank": 1,
"capability": 1,
"crisis": 1,
"distribution": 1,
"evidence": 1,
"gov": 1,
"mint": 1,
"params": 1,
"slashing": 1,
"staking": 1,
"upgrade": 1,
"vesting": 1,
"ibc": 1,
"genutil": 1,
"transfer": 1,
"ecocredit": 1, // we don't run InitGenesis for ecocredit in `RunMigrations`, but manually instead.
const upgradeName = "v3.0.0"
app.UpgradeKeeper.SetUpgradeHandler(upgradeName, func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
// TODO: once integrating basepp need to register a proper ecocredit consensus version
// fromVM[ecocredit.ModuleName] = ecocreditmodule.Module{}.ConsensusVersion() - 1

ecoParams, ok := app.ParamsKeeper.GetSubspace(ecocredit.ModuleName)
if !ok {
return nil, fmt.Errorf("unable to upgrade: subspace %s not found", ecocredit.ModuleName)
}

gen := ecocredittypes.DefaultGenesisState()
gen.Params.AllowlistEnabled = true
gen.Params.CreditClassFee = sdk.NewCoins(sdk.NewCoin("uregen", ecocredittypes.DefaultCreditClassFeeTokens))

modules := make(map[string]json.RawMessage)
modules[ecocredittypes.ModuleName] = app.cdc.MustMarshalJSON(gen)
app.smm.InitGenesis(ctx, modules, []abci.ValidatorUpdate{})

return app.mm.RunMigrations(ctx, app.configurator, fromVM)
})
// set basket creation fee to 1,000 REGEN
ecoParams.Set(ctx, ecocredit.KeyBasketCreationFee, sdk.NewCoins(sdk.NewInt64Coin("uregen", 1e9)))

app.UpgradeKeeper.SetUpgradeHandler("v3.0.0", func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
return app.mm.RunMigrations(ctx, app.configurator, fromVM)
})

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

if upgradeInfo.Name == upgradeName && !app.UpgradeKeeper.IsSkipHeight(upgradeInfo.Height) {
storeUpgrades := storetypes.StoreUpgrades{
Added: []string{authz.ModuleName, feegrant.ModuleName, ecocredittypes.ModuleName},
}

// configure store loader that checks if version == upgradeHeight and applies store upgrades
app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, &storeUpgrades))
}
}

func (app *RegenApp) setCustomModuleManager() []module.AppModule {
Expand Down
9 changes: 0 additions & 9 deletions x/ecocredit/module/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,6 @@ func (a Module) RegisterInterfaces(registry types.InterfaceRegistry) {
func (a Module) RegisterServices(configurator servermodule.Configurator) {
server.RegisterServices(configurator, a.paramSpace, a.accountKeeper, a.bankKeeper, a.distributionKeeper)

err := configurator.RegisterMigration(ecocredit.ModuleName, 1,
func(ctx sdk.Context) error {
// set basket creation fee to 1,000 REGEN
a.paramSpace.Set(ctx, ecocredit.KeyBasketCreationFee, sdk.NewCoins(sdk.NewInt64Coin("uregen", 1e9)))
return nil
})
if err != nil {
panic(fmt.Sprintf("failed to migrate x/ecocredit from version 1 to 2: %v", err))
}
}

//nolint:errcheck
Expand Down