@@ -86,6 +86,10 @@ func (s *SBFT) checkNewViewSignatures(nv *NewView) ([]*ViewChange, error) {
86
86
}
87
87
88
88
func (s * SBFT ) handleNewView (nv * NewView , src uint64 ) {
89
+ if nv == nil {
90
+ return
91
+ }
92
+
89
93
if nv .View < s .view {
90
94
log .Debugf ("replica %d: discarding old new view from %d for %d, we are in %d" , s .id , src , nv .View , s .view )
91
95
return
@@ -108,7 +112,7 @@ func (s *SBFT) handleNewView(nv *NewView, src uint64) {
108
112
return
109
113
}
110
114
111
- xset , _ , ok := s .makeXset (vcs )
115
+ xset , prevBatch , ok := s .makeXset (vcs )
112
116
113
117
if ! ok || ! reflect .DeepEqual (nv .Xset , xset ) {
114
118
log .Warningf ("replica %d: invalid new view from %d: xset incorrect: %v, %v" , s .id , src , nv .Xset , xset )
@@ -139,36 +143,26 @@ func (s *SBFT) handleNewView(nv *NewView, src uint64) {
139
143
}
140
144
}
141
145
142
- s .replicaState [s .primaryIDView (nv .View )].newview = nv
143
146
s .view = nv .View
144
- s .activeView = false
145
-
146
- s .processNewView ()
147
- }
148
-
149
- func (s * SBFT ) processNewView () {
150
- if s .activeView {
151
- return
152
- }
147
+ s .discardBacklog (s .primaryID ())
153
148
154
- nv := s .replicaState [s .primaryIDView (s .view )].newview
155
- if nv == nil || nv .View != s .view {
156
- return
149
+ // maybe deliver using xset
150
+ if s .sys .LastBatch ().DecodeHeader ().Seq < prevBatch .DecodeHeader ().Seq {
151
+ if prevBatch .DecodeHeader ().Seq == s .cur .subject .Seq .Seq {
152
+ // we just received a signature set for a request which we preprepared, but never delivered.
153
+ prevBatch .Payloads = s .cur .preprep .Batch .Payloads
154
+ }
155
+ s .deliverBatch (prevBatch )
157
156
}
158
157
158
+ // after a new-view message, prepare to accept new requests.
159
159
s .activeView = true
160
- s .discardBacklog (s .primaryID ())
161
-
162
- s .maybeDeliverUsingXset (nv )
163
-
164
- // By now we cannot be waiting for any more outstanding
165
- // messages. after a new-view message, by definition all
166
- // activity has acquiesced. Prepare to accept a new request.
167
160
s .cur .checkpointDone = true
168
161
s .cur .subject .Seq .Seq = 0
169
162
170
163
log .Infof ("replica %d now active in view %d; primary: %v" , s .id , s .view , s .isPrimary ())
171
164
165
+ //process pre-prepare if piggybacked to new-view
172
166
if nv .Batch != nil {
173
167
pp := & Preprepare {
174
168
Seq : & SeqView {Seq : nv .Batch .DecodeHeader ().Seq , View : s .view },
@@ -184,23 +178,3 @@ func (s *SBFT) processNewView() {
184
178
185
179
s .processBacklog ()
186
180
}
187
-
188
- func (s * SBFT ) maybeDeliverUsingXset (nv * NewView ) {
189
- // TODO we could cache vcs in replicaState
190
- vcs , err := s .checkNewViewSignatures (nv )
191
- if err != nil {
192
- panic (err )
193
- }
194
-
195
- _ , prevBatch , ok := s .makeXset (vcs )
196
- if ! ok {
197
- panic ("invalid newview" )
198
- }
199
- if s .sys .LastBatch ().DecodeHeader ().Seq < prevBatch .DecodeHeader ().Seq {
200
- if prevBatch .DecodeHeader ().Seq == s .cur .subject .Seq .Seq {
201
- // we just received a signature set for a request which we preprepared, but never delivered.
202
- prevBatch .Payloads = s .cur .preprep .Batch .Payloads
203
- }
204
- s .deliverBatch (prevBatch )
205
- }
206
- }
0 commit comments