Skip to content

Commit

Permalink
Merge PR #3037: Updates to negative stake fix
Browse files Browse the repository at this point in the history
* Update invariant; fix lint

* Fix linter
  • Loading branch information
cwgoes authored and rigelrozanski committed Dec 7, 2018
1 parent 19afe72 commit 2c0217f
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion cmd/gaia/app/invariants.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func (app *GaiaApp) runtimeInvariants() []simulation.Invariant {
distrsim.ValAccumInvariants(app.distrKeeper, app.stakeKeeper),
stakesim.SupplyInvariants(app.bankKeeper, app.stakeKeeper,
app.feeCollectionKeeper, app.distrKeeper, app.accountKeeper),
stakesim.PositivePowerInvariant(app.stakeKeeper),
stakesim.NonNegativePowerInvariant(app.stakeKeeper),
}
}

Expand Down
4 changes: 3 additions & 1 deletion cmd/gaia/cmd/gaiareplay/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,9 @@ func run(rootDir string) {
if err != nil {
panic(err)
}
defer proxyApp.Stop()
defer func() {
_ = proxyApp.Stop()
}()

var state tmsm.State = tmsm.LoadState(tmDB)
if state.LastBlockHeight == 0 {
Expand Down
3 changes: 1 addition & 2 deletions types/decimal.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,9 +304,8 @@ func (d Dec) String() string {
}
if isNeg {
return "-" + string(bzWDec)
} else {
return string(bzWDec)
}
return string(bzWDec)
}

// ____
Expand Down
10 changes: 7 additions & 3 deletions x/stake/simulation/invariants.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func AllInvariants(ck bank.Keeper, k stake.Keeper,
return err
}

err = PositivePowerInvariant(k)(ctx)
err = NonNegativePowerInvariant(k)(ctx)
if err != nil {
return err
}
Expand Down Expand Up @@ -111,8 +111,8 @@ func SupplyInvariants(ck bank.Keeper, k stake.Keeper,
}
}

// PositivePowerInvariant checks that all stored validators have > 0 power.
func PositivePowerInvariant(k stake.Keeper) simulation.Invariant {
// NonNegativePowerInvariant checks that all stored validators have >= 0 power.
func NonNegativePowerInvariant(k stake.Keeper) simulation.Invariant {
return func(ctx sdk.Context) error {
iterator := k.ValidatorsPowerStoreIterator(ctx)

Expand All @@ -128,6 +128,10 @@ func PositivePowerInvariant(k stake.Keeper) simulation.Invariant {
return fmt.Errorf("power store invariance:\n\tvalidator.Power: %v"+
"\n\tkey should be: %v\n\tkey in store: %v", validator.GetPower(), powerKey, iterator.Key())
}

if validator.Tokens.LT(sdk.ZeroDec()) {
return fmt.Errorf("negative tokens for validator: %v", validator)
}
}
iterator.Close()
return nil
Expand Down

0 comments on commit 2c0217f

Please sign in to comment.