Skip to content

Commit

Permalink
Merge PR #3654: x/mint now uses total supply instead of bonded supply
Browse files Browse the repository at this point in the history
  • Loading branch information
rigelrozanski authored and cwgoes committed Feb 15, 2019
1 parent 8371095 commit c0eec30
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 10 deletions.
1 change: 1 addition & 0 deletions PENDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 2 additions & 1 deletion types/stake.go → types/staking.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 0 additions & 1 deletion x/distribution/types/expected_keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions x/gov/tally.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion x/mint/abci_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion x/mint/expected_keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
12 changes: 9 additions & 3 deletions x/staking/keeper/alias_functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion x/staking/types/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit c0eec30

Please sign in to comment.