Skip to content

Commit 8b0a736

Browse files
authored
Merge pull request hyperledger-labs#74 from HagarMeir/master
get rid of viewReadyChan
2 parents fdacb8c + 6c348c5 commit 8b0a736

File tree

2 files changed

+7
-12
lines changed

2 files changed

+7
-12
lines changed

internal/bft/controller.go

+6-11
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,6 @@ type Controller struct {
108108
stopWG sync.WaitGroup
109109

110110
deliverChan chan struct{}
111-
112-
viewReadyChan chan struct{}
113111
}
114112

115113
func (c *Controller) iAmTheLeader() bool {
@@ -143,7 +141,7 @@ func (c *Controller) ProcessMessages(sender uint64, m *protos.Message) {
143141
// TODO the msg can be a view change message or a tx req coming from a node after a timeout
144142
}
145143

146-
func (c *Controller) startView(proposalSequence uint64) {
144+
func (c *Controller) startView(proposalSequence uint64) Future {
147145
// TODO view builder according to metadata returned by sync
148146
view := View{
149147
N: c.N,
@@ -164,11 +162,8 @@ func (c *Controller) startView(proposalSequence uint64) {
164162
c.viewLock.Lock()
165163
c.currView = view
166164
c.Logger.Debugf("Starting view with number %d", atomic.LoadUint64(&c.currViewNumber))
167-
end := c.currView.Start()
168165
c.viewLock.Unlock()
169-
c.viewReadyChan <- struct{}{}
170-
end.Wait()
171-
c.viewAbortChan <- struct{}{}
166+
return c.currView.Start()
172167
}
173168

174169
func (c *Controller) viewAbort() {
@@ -181,14 +176,15 @@ func (c *Controller) viewAbort() {
181176

182177
func (c *Controller) startNewView(newViewNumber uint64, newProposalSequence uint64) {
183178
atomic.StoreUint64(&c.currViewNumber, newViewNumber)
179+
end := c.startView(newProposalSequence)
184180
c.stopWG.Add(1)
185181
go func() {
186182
defer c.stopWG.Done()
187-
c.startView(newProposalSequence)
183+
end.Wait()
184+
c.viewAbortChan <- struct{}{}
188185
}()
189-
<-c.viewReadyChan
190186
if c.iAmTheLeader() {
191-
c.Logger.Debugf("Starting leader thread")
187+
c.Logger.Debugf("Starting leader thread in view %d", atomic.LoadUint64(&c.currViewNumber))
192188
c.stopWG.Add(1)
193189
go func() {
194190
defer c.stopWG.Done()
@@ -262,7 +258,6 @@ func (c *Controller) Start(startViewNumber uint64, startProposalSequence uint64)
262258
c.viewAbortChan = make(chan struct{})
263259
c.stopChan = make(chan struct{})
264260
c.deliverChan = make(chan struct{})
265-
c.viewReadyChan = make(chan struct{})
266261
c.quorum = c.computeQuorum()
267262
c.startNewView(startViewNumber, startProposalSequence)
268263
return &c.stopWG

internal/bft/controller_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ func TestLeaderPropose(t *testing.T) {
162162
commit3Get := commit3.GetCommit()
163163
commit3Get.Signature.Signer = 3
164164
appWG.Add(1) // deliver
165-
commWG.Add(1) // next proposal
165+
commWG.Add(2) // next proposal
166166
controller.ProcessMessages(3, commit3)
167167
appWG.Wait()
168168
commWG.Wait()

0 commit comments

Comments
 (0)