Skip to content

Commit

Permalink
sbft: send view change message on reconnect
Browse files Browse the repository at this point in the history
Change-Id: Iaff9f6deb1ebb727e5d262d2efb9f9bfd5252944
Signed-off-by: Simon Schubert <sis@zurich.ibm.com>
  • Loading branch information
corecode authored and Simon Schubert committed Nov 21, 2016
1 parent 252d630 commit c163c86
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
5 changes: 5 additions & 0 deletions orderer/sbft/simplebft/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ func (s *SBFT) Connection(replica uint64) {
}
s.sys.Send(&Msg{&Msg_Hello{hello}}, replica)

svc := s.replicaState[s.id].signedViewchange
if svc != nil {
s.sys.Send(&Msg{&Msg_ViewChange{svc}}, replica)
}

// A reconnecting replica can play forward its blockchain to
// the batch listed in the hello message. However, the
// currently in-flight batch will not be reflected in the
Expand Down
59 changes: 59 additions & 0 deletions orderer/sbft/simplebft/simplebft_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -885,3 +885,62 @@ func TestViewChangeTimer(t *testing.T) {
}
}
}

func TestResendViewChange(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 := make(map[uint64]int)

// prevent first view change from being delivered
sys.filterFn = func(e testElem) (testElem, bool) {
if msg, ok := e.ev.(*testMsgEvent); ok {
if msg.dst == msg.src {
return e, true
} else if phase[msg.src] == 0 && msg.msg.GetViewChange() != nil {
return e, false
} else if msg.msg.GetHello() != nil {
phase[msg.src] = 1
}
}

return e, true
}

for _, r := range repls {
r.sendViewChange()
}
sys.Run()

connectAll(sys)
r1 := []byte{1, 2, 3}
repls[0].Request(r1)
sys.Run()
r2 := []byte{3, 1, 2}
r3 := []byte{3, 5, 2}
repls[1].Request(r2)
repls[1].Request(r3)
sys.Run()
for _, a := range adapters {
if len(a.batches) != 3 {
t.Fatal("expected execution of 2 batches")
}
if !reflect.DeepEqual([][]byte{r1}, a.batches[1].Payloads) {
t.Error("wrong request executed (1)")
}
if !reflect.DeepEqual([][]byte{r2, r3}, a.batches[2].Payloads) {
t.Error("wrong request executed (2)")
}
}
}

0 comments on commit c163c86

Please sign in to comment.