-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathabci.go
83 lines (67 loc) · 1.97 KB
/
abci.go
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package module
import (
"context"
"fmt"
"github.com/cosmos/cosmos-sdk/telemetry"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/strangelove-ventures/poa"
)
// BeginBlocker updates the validator set without applying updates.
// Since this module depends on staking, that module will `ApplyAndReturnValidatorSetUpdates` from x/staking.
func (am AppModule) BeginBlocker(ctx context.Context) error {
sdkCtx := sdk.UnwrapSDKContext(ctx)
defer telemetry.ModuleMeasureSince(poa.ModuleName, sdkCtx.BlockTime(), telemetry.MetricKeyBeginBlocker)
iterator, err := am.keeper.UpdatedValidatorsCache.Iterate(ctx, nil)
if err != nil {
return err
}
defer iterator.Close()
sk := am.keeper.GetStakingKeeper()
for ; iterator.Valid(); iterator.Next() {
valOperAddr, err := iterator.Key()
if err != nil {
return err
}
am.keeper.Logger().Info("UpdatedValidatorsCache: %s\n", valOperAddr)
valAddr, err := sk.ValidatorAddressCodec().StringToBytes(valOperAddr)
if err != nil {
return err
}
val, err := sk.GetValidator(ctx, valAddr)
if err != nil {
return err
}
// Remove it from persisting across many blocks
if err := sk.DeleteValidatorByPowerIndex(ctx, val); err != nil {
return err
}
if err := am.keeper.UpdatedValidatorsCache.Remove(ctx, valOperAddr); err != nil {
return err
}
}
// reset caches
if sdkCtx.BlockHeight() > 1 {
// non gentx messages reset the cached block powers for IBC validations.
if err := am.keeper.ResetCachedTotalPower(ctx); err != nil {
return err
}
if err := am.keeper.ResetAbsoluteBlockPower(ctx); err != nil {
return err
}
}
// Event Debugging
events, err := am.keeper.GetStakingKeeper().GetValidatorUpdates(ctx)
if err != nil {
return err
}
if len(events) == 0 {
return nil
}
am.keeper.Logger().Info("BeginBlocker events:\n")
for _, e := range events {
e := e
am.keeper.Logger().Info(fmt.Sprintf("PubKey: %s, Power: %d", &e.PubKey, e.Power))
}
am.keeper.Logger().Info("\n")
return nil
}