Skip to content

Commit c163c86

Browse files
corecodeSimon Schubert
authored and
Simon Schubert
committed
sbft: send view change message on reconnect
Change-Id: Iaff9f6deb1ebb727e5d262d2efb9f9bfd5252944 Signed-off-by: Simon Schubert <[email protected]>
1 parent 252d630 commit c163c86

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed

orderer/sbft/simplebft/connection.go

+5
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ func (s *SBFT) Connection(replica uint64) {
2929
}
3030
s.sys.Send(&Msg{&Msg_Hello{hello}}, replica)
3131

32+
svc := s.replicaState[s.id].signedViewchange
33+
if svc != nil {
34+
s.sys.Send(&Msg{&Msg_ViewChange{svc}}, replica)
35+
}
36+
3237
// A reconnecting replica can play forward its blockchain to
3338
// the batch listed in the hello message. However, the
3439
// currently in-flight batch will not be reflected in the

orderer/sbft/simplebft/simplebft_test.go

+59
Original file line numberDiff line numberDiff line change
@@ -885,3 +885,62 @@ func TestViewChangeTimer(t *testing.T) {
885885
}
886886
}
887887
}
888+
889+
func TestResendViewChange(t *testing.T) {
890+
N := uint64(4)
891+
sys := newTestSystem(N)
892+
var repls []*SBFT
893+
var adapters []*testSystemAdapter
894+
for i := uint64(0); i < N; i++ {
895+
a := sys.NewAdapter(i)
896+
s, err := New(i, &Config{N: N, F: 1, BatchDurationNsec: 2000000000, BatchSizeBytes: 10, RequestTimeoutNsec: 20000000000}, a)
897+
if err != nil {
898+
t.Fatal(err)
899+
}
900+
repls = append(repls, s)
901+
adapters = append(adapters, a)
902+
}
903+
904+
phase := make(map[uint64]int)
905+
906+
// prevent first view change from being delivered
907+
sys.filterFn = func(e testElem) (testElem, bool) {
908+
if msg, ok := e.ev.(*testMsgEvent); ok {
909+
if msg.dst == msg.src {
910+
return e, true
911+
} else if phase[msg.src] == 0 && msg.msg.GetViewChange() != nil {
912+
return e, false
913+
} else if msg.msg.GetHello() != nil {
914+
phase[msg.src] = 1
915+
}
916+
}
917+
918+
return e, true
919+
}
920+
921+
for _, r := range repls {
922+
r.sendViewChange()
923+
}
924+
sys.Run()
925+
926+
connectAll(sys)
927+
r1 := []byte{1, 2, 3}
928+
repls[0].Request(r1)
929+
sys.Run()
930+
r2 := []byte{3, 1, 2}
931+
r3 := []byte{3, 5, 2}
932+
repls[1].Request(r2)
933+
repls[1].Request(r3)
934+
sys.Run()
935+
for _, a := range adapters {
936+
if len(a.batches) != 3 {
937+
t.Fatal("expected execution of 2 batches")
938+
}
939+
if !reflect.DeepEqual([][]byte{r1}, a.batches[1].Payloads) {
940+
t.Error("wrong request executed (1)")
941+
}
942+
if !reflect.DeepEqual([][]byte{r2, r3}, a.batches[2].Payloads) {
943+
t.Error("wrong request executed (2)")
944+
}
945+
}
946+
}

0 commit comments

Comments
 (0)