/
consensus.go
73 lines (67 loc) · 2.25 KB
/
consensus.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
package server
import (
pb "github.com/PomeloCloud/BFTRaft4go/proto/server"
"github.com/PomeloCloud/BFTRaft4go/utils"
)
func (m *RTGroup) prepareApproveChan(groupId uint64, logIndex uint64) {
//cache_key := fmt.Sprint(logIndex)
//if _, existed := s.GroupAppendedLogs.Get(cache_key); !existed {
// s.GroupAppendedLogs.Set(cache_key, make(chan bool, 1), cache.DefaultExpiration)
//}
}
func (m *RTGroup) WaitLogApproved(logIndex uint64) bool {
// TODO: fix wait approved
//s.prepareApproveChan(groupId, logIndex)
//cache_key := fmt.Sprint(groupId, "-", logIndex)
//cache_chan, _ := s.GroupAppendedLogs.Get(cache_key)
//select {
//case approved := <-cache_chan.(chan bool):
// return approved
//case <-time.After(s.Opts.ConsensusTimeout):
// log.Println("wait apprival timeout, group:", groupId, "log:", logIndex)
// return false
//}
return true
}
func (m *RTGroup) SetLogAppended(groupId uint64, logIndex uint64, isApproved bool) {
//m.prepareApproveChan(groupId, logIndex)
//cache_key := fmt.Sprint(groupId, "-", logIndex)
//if c, existed := m.GroupAppendedLogs.Get(cache_key); existed {
// go func() {
// c.(chan bool) <- isApproved
// }()
//}
}
func (m *RTGroup) ExpectedHonestPeers() int {
num_peers := len(m.GroupPeers)
return utils.ExpectedPlayers(num_peers)
}
func (s *BFTRaftServer) PeerApprovedAppend(groupId uint64, logIndex uint64, peer uint64, group_peers []*pb.Peer, isApproved bool) {
//cache_key := fmt.Sprint(groupId, "-", logIndex)
//if _, existed := s.GroupApprovedLogs.Get(cache_key); !existed {
// s.GroupApprovedLogs.Set(cache_key, map[uint64]bool{}, cache.DefaultExpiration)
//}
//approvedPeers, _ := s.GroupApprovedLogs.Get(cache_key)
//approvedPeersMap := approvedPeers.(map[uint64]bool)
//approvedPeersMap[peer] = isApproved
//expectedVotes := ExpectedHonestPeers(group_peers)
//if len(approvedPeersMap) >= expectedVotes {
// approvedVotes := 0
// rejectedVotes := 0
// for _, vote := range approvedPeersMap {
// if vote {
// approvedVotes++
// } else {
// rejectedVotes++
// }
// }
// if approvedVotes >= expectedVotes {
// s.SetLogAppended(groupId, logIndex, true)
// return
// }
// if rejectedVotes >= (len(group_peers) - expectedVotes) {
// s.SetLogAppended(groupId, logIndex, false)
// return
// }
//}
}