Inflation bug fixes (#2982)
* PENDING.md; swap BeginBlocker ordering * Calculate inflation every block * Update x/mint spec * Reset distribution info bond height instead
This commit is contained in:
committed by
Jack Zampolin
parent
bcfd93f544
commit
dfd00a661a
+4
-4
@@ -189,12 +189,12 @@ func MakeCodec() *codec.Codec {
|
||||
// application updates every end block
|
||||
func (app *GaiaApp) BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock) abci.ResponseBeginBlock {
|
||||
|
||||
// distribute rewards from previous block
|
||||
distr.BeginBlocker(ctx, req, app.distrKeeper)
|
||||
|
||||
// mint new tokens for this new block
|
||||
// mint new tokens for the previous block
|
||||
mint.BeginBlocker(ctx, app.mintKeeper)
|
||||
|
||||
// distribute rewards for the previous block
|
||||
distr.BeginBlocker(ctx, req, app.distrKeeper)
|
||||
|
||||
// slash anyone who double signed.
|
||||
// NOTE: This should happen after distr.BeginBlocker so that
|
||||
// there is nothing left over in the validator fee pool,
|
||||
|
||||
+17
-29
@@ -56,34 +56,13 @@ func (app *GaiaApp) ExportAppStateAndValidators(forZeroHeight bool) (
|
||||
// prepare for fresh start at zero height
|
||||
func (app *GaiaApp) prepForZeroHeightGenesis(ctx sdk.Context) {
|
||||
|
||||
/* TODO XXX check some invariants */
|
||||
|
||||
height := ctx.BlockHeight()
|
||||
|
||||
valAccum := sdk.ZeroDec()
|
||||
vdiIter := func(_ int64, vdi distr.ValidatorDistInfo) bool {
|
||||
lastValPower := app.stakeKeeper.GetLastValidatorPower(ctx, vdi.OperatorAddr)
|
||||
valAccum = valAccum.Add(vdi.GetValAccum(height, sdk.NewDecFromInt(lastValPower)))
|
||||
return false
|
||||
}
|
||||
app.distrKeeper.IterateValidatorDistInfos(ctx, vdiIter)
|
||||
|
||||
lastTotalPower := sdk.NewDecFromInt(app.stakeKeeper.GetLastTotalPower(ctx))
|
||||
totalAccum := app.distrKeeper.GetFeePool(ctx).GetTotalValAccum(height, lastTotalPower)
|
||||
|
||||
if !totalAccum.Equal(valAccum) {
|
||||
panic(fmt.Errorf("validator accum invariance: \n\tfee pool totalAccum: %v"+
|
||||
"\n\tvalidator accum \t%v\n", totalAccum.String(), valAccum.String()))
|
||||
}
|
||||
|
||||
fmt.Printf("accum invariant ok!\n")
|
||||
|
||||
/* END TODO XXX */
|
||||
/* Just to be safe, assert the invariants on current state. */
|
||||
app.assertRuntimeInvariantsOnContext(ctx)
|
||||
|
||||
/* Handle fee distribution state. */
|
||||
|
||||
// withdraw all delegator & validator rewards
|
||||
vdiIter = func(_ int64, valInfo distr.ValidatorDistInfo) (stop bool) {
|
||||
vdiIter := func(_ int64, valInfo distr.ValidatorDistInfo) (stop bool) {
|
||||
err := app.distrKeeper.WithdrawValidatorRewardsAll(ctx, valInfo.OperatorAddr)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
@@ -102,10 +81,19 @@ func (app *GaiaApp) prepForZeroHeightGenesis(ctx sdk.Context) {
|
||||
}
|
||||
app.distrKeeper.IterateDelegationDistInfos(ctx, ddiIter)
|
||||
|
||||
// delete all distribution infos
|
||||
// these will be recreated in InitGenesis
|
||||
app.distrKeeper.RemoveValidatorDistInfos(ctx)
|
||||
app.distrKeeper.RemoveDelegationDistInfos(ctx)
|
||||
app.assertRuntimeInvariantsOnContext(ctx)
|
||||
|
||||
// set distribution info withdrawal heights to 0
|
||||
app.distrKeeper.IterateDelegationDistInfos(ctx, func(_ int64, delInfo distr.DelegationDistInfo) (stop bool) {
|
||||
delInfo.DelPoolWithdrawalHeight = 0
|
||||
app.distrKeeper.SetDelegationDistInfo(ctx, delInfo)
|
||||
return false
|
||||
})
|
||||
app.distrKeeper.IterateValidatorDistInfos(ctx, func(_ int64, valInfo distr.ValidatorDistInfo) (stop bool) {
|
||||
valInfo.FeePoolWithdrawalHeight = 0
|
||||
app.distrKeeper.SetValidatorDistInfo(ctx, valInfo)
|
||||
return false
|
||||
})
|
||||
|
||||
// assert that the fee pool is empty
|
||||
feePool := app.distrKeeper.GetFeePool(ctx)
|
||||
@@ -119,7 +107,7 @@ func (app *GaiaApp) prepForZeroHeightGenesis(ctx sdk.Context) {
|
||||
}
|
||||
|
||||
// reset fee pool height, save fee pool
|
||||
feePool.TotalValAccum.UpdateHeight = 0
|
||||
feePool.TotalValAccum = distr.NewTotalAccum(0)
|
||||
app.distrKeeper.SetFeePool(ctx, feePool)
|
||||
|
||||
/* Handle stake state. */
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
banksim "github.com/cosmos/cosmos-sdk/x/bank/simulation"
|
||||
distrsim "github.com/cosmos/cosmos-sdk/x/distribution/simulation"
|
||||
"github.com/cosmos/cosmos-sdk/x/mock/simulation"
|
||||
@@ -22,9 +23,13 @@ func (app *GaiaApp) runtimeInvariants() []simulation.Invariant {
|
||||
}
|
||||
|
||||
func (app *GaiaApp) assertRuntimeInvariants() {
|
||||
invariants := app.runtimeInvariants()
|
||||
start := time.Now()
|
||||
ctx := app.NewContext(false, abci.Header{Height: app.LastBlockHeight() + 1})
|
||||
app.assertRuntimeInvariantsOnContext(ctx)
|
||||
}
|
||||
|
||||
func (app *GaiaApp) assertRuntimeInvariantsOnContext(ctx sdk.Context) {
|
||||
start := time.Now()
|
||||
invariants := app.runtimeInvariants()
|
||||
for _, inv := range invariants {
|
||||
if err := inv(ctx); err != nil {
|
||||
panic(fmt.Errorf("invariant broken: %s", err))
|
||||
|
||||
Reference in New Issue
Block a user