Skip to content

Commit

Permalink
add ck
Browse files Browse the repository at this point in the history
  • Loading branch information
mmsqe committed Jun 27, 2023
1 parent 9f6994d commit 591d7cf
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 18 deletions.
2 changes: 1 addition & 1 deletion simapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ func NewSimApp(
logger,
)
app.StakingKeeper = stakingkeeper.NewKeeper(
appCodec, runtime.NewKVStoreService(keys[stakingtypes.StoreKey]), app.AccountKeeper, app.BankKeeper, authtypes.NewModuleAddress(govtypes.ModuleName).String(),
appCodec, runtime.NewKVStoreService(keys[stakingtypes.StoreKey]), app.AccountKeeper, app.BankKeeper, app.ConsensusParamsKeeper, authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)
app.MintKeeper = mintkeeper.NewKeeper(appCodec, runtime.NewKVStoreService(keys[minttypes.StoreKey]), app.StakingKeeper, app.AccountKeeper, app.BankKeeper, authtypes.FeeCollectorName, authtypes.NewModuleAddress(govtypes.ModuleName).String())

Expand Down
9 changes: 9 additions & 0 deletions x/consensus/types/expected_keepers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package types

import (
context "context"
)

type ConsensusKeeper interface {
Params(ctx context.Context, _ *QueryParamsRequest) (*QueryParamsResponse, error)
}
28 changes: 16 additions & 12 deletions x/staking/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (

"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
consensustypes "github.com/cosmos/cosmos-sdk/x/consensus/types"
"github.com/cosmos/cosmos-sdk/x/staking/types"
)

Expand All @@ -23,12 +24,13 @@ var _ types.DelegationSet = Keeper{}

// Keeper of the x/staking store
type Keeper struct {
storeService storetypes.KVStoreService
cdc codec.BinaryCodec
authKeeper types.AccountKeeper
bankKeeper types.BankKeeper
hooks types.StakingHooks
authority string
storeService storetypes.KVStoreService
cdc codec.BinaryCodec
authKeeper types.AccountKeeper
bankKeeper types.BankKeeper
hooks types.StakingHooks
consensusKeeper consensustypes.ConsensusKeeper
authority string
}

// NewKeeper creates a new staking Keeper instance
Expand All @@ -37,6 +39,7 @@ func NewKeeper(
storeService storetypes.KVStoreService,
ak types.AccountKeeper,
bk types.BankKeeper,
ck consensustypes.ConsensusKeeper,
authority string,
) *Keeper {
// ensure bonded and not bonded module accounts are set
Expand All @@ -54,12 +57,13 @@ func NewKeeper(
}

return &Keeper{
storeService: storeService,
cdc: cdc,
authKeeper: ak,
bankKeeper: bk,
hooks: nil,
authority: authority,
storeService: storeService,
cdc: cdc,
authKeeper: ak,
bankKeeper: bk,
consensusKeeper: ck,
hooks: nil,
authority: authority,
}
}

Expand Down
3 changes: 3 additions & 0 deletions x/staking/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,14 @@ func (s *KeeperTestSuite) SetupTest() {

bankKeeper := stakingtestutil.NewMockBankKeeper(ctrl)

consensusKeeper := stakingtestutil.NewMockConsensusKeeper(ctrl)

keeper := stakingkeeper.NewKeeper(
encCfg.Codec,
storeService,
accountKeeper,
bankKeeper,
consensusKeeper,
authtypes.NewModuleAddress(stakingtypes.GovModuleName).String(),
)
require.NoError(keeper.SetParams(ctx, stakingtypes.DefaultParams()))
Expand Down
7 changes: 7 additions & 0 deletions x/staking/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,13 @@ func (k msgServer) CreateValidator(ctx context.Context, msg *types.MsgCreateVali

sdkCtx := sdk.UnwrapSDKContext(ctx)
cp := sdkCtx.ConsensusParams()
if cp.Block == nil {
res, err := k.consensusKeeper.Params(ctx, nil)
if err != nil {
return nil, err
}
cp = *res.Params
}
if cp.Validator != nil {
pkType := pk.Type()
hasKeyType := false
Expand Down
13 changes: 8 additions & 5 deletions x/staking/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/cosmos/cosmos-sdk/types/module"
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
consensusparamkeeper "github.com/cosmos/cosmos-sdk/x/consensus/keeper"
"github.com/cosmos/cosmos-sdk/x/staking/client/cli"
"github.com/cosmos/cosmos-sdk/x/staking/exported"
"github.com/cosmos/cosmos-sdk/x/staking/keeper"
Expand Down Expand Up @@ -209,11 +210,12 @@ func init() {
type ModuleInputs struct {
depinject.In

Config *modulev1.Module
AccountKeeper types.AccountKeeper
BankKeeper types.BankKeeper
Cdc codec.Codec
StoreService store.KVStoreService
Config *modulev1.Module
AccountKeeper types.AccountKeeper
BankKeeper types.BankKeeper
consensusKeeper consensusparamkeeper.Keeper
Cdc codec.Codec
StoreService store.KVStoreService

// LegacySubspace is used solely for migration of x/params managed parameters
LegacySubspace exported.Subspace `optional:"true"`
Expand All @@ -239,6 +241,7 @@ func ProvideModule(in ModuleInputs) ModuleOutputs {
in.StoreService,
in.AccountKeeper,
in.BankKeeper,
in.consensusKeeper,
authority.String(),
)
m := NewAppModule(in.Cdc, k, in.AccountKeeper, in.BankKeeper, in.LegacySubspace)
Expand Down
38 changes: 38 additions & 0 deletions x/staking/testutil/expected_keepers_mocks.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 591d7cf

Please sign in to comment.