Skip to content

Commit

Permalink
nits
Browse files Browse the repository at this point in the history
  • Loading branch information
sainoe committed Aug 27, 2024
1 parent c07c99e commit 8499f3c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
8 changes: 4 additions & 4 deletions x/ccv/provider/keeper/partial_set_security_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -397,16 +397,16 @@ func TestCanValidateChain(t *testing.T) {
// with TopN chains, the validator can be considered,
mocks.MockStakingKeeper.EXPECT().GetValidatorByConsAddr(gomock.Any(), providerAddr.Address).Return(validator, nil).Times(2)
providerKeeper.SetConsumerPowerShapingParameters(ctx, consumerID, types.PowerShapingParameters{Top_N: 50})
// validator is LT min power
// validator's power is LT the min power
require.False(t, providerKeeper.CanValidateChain(ctx, consumerID, providerAddr, 2))
// validator is GTE min power
// validator's power is GTE the min power
require.True(t, providerKeeper.CanValidateChain(ctx, consumerID, providerAddr, 1))

// when validator is opted-in it can validate regardless of it the min power
// when validator is opted-in it can validate regardless of its min power
providerKeeper.SetOptedIn(ctx, consumerID, types.NewProviderConsAddress(consAddr))
require.True(t, providerKeeper.CanValidateChain(ctx, consumerID, providerAddr, 0))

// With OptIn chains, validator can validator only if it's opted-in
// With OptIn chains, validator can validate only if it has already opted-in
providerKeeper.SetConsumerPowerShapingParameters(ctx, consumerID, types.PowerShapingParameters{Top_N: 0})
require.True(t, providerKeeper.CanValidateChain(ctx, consumerID, providerAddr, 0))

Expand Down
12 changes: 6 additions & 6 deletions x/ccv/provider/keeper/proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ func (k Keeper) MakeConsumerGenesis(
return gen, nil, errorsmod.Wrapf(stakingtypes.ErrNoValidatorFound, "error getting last bonded validators: %s", err)
}

minPowerToOptIn := int64(0)
minPower := int64(0)
if powerShapingParameters.Top_N > 0 {
// get the consensus active validators
// we do not want to base the power calculation for the top N
Expand All @@ -244,21 +244,21 @@ func (k Keeper) MakeConsumerGenesis(
}

// in a Top-N chain, we automatically opt in all validators that belong to the top N
minPowerToOptIn, err = k.ComputeMinPowerInTopN(ctx, activeValidators, powerShapingParameters.Top_N)
minPower, err = k.ComputeMinPowerInTopN(ctx, activeValidators, powerShapingParameters.Top_N)
if err != nil {
return gen, nil, err
}
// log the minimum power in top N
k.Logger(ctx).Info("minimum power in top N at consumer genesis",
"consumerId", consumerId,
"minPower", minPowerToOptIn,
"minPower", minPower,
)
k.OptInTopNValidators(ctx, consumerId, activeValidators, minPowerToOptIn)
k.SetMinimumPowerInTopN(ctx, consumerId, minPowerToOptIn)
k.OptInTopNValidators(ctx, consumerId, activeValidators, minPower)
k.SetMinimumPowerInTopN(ctx, consumerId, minPower)
}

// need to use the bondedValidators, not activeValidators, here since the chain might be opt-in and allow inactive vals
nextValidators := k.ComputeNextValidators(ctx, consumerId, bondedValidators, minPowerToOptIn)
nextValidators := k.ComputeNextValidators(ctx, consumerId, bondedValidators, minPower)
k.SetConsumerValSet(ctx, consumerId, nextValidators)

// get the initial updates with the latest set consumer public keys
Expand Down

0 comments on commit 8499f3c

Please sign in to comment.