Skip to content

Commit

Permalink
chore: bank subspace fix
Browse files Browse the repository at this point in the history
  • Loading branch information
deepan95dev committed Feb 27, 2024
1 parent 9748dca commit 6fe8f82
Showing 1 changed file with 4 additions and 156 deletions.
160 changes: 4 additions & 156 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import (

autocliv1 "cosmossdk.io/api/cosmos/autocli/v1"
reflectionv1 "cosmossdk.io/api/cosmos/reflection/v1"
"github.com/cheqd/cheqd-node/app/migrations"
upgradeV1 "github.com/cheqd/cheqd-node/app/upgrades/v1"
upgradeV2 "github.com/cheqd/cheqd-node/app/upgrades/v2"
posthandler "github.com/cheqd/cheqd-node/post"
did "github.com/cheqd/cheqd-node/x/did"
Expand Down Expand Up @@ -797,8 +795,8 @@ func New(

// Note: This migration is completed, we can remove these lines.
// Upgrade handler for v1
v1UpgradeHandler := app.upgradeHandlerV1(icaModule, keys[didtypes.StoreKey], keys[resourcetypes.StoreKey])
app.UpgradeKeeper.SetUpgradeHandler(upgradeV1.UpgradeName, v1UpgradeHandler)
// v1UpgradeHandler := app.upgradeHandlerV1(icaModule, keys[didtypes.StoreKey], keys[resourcetypes.StoreKey])
// app.UpgradeKeeper.SetUpgradeHandler(upgradeV1.UpgradeName, v1UpgradeHandler)

if loadLatest {
if err := app.LoadLatestVersion(); err != nil {
Expand Down Expand Up @@ -990,158 +988,6 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino
return paramsKeeper
}

func (app *App) upgradeHandlerV1(icaModule ica.AppModule, didStoreKey *storetypes.KVStoreKey, resourceStoreKey *storetypes.KVStoreKey) upgradetypes.UpgradeHandler {
return func(ctx sdk.Context, _ upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
ctx.Logger().Info("Handler for upgrade plan: " + upgradeV1.UpgradeName)

// Fix lack of version map initialization in InitChainer for new chains
if len(fromVM) == 0 {
ctx.Logger().Info("Version map is empty. Initialising to required values.")

// Set these explicitly to avoid calling InitGenesis on modules that don't need it.
// Explicitly skipping x/auth migrations.
fromVM = map[string]uint64{
"auth": 2,
"authz": 1,
"bank": 2,
"capability": 1,
"cheqd": 3,
"crisis": 1,
"distribution": 2,
"evidence": 1,
"feegrant": 1,
"genutil": 1,
"gov": 2,
"ibc": 2,
"interchainaccounts": 1,
"mint": 1,
"params": 1,
"resource": 1,
"slashing": 2,
"staking": 2,
"transfer": 1,
"upgrade": 1,
"vesting": 1,
}
}

ctx.Logger().Info("Version map is populated. Running migrations.")
ctx.Logger().Debug(fmt.Sprintf("Previous version map: %v", fromVM))

// Get current version map
newVM := app.ModuleManager.GetVersionMap()
ctx.Logger().Debug(fmt.Sprintf("Target version map: %v", newVM))

// Set cheqd/DID module to ConsensusVersion
fromVM[didtypes.ModuleName] = newVM[didtypes.ModuleName]

// Set resource module to ConsensusVersion
fromVM[resourcetypes.ModuleName] = newVM[resourcetypes.ModuleName]

// Add defaults for DID module subspace
didSubspace := app.GetSubspace(didtypes.ModuleName)
didSubspace.Set(ctx, didtypes.ParamStoreKeyFeeParams, didtypes.DefaultFeeParams())

// Add defaults for resource subspace
resourceSubspace := app.GetSubspace(resourcetypes.ModuleName)
resourceSubspace.Set(ctx, resourcetypes.ParamStoreKeyFeeParams, resourcetypes.DefaultFeeParams())

// create ICS27 Controller submodule params
controllerParams := icacontrollertypes.Params{
ControllerEnabled: true,
}

// create ICS27 Host submodule params
hostParams := icahosttypes.Params{
HostEnabled: true,
AllowMessages: []string{
authzMsgExec,
authzMsgGrant,
authzMsgRevoke,
bankMsgSend,
bankMsgMultiSend,
distrMsgSetWithdrawAddr,
distrMsgWithdrawValidatorCommission,
distrMsgFundCommunityPool,
distrMsgWithdrawDelegatorReward,
feegrantMsgGrantAllowance,
feegrantMsgRevokeAllowance,
govMsgVoteWeighted,
govMsgSubmitProposal,
govMsgDeposit,
govMsgVote,
stakingMsgEditValidator,
stakingMsgDelegate,
stakingMsgUndelegate,
stakingMsgBeginRedelegate,
stakingMsgCreateValidator,
vestingMsgCreateVestingAccount,
ibcMsgTransfer,
// cheqd namespace
didMsgCreateDidDoc,
didMsgUpdateDidDoc,
didMsgDeactivateDidDoc,
resourceMsgCreateResource,
},
}

// initialize ICS27 module
ctx.Logger().Debug("Initialise interchainaccount module...")
icaModule.InitModule(ctx, controllerParams, hostParams)

// cheqd migrations
migrationContext := migrations.NewMigrationContext(
app.appCodec,
didStoreKey,
app.GetSubspace(didtypes.ModuleName),
resourceStoreKey,
app.GetSubspace(resourcetypes.ModuleName),
&app.IBCKeeper.PortKeeper,
app.ScopedResourceKeeper,
)

ctx.Logger().Debug("Initialise cheqd DID and Resource module migrations...")
cheqdMigrator := migrations.NewMigrator(
migrationContext,
[]migrations.Migration{
// Protobufs
// migrations.MigrateDidProtobuf,
// migrations.MigrateResourceProtobuf,

// Indy style
migrations.MigrateDidIndyStyle,
migrations.MigrateResourceIndyStyle,

// UUID normalization
migrations.MigrateDidUUID,
migrations.MigrateResourceUUID,

// Did version id
migrations.MigrateDidVersionID,

// Resource checksum
migrations.MigrateResourceChecksum,

// Resource version links
migrations.MigrateResourceVersionLinks,

// Resource default alternative url
migrations.MigrateResourceDefaultAlternativeURL,
})

err := cheqdMigrator.Migrate(ctx)
if err != nil {
panic(err)
}

// Run all default migrations
ctx.Logger().Debug(fmt.Sprintf("Previous version map (for default RunMigrations): %v", fromVM))
toVM, err := app.ModuleManager.RunMigrations(ctx, app.configurator, fromVM)
ctx.Logger().Debug(fmt.Sprintf("New version map (after default RunMigrations): %v", toVM))
return toVM, err
}
}

// GetMaccPerms returns a copy of the module account permissions
//
// NOTE: This is solely to be used for testing purposes.
Expand Down Expand Up @@ -1199,6 +1045,8 @@ func (app *App) RegisterUpgradeHandlers() {
return nil, err
}
ctx.Logger().Info("Handler for upgrade plan: " + upgradeV2.UpgradeName)
bankSubspace := app.GetSubspace(banktypes.ModuleName)
bankSubspace.Set(ctx, didtypes.ParamStoreKeyFeeParams, banktypes.DefaultParams())
// Migrate Tendermint consensus parameters from x/params module to a
// dedicated x/consensus module.
baseapp.MigrateParams(ctx, baseAppLegacySS, &app.ConsensusParamsKeeper)
Expand Down

0 comments on commit 6fe8f82

Please sign in to comment.