Skip to content

Commit

Permalink
nits
Browse files Browse the repository at this point in the history
  • Loading branch information
sainoe committed Mar 18, 2024
1 parent d6fe8fa commit 080c063
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
5 changes: 3 additions & 2 deletions tests/integration/distribution.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func (s *CCVTestSuite) TestRewardsDistribution() {
rewardPool := providerAccountKeeper.GetModuleAccount(s.providerCtx(), providertypes.ConsumerRewardsPool).GetAddress()
rewardCoins := providerBankKeeper.GetAllBalances(s.providerCtx(), rewardPool)

// Check that the reward pool contains a coin with a IBC denom
// Check that the reward pool contains a coin with an IBC denom
rewardsIBCdenom := ""
for _, coin := range rewardCoins {
if strings.HasPrefix(coin.Denom, "ibc") {
Expand Down Expand Up @@ -149,7 +149,8 @@ func (s *CCVTestSuite) TestRewardsDistribution() {
1,
)

// Check that the consumer rewards allocation are empty since relayAllCommittedPackets call BeginBlockRD
// Check that the consumer rewards allocation are empty since relayAllCommittedPackets calls BeginBlockRD,
// which in turns call AllocateTokens.
rewardsAlloc := providerKeeper.GetConsumerRewardsAllocation(s.providerCtx(), s.consumerChain.ChainID)
s.Require().Empty(rewardsAlloc.Rewards)

Expand Down
18 changes: 10 additions & 8 deletions x/ccv/provider/keeper/distribution.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ func (k Keeper) AllocateTokens(ctx sdk.Context) {
}
}

// AllocateTokensToConsumerValidators allocates the given tokens from the
// from consumer rewards pool to validator according to their voting power
// AllocateTokensToConsumerValidators allocates tokens
// to the given consumer chain's validator set
func (k Keeper) AllocateTokensToConsumerValidators(
ctx sdk.Context,
chainID string,
Expand All @@ -136,16 +136,18 @@ func (k Keeper) AllocateTokensToConsumerValidators(
return allocated
}

// get the consumer total voting power from the votes
// get the total voting power of the consumer valset
totalPower := k.ComputeConsumerTotalVotingPower(ctx, chainID)
if totalPower == 0 {
return allocated
}

for _, val := range k.GetConsumerValSet(ctx, chainID) {
consAddr := sdk.ConsAddress(val.ProviderConsAddr)
// Allocate tokens by iterating over the consumer validators
for _, consumerVal := range k.GetConsumerValSet(ctx, chainID) {
consAddr := sdk.ConsAddress(consumerVal.ProviderConsAddr)

powerFraction := math.LegacyNewDec(val.Power).QuoTruncate(math.LegacyNewDec(totalPower))
// get the validator tokens fraction using its voting power
powerFraction := math.LegacyNewDec(consumerVal.Power).QuoTruncate(math.LegacyNewDec(totalPower))
tokensFraction := tokens.MulDecTruncate(powerFraction)

// get the validator type struct for the consensus address
Expand Down Expand Up @@ -230,8 +232,8 @@ func (k Keeper) GetConsumerRewardsPool(ctx sdk.Context) sdk.Coins {
)
}

// ComputeConsumerTotalVotingPower returns the total voting power of the given consumer chain
// validator set
// ComputeConsumerTotalVotingPower returns the validator set total voting power
// for the given consumer chain
func (k Keeper) ComputeConsumerTotalVotingPower(ctx sdk.Context, chainID string) (totalPower int64) {
// sum the opted-in validators set voting powers
for _, v := range k.GetConsumerValSet(ctx, chainID) {
Expand Down

0 comments on commit 080c063

Please sign in to comment.