From 80dce32e3ad9fcedbc0b4dcc0eeb1e5c96c234b0 Mon Sep 17 00:00:00 2001 From: Cosmic Vagabond <121588426+cosmic-vagabond@users.noreply.github.com> Date: Wed, 22 May 2024 00:24:28 +0200 Subject: [PATCH] fix: distribution module param migration + reset module balance (#514) --- app/setup_handlers.go | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/app/setup_handlers.go b/app/setup_handlers.go index 1823e4525..ea0115eda 100644 --- a/app/setup_handlers.go +++ b/app/setup_handlers.go @@ -1,6 +1,7 @@ package app import ( + "github.com/cosmos/cosmos-sdk/baseapp" storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" m "github.com/cosmos/cosmos-sdk/types/module" @@ -8,6 +9,7 @@ import ( distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types" govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" minttypes "github.com/cosmos/cosmos-sdk/x/mint/types" + paramstypes "github.com/cosmos/cosmos-sdk/x/params/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" estakingtypes "github.com/elys-network/elys/x/estaking/types" @@ -21,11 +23,36 @@ func SetupHandlers(app *ElysApp) { } func setUpgradeHandler(app *ElysApp) { + // Set param key table for params module migration + for _, subspace := range app.ParamsKeeper.GetSubspaces() { + subspace := subspace + + app.Logger().Info("Setting up upgrade handler for " + subspace.Name()) + + var keyTable paramstypes.KeyTable + switch subspace.Name() { + case distrtypes.ModuleName: + keyTable = distrtypes.ParamKeyTable() //nolint:staticcheck + default: + continue + } + + if !subspace.HasKeyTable() { + subspace.WithKeyTable(keyTable) + } + } + + baseAppLegacySS := app.ParamsKeeper.Subspace(baseapp.Paramspace).WithKeyTable(paramstypes.ConsensusParamsKeyTable()) + app.UpgradeKeeper.SetUpgradeHandler( version.Version, func(ctx sdk.Context, plan upgradetypes.Plan, vm m.VersionMap) (m.VersionMap, error) { app.Logger().Info("Running upgrade handler for " + version.Version) + // Migrate Tendermint consensus parameters from x/params module to a + // dedicated x/consensus module. + baseapp.MigrateParams(ctx, baseAppLegacySS, &app.ConsensusParamsKeeper) + if version.Version == "v0.31.0" { app.Logger().Info("Deleting proposals with ID <= 185") store := ctx.KVStore(app.keys[govtypes.StoreKey]) @@ -92,6 +119,14 @@ func setUpgradeHandler(app *ElysApp) { app.StakingKeeper.SetValidator(ctx, validator) app.Logger().Info("reset unbonded status for validator", "operator", operator) } + + // send missing funds to distribution module account + missingFunds := sdk.NewCoins(sdk.NewCoin("uelys", sdk.NewInt(75896784878))) + // send missing funds to distribution module account + err := app.BankKeeper.SendCoinsFromModuleToAccount(ctx, distrtypes.ModuleName, sdk.MustAccAddressFromBech32("elys1dh0axa623u3xstkmysfe78l0rnypsd7y3eyhue"), missingFunds) + if err != nil { + app.Logger().Error("failed to send missing funds to distribution module account", "error", err) + } } return app.mm.RunMigrations(ctx, app.configurator, vm)