forked from maticnetwork/heimdall
-
Notifications
You must be signed in to change notification settings - Fork 0
/
abci.go
47 lines (40 loc) · 1.58 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
package slashing
import (
"fmt"
abci "github.com/tendermint/tendermint/abci/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/maticnetwork/heimdall/slashing/types"
tmtypes "github.com/tendermint/tendermint/types"
)
func BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock, k Keeper) {
if !k.GetParams(ctx).EnableSlashing {
k.Logger(ctx).Debug("slashing is not enabled. To enable, send a proposal via governance")
return
}
// BeginBlocker iterates through and handles any newly discovered evidence of
// misbehavior submitted by Tendermint. Currently, only equivocation is handled.
for _, tmEvidence := range req.ByzantineValidators {
switch tmEvidence.Type {
case tmtypes.ABCIEvidenceTypeDuplicateVote:
evidence := types.ConvertDuplicateVoteEvidence(tmEvidence)
if err := k.HandleDoubleSign(ctx, evidence.(types.Equivocation)); err != nil {
k.Logger(ctx).Error("Failed to handle double sign", "Error", err)
}
default:
k.Logger(ctx).Error(fmt.Sprintf("ignored unknown evidence type: %s", tmEvidence.Type))
}
}
// Iterate over all the validators which *should* have signed this block
// store whether or not they have actually signed it and slash/unbond any
// which have missed too many blocks in a row (downtime slashing)
for _, voteInfo := range req.LastCommitInfo.GetVotes() {
if err := k.HandleValidatorSignature(
ctx,
voteInfo.Validator.Address,
voteInfo.Validator.Power,
voteInfo.SignedLastBlock,
); err != nil {
k.Logger(ctx).Error("Failed to handle validator signature", "Error", err, "address", voteInfo.Validator)
}
}
}