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

     1  package distribution
     2  
     3  import (
     4  	abci "github.com/fibonacci-chain/fbc/libs/tendermint/abci/types"
     5  	tmtypes "github.com/fibonacci-chain/fbc/libs/tendermint/types"
     6  
     7  	sdk "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/types"
     8  	"github.com/fibonacci-chain/fbc/x/distribution/keeper"
     9  )
    10  
    11  // BeginBlocker set the proposer for determining distribution during endblock
    12  // and distribute rewards for the previous block
    13  func BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock, k keeper.Keeper) {
    14  	// determine the total power signing the block
    15  	var previousTotalPower int64
    16  	for _, voteInfo := range req.LastCommitInfo.GetVotes() {
    17  		previousTotalPower += voteInfo.Validator.Power
    18  	}
    19  
    20  	// TODO this is Tendermint-dependent
    21  	// ref https://github.com/cosmos/cosmos-sdk/issues/3095
    22  	if ctx.BlockHeight() > tmtypes.GetStartBlockHeight()+1 {
    23  		previousProposer := k.GetPreviousProposerConsAddr(ctx)
    24  
    25  		/* allocate tokens by fbchain custom rule */
    26  		k.AllocateTokens(ctx, 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  }