Skip to content

Commit

Permalink
Make invariant fail early when param is 0
Browse files Browse the repository at this point in the history
  • Loading branch information
p-offtermatt committed Jul 22, 2024
1 parent e7978b4 commit 8720165
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions x/ccv/provider/keeper/invariants.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ func MaxProviderConsensusValidatorsInvariant(k *Keeper) sdk.Invariant {
// i.e. the functions from staking_keeper_interface.go
func StakingKeeperEquivalenceInvariant(k Keeper) sdk.Invariant {
return func(ctx sdk.Context) (string, bool) {
maxProviderConsensusValidators := k.GetParams(ctx).MaxProviderConsensusValidators
if maxProviderConsensusValidators == 0 {
return sdk.FormatInvariant(types.ModuleName, "staking-keeper-equivalence",
fmt.Sprintf("maxProviderConsensusVals is 0: %v", maxProviderConsensusValidators)), true
}
stakingKeeper := k.stakingKeeper

maxValidators, err := stakingKeeper.MaxValidators(ctx)
Expand All @@ -49,10 +54,6 @@ func StakingKeeperEquivalenceInvariant(k Keeper) sdk.Invariant {
fmt.Sprintf("error getting max validators from staking keeper: %v", err)), true
}

maxProviderConsensusValidators := k.GetParams(ctx).MaxProviderConsensusValidators

fmt.Println(k.GetParams(ctx))

if maxValidators != uint32(maxProviderConsensusValidators) {
// the invariant should only check something if these two numbers are equal,
// so skip in this case
Expand Down

0 comments on commit 8720165

Please sign in to comment.