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: set upgrade handler for v0.2.1 for testnet #69

Merged
merged 1 commit into from
Mar 9, 2023
Merged
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
67 changes: 60 additions & 7 deletions app/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,17 @@ package app
import (
"encoding/json"

"github.com/Nolus-Protocol/nolus-core/app/keepers"
"github.com/Nolus-Protocol/nolus-core/app/upgrades"

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"

contractmanagermoduletypes "github.com/neutron-org/neutron/x/contractmanager/types"
"github.com/neutron-org/neutron/x/feerefunder"
feeRefunderTypes "github.com/neutron-org/neutron/x/feerefunder/types"
"github.com/neutron-org/neutron/x/interchainqueries"
interchainqueriestypes "github.com/neutron-org/neutron/x/interchainqueries/types"
"github.com/neutron-org/neutron/x/interchaintxs"
Expand All @@ -23,7 +29,7 @@ func (app *App) RegisterUpgradeHandlers() {
app.registerUpgradeV1_43(upgradeInfo)
app.registerUpgradeV1_44(upgradeInfo)
app.registerUpgradeV2_0(upgradeInfo)
app.registerUpgradeV2_1(upgradeInfo)
app.registerUpgradeV2_1_testnet(upgradeInfo)
}

// performs upgrade from v0.1.39 -> v0.1.43.
Expand Down Expand Up @@ -53,11 +59,13 @@ func (app *App) registerUpgradeV2_0(_ storetypes.UpgradeInfo) {
})
}

// performs upgrade from v0.2.0 -> v0.2.1.
func (app *App) registerUpgradeV2_1(_ storetypes.UpgradeInfo) {
const UpgradeV2_0Plan = "v0.2.1"
app.UpgradeKeeper.SetUpgradeHandler(UpgradeV2_0Plan, func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
ctx.Logger().Info("Upgrade handler execution", "name", UpgradeV2_0Plan)
func (app *App) createUpgradeHandlerTestnet(
mm *module.Manager,
configurator module.Configurator,
keepers *keepers.AppKeepers,
) upgradetypes.UpgradeHandler {
return func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
ctx.Logger().Info("Upgrade handler execution", "name", "v0.2.1")
appCodec := app.appCodec
// Register the consensus version in the version map
// to avoid the SDK from triggering the default
Expand Down Expand Up @@ -95,7 +103,52 @@ func (app *App) registerUpgradeV2_1(_ storetypes.UpgradeInfo) {
}
app.mm.Modules["interchaintxs"].InitGenesis(ctx, appCodec, interchainTxsCustomGenesisJSON)

// Register the consensus version in the version map
// to avoid the SDK from triggering the default
// InitGenesis function.
fromVM[feeRefunderTypes.ModuleName] = feerefunder.AppModule{}.ConsensusVersion()

// Make custom genesis state and run InitGenesis for interchaintxs
feeRefunderCustomGenesis := feeRefunderTypes.GenesisState{
Params: feeRefunderTypes.Params{
MinFee: feeRefunderTypes.Fee{
AckFee: sdk.Coins{
sdk.NewCoin("unls", sdk.NewInt(1)),
},
TimeoutFee: sdk.Coins{
sdk.NewCoin("unls", sdk.NewInt(1)),
},
},
},
}
feeRefunderCustomGenesisJSON, err := json.Marshal(feeRefunderCustomGenesis)
if err != nil {
return nil, err
}
app.mm.Modules[feeRefunderTypes.ModuleName].InitGenesis(ctx, appCodec, feeRefunderCustomGenesisJSON)

ctx.Logger().Info("Running migrations")
return app.mm.RunMigrations(ctx, app.configurator, fromVM)
})
}
}

func (app *App) registerUpgradeV2_1_testnet(_ storetypes.UpgradeInfo) {
testnetUpgrade := upgrades.Upgrade{
UpgradeName: "v0.2.1",
CreateUpgradeHandler: app.createUpgradeHandlerTestnet,
StoreUpgrades: storetypes.StoreUpgrades{
Added: []string{
contractmanagermoduletypes.ModuleName,
feeRefunderTypes.ModuleName,
},
},
}
app.UpgradeKeeper.SetUpgradeHandler(
testnetUpgrade.UpgradeName,
testnetUpgrade.CreateUpgradeHandler(
app.mm,
app.configurator,
&app.AppKeepers,
),
)
}