Skip to content

Commit 0e3a6cf

Browse files
author
Marko Vukolic
committed
fix acceptance of sbft new-view messages
per pbft protocol, new-view messages for old views must not be processed. It is not clear if there was a bug, but with this changeset the implementation is more streamlined and slightly optimized. Change-Id: Idbd9e9fdb883516dcf142ef7bdf56794313c8352 Signed-off-by: Marko Vukolic <[email protected]>
1 parent 2b53f2a commit 0e3a6cf

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

orderer/sbft/simplebft/connection.go

+3-5
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ func (s *SBFT) handleHello(h *Hello, src uint64) {
7575
s.deliverBatch(h.Batch)
7676
}
7777

78-
if h.NewView != nil {
78+
if h.NewView != nil && s.view <= h.NewView.View {
7979
if s.primaryIDView(h.NewView.View) != src {
8080
log.Warningf("replica %d: invalid hello with new view from non-primary %d", s.id, src)
8181
return
@@ -93,10 +93,8 @@ func (s *SBFT) handleHello(h *Hello, src uint64) {
9393
return
9494
}
9595

96-
if s.view <= h.NewView.View {
97-
s.view = h.NewView.View
98-
s.activeView = true
99-
}
96+
s.view = h.NewView.View
97+
s.activeView = true
10098

10199
s.maybeDeliverUsingXset(h.NewView)
102100
}

orderer/sbft/simplebft/newview.go

+11-9
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,18 @@ func (s *SBFT) checkNewViewSignatures(nv *NewView) ([]*ViewChange, error) {
8686
}
8787

8888
func (s *SBFT) handleNewView(nv *NewView, src uint64) {
89-
if src != s.primaryIDView(nv.View) {
90-
log.Warningf("replica %d: invalid new view from %d for %d", s.id, src, nv.View)
89+
if nv.View < s.view {
90+
log.Debugf("replica %d: discarding old new view from %d for %d, we are in %d", s.id, src, nv.View, s.view)
9191
return
9292
}
9393

94-
if onv := s.replicaState[s.primaryIDView(nv.View)].newview; onv != nil && onv.View >= nv.View {
95-
log.Debugf("replica %d: discarding duplicate new view for %d", s.id, nv.View)
94+
if nv.View == s.view && s.activeView {
95+
log.Debugf("replica %d: discarding new view from %d for %d, we are already active in %d", s.id, src, nv.View, s.view)
96+
return
97+
}
98+
99+
if src != s.primaryIDView(nv.View) {
100+
log.Warningf("replica %d: invalid new view from %d for %d", s.id, src, nv.View)
96101
return
97102
}
98103

@@ -135,11 +140,8 @@ func (s *SBFT) handleNewView(nv *NewView, src uint64) {
135140
}
136141

137142
s.replicaState[s.primaryIDView(nv.View)].newview = nv
138-
139-
if nv.View > s.view {
140-
s.view = nv.View
141-
s.activeView = false
142-
}
143+
s.view = nv.View
144+
s.activeView = false
143145

144146
s.processNewView()
145147
}

0 commit comments

Comments
 (0)