Merge pull request #1751 from cosmos/rigel/no-endblock-rat-calcs
R4R: remove rationals in endblock
This commit is contained in:
commit
a19cc0fb7e
|
@ -4,6 +4,7 @@ BREAKING CHANGES
|
|||
* [baseapp] Msgs are no longer run on CheckTx, removed `ctx.IsCheckTx()`
|
||||
* [x/gov] CLI flag changed from `proposalID` to `proposal-id`
|
||||
* [x/stake] Fixed the period check for the inflation calculation
|
||||
* [x/stake] Inflation doesn't use rationals in calculation (performance boost)
|
||||
* [baseapp] NewBaseApp constructor now takes sdk.TxDecoder as argument instead of wire.Codec
|
||||
* [x/auth] Default TxDecoder can be found in `x/auth` rather than baseapp
|
||||
* \#1606 The following CLI commands have been switched to use `--from`
|
||||
|
|
|
@ -143,8 +143,8 @@ func (app *GaiaApp) BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock) ab
|
|||
// application updates every end block
|
||||
// nolint: unparam
|
||||
func (app *GaiaApp) EndBlocker(ctx sdk.Context, req abci.RequestEndBlock) abci.ResponseEndBlock {
|
||||
validatorUpdates := stake.EndBlocker(ctx, app.stakeKeeper)
|
||||
|
||||
validatorUpdates := stake.EndBlocker(ctx, app.stakeKeeper)
|
||||
tags, _ := gov.EndBlocker(ctx, app.govKeeper)
|
||||
|
||||
return abci.ResponseEndBlock{
|
||||
|
|
|
@ -11,6 +11,7 @@ import (
|
|||
|
||||
// slashing begin block functionality
|
||||
func BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock, sk Keeper) (tags sdk.Tags) {
|
||||
|
||||
// Tag the height
|
||||
heightBytes := make([]byte, 8)
|
||||
binary.LittleEndian.PutUint64(heightBytes, uint64(req.Header.Height))
|
||||
|
|
|
@ -35,17 +35,15 @@ func NewHandler(k keeper.Keeper) sdk.Handler {
|
|||
// Called every block, process inflation, update validator set
|
||||
func EndBlocker(ctx sdk.Context, k keeper.Keeper) (ValidatorUpdates []abci.Validator) {
|
||||
pool := k.GetPool(ctx)
|
||||
params := k.GetParams(ctx)
|
||||
|
||||
// Process types.Validator Provisions
|
||||
// Process provision inflation
|
||||
blockTime := ctx.BlockHeader().Time
|
||||
if blockTime-pool.InflationLastTime >= 3600 {
|
||||
params := k.GetParams(ctx)
|
||||
pool.InflationLastTime = blockTime
|
||||
pool = pool.ProcessProvisions(params)
|
||||
}
|
||||
|
||||
// save the params
|
||||
k.SetPool(ctx, pool)
|
||||
}
|
||||
|
||||
// reset the intra-transaction counter
|
||||
k.SetIntraTxCounter(ctx, 0)
|
||||
|
|
|
@ -39,11 +39,11 @@ func TestGetInflation(t *testing.T) {
|
|||
|
||||
// test 7% minimum stop (testing with 100% bonded)
|
||||
{"test 4", sdk.OneRat(), sdk.ZeroRat(), sdk.NewRat(7, 100), sdk.ZeroRat()},
|
||||
{"test 5", sdk.OneRat(), sdk.ZeroRat(), sdk.NewRat(70001, 1000000), sdk.NewRat(-1, 1000000).Round(precision)},
|
||||
{"test 5", sdk.OneRat(), sdk.ZeroRat(), sdk.NewRat(70001, 1000000), sdk.NewRat(-1, 1000000)},
|
||||
|
||||
// test 20% maximum stop (testing with 0% bonded)
|
||||
{"test 6", sdk.ZeroRat(), sdk.ZeroRat(), sdk.NewRat(20, 100), sdk.ZeroRat()},
|
||||
{"test 7", sdk.ZeroRat(), sdk.ZeroRat(), sdk.NewRat(199999, 1000000), sdk.NewRat(1, 1000000).Round(precision)},
|
||||
{"test 7", sdk.ZeroRat(), sdk.ZeroRat(), sdk.NewRat(199999, 1000000), sdk.NewRat(1, 1000000)},
|
||||
|
||||
// perfect balance shouldn't change inflation
|
||||
{"test 8", sdk.NewRat(67), sdk.NewRat(33), sdk.NewRat(15, 100), sdk.ZeroRat()},
|
||||
|
@ -94,8 +94,9 @@ func checkFinalPoolValues(t *testing.T, pool Pool, initialTotalTokens, cumulativ
|
|||
// Processes provisions are added to the pool correctly every hour
|
||||
// Returns expected Provisions, expected Inflation, and pool, to help with cumulative calculations back in main Tests
|
||||
func updateProvisions(t *testing.T, pool Pool, params Params, hr int) (sdk.Rat, sdk.Rat, Pool) {
|
||||
|
||||
expInflation := pool.NextInflation(params)
|
||||
expProvisions := expInflation.Mul(pool.TokenSupply()).Quo(hrsPerYrRat)
|
||||
expProvisions := expInflation.Mul(pool.TokenSupply().Round(precision)).Quo(hrsPerYrRat)
|
||||
startTotalSupply := pool.TokenSupply()
|
||||
pool = pool.ProcessProvisions(params)
|
||||
|
||||
|
|
|
@ -80,13 +80,15 @@ func (p Pool) bondedTokensToLoose(bondedTokens sdk.Rat) Pool {
|
|||
//_______________________________________________________________________
|
||||
// Inflation
|
||||
|
||||
const precision = 100000000000 // increased to this precision for accuracy
|
||||
const precision = 10000 // increased to this precision for accuracy
|
||||
var hrsPerYrRat = sdk.NewRat(8766) // as defined by a julian year of 365.25 days
|
||||
|
||||
// process provisions for an hour period
|
||||
func (p Pool) ProcessProvisions(params Params) Pool {
|
||||
p.Inflation = p.NextInflation(params)
|
||||
provisions := p.Inflation.Mul(p.TokenSupply()).Quo(hrsPerYrRat)
|
||||
provisions := p.Inflation.
|
||||
Mul(p.TokenSupply().Round(precision)).
|
||||
Quo(hrsPerYrRat)
|
||||
|
||||
// TODO add to the fees provisions
|
||||
p.LooseTokens = p.LooseTokens.Add(provisions)
|
||||
|
@ -103,7 +105,10 @@ func (p Pool) NextInflation(params Params) (inflation sdk.Rat) {
|
|||
// 7% and 20%.
|
||||
|
||||
// (1 - bondedRatio/GoalBonded) * InflationRateChange
|
||||
inflationRateChangePerYear := sdk.OneRat().Sub(p.BondedRatio().Quo(params.GoalBonded)).Mul(params.InflationRateChange)
|
||||
inflationRateChangePerYear := sdk.OneRat().
|
||||
Sub(p.BondedRatio().Round(precision).
|
||||
Quo(params.GoalBonded)).
|
||||
Mul(params.InflationRateChange)
|
||||
inflationRateChange := inflationRateChangePerYear.Quo(hrsPerYrRat)
|
||||
|
||||
// increase the new annual inflation for this next cycle
|
||||
|
|
Loading…
Reference in New Issue