Skip to content

Commit

Permalink
Remove DefaultParamspace and simplify simapp creation. (cosmos#6564)
Browse files Browse the repository at this point in the history
* Remove DefaultParamspace and simplify simapp creation.

* Update changelog.

* Create function that inits ParamsKeeper.

* Update CHANGELOG.md

Co-authored-by: Alexander Bezobchuk <alexanderbez@users.noreply.github.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
3 people committed Jul 1, 2020
1 parent b671bff commit 6a52c5a
Show file tree
Hide file tree
Showing 11 changed files with 29 additions and 49 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ older clients.

### API Breaking Changes

* (modules) [\#6564](https://github.com/cosmos/cosmos-sdk/pull/6564) Constant `DefaultParamspace` is removed from all modules, use ModuleName instead.
* (client) [\#6525](https://github.com/cosmos/cosmos-sdk/pull/6525) Removed support for `indent` in JSON responses. Clients should consider piping to an external tool such as `jq`.
* (x/staking) [\#6451](https://github.com/cosmos/cosmos-sdk/pull/6451) `DefaultParamspace` and `ParamKeyTable` in staking module are moved from keeper to types to enforce consistency.
* [\#6409](https://github.com/cosmos/cosmos-sdk/pull/6409) Rename all IsEmpty methods to Empty across the codebase and enforce consistency.
Expand Down
50 changes: 27 additions & 23 deletions simapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,6 @@ type SimApp struct {
tkeys map[string]*sdk.TransientStoreKey
memKeys map[string]*sdk.MemoryStoreKey

// subspaces
subspaces map[string]paramstypes.Subspace

// keepers
AccountKeeper authkeeper.AccountKeeper
BankKeeper bankkeeper.Keeper
Expand Down Expand Up @@ -199,19 +196,9 @@ func NewSimApp(
keys: keys,
tkeys: tkeys,
memKeys: memKeys,
subspaces: make(map[string]paramstypes.Subspace),
}

// init params keeper and subspaces
app.ParamsKeeper = paramskeeper.NewKeeper(appCodec, keys[paramstypes.StoreKey], tkeys[paramstypes.TStoreKey])
app.subspaces[authtypes.ModuleName] = app.ParamsKeeper.Subspace(authtypes.DefaultParamspace)
app.subspaces[banktypes.ModuleName] = app.ParamsKeeper.Subspace(banktypes.DefaultParamspace)
app.subspaces[stakingtypes.ModuleName] = app.ParamsKeeper.Subspace(stakingtypes.DefaultParamspace)
app.subspaces[minttypes.ModuleName] = app.ParamsKeeper.Subspace(minttypes.DefaultParamspace)
app.subspaces[distrtypes.ModuleName] = app.ParamsKeeper.Subspace(distrtypes.DefaultParamspace)
app.subspaces[slashingtypes.ModuleName] = app.ParamsKeeper.Subspace(slashingtypes.DefaultParamspace)
app.subspaces[govtypes.ModuleName] = app.ParamsKeeper.Subspace(govtypes.DefaultParamspace).WithKeyTable(govtypes.ParamKeyTable())
app.subspaces[crisistypes.ModuleName] = app.ParamsKeeper.Subspace(crisistypes.DefaultParamspace)
app.ParamsKeeper = initParamsKeeper(appCodec, keys[paramstypes.StoreKey], tkeys[paramstypes.TStoreKey])

// set the BaseApp's parameter store
bApp.SetParamStore(app.ParamsKeeper.Subspace(baseapp.Paramspace).WithKeyTable(std.ConsensusParamsKeyTable()))
Expand All @@ -223,27 +210,27 @@ func NewSimApp(

// add keepers
app.AccountKeeper = authkeeper.NewAccountKeeper(
appCodec, keys[authtypes.StoreKey], app.subspaces[authtypes.ModuleName], authtypes.ProtoBaseAccount, maccPerms,
appCodec, keys[authtypes.StoreKey], app.GetSubspace(authtypes.ModuleName), authtypes.ProtoBaseAccount, maccPerms,
)
app.BankKeeper = bankkeeper.NewBaseKeeper(
appCodec, keys[banktypes.StoreKey], app.AccountKeeper, app.subspaces[banktypes.ModuleName], app.BlockedAddrs(),
appCodec, keys[banktypes.StoreKey], app.AccountKeeper, app.GetSubspace(banktypes.ModuleName), app.BlockedAddrs(),
)
stakingKeeper := stakingkeeper.NewKeeper(
appCodec, keys[stakingtypes.StoreKey], app.AccountKeeper, app.BankKeeper, app.subspaces[stakingtypes.ModuleName],
appCodec, keys[stakingtypes.StoreKey], app.AccountKeeper, app.BankKeeper, app.GetSubspace(stakingtypes.ModuleName),
)
app.MintKeeper = mintkeeper.NewKeeper(
appCodec, keys[minttypes.StoreKey], app.subspaces[minttypes.ModuleName], &stakingKeeper,
appCodec, keys[minttypes.StoreKey], app.GetSubspace(minttypes.ModuleName), &stakingKeeper,
app.AccountKeeper, app.BankKeeper, authtypes.FeeCollectorName,
)
app.DistrKeeper = distrkeeper.NewKeeper(
appCodec, keys[distrtypes.StoreKey], app.subspaces[distrtypes.ModuleName], app.AccountKeeper, app.BankKeeper,
appCodec, keys[distrtypes.StoreKey], app.GetSubspace(distrtypes.ModuleName), app.AccountKeeper, app.BankKeeper,
&stakingKeeper, authtypes.FeeCollectorName, app.ModuleAccountAddrs(),
)
app.SlashingKeeper = slashingkeeper.NewKeeper(
appCodec, keys[slashingtypes.StoreKey], &stakingKeeper, app.subspaces[slashingtypes.ModuleName],
appCodec, keys[slashingtypes.StoreKey], &stakingKeeper, app.GetSubspace(slashingtypes.ModuleName),
)
app.CrisisKeeper = crisiskeeper.NewKeeper(
app.subspaces[crisistypes.ModuleName], invCheckPeriod, app.BankKeeper, authtypes.FeeCollectorName,
app.GetSubspace(crisistypes.ModuleName), invCheckPeriod, app.BankKeeper, authtypes.FeeCollectorName,
)
app.UpgradeKeeper = upgradekeeper.NewKeeper(skipUpgradeHeights, keys[upgradetypes.StoreKey], appCodec, homePath)

Expand All @@ -254,7 +241,7 @@ func NewSimApp(
AddRoute(distrtypes.RouterKey, distr.NewCommunityPoolSpendProposalHandler(app.DistrKeeper)).
AddRoute(upgradetypes.RouterKey, upgrade.NewSoftwareUpgradeProposalHandler(app.UpgradeKeeper))
app.GovKeeper = govkeeper.NewKeeper(
appCodec, keys[govtypes.StoreKey], app.subspaces[govtypes.ModuleName], app.AccountKeeper, app.BankKeeper,
appCodec, keys[govtypes.StoreKey], app.GetSubspace(govtypes.ModuleName), app.AccountKeeper, app.BankKeeper,
&stakingKeeper, govRouter,
)

Expand Down Expand Up @@ -494,7 +481,8 @@ func (app *SimApp) GetMemKey(storeKey string) *sdk.MemoryStoreKey {
//
// NOTE: This is solely to be used for testing purposes.
func (app *SimApp) GetSubspace(moduleName string) paramstypes.Subspace {
return app.subspaces[moduleName]
subspace, _ := app.ParamsKeeper.GetSubspace(moduleName)
return subspace
}

// SimulationManager implements the SimulationApp interface
Expand All @@ -518,3 +506,19 @@ func GetMaccPerms() map[string][]string {
}
return dupMaccPerms
}

// initParamsKeeper init params keeper and its subspaces
func initParamsKeeper(appCodec codec.Marshaler, key, tkey sdk.StoreKey) paramskeeper.Keeper {
paramsKeeper := paramskeeper.NewKeeper(appCodec, key, tkey)

paramsKeeper.Subspace(authtypes.ModuleName)
paramsKeeper.Subspace(banktypes.ModuleName)
paramsKeeper.Subspace(stakingtypes.ModuleName)
paramsKeeper.Subspace(minttypes.ModuleName)
paramsKeeper.Subspace(distrtypes.ModuleName)
paramsKeeper.Subspace(slashingtypes.ModuleName)
paramsKeeper.Subspace(govtypes.ModuleName).WithKeyTable(govtypes.ParamKeyTable())
paramsKeeper.Subspace(crisistypes.ModuleName)

return paramsKeeper
}
3 changes: 0 additions & 3 deletions x/auth/types/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ import (
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
)

// DefaultParamspace defines the default auth module parameter subspace
const DefaultParamspace = ModuleName

// Default parameter values
const (
DefaultMaxMemoCharacters uint64 = 256
Expand Down
2 changes: 0 additions & 2 deletions x/bank/types/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import (
)

const (
// DefaultParamspace for params keeper
DefaultParamspace = ModuleName
// DefaultSendEnabled enabled
DefaultSendEnabled = true
)
Expand Down
5 changes: 0 additions & 5 deletions x/crisis/types/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@ import (
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
)

// Default parameter namespace
const (
DefaultParamspace = ModuleName
)

var (
// key for constant fee parameter
ParamStoreKeyConstantFee = []byte("ConstantFee")
Expand Down
5 changes: 0 additions & 5 deletions x/distribution/types/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@ import (
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
)

const (
// default paramspace for params keeper
DefaultParamspace = ModuleName
)

// Parameter keys
var (
ParamStoreKeyCommunityTax = []byte("communitytax")
Expand Down
2 changes: 1 addition & 1 deletion x/evidence/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ A full setup of the evidence module may look something as follows:
)
// First, create the keeper's subspace for parameters and the keeper itself.
evidenceParamspace := app.ParamsKeeper.Subspace(evidence.DefaultParamspace)
evidenceParamspace := app.ParamsKeeper.Subspace(evidence.ModuleName)
evidenceKeeper := evidence.NewKeeper(
app.cdc, keys[evidence.StoreKey], evidenceParamspace, evidence.DefaultCodespace,
)
Expand Down
3 changes: 0 additions & 3 deletions x/gov/types/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ const (

// QuerierRoute is the querier route for gov
QuerierRoute = ModuleName

// DefaultParamspace default name for parameter store
DefaultParamspace = ModuleName
)

// Keys for governance store
Expand Down
3 changes: 0 additions & 3 deletions x/mint/types/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ const (
// module name
ModuleName = "mint"

// default paramspace for params keeper
DefaultParamspace = ModuleName

// StoreKey is the default store key for mint
StoreKey = ModuleName

Expand Down
1 change: 0 additions & 1 deletion x/slashing/types/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (

// Default parameter namespace
const (
DefaultParamspace = ModuleName
DefaultSignedBlocksWindow = int64(100)
DefaultDowntimeJailDuration = 60 * 10 * time.Second
)
Expand Down
3 changes: 0 additions & 3 deletions x/staking/types/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ import (

// Staking params default values
const (
// Default parameter namespace
DefaultParamspace = ModuleName

// DefaultUnbondingTime reflects three weeks in seconds as the default
// unbonding time.
// TODO: Justify our choice of default here.
Expand Down

0 comments on commit 6a52c5a

Please sign in to comment.