diff --git a/app/app.go b/app/app.go index dd8d489c84..812de3cf09 100644 --- a/app/app.go +++ b/app/app.go @@ -219,19 +219,24 @@ func NewApp( app.BlockedAddrs(), ) - skeeper := stakingkeeper.NewKeeper( - appCodec, - app.keys[stakingtypes.StoreKey], - app.Keepers.Cosmos.Acct, - app.Keepers.Cosmos.Bank, - app.GetSubspace(stakingtypes.ModuleName), - ) + // allocation of staking keeper is scoped deliberately, + // so it's being referenced by pointer within modules that need it + { + skeeper := stakingkeeper.NewKeeper( + appCodec, + app.keys[stakingtypes.StoreKey], + app.Keepers.Cosmos.Acct, + app.Keepers.Cosmos.Bank, + app.GetSubspace(stakingtypes.ModuleName), + ) + app.Keepers.Cosmos.Staking = &skeeper + } app.Keepers.Cosmos.Mint = mintkeeper.NewKeeper( appCodec, app.keys[minttypes.StoreKey], app.GetSubspace(minttypes.ModuleName), - &skeeper, + app.Keepers.Cosmos.Staking, app.Keepers.Cosmos.Acct, app.Keepers.Cosmos.Bank, authtypes.FeeCollectorName, @@ -243,7 +248,7 @@ func NewApp( app.GetSubspace(distrtypes.ModuleName), app.Keepers.Cosmos.Acct, app.Keepers.Cosmos.Bank, - &skeeper, + app.Keepers.Cosmos.Staking, authtypes.FeeCollectorName, app.ModuleAccountAddrs(), ) @@ -251,10 +256,19 @@ func NewApp( app.Keepers.Cosmos.Slashing = slashingkeeper.NewKeeper( appCodec, app.keys[slashingtypes.StoreKey], - &skeeper, + app.Keepers.Cosmos.Staking, app.GetSubspace(slashingtypes.ModuleName), ) + // register the staking hooks + // NOTE: stakingKeeper above is passed by reference, so that it will contain these hooks + app.Keepers.Cosmos.Staking.SetHooks( + stakingtypes.NewMultiStakingHooks( + app.Keepers.Cosmos.Distr.Hooks(), + app.Keepers.Cosmos.Slashing.Hooks(), + ), + ) + app.Keepers.Cosmos.Crisis = crisiskeeper.NewKeeper( app.GetSubspace(crisistypes.ModuleName), invCheckPeriod, @@ -262,15 +276,12 @@ func NewApp( authtypes.FeeCollectorName, ) - app.Keepers.Cosmos.Upgrade = upgradekeeper.NewKeeper(skipUpgradeHeights, app.keys[upgradetypes.StoreKey], appCodec, homePath, app.BaseApp) - - // register the staking hooks - // NOTE: stakingKeeper above is passed by reference, so that it will contain these hooks - app.Keepers.Cosmos.Staking = *skeeper.SetHooks( - stakingtypes.NewMultiStakingHooks( - app.Keepers.Cosmos.Distr.Hooks(), - app.Keepers.Cosmos.Slashing.Hooks(), - ), + app.Keepers.Cosmos.Upgrade = upgradekeeper.NewKeeper( + skipUpgradeHeights, + app.keys[upgradetypes.StoreKey], + appCodec, + homePath, + app.BaseApp, ) // register IBC Keeper @@ -309,7 +320,7 @@ func NewApp( app.GetSubspace(govtypes.ModuleName), app.Keepers.Cosmos.Acct, app.Keepers.Cosmos.Bank, - &skeeper, + app.Keepers.Cosmos.Staking, govRouter, ) @@ -339,7 +350,7 @@ func NewApp( evidenceKeeper := evidencekeeper.NewKeeper( appCodec, app.keys[evidencetypes.StoreKey], - &app.Keepers.Cosmos.Staking, + app.Keepers.Cosmos.Staking, app.Keepers.Cosmos.Slashing, ) @@ -368,7 +379,7 @@ func NewApp( // mint.NewAppModule(appCodec, app.Keepers.Cosmos.Mint, app.Keepers.Cosmos.Acct, nil), slashing.NewAppModule(appCodec, app.Keepers.Cosmos.Slashing, app.Keepers.Cosmos.Acct, app.Keepers.Cosmos.Bank, app.Keepers.Cosmos.Staking), distr.NewAppModule(appCodec, app.Keepers.Cosmos.Distr, app.Keepers.Cosmos.Acct, app.Keepers.Cosmos.Bank, app.Keepers.Cosmos.Staking), - staking.NewAppModule(appCodec, app.Keepers.Cosmos.Staking, app.Keepers.Cosmos.Acct, app.Keepers.Cosmos.Bank), + staking.NewAppModule(appCodec, *app.Keepers.Cosmos.Staking, app.Keepers.Cosmos.Acct, app.Keepers.Cosmos.Bank), upgrade.NewAppModule(app.Keepers.Cosmos.Upgrade), evidence.NewAppModule(app.Keepers.Cosmos.Evidence), ibc.NewAppModule(app.Keepers.Cosmos.IBC), @@ -414,7 +425,7 @@ func NewApp( mint.NewAppModule(appCodec, app.Keepers.Cosmos.Mint, app.Keepers.Cosmos.Acct), // todo akash-network/support#4 // mint.NewAppModule(appCodec, app.Keepers.Cosmos.Mint, app.Keepers.Cosmos.Acct, nil), - staking.NewAppModule(appCodec, app.Keepers.Cosmos.Staking, app.Keepers.Cosmos.Acct, app.Keepers.Cosmos.Bank), + staking.NewAppModule(appCodec, *app.Keepers.Cosmos.Staking, app.Keepers.Cosmos.Acct, app.Keepers.Cosmos.Bank), distr.NewAppModule(appCodec, app.Keepers.Cosmos.Distr, app.Keepers.Cosmos.Acct, app.Keepers.Cosmos.Bank, app.Keepers.Cosmos.Staking), slashing.NewAppModule(appCodec, app.Keepers.Cosmos.Slashing, app.Keepers.Cosmos.Acct, app.Keepers.Cosmos.Bank, app.Keepers.Cosmos.Staking), params.NewAppModule(app.Keepers.Cosmos.Params), diff --git a/app/decorators/min_commision.go b/app/decorators/min_commision.go index 8603681f9f..9fd47dced9 100644 --- a/app/decorators/min_commision.go +++ b/app/decorators/min_commision.go @@ -36,10 +36,11 @@ func (min *MinCommissionDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simula func (min *MinCommissionDecorator) isValidMsg(ctx sdk.Context, m sdk.Msg) error { var rate sdk.Dec + var maxRate *sdk.Dec switch msg := m.(type) { case *stakingtypes.MsgCreateValidator: - + maxRate = &msg.Commission.MaxRate rate = msg.Commission.Rate case *stakingtypes.MsgEditValidator: // if commission rate is nil, it means only @@ -62,6 +63,10 @@ func (min *MinCommissionDecorator) isValidMsg(ctx sdk.Context, m sdk.Msg) error return sdkerrors.Wrap(sdkerrors.ErrUnauthorized, fmt.Sprintf("commission can't be lower than %s%%", minRate)) } + if maxRate != nil && maxRate.LT(minRate) { + return sdkerrors.Wrap(sdkerrors.ErrUnauthorized, fmt.Sprintf("commission max rate can't be lower than %s%%", minRate)) + } + return nil } diff --git a/app/export.go b/app/export.go index 807d6196bf..e86f20b398 100644 --- a/app/export.go +++ b/app/export.go @@ -44,7 +44,7 @@ func (app *AkashApp) ExportAppStateAndValidators( return servertypes.ExportedApp{}, err } - validators, err := staking.WriteValidators(ctx, app.Keepers.Cosmos.Staking) + validators, err := staking.WriteValidators(ctx, *app.Keepers.Cosmos.Staking) if err != nil { return servertypes.ExportedApp{}, err } diff --git a/app/types/app.go b/app/types/app.go index 73d19a496c..c74147118a 100644 --- a/app/types/app.go +++ b/app/types/app.go @@ -44,7 +44,7 @@ type AppKeepers struct { FeeGrant feegrantkeeper.Keeper Bank bankkeeper.Keeper Cap *capabilitykeeper.Keeper - Staking stakingkeeper.Keeper + Staking *stakingkeeper.Keeper Slashing slashingkeeper.Keeper Mint mintkeeper.Keeper Distr distrkeeper.Keeper