github.com/fibonacci-chain/fbc@v0.0.0-20231124064014-c7636198c1e9/libs/cosmos-sdk/x/distribution/abci.go (about)

     1  package distribution
     2  
     3  import (
     4  	abci "github.com/fibonacci-chain/fbc/libs/tendermint/abci/types"
     5  
     6  	sdk "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/types"
     7  	"github.com/fibonacci-chain/fbc/libs/cosmos-sdk/x/distribution/keeper"
     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, req abci.RequestBeginBlock, k keeper.Keeper) {
    13  	// determine the total power signing the block
    14  	var previousTotalPower, sumPreviousPrecommitPower int64
    15  	for _, voteInfo := range req.LastCommitInfo.GetVotes() {
    16  		previousTotalPower += voteInfo.Validator.Power
    17  		if voteInfo.SignedLastBlock {
    18  			sumPreviousPrecommitPower += voteInfo.Validator.Power
    19  		}
    20  	}
    21  
    22  	// TODO this is Tendermint-dependent
    23  	// ref https://github.com/cosmos/cosmos-sdk/issues/3095
    24  	if ctx.BlockHeight() > 1 {
    25  		previousProposer := k.GetPreviousProposerConsAddr(ctx)
    26  		k.AllocateTokens(ctx, sumPreviousPrecommitPower, previousTotalPower, previousProposer, req.LastCommitInfo.GetVotes())
    27  	}
    28  
    29  	// record the proposer for when we payout on the next block
    30  	consAddr := sdk.ConsAddress(req.Header.ProposerAddress)
    31  	k.SetPreviousProposerConsAddr(ctx, consAddr)
    32  }