diff --git a/tests/integration/distribution.go b/tests/integration/distribution.go index a2bd51067f..722c37be0b 100644 --- a/tests/integration/distribution.go +++ b/tests/integration/distribution.go @@ -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") { @@ -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) diff --git a/x/ccv/provider/keeper/distribution.go b/x/ccv/provider/keeper/distribution.go index fd5a7010d6..acf0e8d0e5 100644 --- a/x/ccv/provider/keeper/distribution.go +++ b/x/ccv/provider/keeper/distribution.go @@ -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, @@ -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 @@ -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) {