diff --git a/PENDING.md b/PENDING.md index e82bc08818d0..78077de88e17 100644 --- a/PENDING.md +++ b/PENDING.md @@ -63,5 +63,6 @@ BUG FIXES * Gaia * SDK + * \#3646 `x/mint` now uses total token supply instead of total bonded tokens to calculate inflation * Tendermint diff --git a/types/stake.go b/types/staking.go similarity index 97% rename from types/stake.go rename to types/staking.go index 8169307c9ef2..d9143fa4ed1b 100644 --- a/types/stake.go +++ b/types/staking.go @@ -100,7 +100,8 @@ type ValidatorSet interface { Validator(Context, ValAddress) Validator // get a particular validator by operator address ValidatorByConsAddr(Context, ConsAddress) Validator // get a particular validator by consensus address - TotalPower(Context) Int // total power of the validator set + TotalBondedTokens(Context) Int // total bonded tokens within the validator set + TotalTokens(Context) Int // total token supply // slash the validator and delegators of the validator, specifying offence height, offence power, and slash fraction Slash(Context, ConsAddress, int64, int64, Dec) diff --git a/x/distribution/types/expected_keepers.go b/x/distribution/types/expected_keepers.go index 51b992b3bb1e..eef0daa547b2 100644 --- a/x/distribution/types/expected_keepers.go +++ b/x/distribution/types/expected_keepers.go @@ -9,7 +9,6 @@ type StakingKeeper interface { Delegation(ctx sdk.Context, delAddr sdk.AccAddress, valAddr sdk.ValAddress) sdk.Delegation Validator(ctx sdk.Context, valAddr sdk.ValAddress) sdk.Validator ValidatorByConsAddr(ctx sdk.Context, consAddr sdk.ConsAddress) sdk.Validator - TotalPower(ctx sdk.Context) sdk.Int GetLastTotalPower(ctx sdk.Context) sdk.Int GetLastValidatorPower(ctx sdk.Context, valAddr sdk.ValAddress) int64 diff --git a/x/gov/tally.go b/x/gov/tally.go index cc7df2412ffa..1bf28e493fbe 100644 --- a/x/gov/tally.go +++ b/x/gov/tally.go @@ -103,11 +103,11 @@ func tally(ctx sdk.Context, keeper Keeper, proposal Proposal) (passes bool, tall // TODO: Upgrade the spec to cover all of these cases & remove pseudocode. // If there is no staked coins, the proposal fails - if keeper.vs.TotalPower(ctx).IsZero() { + if keeper.vs.TotalBondedTokens(ctx).IsZero() { return false, tallyResults } // If there is not enough quorum of votes, the proposal fails - percentVoting := totalVotingPower.Quo(sdk.NewDecFromInt(keeper.vs.TotalPower(ctx))) + percentVoting := totalVotingPower.Quo(sdk.NewDecFromInt(keeper.vs.TotalBondedTokens(ctx))) if percentVoting.LT(tallyParams.Quorum) { return false, tallyResults } diff --git a/x/mint/abci_app.go b/x/mint/abci_app.go index 1758a5c170d3..5016a464d18a 100644 --- a/x/mint/abci_app.go +++ b/x/mint/abci_app.go @@ -12,7 +12,7 @@ func BeginBlocker(ctx sdk.Context, k Keeper) { params := k.GetParams(ctx) // recalculate inflation rate - totalSupply := k.sk.TotalPower(ctx) + totalSupply := k.sk.TotalTokens(ctx) bondedRatio := k.sk.BondedRatio(ctx) minter.Inflation = minter.NextInflationRate(params, bondedRatio) minter.AnnualProvisions = minter.NextAnnualProvisions(params, totalSupply) diff --git a/x/mint/expected_keepers.go b/x/mint/expected_keepers.go index 72bc36a5f5cd..5169b0957668 100644 --- a/x/mint/expected_keepers.go +++ b/x/mint/expected_keepers.go @@ -6,7 +6,7 @@ import ( // expected staking keeper type StakingKeeper interface { - TotalPower(ctx sdk.Context) sdk.Int + TotalTokens(ctx sdk.Context) sdk.Int BondedRatio(ctx sdk.Context) sdk.Dec InflateSupply(ctx sdk.Context, newTokens sdk.Int) } diff --git a/x/staking/keeper/alias_functions.go b/x/staking/keeper/alias_functions.go index 848f66051880..aff57bda9fc5 100644 --- a/x/staking/keeper/alias_functions.go +++ b/x/staking/keeper/alias_functions.go @@ -87,13 +87,19 @@ func (k Keeper) ValidatorByConsAddr(ctx sdk.Context, addr sdk.ConsAddress) sdk.V return val } -// total power from the bond (not last, but current) -func (k Keeper) TotalPower(ctx sdk.Context) sdk.Int { +// total staking tokens supply which is bonded +func (k Keeper) TotalBondedTokens(ctx sdk.Context) sdk.Int { pool := k.GetPool(ctx) return pool.BondedTokens } -// total power from the bond +// total staking tokens supply bonded and unbonded +func (k Keeper) TotalTokens(ctx sdk.Context) sdk.Int { + pool := k.GetPool(ctx) + return pool.TokenSupply() +} + +// the fraction of the staking tokens which are currently bonded func (k Keeper) BondedRatio(ctx sdk.Context) sdk.Dec { pool := k.GetPool(ctx) return pool.BondedRatio() diff --git a/x/staking/types/validator.go b/x/staking/types/validator.go index 7d1f6fa80b7c..08c095cd49a9 100644 --- a/x/staking/types/validator.go +++ b/x/staking/types/validator.go @@ -416,7 +416,7 @@ func (v Validator) BondedTokens() sdk.Int { } // get the Tendermint Power -// a reduction of 10^9 from validator tokens is applied +// a reduction of 10^6 from validator tokens is applied func (v Validator) TendermintPower() int64 { if v.Status == sdk.Bonded { return v.PotentialTendermintPower()