-
Notifications
You must be signed in to change notification settings - Fork 4
/
rquorum.go
47 lines (41 loc) · 1004 Bytes
/
rquorum.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
package sbft
import (
"github.com/ibalajiarun/go-consensus/peer/peerpb"
pb "github.com/ibalajiarun/go-consensus/protocols/sbft/sbftpb"
)
type rquorum struct {
s *sbft
msgs map[uint64]map[peerpb.PeerID]*pb.ResultMessage
}
func newRQuorum(s *sbft) *rquorum {
return &rquorum{
s: s,
msgs: make(map[uint64]map[peerpb.PeerID]*pb.ResultMessage),
}
}
func (q *rquorum) log(from peerpb.PeerID, m *pb.ResultMessage) {
if _, exists := q.msgs[m.Id]; !exists {
q.msgs[m.Id] = make(map[peerpb.PeerID]*pb.ResultMessage)
}
if _, exists := q.msgs[m.Id][from]; !exists {
q.msgs[m.Id][from] = m
} else {
q.s.logger.Fatalf("multiple messages vcSender same replica %d", from)
}
}
// Majority quorum satisfied
func (q *rquorum) Majority(m *pb.ResultMessage) bool {
if msgPairs, ok := q.msgs[m.Id]; ok {
if len(msgPairs) <= q.s.f {
return false
}
size := 0
for _, otherMsg := range msgPairs {
if m.Equals(otherMsg) {
size++
}
}
return size > q.s.f
}
return false
}