/
rpc_goodbye_codes.go
44 lines (37 loc) · 1.35 KB
/
rpc_goodbye_codes.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
package types
import (
"github.com/prysmaticlabs/prysm/v4/consensus-types/primitives"
)
// RPCGoodbyeCode represents goodbye code, used in sync package.
type RPCGoodbyeCode = primitives.SSZUint64
const (
// Spec defined codes.
GoodbyeCodeClientShutdown RPCGoodbyeCode = iota + 1
GoodbyeCodeWrongNetwork
GoodbyeCodeGenericError
// Teku specific codes
GoodbyeCodeUnableToVerifyNetwork = RPCGoodbyeCode(128)
// Lighthouse specific codes
GoodbyeCodeTooManyPeers = RPCGoodbyeCode(129)
GoodbyeCodeBadScore = RPCGoodbyeCode(250)
GoodbyeCodeBanned = RPCGoodbyeCode(251)
)
// GoodbyeCodeMessages defines a mapping between goodbye codes and string messages.
var GoodbyeCodeMessages = map[RPCGoodbyeCode]string{
GoodbyeCodeClientShutdown: "client shutdown",
GoodbyeCodeWrongNetwork: "irrelevant network",
GoodbyeCodeGenericError: "fault/error",
GoodbyeCodeUnableToVerifyNetwork: "unable to verify network",
GoodbyeCodeTooManyPeers: "client has too many peers",
GoodbyeCodeBadScore: "peer score too low",
GoodbyeCodeBanned: "client banned this node",
}
// ErrToGoodbyeCode converts given error to RPC goodbye code.
func ErrToGoodbyeCode(err error) RPCGoodbyeCode {
switch err {
case ErrWrongForkDigestVersion:
return GoodbyeCodeWrongNetwork
default:
return GoodbyeCodeGenericError
}
}