From 87201654d99507ae382004bb692a9c59c7b46055 Mon Sep 17 00:00:00 2001 From: Philip Offtermatt Date: Thu, 18 Jul 2024 15:28:03 +0200 Subject: [PATCH] Make invariant fail early when param is 0 --- x/ccv/provider/keeper/invariants.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/x/ccv/provider/keeper/invariants.go b/x/ccv/provider/keeper/invariants.go index e48a2822b3..d23bebcaf1 100644 --- a/x/ccv/provider/keeper/invariants.go +++ b/x/ccv/provider/keeper/invariants.go @@ -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) @@ -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