Test runtime-assertable invariants every block (#2807)
* Initial pass * Minor cleanup
This commit is contained in:
parent
e04d32c8d5
commit
cf6b7ef6d8
|
@ -34,6 +34,7 @@ FEATURES
|
|||
* [app] \#2791 Support export at a specific height, with `gaiad export --height=HEIGHT`.
|
||||
* [x/gov] [#2479](https://github.com/cosmos/cosmos-sdk/issues/2479) Implemented querier
|
||||
for getting governance parameters.
|
||||
* [app] \#2663 - Runtime-assertable invariants
|
||||
* [app] \#2791 Support export at a specific height, with `gaiad export --height=HEIGHT`.
|
||||
|
||||
* SDK
|
||||
|
|
|
@ -210,6 +210,8 @@ func (app *GaiaApp) EndBlocker(ctx sdk.Context, req abci.RequestEndBlock) abci.R
|
|||
tags := gov.EndBlocker(ctx, app.govKeeper)
|
||||
validatorUpdates := stake.EndBlocker(ctx, app.stakeKeeper)
|
||||
|
||||
app.assertRuntimeInvariants()
|
||||
|
||||
return abci.ResponseEndBlock{
|
||||
ValidatorUpdates: validatorUpdates,
|
||||
Tags: tags,
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
package app
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
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"
|
||||
stakesim "github.com/cosmos/cosmos-sdk/x/stake/simulation"
|
||||
)
|
||||
|
||||
func (app *GaiaApp) runtimeInvariants() []simulation.Invariant {
|
||||
return []simulation.Invariant{
|
||||
banksim.NonnegativeBalanceInvariant(app.accountKeeper),
|
||||
distrsim.ValAccumInvariants(app.distrKeeper, app.stakeKeeper),
|
||||
stakesim.SupplyInvariants(app.bankKeeper, app.stakeKeeper,
|
||||
app.feeCollectionKeeper, app.distrKeeper, app.accountKeeper),
|
||||
stakesim.PositivePowerInvariant(app.stakeKeeper),
|
||||
}
|
||||
}
|
||||
|
||||
func (app *GaiaApp) assertRuntimeInvariants() {
|
||||
invariants := app.runtimeInvariants()
|
||||
start := time.Now()
|
||||
for _, inv := range invariants {
|
||||
if err := inv(app.BaseApp); err != nil {
|
||||
panic(fmt.Errorf("invariant broken: %s", err))
|
||||
}
|
||||
}
|
||||
end := time.Now()
|
||||
diff := end.Sub(start)
|
||||
app.BaseApp.Logger.With("module", "invariants").Info("Asserted all invariants", "duration", diff)
|
||||
}
|
Loading…
Reference in New Issue