Skip to content

Commit 90d6745

Browse files
feat: migrate x/staking to app wiring (#12102)
## Description Migrate x/staking to the new app wiring (dependency injection). Tracking progress at #12036 --- ### Author Checklist *All items are required. Please add a note to the item if the item is not applicable and please add links to any relevant follow up issues.* I have... - [ ] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] added `!` to the type prefix if API or client breaking change - [ ] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/main/CONTRIBUTING.md#pr-targeting)) - [ ] provided a link to the relevant issue or specification - [ ] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/main/docs/building-modules) - [ ] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/main/CONTRIBUTING.md#testing) - [ ] added a changelog entry to `CHANGELOG.md` - [ ] included comments for [documenting Go code](https://blog.golang.org/godoc) - [ ] updated the relevant documentation or specification - [ ] reviewed "Files changed" and left comments if necessary - [ ] confirmed all CI checks have passed ### Reviewers Checklist *All items are required. Please add a note if the item is not applicable and please add your handle next to the items reviewed if you only reviewed selected items.* I have... - [x] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] confirmed `!` in the type prefix if API or client breaking change - [ ] confirmed all author checklist items have been addressed - [ ] reviewed state machine logic - [ ] reviewed API design and naming - [ ] reviewed documentation is accurate - [ ] reviewed tests and test coverage - [ ] manually tested (if applicable)
1 parent fe5c22e commit 90d6745

File tree

23 files changed

+640
-91
lines changed

23 files changed

+640
-91
lines changed

api/cosmos/staking/module/v1/module.pulsar.go

Lines changed: 503 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
syntax = "proto3";
2+
3+
package cosmos.staking.module.v1;
4+
5+
import "cosmos/app/v1alpha1/module.proto";
6+
7+
// Module is the config object of the staking module.
8+
message Module {
9+
option (cosmos.app.v1alpha1.module) = {
10+
go_import: "github.com/cosmos/cosmos-sdk/x/staking"
11+
};
12+
}

simapp/app.go

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ type SimApp struct {
170170
AccountKeeper authkeeper.AccountKeeper
171171
BankKeeper bankkeeper.Keeper
172172
CapabilityKeeper *capabilitykeeper.Keeper
173-
StakingKeeper stakingkeeper.Keeper
173+
StakingKeeper *stakingkeeper.Keeper
174174
SlashingKeeper slashingkeeper.Keeper
175175
MintKeeper mintkeeper.Keeper
176176
DistrKeeper distrkeeper.Keeper
@@ -224,6 +224,7 @@ func NewSimApp(
224224
&app.AccountKeeper,
225225
&app.BankKeeper,
226226
&app.FeeGrantKeeper,
227+
&app.StakingKeeper,
227228
)
228229
if err != nil {
229230
panic(err)
@@ -232,7 +233,7 @@ func NewSimApp(
232233
app.App = appBuilder.Build(logger, db, traceStore, baseAppOptions...)
233234

234235
app.keys = sdk.NewKVStoreKeys(
235-
stakingtypes.StoreKey, minttypes.StoreKey, distrtypes.StoreKey,
236+
minttypes.StoreKey, distrtypes.StoreKey,
236237
slashingtypes.StoreKey, govtypes.StoreKey, upgradetypes.StoreKey,
237238
evidencetypes.StoreKey, authzkeeper.StoreKey, nftkeeper.StoreKey,
238239
group.StoreKey,
@@ -249,28 +250,22 @@ func NewSimApp(
249250

250251
initParamsKeeper(app.ParamsKeeper)
251252

252-
// add keepers
253-
stakingKeeper := stakingkeeper.NewKeeper(
254-
app.appCodec, app.keys[stakingtypes.StoreKey], app.AccountKeeper, app.BankKeeper, app.GetSubspace(stakingtypes.ModuleName),
255-
)
256253
app.MintKeeper = mintkeeper.NewKeeper(
257-
app.appCodec, app.keys[minttypes.StoreKey], app.GetSubspace(minttypes.ModuleName), &stakingKeeper,
254+
app.appCodec, app.keys[minttypes.StoreKey], app.GetSubspace(minttypes.ModuleName), app.StakingKeeper,
258255
app.AccountKeeper, app.BankKeeper, authtypes.FeeCollectorName,
259256
)
260257
app.DistrKeeper = distrkeeper.NewKeeper(
261258
app.appCodec, app.keys[distrtypes.StoreKey], app.GetSubspace(distrtypes.ModuleName), app.AccountKeeper, app.BankKeeper,
262-
&stakingKeeper, authtypes.FeeCollectorName,
259+
app.StakingKeeper, authtypes.FeeCollectorName,
263260
)
264261
app.SlashingKeeper = slashingkeeper.NewKeeper(
265-
app.appCodec, app.keys[slashingtypes.StoreKey], &stakingKeeper, app.GetSubspace(slashingtypes.ModuleName),
262+
app.appCodec, app.keys[slashingtypes.StoreKey], app.StakingKeeper, app.GetSubspace(slashingtypes.ModuleName),
266263
)
267264
app.CrisisKeeper = crisiskeeper.NewKeeper(
268265
app.GetSubspace(crisistypes.ModuleName), invCheckPeriod, app.BankKeeper, authtypes.FeeCollectorName,
269266
)
270267

271-
// register the staking hooks
272-
// NOTE: stakingKeeper above is passed by reference, so that it will contain these hooks
273-
app.StakingKeeper = *stakingKeeper.SetHooks(
268+
app.StakingKeeper.SetHooks(
274269
stakingtypes.NewMultiStakingHooks(app.DistrKeeper.Hooks(), app.SlashingKeeper.Hooks()),
275270
)
276271

@@ -296,7 +291,7 @@ func NewSimApp(
296291
*/
297292
govKeeper := govkeeper.NewKeeper(
298293
app.appCodec, app.keys[govtypes.StoreKey], app.GetSubspace(govtypes.ModuleName), app.AccountKeeper, app.BankKeeper,
299-
&stakingKeeper, govRouter, app.MsgServiceRouter(), govConfig,
294+
app.StakingKeeper, govRouter, app.MsgServiceRouter(), govConfig,
300295
)
301296

302297
app.GovKeeper = *govKeeper.SetHooks(
@@ -311,7 +306,7 @@ func NewSimApp(
311306

312307
// create evidence keeper with router
313308
evidenceKeeper := evidencekeeper.NewKeeper(
314-
app.appCodec, app.keys[evidencetypes.StoreKey], &app.StakingKeeper, app.SlashingKeeper,
309+
app.appCodec, app.keys[evidencetypes.StoreKey], app.StakingKeeper, app.SlashingKeeper,
315310
)
316311
// If evidence needs to be handled for the app, set routes in router here and seal
317312
app.EvidenceKeeper = *evidenceKeeper
@@ -335,7 +330,6 @@ func NewSimApp(
335330
mint.NewAppModule(app.appCodec, app.MintKeeper, app.AccountKeeper, nil),
336331
slashing.NewAppModule(app.appCodec, app.SlashingKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper),
337332
distr.NewAppModule(app.appCodec, app.DistrKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper),
338-
staking.NewAppModule(app.appCodec, app.StakingKeeper, app.AccountKeeper, app.BankKeeper),
339333
upgrade.NewAppModule(app.UpgradeKeeper),
340334
evidence.NewAppModule(app.EvidenceKeeper),
341335
authzmodule.NewAppModule(app.appCodec, app.AuthzKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry),
@@ -582,7 +576,6 @@ func GetMaccPerms() map[string][]string {
582576

583577
// initParamsKeeper init params keeper and its subspaces
584578
func initParamsKeeper(paramsKeeper paramskeeper.Keeper) {
585-
paramsKeeper.Subspace(stakingtypes.ModuleName)
586579
paramsKeeper.Subspace(minttypes.ModuleName)
587580
paramsKeeper.Subspace(distrtypes.ModuleName)
588581
paramsKeeper.Subspace(slashingtypes.ModuleName)

simapp/app.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,7 @@ modules:
5959
config:
6060
"@type": cosmos.capability.module.v1.Module
6161
seal_keeper: true
62+
63+
- name: staking
64+
config:
65+
"@type": cosmos.staking.module.v1.Module

simapp/export.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ func (app *SimApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs []
163163

164164
// Iterate through validators by power descending, reset bond heights, and
165165
// update bond intra-tx counters.
166-
store := ctx.KVStore(app.keys[stakingtypes.StoreKey])
166+
store := ctx.KVStore(app.GetKey(stakingtypes.StoreKey))
167167
iter := sdk.KVStoreReversePrefixIterator(store, stakingtypes.ValidatorsKey)
168168
counter := int16(0)
169169

x/bank/module.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,8 @@ type bankInputs struct {
231231
type bankOutputs struct {
232232
depinject.Out
233233

234-
Keeper keeper.Keeper `key:"cosmos.bank.v1.Keeper"`
235-
Module runtime.AppModuleWrapper
234+
BankKeeper keeper.Keeper `key:"cosmos.bank.v1.Keeper"`
235+
Module runtime.AppModuleWrapper
236236
}
237237

238238
func provideModule(in bankInputs) bankOutputs {
@@ -254,5 +254,5 @@ func provideModule(in bankInputs) bankOutputs {
254254

255255
bankKeeper := keeper.NewBaseKeeper(in.Cdc, in.Key, in.AccountKeeper, in.Subspace, blockedAddresses)
256256
m := NewAppModule(in.Cdc, bankKeeper, in.AccountKeeper)
257-
return bankOutputs{Keeper: bankKeeper, Module: runtime.WrapAppModule(m)}
257+
return bankOutputs{BankKeeper: bankKeeper, Module: runtime.WrapAppModule(m)}
258258
}

x/distribution/module.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,13 @@ type AppModule struct {
8989
keeper keeper.Keeper
9090
accountKeeper types.AccountKeeper
9191
bankKeeper types.BankKeeper
92-
stakingKeeper stakingkeeper.Keeper
92+
stakingKeeper *stakingkeeper.Keeper
9393
}
9494

9595
// NewAppModule creates a new AppModule object
9696
func NewAppModule(
9797
cdc codec.Codec, keeper keeper.Keeper, accountKeeper types.AccountKeeper,
98-
bankKeeper types.BankKeeper, stakingKeeper stakingkeeper.Keeper,
98+
bankKeeper types.BankKeeper, stakingKeeper *stakingkeeper.Keeper,
9999
) AppModule {
100100
return AppModule{
101101
AppModuleBasic: AppModuleBasic{cdc: cdc},

x/distribution/simulation/operations.go

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,7 @@ const (
2424
)
2525

2626
// WeightedOperations returns all the operations from the module with their respective weights
27-
func WeightedOperations(
28-
appParams simtypes.AppParams, cdc codec.JSONCodec, ak types.AccountKeeper,
29-
bk types.BankKeeper, k keeper.Keeper, sk stakingkeeper.Keeper,
30-
) simulation.WeightedOperations {
27+
func WeightedOperations(appParams simtypes.AppParams, cdc codec.JSONCodec, ak types.AccountKeeper, bk types.BankKeeper, k keeper.Keeper, sk *stakingkeeper.Keeper) simulation.WeightedOperations {
3128
var weightMsgSetWithdrawAddress int
3229
appParams.GetOrGenerate(cdc, OpWeightMsgSetWithdrawAddress, &weightMsgSetWithdrawAddress, nil,
3330
func(_ *rand.Rand) {
@@ -113,7 +110,7 @@ func SimulateMsgSetWithdrawAddress(ak types.AccountKeeper, bk types.BankKeeper,
113110
}
114111

115112
// SimulateMsgWithdrawDelegatorReward generates a MsgWithdrawDelegatorReward with random values.
116-
func SimulateMsgWithdrawDelegatorReward(ak types.AccountKeeper, bk types.BankKeeper, k keeper.Keeper, sk stakingkeeper.Keeper) simtypes.Operation {
113+
func SimulateMsgWithdrawDelegatorReward(ak types.AccountKeeper, bk types.BankKeeper, k keeper.Keeper, sk *stakingkeeper.Keeper) simtypes.Operation {
117114
return func(
118115
r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string,
119116
) (simtypes.OperationMsg, []simtypes.FutureOperation, error) {
@@ -155,7 +152,7 @@ func SimulateMsgWithdrawDelegatorReward(ak types.AccountKeeper, bk types.BankKee
155152
}
156153

157154
// SimulateMsgWithdrawValidatorCommission generates a MsgWithdrawValidatorCommission with random values.
158-
func SimulateMsgWithdrawValidatorCommission(ak types.AccountKeeper, bk types.BankKeeper, k keeper.Keeper, sk stakingkeeper.Keeper) simtypes.Operation {
155+
func SimulateMsgWithdrawValidatorCommission(ak types.AccountKeeper, bk types.BankKeeper, k keeper.Keeper, sk *stakingkeeper.Keeper) simtypes.Operation {
159156
return func(
160157
r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string,
161158
) (simtypes.OperationMsg, []simtypes.FutureOperation, error) {
@@ -200,7 +197,7 @@ func SimulateMsgWithdrawValidatorCommission(ak types.AccountKeeper, bk types.Ban
200197

201198
// SimulateMsgFundCommunityPool simulates MsgFundCommunityPool execution where
202199
// a random account sends a random amount of its funds to the community pool.
203-
func SimulateMsgFundCommunityPool(ak types.AccountKeeper, bk types.BankKeeper, k keeper.Keeper, sk stakingkeeper.Keeper) simtypes.Operation {
200+
func SimulateMsgFundCommunityPool(ak types.AccountKeeper, bk types.BankKeeper, k keeper.Keeper, sk *stakingkeeper.Keeper) simtypes.Operation {
204201
return func(
205202
r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string,
206203
) (simtypes.OperationMsg, []simtypes.FutureOperation, error) {

x/slashing/module.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,11 @@ type AppModule struct {
9191
keeper keeper.Keeper
9292
accountKeeper types.AccountKeeper
9393
bankKeeper types.BankKeeper
94-
stakingKeeper stakingkeeper.Keeper
94+
stakingKeeper *stakingkeeper.Keeper
9595
}
9696

9797
// NewAppModule creates a new AppModule object
98-
func NewAppModule(cdc codec.Codec, keeper keeper.Keeper, ak types.AccountKeeper, bk types.BankKeeper, sk stakingkeeper.Keeper) AppModule {
98+
func NewAppModule(cdc codec.Codec, keeper keeper.Keeper, ak types.AccountKeeper, bk types.BankKeeper, sk *stakingkeeper.Keeper) AppModule {
9999
return AppModule{
100100
AppModuleBasic: AppModuleBasic{cdc: cdc},
101101
keeper: keeper,

x/slashing/simulation/operations.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const (
2424
// WeightedOperations returns all the operations from the module with their respective weights
2525
func WeightedOperations(
2626
appParams simtypes.AppParams, cdc codec.JSONCodec, ak types.AccountKeeper,
27-
bk types.BankKeeper, k keeper.Keeper, sk stakingkeeper.Keeper,
27+
bk types.BankKeeper, k keeper.Keeper, sk *stakingkeeper.Keeper,
2828
) simulation.WeightedOperations {
2929
var weightMsgUnjail int
3030
appParams.GetOrGenerate(cdc, OpWeightMsgUnjail, &weightMsgUnjail, nil,
@@ -42,7 +42,7 @@ func WeightedOperations(
4242
}
4343

4444
// SimulateMsgUnjail generates a MsgUnjail with random values
45-
func SimulateMsgUnjail(ak types.AccountKeeper, bk types.BankKeeper, k keeper.Keeper, sk stakingkeeper.Keeper) simtypes.Operation {
45+
func SimulateMsgUnjail(ak types.AccountKeeper, bk types.BankKeeper, k keeper.Keeper, sk *stakingkeeper.Keeper) simtypes.Operation {
4646
return func(
4747
r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context,
4848
accs []simtypes.Account, chainID string,

0 commit comments

Comments
 (0)