Skip to content

Commit

Permalink
Add rough outline for v47 upgrade handler + hide paramsKeeper.Subspace
Browse files Browse the repository at this point in the history
  • Loading branch information
Reecepbcups committed May 11, 2023
1 parent 64f29cd commit 1c3bac7
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 16 deletions.
37 changes: 21 additions & 16 deletions app/keepers/keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,10 @@ func NewAppKeepers(
tkeys[paramstypes.TStoreKey],
)

govModAddress := authtypes.NewModuleAddress(govtypes.ModuleName).String()

// set the BaseApp's parameter store
appKeepers.ConsensusParamsKeeper = consensusparamkeeper.NewKeeper(appCodec, keys[consensusparamtypes.StoreKey], authtypes.NewModuleAddress(govtypes.ModuleName).String())
appKeepers.ConsensusParamsKeeper = consensusparamkeeper.NewKeeper(appCodec, keys[consensusparamtypes.StoreKey], govModAddress)
bApp.SetParamStore(&appKeepers.ConsensusParamsKeeper)

// add capability keeper and ScopeToModule for ibc module
Expand All @@ -218,23 +220,23 @@ func NewAppKeepers(
authtypes.ProtoBaseAccount,
maccPerms,
Bech32Prefix,
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
govModAddress,
)

appKeepers.BankKeeper = bankkeeper.NewBaseKeeper(
appCodec,
keys[banktypes.StoreKey],
appKeepers.AccountKeeper,
BlockedAddresses(),
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
govModAddress,
)

