cosmos-sdk/x/distribution/abci_app.go

34 lines
1.0 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) {
2019-01-16 13:38:05 -08:00
// determine the total power signing the block
var totalPower, sumPrecommitPower int64
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
2019-01-16 13:38:05 -08:00
// TODO this is Tendermint-dependent
// ref https://github.com/cosmos/cosmos-sdk/issues/3095
if ctx.BlockHeight() > 1 {
previousProposer := k.GetPreviousProposerConsAddr(ctx)
k.AllocateTokens(ctx, sumPrecommitPower, totalPower, previousProposer, req.LastCommitInfo.GetVotes())
2018-09-28 01:02:07 -07:00
}
2019-01-16 13:38:05 -08:00
// record the proposer for when we payout on the next block
consAddr := sdk.ConsAddress(req.Header.ProposerAddress)
k.SetPreviousProposerConsAddr(ctx, consAddr)
2018-09-13 23:35:02 -07:00
}