Skip to content

Commit 1defba5

Browse files
author
Marko Vukolic
committed
sbft: amplify view-change from abdicating primary
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 <[email protected]>
1 parent fe16a6d commit 1defba5

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed

orderer/sbft/simplebft/simplebft_test.go

+58
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,64 @@ func TestRestart(t *testing.T) {
531531
}
532532
}
533533

534+
func TestAbdicatingPrimary(t *testing.T) {
535+
N := uint64(4)
536+
sys := newTestSystem(N)
537+
var repls []*SBFT
538+
var adapters []*testSystemAdapter
539+
for i := uint64(0); i < N; i++ {
540+
a := sys.NewAdapter(i)
541+
s, err := New(i, &Config{N: N, F: 1, BatchDurationNsec: 2000000000, BatchSizeBytes: 10, RequestTimeoutNsec: 20000000000}, a)
542+
if err != nil {
543+
t.Fatal(err)
544+
}
545+
repls = append(repls, s)
546+
adapters = append(adapters, a)
547+
}
548+
549+
phase := 1
550+
// Dropping all phase 1 msgs except requests and viewchange to 0
551+
// (preprepare to primary 0 is automatically delivered)
552+
sys.filterFn = func(e testElem) (testElem, bool) {
553+
if phase == 1 {
554+
if msg, ok := e.ev.(*testMsgEvent); ok {
555+
if c := msg.msg.GetRequest(); c != nil {
556+
return e, true
557+
}
558+
if c := msg.msg.GetViewChange(); c != nil && msg.dst == 0 {
559+
return e, true
560+
}
561+
return e, false
562+
}
563+
return e, true
564+
}
565+
return e, true
566+
}
567+
568+
connectAll(sys)
569+
570+
r1 := []byte{1, 2, 3}
571+
repls[0].Request(r1)
572+
sys.Run()
573+
574+
phase = 2
575+
576+
testLog.Notice("TEST: restarting connections from 0")
577+
for _, a := range adapters {
578+
if a.id != 0 {
579+
a.receiver.Connection(0)
580+
adapters[0].receiver.Connection(a.id)
581+
}
582+
}
583+
584+
sys.Run()
585+
for _, a := range adapters {
586+
if len(a.batches) != 1 {
587+
t.Fatalf("expected execution of 1 batch, %d got %v", a.id, a.batches)
588+
}
589+
}
590+
}
591+
534592
func TestRestartAfterPrepare(t *testing.T) {
535593
N := uint64(4)
536594
sys := newTestSystem(N)

orderer/sbft/simplebft/viewchange.go

+7
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,13 @@ func (s *SBFT) handleViewChange(svc *Signed, src uint64) {
8484
s.replicaState[src].signedViewchange = svc
8585

8686
min := vc.View
87+
88+
//amplify current primary abdication
89+
if s.view == min-1 && s.primaryID() == src {
90+
s.sendViewChange()
91+
return
92+
}
93+
8794
quorum := 0
8895
for _, state := range s.replicaState {
8996
if state.viewchange != nil {

0 commit comments

Comments
 (0)