github.com/cosmos/cosmos-sdk@v0.50.10/x/distribution/abci.go (about)

     1  package distribution
     2  
     3  import (
     4  	"github.com/cosmos/cosmos-sdk/telemetry"
     5  	sdk "github.com/cosmos/cosmos-sdk/types"
     6  	"github.com/cosmos/cosmos-sdk/x/distribution/keeper"
     7  	"github.com/cosmos/cosmos-sdk/x/distribution/types"
     8  )
     9  
    10  // BeginBlocker sets the proposer for determining distribution during endblock
    11  // and distribute rewards for the previous block.
    12  func BeginBlocker(ctx sdk.Context, k keeper.Keeper) error {
    13  	defer telemetry.ModuleMeasureSince(types.ModuleName, telemetry.Now(), telemetry.MetricKeyBeginBlocker)
    14  
    15  	// determine the total power signing the block
    16  	var previousTotalPower int64
    17  	for _, voteInfo := range ctx.VoteInfos() {
    18  		previousTotalPower += voteInfo.Validator.Power
    19  	}
    20  
    21  	// TODO this is Tendermint-dependent
    22  	// ref https://github.com/cosmos/cosmos-sdk/issues/3095
    23  	if ctx.BlockHeight() > 1 {
    24  		if err := k.AllocateTokens(ctx, previousTotalPower, ctx.VoteInfos()); err != nil {
    25  			return err
    26  		}
    27  	}
    28  
    29  	// record the proposer for when we payout on the next block
    30  	consAddr := sdk.ConsAddress(ctx.BlockHeader().ProposerAddress)
    31  	return k.SetPreviousProposerConsAddr(ctx, consAddr)
    32  }