-
Notifications
You must be signed in to change notification settings - Fork 211
/
malfeasance.go
37 lines (33 loc) · 955 Bytes
/
malfeasance.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
package events
import (
"github.com/spacemeshos/go-spacemesh/common/types"
"github.com/spacemeshos/go-spacemesh/log"
)
// EventMalfeasance includes the malfeasance proof.
type EventMalfeasance struct {
Smesher types.NodeID
Proof *types.MalfeasanceProof
}
// SubscribeMalfeasance subscribes malfeasance events.
func SubscribeMalfeasance() Subscription {
mu.RLock()
defer mu.RUnlock()
if reporter != nil {
sub, err := reporter.bus.Subscribe(new(EventMalfeasance))
if err != nil {
log.With().Panic("Failed to subscribe to malfeasance proof")
}
return sub
}
return nil
}
// ReportMalfeasance reports a malfeasance proof.
func ReportMalfeasance(nodeID types.NodeID, mp *types.MalfeasanceProof) {
mu.RLock()
defer mu.RUnlock()
if reporter != nil {
if err := reporter.malfeasanceEmitter.Emit(EventMalfeasance{Smesher: nodeID, Proof: mp}); err != nil {
log.With().Error("failed to emit malfeasance proof", log.Err(err))
}
}
}