Skip to content

Commit

Permalink
total power logic in loop
Browse files Browse the repository at this point in the history
  • Loading branch information
czarcas7ic committed Feb 15, 2024
1 parent 145d46e commit bf8248c
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions x/distribution/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@ import (
func BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock, k keeper.Keeper) {
defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now(), telemetry.MetricKeyBeginBlocker)

// determine the total power signing the block
var previousTotalPower int64
for _, voteInfo := range req.LastCommitInfo.GetVotes() {
previousTotalPower += voteInfo.Validator.Power
}

// TODO this is Tendermint-dependent
// ref https://github.com/cosmos/cosmos-sdk/issues/3095
blockHeight := ctx.BlockHeight()
// only allocate rewards if the block height is greater than 1
// and only allocate rewards for every multiple of 10 blocks for performance reasons.
if blockHeight > 1 && blockHeight%10 == 0 {
// determine the total power signing the block
var previousTotalPower int64
for _, voteInfo := range req.LastCommitInfo.GetVotes() {
previousTotalPower += voteInfo.Validator.Power
}

k.AllocateTokens(ctx, previousTotalPower, req.LastCommitInfo.GetVotes())
}

Expand Down

0 comments on commit bf8248c

Please sign in to comment.