2019-06-20 13:37:57 +00:00
|
|
|
package app
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
abci "github.com/tendermint/tendermint/abci/types"
|
|
|
|
|
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
|
|
)
|
|
|
|
|
2019-06-20 17:02:29 +00:00
|
|
|
func (app *App) assertRuntimeInvariants() {
|
2019-06-20 13:37:57 +00:00
|
|
|
ctx := app.NewContext(false, abci.Header{Height: app.LastBlockHeight() + 1})
|
|
|
|
app.assertRuntimeInvariantsOnContext(ctx)
|
|
|
|
}
|
|
|
|
|
2019-06-20 17:02:29 +00:00
|
|
|
func (app *App) assertRuntimeInvariantsOnContext(ctx sdk.Context) {
|
2019-06-20 13:37:57 +00:00
|
|
|
start := time.Now()
|
|
|
|
invarRoutes := app.crisisKeeper.Routes()
|
|
|
|
for _, ir := range invarRoutes {
|
|
|
|
if err := ir.Invar(ctx); err != nil {
|
|
|
|
panic(fmt.Errorf("invariant broken: %s\n"+
|
|
|
|
"\tCRITICAL please submit the following transaction:\n"+
|
2019-06-20 17:08:58 +00:00
|
|
|
"\t\t kvcli tx crisis invariant-broken %v %v", err, ir.ModuleName, ir.Route))
|
2019-06-20 13:37:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
end := time.Now()
|
|
|
|
diff := end.Sub(start)
|
|
|
|
app.BaseApp.Logger().With("module", "invariants").Info(
|
|
|
|
"Asserted all invariants", "duration", diff, "height", app.LastBlockHeight())
|
|
|
|
}
|