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

WIP: Parallelize Invariants #12775

Closed
wants to merge 1 commit into from
Closed
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
33 changes: 22 additions & 11 deletions x/crisis/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"time"

"github.com/tendermint/tendermint/libs/log"
"golang.org/x/sync/errgroup"

"github.com/cosmos/cosmos-sdk/codec"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
Expand Down Expand Up @@ -77,19 +78,29 @@ func (k *Keeper) Invariants() []sdk.Invariant {
// AssertInvariants asserts all registered invariants. If any invariant fails,
// the method panics.
func (k *Keeper) AssertInvariants(ctx sdk.Context) {
logger := k.Logger(ctx)

start := time.Now()
invarRoutes := k.Routes()
n := len(invarRoutes)
var (
logger = k.Logger(ctx)
start = time.Now()

Check warning

Code scanning / CodeQL

Calling the system time

Calling the system time may be a possible source of non-determinism
invarRoutes = k.Routes()
n = len(invarRoutes)
eg errgroup.Group
)
for i, ir := range invarRoutes {
ir := ir
i := i
logger.Info("asserting crisis invariants", "inv", fmt.Sprint(i+1, "/", n), "name", ir.FullRoute())
if res, stop := ir.Invar(ctx); stop {
// TODO: Include app name as part of context to allow for this to be
// variable.
panic(fmt.Errorf("invariant broken: %s\n"+
"\tCRITICAL please submit the following transaction:\n"+
"\t\t tx crisis invariant-broken %s %s", res, ir.ModuleName, ir.Route))
eg.Go(func() (err error) {
if res, stop := ir.Invar(ctx); stop {
// TODO: Include app name as part of context to allow for this to be
// variable.
err = fmt.Errorf("invariant broken: %s\n"+
"\tCRITICAL please submit the following transaction:\n"+
"\t\t tx crisis invariant-broken %s %s", res, ir.ModuleName, ir.Route)
}
return err
})
if err := eg.Wait(); err != nil {
panic(err)
}
}
Comment on lines +102 to 105

Choose a reason for hiding this comment

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

Suggested change
if err := eg.Wait(); err != nil {
panic(err)
}
}
}
if err := eg.Wait(); err != nil {
panic(err)
}

Choose a reason for hiding this comment

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

This code needs tests.


Expand Down