Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

R4R: mint use total supply instead of power #3654

Merged
merged 4 commits into from
Feb 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions PENDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

interested in the rationale behind the interface change here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Power refers to Tendermint Power which is intended to be used nearly nowhere besides for Tendermint (and slashing which needs to interface with tendermint responses) - this interface didn't make a difference pre-Tendermint Power Reduction (#3400) but now these two things are intended to mean very different values

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed with @rigelrozanski - this is much clearer, thanks

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
rigelrozanski marked this conversation as resolved.
Show resolved Hide resolved
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