/
validator.go
52 lines (45 loc) · 2.19 KB
/
validator.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
package tendermint
import (
cryptoTypes "github.com/cosmos/cosmos-sdk/crypto/types"
"github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/relayer/relayer"
"github.com/persistenceOne/persistenceBridge/application/db"
"github.com/persistenceOne/persistenceBridge/utilities/logging"
)
//Map to keep track of missed blocks during previous CheckValidators() call
var missedBlockCounterForValidator = make(map[string]int64)
func CheckValidators(chain *relayer.Chain, processHeight int64, lowerLimitForWarningValidator int64) {
//Get validators list from db
validators, err := db.GetValidators()
if err != nil {
logging.Error("Could not fetch validators from DB", processHeight, "ERR:", err)
}
for _, validator := range validators {
//Query details about validator
validatorDetails, err := QueryValidator(validator.Address, chain)
if err != nil {
logging.Error("Could not query the validator", processHeight, "Validator Name:", validator.Name, "ERR:", err)
}
//Convert type.Any key to consensus pubKey
var pubKey cryptoTypes.PubKey
err = chain.CLIContext(0).InterfaceRegistry.UnpackAny(validatorDetails.Validator.ConsensusPubkey, &pubKey)
if err != nil {
logging.Error("Could not unpack consensus pubKey", processHeight, "ERR:", err)
}
//Convert PubKey to consAddress to query Slashing Info
consAddress := types.ConsAddress(pubKey.Address())
validatorSlashingInfo, err := QuerySlashingSigningInfo(consAddress, chain)
if err != nil {
logging.Error("Could not find the signing info about the validator", processHeight, "Validator Name:", validator.Name, "ERR:", err)
}
// only above lowerLimitForWarningValidator, warning will be sent
if validatorSlashingInfo.ValSigningInfo.MissedBlocksCounter > missedBlockCounterForValidator[validator.Name] &&
validatorSlashingInfo.ValSigningInfo.MissedBlocksCounter > lowerLimitForWarningValidator {
logging.Warn("Validator is about to be jailed", processHeight, "Validator Name:", validator.Name)
}
if validatorDetails.Validator.Jailed {
logging.Warn("Validator is Jailed", processHeight, "Validator Name:", validator.Name)
}
missedBlockCounterForValidator[validator.Name] = validatorSlashingInfo.ValSigningInfo.MissedBlocksCounter
}
}