stakingKeeper := stakingkeeper.NewKeeper(
appCodec,
appKeepers.keys[stakingtypes.StoreKey],
appKeepers.AccountKeeper,
appKeepers.BankKeeper,
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
govModAddress,
)
appKeepers.MintKeeper = mintkeeper.NewKeeper(
appCodec,
Expand All @@ -252,14 +254,14 @@ func NewAppKeepers(
appKeepers.BankKeeper,
stakingKeeper,
authtypes.FeeCollectorName,
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
govModAddress,
)
appKeepers.SlashingKeeper = slashingkeeper.NewKeeper(
appCodec,
cdc,
appKeepers.keys[slashingtypes.StoreKey],
stakingKeeper,
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
govModAddress,
)

invCheckPeriod := cast.ToUint(appOpts.Get(server.FlagInvCheckPeriod))
Expand All @@ -269,7 +271,7 @@ func NewAppKeepers(
invCheckPeriod,
appKeepers.BankKeeper,
authtypes.FeeCollectorName,
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
govModAddress,
)

skipUpgradeHeights := map[int64]bool{}
Expand All @@ -284,7 +286,7 @@ func NewAppKeepers(
appCodec,
homePath,
bApp,
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
govModAddress,
)

// register the staking hooks
Expand Down Expand Up @@ -335,7 +337,7 @@ func NewAppKeepers(
appKeepers.StakingKeeper,
bApp.MsgServiceRouter(),
govtypes.DefaultConfig(),
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
govModAddress,
)
appKeepers.GovKeeper = *govKeeper.SetHooks(
govtypes.NewMultiGovHooks(
Expand Down Expand Up @@ -509,7 +511,7 @@ func NewAppKeepers(
wasmDir,
wasmConfig,
wasmCapabilities,
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
govModAddress,
wasmOpts...,
)

Expand Down Expand Up @@ -584,14 +586,17 @@ func NewAppKeepers(
func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino, key, tkey storetypes.StoreKey) paramskeeper.Keeper {
paramsKeeper := paramskeeper.NewKeeper(appCodec, legacyAmino, key, tkey)

paramsKeeper.Subspace(authtypes.ModuleName)
paramsKeeper.Subspace(banktypes.ModuleName)
// https://github.com/cosmos/ibc-go/issues/2010
// can remove all since v47 moves all params to each module
// paramsKeeper.Subspace(authtypes.ModuleName)
// paramsKeeper.Subspace(banktypes.ModuleName)
// paramsKeeper.Subspace(distrtypes.ModuleName)
// paramsKeeper.Subspace(slashingtypes.ModuleName)
// paramsKeeper.Subspace(govtypes.ModuleName)
// paramsKeeper.Subspace(crisistypes.ModuleName)

paramsKeeper.Subspace(stakingtypes.ModuleName).WithKeyTable(stakingtypes.ParamKeyTable()) // Used for GlobalFee
paramsKeeper.Subspace(minttypes.ModuleName)
paramsKeeper.Subspace(distrtypes.ModuleName)
paramsKeeper.Subspace(slashingtypes.ModuleName)
paramsKeeper.Subspace(govtypes.ModuleName)
paramsKeeper.Subspace(crisistypes.ModuleName)

// custom
paramsKeeper.Subspace(ibctransfertypes.ModuleName)
Expand Down
3 changes: 3 additions & 0 deletions app/upgrades/v15/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ var Upgrade = upgrades.Upgrade{
CreateUpgradeHandler: CreateV15UpgradeHandler,
StoreUpgrades: store.StoreUpgrades{
Added: []string{
// new module
icqtypes.ModuleName,

// v47 module upgrades
crisistypes.ModuleName,
consensustypes.ModuleName,
},
Expand Down
59 changes: 59 additions & 0 deletions app/upgrades/v15/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"

"github.com/CosmosContracts/juno/v15/app/keepers"
"github.com/cosmos/cosmos-sdk/baseapp"

"github.com/CosmosContracts/juno/v15/app/upgrades"
sdk "github.com/cosmos/cosmos-sdk/types"
Expand All @@ -13,6 +14,18 @@ import (
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"

icqtypes "github.com/strangelove-ventures/async-icq/v7/types"

// SDK v47 modules
// minttypes "github.com/cosmos/cosmos-sdk/x/mint/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
crisistypes "github.com/cosmos/cosmos-sdk/x/crisis/types"
distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
govv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1"
paramstypes "github.com/cosmos/cosmos-sdk/x/params/types"
slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
)

// We now charge 2 million gas * gas price to create a denom.
Expand All @@ -26,9 +39,49 @@ func CreateV15UpgradeHandler(
return func(ctx sdk.Context, _ upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) {
logger := ctx.Logger().With("upgrade", UpgradeName)

// TODO: Add postHandler (like antehandler but runs after runMsgs)

nativeDenom := upgrades.GetChainsDenomToken(ctx.ChainID())
logger.Info(fmt.Sprintf("With native denom %s", nativeDenom))

// TODO: Our mint module needs to be migrated to v47 for minttypes.ModuleName
// https://github.com/cosmos/cosmos-sdk/pull/12363/files
// Set param key table for params module migration
for _, subspace := range keepers.ParamsKeeper.GetSubspaces() {
subspace := subspace

var keyTable paramstypes.KeyTable
switch subspace.Name() {
case authtypes.ModuleName:
keyTable = authtypes.ParamKeyTable() //nolint:staticcheck
case banktypes.ModuleName:
keyTable = banktypes.ParamKeyTable() //nolint:staticcheck
case stakingtypes.ModuleName:
keyTable = stakingtypes.ParamKeyTable() //nolint:staticcheck
// TODO: mint module v47?
// case minttypes.ModuleName:
// keyTable = minttypes.ParamKeyTable() //nolint:staticcheck
case distrtypes.ModuleName:
keyTable = distrtypes.ParamKeyTable() //nolint:staticcheck
case slashingtypes.ModuleName:
keyTable = slashingtypes.ParamKeyTable() //nolint:staticcheck
case govtypes.ModuleName:
keyTable = govv1.ParamKeyTable() //nolint:staticcheck
case crisistypes.ModuleName:
keyTable = crisistypes.ParamKeyTable() //nolint:staticcheck
}

if !subspace.HasKeyTable() {
subspace.WithKeyTable(keyTable)
}
}

// Migrate Tendermint consensus parameters from x/params module to a
// x/consensus module.
// The old params module is required to still be imported in your app.go in order to handle this migration.
baseAppLegacySS := keepers.ParamsKeeper.Subspace(baseapp.Paramspace).WithKeyTable(paramstypes.ConsensusParamsKeyTable())
baseapp.MigrateParams(ctx, baseAppLegacySS, &keepers.ConsensusParamsKeeper)

// Run migrations
logger.Info(fmt.Sprintf("pre migrate version map: %v", vm))
versionMap, err := mm.RunMigrations(ctx, cfg, vm)
Expand All @@ -43,6 +96,12 @@ func CreateV15UpgradeHandler(
icqParams := icqtypes.NewParams(true, nil)
keepers.ICQKeeper.SetParams(ctx, icqParams)

// update gov params to use a 20% initial deposit ratio, allowing us to remote the ante handler
// TODO: Add test for this
govParams := keepers.GovKeeper.GetParams(ctx)
govParams.MinInitialDepositRatio = sdk.NewDec(20).Quo(sdk.NewDec(100)).String()
keepers.GovKeeper.SetParams(ctx, govParams)

// x/TokenFactory
// Use denom creation gas consumtion instead of fee for contract developers
updatedTf := tokenfactorytypes.Params{
Expand Down

0 comments on commit 1c3bac7

Please sign in to comment.