cosmos-sdk/x/distribution/abci_app.go

40 lines
1.2 KiB
Go
Raw Normal View History

2018-09-13 23:35:02 -07:00
package distribution
import (
abci "github.com/tendermint/tendermint/abci/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/distribution/keeper"
2018-09-13 23:35:02 -07:00
)
// set the proposer for determining distribution during endblock
func BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock, k keeper.Keeper) {
if ctx.BlockHeight() > 1 {
previousPercentPrecommitVotes := getPreviousPercentPrecommitVotes(req)
previousProposer := k.GetPreviousProposerConsAddr(ctx)
2018-10-19 11:36:00 -07:00
k.AllocateTokens(ctx, previousPercentPrecommitVotes, previousProposer)
}
2018-10-04 15:37:46 -07:00
consAddr := sdk.ConsAddress(req.Header.ProposerAddress)
k.SetPreviousProposerConsAddr(ctx, consAddr)
}
// percent precommit votes for the previous block
func getPreviousPercentPrecommitVotes(req abci.RequestBeginBlock) sdk.Dec {
// determine the total number of signed power
2018-10-14 23:34:01 -07:00
totalPower, sumPrecommitPower := int64(0), int64(0)
for _, voteInfo := range req.LastCommitInfo.GetVotes() {
2018-10-14 23:34:01 -07:00
totalPower += voteInfo.Validator.Power
if voteInfo.SignedLastBlock {
sumPrecommitPower += voteInfo.Validator.Power
}
}
2018-10-14 23:34:01 -07:00
if totalPower == 0 {
return sdk.ZeroDec()
2018-09-28 01:02:07 -07:00
}
return sdk.NewDec(sumPrecommitPower).Quo(sdk.NewDec(totalPower))
2018-09-13 23:35:02 -07:00
}