-
Notifications
You must be signed in to change notification settings - Fork 206
/
slashing.go
41 lines (34 loc) · 1.27 KB
/
slashing.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
package keeper
import (
"fmt"
abci "github.com/cometbft/cometbft/abci/types"
sdk "github.com/cosmos/cosmos-sdk/types"
evidenceTypes "github.com/cosmos/cosmos-sdk/x/evidence/types"
)
// balance delegators dualstaking after potential validators slashing
func (k Keeper) HandleSlashedValidators(ctx sdk.Context, req abci.RequestBeginBlock) {
for _, tmEvidence := range req.ByzantineValidators {
switch tmEvidence.Type {
case abci.MisbehaviorType_DUPLICATE_VOTE, abci.MisbehaviorType_LIGHT_CLIENT_ATTACK:
evidence := evidenceTypes.FromABCIEvidence(tmEvidence)
evidenceEq, ok := evidence.(*evidenceTypes.Equivocation)
if ok {
k.BalanceValidatorsDelegators(ctx, evidenceEq)
}
default:
k.Logger(ctx).Error(fmt.Sprintf("ignored unknown evidence type: %s", tmEvidence.Type))
}
}
}
func (k Keeper) BalanceValidatorsDelegators(ctx sdk.Context, evidence *evidenceTypes.Equivocation) {
consAddr := evidence.GetConsensusAddress()
validator := k.stakingKeeper.ValidatorByConsAddr(ctx, consAddr)
if validator == nil || validator.GetOperator().Empty() {
return
}
delegators := k.stakingKeeper.GetValidatorDelegations(ctx, validator.GetOperator())
for _, delegator := range delegators {
delAddr := delegator.GetDelegatorAddr()
k.BalanceDelegator(ctx, delAddr)
}
}