-
Notifications
You must be signed in to change notification settings - Fork 170
/
proposal_violation_distributor.go
46 lines (38 loc) · 1.38 KB
/
proposal_violation_distributor.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
package pubsub
import (
"sync"
"github.com/onflow/flow-go/consensus/hotstuff"
"github.com/onflow/flow-go/consensus/hotstuff/model"
"github.com/onflow/flow-go/model/flow"
)
// ProposalViolationDistributor ingests notifications about HotStuff-protocol violations and
// distributes them to consumers. Such notifications are produced by the active consensus
// participants and the consensus follower.
// Concurrently safe.
type ProposalViolationDistributor struct {
consumers []hotstuff.ProposalViolationConsumer
lock sync.RWMutex
}
var _ hotstuff.ProposalViolationConsumer = (*ProposalViolationDistributor)(nil)
func NewProtocolViolationDistributor() *ProposalViolationDistributor {
return &ProposalViolationDistributor{}
}
func (d *ProposalViolationDistributor) AddProposalViolationConsumer(consumer hotstuff.ProposalViolationConsumer) {
d.lock.Lock()
defer d.lock.Unlock()
d.consumers = append(d.consumers, consumer)
}
func (d *ProposalViolationDistributor) OnInvalidBlockDetected(err flow.Slashable[model.InvalidProposalError]) {
d.lock.RLock()
defer d.lock.RUnlock()
for _, subscriber := range d.consumers {
subscriber.OnInvalidBlockDetected(err)
}
}
func (d *ProposalViolationDistributor) OnDoubleProposeDetected(block1, block2 *model.Block) {
d.lock.RLock()
defer d.lock.RUnlock()
for _, subscriber := range d.consumers {
subscriber.OnDoubleProposeDetected(block1, block2)
}
}