Skip to content

Commit

Permalink
sbft: amplify view-change from abdicating primary
Browse files Browse the repository at this point in the history
Towards FAB-474, we amplify the view-change when the primary of the current
view sends a view change. In this case there is nothing to wait for and we
proceed to the next view.

Included a test that was failing (falling under FAB-474) but passes now.

Change-Id: Ib5bb5ae827329aa7934c09cacfd6b6474475935c
Signed-off-by: Marko Vukolic <mvu@zurich.ibm.com>
  • Loading branch information
Marko Vukolic committed Dec 13, 2016
1 parent fe16a6d commit 1defba5
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
58 changes: 58 additions & 0 deletions orderer/sbft/simplebft/simplebft_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,64 @@ func TestRestart(t *testing.T) {
}
}

func TestAbdicatingPrimary(t *testing.T) {
N := uint64(4)
sys := newTestSystem(N)
var repls []*SBFT
var adapters []*testSystemAdapter
for i := uint64(0); i < N; i++ {
a := sys.NewAdapter(i)
s, err := New(i, &Config{N: N, F: 1, BatchDurationNsec: 2000000000, BatchSizeBytes: 10, RequestTimeoutNsec: 20000000000}, a)
if err != nil {
t.Fatal(err)
}
repls = append(repls, s)
adapters = append(adapters, a)
}

phase := 1
// Dropping all phase 1 msgs except requests and viewchange to 0
// (preprepare to primary 0 is automatically delivered)
sys.filterFn = func(e testElem) (testElem, bool) {
if phase == 1 {
if msg, ok := e.ev.(*testMsgEvent); ok {
if c := msg.msg.GetRequest(); c != nil {
return e, true
}
if c := msg.msg.GetViewChange(); c != nil && msg.dst == 0 {
return e, true
}
return e, false
}
return e, true
}
return e, true
}

connectAll(sys)

r1 := []byte{1, 2, 3}
repls[0].Request(r1)
sys.Run()

phase = 2

testLog.Notice("TEST: restarting connections from 0")
for _, a := range adapters {
if a.id != 0 {
a.receiver.Connection(0)
adapters[0].receiver.Connection(a.id)
}
}

sys.Run()
for _, a := range adapters {
if len(a.batches) != 1 {
t.Fatalf("expected execution of 1 batch, %d got %v", a.id, a.batches)
}
}
}

func TestRestartAfterPrepare(t *testing.T) {
N := uint64(4)
sys := newTestSystem(N)
Expand Down
7 changes: 7 additions & 0 deletions orderer/sbft/simplebft/viewchange.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,13 @@ func (s *SBFT) handleViewChange(svc *Signed, src uint64) {
s.replicaState[src].signedViewchange = svc

min := vc.View

//amplify current primary abdication
if s.view == min-1 && s.primaryID() == src {
s.sendViewChange()
return
}

quorum := 0
for _, state := range s.replicaState {
if state.viewchange != nil {
Expand Down

0 comments on commit 1defba5

Please sign in to comment.