Merge PR #3400: power reduction for Tendermint
* add uncompiled power functionality * fix some compile errors * Power -> TendermintPower * tests rename GetTendermintPower * test fix * working * fix delegation tests * fix slash tests * staking/keeper tests passing * docs reversion * debuggin workin * x/staking test pass * fix gov tests * fix x/slashing tests * working distribution test fixes * fix distribution tests * lint * fix lcd tests * fix gov test * lint * CLI fixes, rm stakingTypes * typos * working cli fixes * cli test fix * cli tests fixed * testnet creation modification * typo * pending * Sanitize Dec.Roundint64 (#3475) * merge fixes * @cwgoes comments * fix tests * change power reduction to 10^-6 * option to turn off minting for LCD tests
This commit is contained in:
@@ -11,7 +11,6 @@ import (
|
||||
"github.com/cosmos/cosmos-sdk/x/mock/simulation"
|
||||
"github.com/cosmos/cosmos-sdk/x/staking"
|
||||
"github.com/cosmos/cosmos-sdk/x/staking/keeper"
|
||||
stakingTypes "github.com/cosmos/cosmos-sdk/x/staking/types"
|
||||
)
|
||||
|
||||
// AllInvariants runs all invariants of the staking module.
|
||||
@@ -55,7 +54,7 @@ func SupplyInvariants(ck bank.Keeper, k staking.Keeper,
|
||||
loose := sdk.ZeroDec()
|
||||
bonded := sdk.ZeroDec()
|
||||
am.IterateAccounts(ctx, func(acc auth.Account) bool {
|
||||
loose = loose.Add(sdk.NewDecFromInt(acc.GetCoins().AmountOf(stakingTypes.DefaultBondDenom)))
|
||||
loose = loose.Add(sdk.NewDecFromInt(acc.GetCoins().AmountOf(staking.DefaultBondDenom)))
|
||||
return false
|
||||
})
|
||||
k.IterateUnbondingDelegations(ctx, func(_ int64, ubd staking.UnbondingDelegation) bool {
|
||||
@@ -67,7 +66,7 @@ func SupplyInvariants(ck bank.Keeper, k staking.Keeper,
|
||||
k.IterateValidators(ctx, func(_ int64, validator sdk.Validator) bool {
|
||||
switch validator.GetStatus() {
|
||||
case sdk.Bonded:
|
||||
bonded = bonded.Add(sdk.NewDecFromInt(validator.GetPower()))
|
||||
bonded = bonded.Add(sdk.NewDecFromInt(validator.GetBondedTokens()))
|
||||
case sdk.Unbonding, sdk.Unbonded:
|
||||
loose = loose.Add(sdk.NewDecFromInt(validator.GetTokens()))
|
||||
}
|
||||
@@ -77,13 +76,13 @@ func SupplyInvariants(ck bank.Keeper, k staking.Keeper,
|
||||
feePool := d.GetFeePool(ctx)
|
||||
|
||||
// add outstanding fees
|
||||
loose = loose.Add(sdk.NewDecFromInt(f.GetCollectedFees(ctx).AmountOf(stakingTypes.DefaultBondDenom)))
|
||||
loose = loose.Add(sdk.NewDecFromInt(f.GetCollectedFees(ctx).AmountOf(staking.DefaultBondDenom)))
|
||||
|
||||
// add community pool
|
||||
loose = loose.Add(feePool.CommunityPool.AmountOf(stakingTypes.DefaultBondDenom))
|
||||
loose = loose.Add(feePool.CommunityPool.AmountOf(staking.DefaultBondDenom))
|
||||
|
||||
// add yet-to-be-withdrawn
|
||||
loose = loose.Add(d.GetOutstandingRewards(ctx).AmountOf(stakingTypes.DefaultBondDenom))
|
||||
loose = loose.Add(d.GetOutstandingRewards(ctx).AmountOf(staking.DefaultBondDenom))
|
||||
|
||||
// Not-bonded tokens should equal coin supply plus unbonding delegations
|
||||
// plus tokens on unbonded validators
|
||||
@@ -119,7 +118,8 @@ func NonNegativePowerInvariant(k staking.Keeper) simulation.Invariant {
|
||||
|
||||
if !bytes.Equal(iterator.Key(), powerKey) {
|
||||
return fmt.Errorf("power store invariance:\n\tvalidator.Power: %v"+
|
||||
"\n\tkey should be: %v\n\tkey in store: %v", validator.GetPower(), powerKey, iterator.Key())
|
||||
"\n\tkey should be: %v\n\tkey in store: %v",
|
||||
validator.GetTendermintPower(), powerKey, iterator.Key())
|
||||
}
|
||||
|
||||
if validator.Tokens.IsNegative() {
|
||||
|
||||
Reference in New Issue
Block a user