/
slashing.go
116 lines (104 loc) · 4.32 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
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
package api
import (
"fmt"
beacon "github.com/oasisprotocol/oasis-core/go/beacon/api"
"github.com/oasisprotocol/oasis-core/go/common/quantity"
)
// SlashReason is the reason why a node was slashed.
type SlashReason uint8
const (
// SlashConsensusEquivocation is slashing due to equivocation.
SlashConsensusEquivocation SlashReason = 0x00
// SlashBeaconInvalidCommit is slashing due to invalid commit behavior.
SlashBeaconInvalidCommit SlashReason = 0x01
// SlashBeaconInvalidReveal is slashing due to invalid reveal behavior.
SlashBeaconInvalidReveal SlashReason = 0x02
// SlashBeaconNonparticipation is slashing due to nonparticipation.
SlashBeaconNonparticipation SlashReason = 0x03
// SlashConsensusLightClientAttack is slashing due to light client attacks.
SlashConsensusLightClientAttack SlashReason = 0x04
// SlashRuntimeIncorrectResults is slashing due to submission of incorrect
// results in runtime executor commitments.
SlashRuntimeIncorrectResults SlashReason = 0x80
// SlashRuntimeEquivocation is slashing due to signing two different
// executor commits or proposed batches for the same round.
SlashRuntimeEquivocation SlashReason = 0x81
// SlashConsensusEquivocationName is the string representation of SlashConsensusEquivocation.
SlashConsensusEquivocationName = "consensus-equivocation"
// SlashBeaconInvalidCommitName is the string representation of SlashBeaconInvalidCommit.
SlashBeaconInvalidCommitName = "beacon-invalid-commit"
// SlashBeaconInvalidRevealName is the string representation of SlashBeaconInvalidReveal.
SlashBeaconInvalidRevealName = "beacon-invalid-reveal"
// SlashBeaconNonparticipationName is the string representation of SlashBeaconNonparticipation.
SlashBeaconNonparticipationName = "beacon-nonparticipation"
// SlashConsensusLightClientAttackName is the string representation of SlashConsensusLightClientAttack.
SlashConsensusLightClientAttackName = "consensus-light-client-attack"
// SlashRuntimeIncorrectResultsName is the string representation of SlashRuntimeIncorrectResultsName.
SlashRuntimeIncorrectResultsName = "runtime-incorrect-results"
// SlashRuntimeEquivocationName is the string representation of SlashRuntimeEquivocation.
SlashRuntimeEquivocationName = "runtime-equivocation"
)
// String returns a string representation of a SlashReason.
func (s SlashReason) String() string {
str, _ := s.checkedString()
return str
}
func (s SlashReason) checkedString() (string, error) {
switch s {
case SlashConsensusEquivocation:
return SlashConsensusEquivocationName, nil
case SlashBeaconInvalidCommit:
return SlashBeaconInvalidCommitName, nil
case SlashBeaconInvalidReveal:
return SlashBeaconInvalidRevealName, nil
case SlashBeaconNonparticipation:
return SlashBeaconNonparticipationName, nil
case SlashConsensusLightClientAttack:
return SlashConsensusLightClientAttackName, nil
case SlashRuntimeIncorrectResults:
return SlashRuntimeIncorrectResultsName, nil
case SlashRuntimeEquivocation:
return SlashRuntimeEquivocationName, nil
default:
return "[unknown slash reason]", fmt.Errorf("unknown slash reason: %d", s)
}
}
// MarshalText encodes a SlashReason into text form.
func (s SlashReason) MarshalText() ([]byte, error) {
str, err := s.checkedString()
if err != nil {
return nil, err
}
return []byte(str), nil
}
// UnmarshalText decodes a text slice into a SlashReason.
func (s *SlashReason) UnmarshalText(text []byte) error {
switch string(text) {
// XXX: The "0" case is only for backward compatibility, so that the old
// genesis file loads -- remove this once mainnet is upgraded!
case "0":
fallthrough
case SlashConsensusEquivocationName:
*s = SlashConsensusEquivocation
case SlashBeaconInvalidCommitName:
*s = SlashBeaconInvalidCommit
case SlashBeaconInvalidRevealName:
*s = SlashBeaconInvalidReveal
case SlashBeaconNonparticipationName:
*s = SlashBeaconNonparticipation
case SlashConsensusLightClientAttackName:
*s = SlashConsensusLightClientAttack
case SlashRuntimeIncorrectResultsName:
*s = SlashRuntimeIncorrectResults
case SlashRuntimeEquivocationName:
*s = SlashRuntimeEquivocation
default:
return fmt.Errorf("invalid slash reason: %s", string(text))
}
return nil
}
// Slash is the per-reason slashing configuration.
type Slash struct {
Amount quantity.Quantity `json:"amount"`
FreezeInterval beacon.EpochTime `json:"freeze_interval"`
}