1
1
package keeper
2
2
3
3
import (
4
+ "context"
5
+
4
6
"cosmossdk.io/x/distribution/types"
5
7
6
8
"github.com/cosmos/cosmos-sdk/telemetry"
@@ -10,31 +12,33 @@ import (
10
12
// BeginBlocker sets the proposer for determining distribution during endblock
11
13
// and distribute rewards for the previous block.
12
14
// TODO: use context.Context after including the comet service
13
- func (k Keeper ) BeginBlocker (ctx sdk .Context ) error {
15
+ func (k Keeper ) BeginBlocker (ctx context .Context ) error {
14
16
defer telemetry .ModuleMeasureSince (types .ModuleName , telemetry .Now (), telemetry .MetricKeyBeginBlocker )
15
17
16
18
// determine the total power signing the block
17
19
var previousTotalPower int64
18
- for _ , vote := range ctx .CometInfo ().LastCommit .Votes {
20
+ header := k .HeaderService .HeaderInfo (ctx )
21
+ ci := k .cometService .CometInfo (ctx )
22
+ for _ , vote := range ci .LastCommit .Votes {
19
23
previousTotalPower += vote .Validator .Power
20
24
}
21
25
22
26
// TODO this is Tendermint-dependent
23
27
// ref https://github.com/cosmos/cosmos-sdk/issues/3095
24
- if ctx . BlockHeight () > 1 {
25
- if err := k .AllocateTokens (ctx , previousTotalPower , ctx . CometInfo () .LastCommit .Votes ); err != nil {
28
+ if header . Height > 1 {
29
+ if err := k .AllocateTokens (ctx , previousTotalPower , ci .LastCommit .Votes ); err != nil {
26
30
return err
27
31
}
28
32
29
33
// every 1000 blocks send whole coins from decimal pool to community pool
30
- if ctx . BlockHeight () % 1000 == 0 {
34
+ if header . Height % 1000 == 0 {
31
35
if err := k .sendDecimalPoolToCommunityPool (ctx ); err != nil {
32
36
return err
33
37
}
34
38
}
35
39
}
36
40
37
41
// record the proposer for when we payout on the next block
38
- consAddr := sdk .ConsAddress (ctx . BlockHeader () .ProposerAddress )
42
+ consAddr := sdk .ConsAddress (ci .ProposerAddress )
39
43
return k .PreviousProposer .Set (ctx , consAddr )
40
44
}
0 commit comments