Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
sainoe committed Aug 27, 2024
1 parent 8499f3c commit 687a877
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 10 deletions.
4 changes: 3 additions & 1 deletion x/ccv/provider/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -441,13 +441,15 @@ func (k Keeper) hasToValidate(
minPowerToOptIn := int64(0)
// If the consumer is TopN compute the minimum power
if topN := k.GetTopN(ctx, consumerId); topN > 0 {
// compute the minimum power to opt-in since the one in the state is stale
// Note that the effective min power will be computed at the end of the epoch
minPowerToOptIn, err = k.ComputeMinPowerInTopN(ctx, activeValidators, topN)
if err != nil {
return false, err
}
}

// if the validator is opted in and belongs to the validators of the next epoch, then if nothing changes
// if the validator belongs to the validators of the next epoch, then if nothing changes
// the validator would have to validate in the next epoch
lastVals, err := k.GetLastBondedValidators(ctx)
if err != nil {
Expand Down
31 changes: 23 additions & 8 deletions x/ccv/provider/keeper/partial_set_security.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ func (k Keeper) CanValidateChain(ctx sdk.Context, consumerId string, providerAdd

// check if the validator is automatically opt-in for a topN chain
if !optedIn && k.GetTopN(ctx, consumerId) > 0 {
optedIn = k.HasMinPower(ctx, providerAddr, uint64(minPowerToOptIn))
optedIn = k.HasMinPower(ctx, providerAddr, minPowerToOptIn)
}

// only consider opted-in validators
Expand Down Expand Up @@ -386,26 +386,41 @@ func (k Keeper) ComputeNextValidators(ctx sdk.Context, consumerId string, bonded
}

// HasMinPower returns true if the `providerAddr` voting power is GTE than the given minimum power
func (k Keeper) HasMinPower(ctx sdk.Context, providerAddr types.ProviderConsAddress, minPower uint64) bool {
func (k Keeper) HasMinPower(ctx sdk.Context, providerAddr types.ProviderConsAddress, minPower int64) bool {
val, err := k.stakingKeeper.GetValidatorByConsAddr(ctx, providerAddr.Address)
if err != nil {
k.Logger(ctx).Error("cannot get last validator power %s: %s", providerAddr, err)
k.Logger(ctx).Error(
"cannot get last validator power",
"provider address",
providerAddr,
"error",
err,
)
return false
}

valAddr, err := sdk.ValAddressFromBech32(val.GetOperator())
if err != nil {
k.Logger(ctx).Error("could not retrieve validator address %s: %s",
val.GetOperator(), err)
k.Logger(ctx).Error(
"could not retrieve validator address",
"operator address",
val.GetOperator(),
"error",
err,
)
return false
}

power, err := k.stakingKeeper.GetLastValidatorPower(ctx, valAddr)
if err != nil {
k.Logger(ctx).Error("could not retrieve last power of validator address: %s: %s",
val.GetOperator(), err)
k.Logger(ctx).Error("could not retrieve last power of validator address",
"operator address",
val.GetOperator(),
"error",
err,
)
return false
}

return uint64(power) >= minPower
return power >= minPower
}
2 changes: 1 addition & 1 deletion x/ccv/provider/keeper/partial_set_security_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -921,7 +921,7 @@ func TestHasMinPower(t *testing.T) {
},
}

minPower := uint64(10)
minPower := int64(10)

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
Expand Down

0 comments on commit 687a877

Please sign in to comment.