Skip to content

Commit

Permalink
Use consensus power for throttle meter
Browse files Browse the repository at this point in the history
  • Loading branch information
p-offtermatt committed May 15, 2024
1 parent 5ccdb18 commit 48a1aba
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
9 changes: 9 additions & 0 deletions x/ccv/provider/keeper/provider_consensus.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package keeper

import (
"cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/cosmos/interchain-security/v4/x/ccv/provider/types"
Expand Down Expand Up @@ -45,3 +46,11 @@ func (k Keeper) GetLastProviderConsensusValSet(
) []types.ConsumerValidator {
return k.getValSet(ctx, []byte{types.LastProviderConsensusValsPrefix})
}

// GetLastTotalProviderConsensusPower returns the total power of the last stored
// validator set sent to the consensus engine on the provider
func (k Keeper) GetLastTotalProviderConsensusPower(
ctx sdk.Context,
) math.Int {
return k.getTotalPower(ctx, []byte{types.LastProviderConsensusValsPrefix})
}
4 changes: 3 additions & 1 deletion x/ccv/provider/keeper/throttle.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,9 @@ func (k Keeper) GetSlashMeterAllowance(ctx sdktypes.Context) math.Int {

// Compute allowance in units of tendermint voting power (integer),
// noting that total power changes over time
totalPower := k.stakingKeeper.GetLastTotalPower(ctx)

// Get total total power of the last consensus validator set on the provider
totalPower := k.GetLastTotalProviderConsensusPower(ctx)

roundedInt := sdktypes.NewInt(decFrac.MulInt(totalPower).RoundInt64())
if roundedInt.IsZero() {
Expand Down
10 changes: 10 additions & 0 deletions x/ccv/provider/keeper/validator_set_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package keeper
import (
"fmt"

"cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/cosmos/interchain-security/v4/x/ccv/provider/types"
Expand Down Expand Up @@ -92,3 +93,12 @@ func (k Keeper) getValSet(

return validators
}

func (k Keeper) getTotalPower(ctx sdk.Context, prefix []byte) math.Int {
var totalPower math.Int
validators := k.getValSet(ctx, prefix)
for _, val := range validators {
totalPower = totalPower.Add(math.NewInt(val.Power))
}
return totalPower
}

0 comments on commit 48a1aba

Please sign in to comment.