-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Expand file tree
/
Copy pathabci.go
More file actions
41 lines (34 loc) · 1.29 KB
/
Copy pathabci.go
File metadata and controls
41 lines (34 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package keeper
import (
"cosmossdk.io/x/distribution/types"
"github.com/cosmos/cosmos-sdk/telemetry"
sdk "github.com/cosmos/cosmos-sdk/types"
)
// BeginBlocker sets the proposer for determining distribution during endblock
// and distribute rewards for the previous block.
// TODO: use context.Context after including the comet service
func (k Keeper) BeginBlocker(ctx sdk.Context) error {
start := telemetry.Now()
defer telemetry.ModuleMeasureSince(types.ModuleName, start, telemetry.MetricKeyBeginBlocker)
// determine the total power signing the block
var previousTotalPower int64
for _, vote := range ctx.CometInfo().LastCommit.Votes {
previousTotalPower += vote.Validator.Power
}
// TODO this is Tendermint-dependent
// ref https://github.com/cosmos/cosmos-sdk/issues/3095
if ctx.BlockHeight() > 1 {
if err := k.AllocateTokens(ctx, previousTotalPower, ctx.CometInfo().LastCommit.Votes); err != nil {
return err
}
// every 1000 blocks send whole coins from decimal pool to community pool
if ctx.BlockHeight()%1000 == 0 {
if err := k.sendDecimalPoolToCommunityPool(ctx); err != nil {
return err
}
}
}
// record the proposer for when we payout on the next block
consAddr := sdk.ConsAddress(ctx.BlockHeader().ProposerAddress)
return k.PreviousProposer.Set(ctx, consAddr)
}