revert: Revert "feat: staking config (#10988)" (#11446)

* Revert "feat: staking config (#10988)"

This reverts commit 5e9656f363.

* remove docs
This commit is contained in:
Marko
2022-03-24 12:26:25 +01:00
committed by GitHub
parent d7ba5d2d9c
commit 66ca3e88aa
46 changed files with 139 additions and 190 deletions
+4 -4
View File
@@ -17,22 +17,22 @@ var (
PKs = simapp.CreateTestPubKeys(500)
)
func init() {
sdk.DefaultPowerReduction = sdk.NewIntFromBigInt(new(big.Int).Exp(big.NewInt(10), big.NewInt(18), nil))
}
// createTestInput Returns a simapp with custom StakingKeeper
// to avoid messing with the hooks.
func createTestInput(t *testing.T) (*codec.LegacyAmino, *simapp.SimApp, sdk.Context) {
app := simapp.Setup(t, false)
ctx := app.BaseApp.NewContext(false, tmproto.Header{})
stakingConfig := types.DefaultConfig()
stakingConfig.PowerReduction = sdk.NewIntFromBigInt(new(big.Int).Exp(big.NewInt(10), big.NewInt(18), nil))
app.StakingKeeper = keeper.NewKeeper(
app.AppCodec(),
app.GetKey(types.StoreKey),
app.AccountKeeper,
app.BankKeeper,
app.GetSubspace(types.ModuleName),
stakingConfig,
)
return app.LegacyAmino(), app, ctx
}
-1
View File
@@ -780,7 +780,6 @@ func createValidators(t *testing.T, ctx sdk.Context, app *simapp.SimApp, powers
app.AccountKeeper,
app.BankKeeper,
app.GetSubspace(types.ModuleName),
types.DefaultConfig(),
)
val1 := teststaking.NewValidator(t, valAddrs[0], pks[0])
+1 -3
View File
@@ -26,13 +26,12 @@ type Keeper struct {
bankKeeper types.BankKeeper
hooks types.StakingHooks
paramstore paramtypes.Subspace
Config types.Config
}
// NewKeeper creates a new staking Keeper instance
func NewKeeper(
cdc codec.BinaryCodec, key storetypes.StoreKey, ak types.AccountKeeper, bk types.BankKeeper,
ps paramtypes.Subspace, cfg types.Config,
ps paramtypes.Subspace,
) Keeper {
// set KeyTable if it has not already been set
if !ps.HasKeyTable() {
@@ -55,7 +54,6 @@ func NewKeeper(
bankKeeper: bk,
paramstore: ps,
hooks: nil,
Config: cfg,
}
}
+5 -2
View File
@@ -40,8 +40,11 @@ func (k Keeper) BondDenom(ctx sdk.Context) (res string) {
}
// PowerReduction - is the amount of staking tokens required for 1 unit of consensus-engine power.
func (k Keeper) PowerReduction(_ sdk.Context) sdk.Int {
return k.Config.PowerReduction
// Currently, this returns a global variable that the app developer can tweak.
// TODO: we might turn this into an on-chain param:
// https://github.com/cosmos/cosmos-sdk/issues/8365
func (k Keeper) PowerReduction(ctx sdk.Context) sdk.Int {
return sdk.DefaultPowerReduction
}
// MinCommissionRate - Minimum validator commission rate
+2 -3
View File
@@ -2,15 +2,14 @@ package keeper
import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/staking/types"
)
// TokensToConsensusPower - convert input tokens to potential consensus-engine power
func (k Keeper) TokensToConsensusPower(ctx sdk.Context, tokens sdk.Int) int64 {
return types.TokensToConsensusPower(tokens, k.PowerReduction(ctx))
return sdk.TokensToConsensusPower(tokens, k.PowerReduction(ctx))
}
// TokensFromConsensusPower - convert input power to tokens
func (k Keeper) TokensFromConsensusPower(ctx sdk.Context, power int64) sdk.Int {
return types.TokensFromConsensusPower(power, k.PowerReduction(ctx))
return sdk.TokensFromConsensusPower(power, k.PowerReduction(ctx))
}
+3 -3
View File
@@ -5,11 +5,11 @@ import (
)
func (suite *KeeperTestSuite) TestTokensToConsensusPower() {
suite.Require().Equal(int64(0), suite.app.StakingKeeper.TokensToConsensusPower(suite.ctx, suite.app.StakingKeeper.Config.PowerReduction.Sub(sdk.NewInt(1))))
suite.Require().Equal(int64(1), suite.app.StakingKeeper.TokensToConsensusPower(suite.ctx, suite.app.StakingKeeper.Config.PowerReduction))
suite.Require().Equal(int64(0), suite.app.StakingKeeper.TokensToConsensusPower(suite.ctx, sdk.DefaultPowerReduction.Sub(sdk.NewInt(1))))
suite.Require().Equal(int64(1), suite.app.StakingKeeper.TokensToConsensusPower(suite.ctx, sdk.DefaultPowerReduction))
}
func (suite *KeeperTestSuite) TestTokensFromConsensusPower() {
suite.Require().Equal(sdk.NewInt(0), suite.app.StakingKeeper.TokensFromConsensusPower(suite.ctx, 0))
suite.Require().Equal(suite.app.StakingKeeper.Config.PowerReduction, suite.app.StakingKeeper.TokensFromConsensusPower(suite.ctx, 1))
suite.Require().Equal(sdk.DefaultPowerReduction, suite.app.StakingKeeper.TokensFromConsensusPower(suite.ctx, 1))
}