2018-09-13 23:35:02 -07:00
|
|
|
package distribution
|
|
|
|
|
|
|
|
import (
|
2020-07-17 08:34:37 -07:00
|
|
|
"time"
|
|
|
|
|
2018-09-13 23:35:02 -07:00
|
|
|
abci "github.com/tendermint/tendermint/abci/types"
|
2018-09-19 19:54:46 -07:00
|
|
|
|
2020-06-18 11:12:44 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/telemetry"
|
2018-09-19 19:54:46 -07:00
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
|
|
"github.com/cosmos/cosmos-sdk/x/distribution/keeper"
|
2020-06-18 11:12:44 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/x/distribution/types"
|
2018-09-13 23:35:02 -07:00
|
|
|
)
|
|
|
|
|
2019-10-23 02:14:45 -07:00
|
|
|
// BeginBlocker sets the proposer for determining distribution during endblock
|
2019-05-16 08:25:32 -07:00
|
|
|
// and distribute rewards for the previous block
|
2019-04-05 13:20:58 -07:00
|
|
|
func BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock, k keeper.Keeper) {
|
2020-07-17 08:34:37 -07:00
|
|
|
defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now().UTC(), telemetry.MetricKeyBeginBlocker)
|
2020-06-18 11:12:44 -07:00
|
|
|
|
2019-01-16 13:38:05 -08:00
|
|
|
// determine the total power signing the block
|
2019-03-14 11:13:15 -07:00
|
|
|
var previousTotalPower, sumPreviousPrecommitPower int64
|
2018-10-12 04:15:13 -07:00
|
|
|
for _, voteInfo := range req.LastCommitInfo.GetVotes() {
|
2019-03-14 11:13:15 -07:00
|
|
|
previousTotalPower += voteInfo.Validator.Power
|
2018-10-12 04:15:13 -07:00
|
|
|
if voteInfo.SignedLastBlock {
|
2019-03-14 11:13:15 -07:00
|
|
|
sumPreviousPrecommitPower += voteInfo.Validator.Power
|
2018-10-12 04:15:13 -07:00
|
|
|
}
|
|
|
|
}
|
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)
|
2019-03-14 11:13:15 -07:00
|
|
|
k.AllocateTokens(ctx, sumPreviousPrecommitPower, previousTotalPower, 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
|
|
|
}
|