@@ -108,8 +108,6 @@ type Controller struct {
108
108
stopWG sync.WaitGroup
109
109
110
110
deliverChan chan struct {}
111
-
112
- viewReadyChan chan struct {}
113
111
}
114
112
115
113
func (c * Controller ) iAmTheLeader () bool {
@@ -143,7 +141,7 @@ func (c *Controller) ProcessMessages(sender uint64, m *protos.Message) {
143
141
// TODO the msg can be a view change message or a tx req coming from a node after a timeout
144
142
}
145
143
146
- func (c * Controller ) startView (proposalSequence uint64 ) {
144
+ func (c * Controller ) startView (proposalSequence uint64 ) Future {
147
145
// TODO view builder according to metadata returned by sync
148
146
view := View {
149
147
N : c .N ,
@@ -164,11 +162,8 @@ func (c *Controller) startView(proposalSequence uint64) {
164
162
c .viewLock .Lock ()
165
163
c .currView = view
166
164
c .Logger .Debugf ("Starting view with number %d" , atomic .LoadUint64 (& c .currViewNumber ))
167
- end := c .currView .Start ()
168
165
c .viewLock .Unlock ()
169
- c .viewReadyChan <- struct {}{}
170
- end .Wait ()
171
- c .viewAbortChan <- struct {}{}
166
+ return c .currView .Start ()
172
167
}
173
168
174
169
func (c * Controller ) viewAbort () {
@@ -181,14 +176,15 @@ func (c *Controller) viewAbort() {
181
176
182
177
func (c * Controller ) startNewView (newViewNumber uint64 , newProposalSequence uint64 ) {
183
178
atomic .StoreUint64 (& c .currViewNumber , newViewNumber )
179
+ end := c .startView (newProposalSequence )
184
180
c .stopWG .Add (1 )
185
181
go func () {
186
182
defer c .stopWG .Done ()
187
- c .startView (newProposalSequence )
183
+ end .Wait ()
184
+ c .viewAbortChan <- struct {}{}
188
185
}()
189
- <- c .viewReadyChan
190
186
if c .iAmTheLeader () {
191
- c .Logger .Debugf ("Starting leader thread" )
187
+ c .Logger .Debugf ("Starting leader thread in view %d" , atomic . LoadUint64 ( & c . currViewNumber ) )
192
188
c .stopWG .Add (1 )
193
189
go func () {
194
190
defer c .stopWG .Done ()
@@ -262,7 +258,6 @@ func (c *Controller) Start(startViewNumber uint64, startProposalSequence uint64)
262
258
c .viewAbortChan = make (chan struct {})
263
259
c .stopChan = make (chan struct {})
264
260
c .deliverChan = make (chan struct {})
265
- c .viewReadyChan = make (chan struct {})
266
261
c .quorum = c .computeQuorum ()
267
262
c .startNewView (startViewNumber , startProposalSequence )
268
263
return & c .stopWG
0 commit comments