Skip to content

Commit

Permalink
fix acceptance of sbft new-view messages
Browse files Browse the repository at this point in the history
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 <mvu@zurich.ibm.com>
  • Loading branch information
Marko Vukolic committed Dec 12, 2016
1 parent 2b53f2a commit 0e3a6cf
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
8 changes: 3 additions & 5 deletions orderer/sbft/simplebft/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func (s *SBFT) handleHello(h *Hello, src uint64) {
s.deliverBatch(h.Batch)
}

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

if s.view <= h.NewView.View {
s.view = h.NewView.View
s.activeView = true
}
s.view = h.NewView.View
s.activeView = true

s.maybeDeliverUsingXset(h.NewView)
}
Expand Down
20 changes: 11 additions & 9 deletions orderer/sbft/simplebft/newview.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,18 @@ func (s *SBFT) checkNewViewSignatures(nv *NewView) ([]*ViewChange, error) {
}

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

if onv := s.replicaState[s.primaryIDView(nv.View)].newview; onv != nil && onv.View >= nv.View {
log.Debugf("replica %d: discarding duplicate new view for %d", s.id, nv.View)
if nv.View == s.view && s.activeView {
log.Debugf("replica %d: discarding new view from %d for %d, we are already active in %d", s.id, src, nv.View, s.view)
return
}

if src != s.primaryIDView(nv.View) {
log.Warningf("replica %d: invalid new view from %d for %d", s.id, src, nv.View)
return
}

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

s.replicaState[s.primaryIDView(nv.View)].newview = nv

if nv.View > s.view {
s.view = nv.View
s.activeView = false
}
s.view = nv.View
s.activeView = false

s.processNewView()
}
Expand Down

0 comments on commit 0e3a6cf

Please sign in to comment.