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

APP: Fix Auth module MVA in-place migration #344

Merged
merged 2 commits into from
Nov 22, 2021
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
6 changes: 3 additions & 3 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ import (

const (
// AppName specifies the global application name.
AppName = "Shentu"
AppName = "Shentu"

// DefaultKeyPass for certik node daemon.
DefaultKeyPass = "12345678"
Expand Down Expand Up @@ -551,8 +551,6 @@ func NewShentuApp(logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest
app.MountTransientStores(tkeys)
app.MountMemoryStores(memKeys)

app.SetInitChainer(app.InitChainer)
app.SetBeginBlocker(app.BeginBlocker)
// The AnteHandler handles signature verification and transaction pre-processing
anteHandler, err := ante.NewAnteHandler(
ante.HandlerOptions{
Expand All @@ -567,6 +565,8 @@ func NewShentuApp(logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest
tmos.Exit(err.Error())
}
app.SetAnteHandler(anteHandler)
app.SetInitChainer(app.InitChainer)
app.SetBeginBlocker(app.BeginBlocker)
app.SetEndBlocker(app.EndBlocker)

app.setUpgradeHandler()
Expand Down
18 changes: 14 additions & 4 deletions app/upgrade_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ package app

import (
"fmt"

storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
"github.com/cosmos/cosmos-sdk/x/authz"
sdkauthz "github.com/cosmos/cosmos-sdk/x/authz"
"github.com/cosmos/cosmos-sdk/x/feegrant"
Expand All @@ -21,16 +21,26 @@ func (app ShentuApp) setUpgradeHandler() {
upgradeName,
func(ctx sdk.Context, _ upgradetypes.Plan, _ module.VersionMap) (module.VersionMap, error) {
app.ibcKeeper.ConnectionKeeper.SetParams(ctx, ibcconnectiontypes.DefaultParams())

fromVM := make(map[string]uint64)
for moduleName := range app.mm.Modules {
fromVM[moduleName] = 1
}
// override versions for _new_ modules as to not skip InitGenesis
fromVM[sdkauthz.ModuleName] = 0
fromVM[sdkfeegrant.ModuleName] = 0

return app.mm.RunMigrations(ctx, app.configurator, fromVM)

temp, err := app.mm.RunMigrations(ctx, app.configurator, fromVM)

if err != nil {
return temp, err
}

authVM := make(map[string]uint64)
authVM[authtypes.ModuleName] = 1

_, err = app.mm.RunMigrations(ctx, app.configurator, authVM)
return temp, err
},
)

Expand Down
24 changes: 22 additions & 2 deletions x/auth/keeper/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ package keeper

import (
"github.com/gogo/protobuf/grpc"
"math"

sdk "github.com/cosmos/cosmos-sdk/types"
v043 "github.com/cosmos/cosmos-sdk/x/auth/legacy/v043"
sdktypes "github.com/cosmos/cosmos-sdk/x/auth/types"
vestingtypes "github.com/cosmos/cosmos-sdk/x/auth/vesting/types"

"github.com/certikfoundation/shentu/v2/x/auth/types"
)
Expand All @@ -26,7 +28,15 @@ func (m Migrator) Migrate1to2(ctx sdk.Context) error {
var iterErr error

m.keeper.IterateAccounts(ctx, func(account sdktypes.AccountI) (stop bool) {
wb, err := v043.MigrateAccount(ctx, account, m.queryServer)
mvacc, ok := account.(*types.ManualVestingAccount)
if !ok {
return false
}

dvAcc := vestingtypes.NewDelayedVestingAccount(
mvacc.BaseAccount, mvacc.OriginalVesting, math.MaxInt64)

wb, err := v043.MigrateAccount(ctx, dvAcc, m.queryServer)
if err != nil {
iterErr = err
return true
Expand All @@ -36,7 +46,17 @@ func (m Migrator) Migrate1to2(ctx sdk.Context) error {
return false
}

m.keeper.SetAccount(ctx, wb)
dvAcc, ok = account.(*vestingtypes.DelayedVestingAccount)
if !ok {
return false
}
unlocker, err := sdk.AccAddressFromBech32(mvacc.Unlocker)
if err != nil {
panic(err)
}
newmvacc := types.NewManualVestingAccount(dvAcc.BaseAccount, dvAcc.OriginalVesting, dvAcc.OriginalVesting, unlocker)

m.keeper.SetAccount(ctx, newmvacc)
return false
})

Expand Down