Skip to content

Commit 1cf8500

Browse files
author
Marko Vukolic
committed
fix sbft backlog issue (#2)
Currently sbft backlog automatically places a message from a replica in the backlog, if there is already in the backlog a message from that replica. This is wrong and makes the new test TestBacklogReordering fail. Change-Id: I4ae40552ad363e4005817e328857caee266588a2 Signed-off-by: Marko Vukolic <[email protected]>
1 parent d148c38 commit 1cf8500

File tree

3 files changed

+53
-9
lines changed

3 files changed

+53
-9
lines changed

orderer/sbft/simplebft/backlog.go

-8
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,6 @@ import "fmt"
2121
const maxBacklogSeq = 4
2222
const msgPerSeq = 3 // (pre)prepare, commit, checkpoint
2323

24-
func (s *SBFT) testBacklog(m *Msg, src uint64) bool {
25-
if len(s.replicaState[src].backLog) > 0 {
26-
return true
27-
}
28-
29-
return s.testBacklogMessage(m, src)
30-
}
31-
3224
func (s *SBFT) testBacklogMessage(m *Msg, src uint64) bool {
3325
record := func(seq *SeqView) bool {
3426
if !s.activeView {

orderer/sbft/simplebft/simplebft.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ func (s *SBFT) Receive(m *Msg, src uint64) {
202202
return
203203
}
204204

205-
if s.testBacklog(m, src) {
205+
if s.testBacklogMessage(m, src) {
206206
log.Debugf("replica %d: message for future seq, storing for later", s.id)
207207
s.recordBacklogMsg(m, src)
208208
return

orderer/sbft/simplebft/simplebft_test.go

+52
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,58 @@ func TestMsgReordering(t *testing.T) {
311311
}
312312
}
313313

314+
func TestBacklogReordering(t *testing.T) {
315+
N := uint64(4)
316+
sys := newTestSystem(N)
317+
var repls []*SBFT
318+
var adapters []*testSystemAdapter
319+
for i := uint64(0); i < N; i++ {
320+
a := sys.NewAdapter(i)
321+
s, err := New(i, &Config{N: N, F: 1, BatchDurationNsec: 2000000000, BatchSizeBytes: 1, RequestTimeoutNsec: 20000000000}, a)
322+
if err != nil {
323+
t.Fatal(err)
324+
}
325+
repls = append(repls, s)
326+
adapters = append(adapters, a)
327+
}
328+
329+
var preprep *testMsgEvent
330+
331+
// forcing pre-prepare from primary 0 to reach replica 1 after some delay
332+
// effectivelly delivering pre-prepare instead of checkpoint
333+
sys.filterFn = func(e testElem) (testElem, bool) {
334+
if msg, ok := e.ev.(*testMsgEvent); ok {
335+
if msg.src == 0 && msg.dst == 1 {
336+
c := msg.msg.GetPreprepare()
337+
if c != nil && c.Seq.View == 0 {
338+
preprep = msg //memorizing pre-prepare
339+
return e, false // but dropping it
340+
}
341+
d := msg.msg.GetCheckpoint()
342+
if d != nil {
343+
msg.msg = &Msg{&Msg_Preprepare{preprep.msg.GetPreprepare()}}
344+
return e, true //and delivering it
345+
}
346+
return e, true //letting prepare and commit from 0 to 1 pass
347+
}
348+
}
349+
return e, true
350+
}
351+
352+
connectAll(sys)
353+
r1 := []byte{1, 2, 3}
354+
repls[0].Request(r1)
355+
sys.Run()
356+
for _, a := range adapters {
357+
if len(a.batches) != 1 {
358+
t.Fatal("expected execution of 1 batch")
359+
}
360+
if !reflect.DeepEqual([][]byte{r1}, a.batches[0].Payloads) {
361+
t.Error("wrong request executed (1)")
362+
}
363+
}
364+
}
365+
314366
func TestViewChangeWithRetransmission(t *testing.T) {
315367
N := uint64(4)
316368
sys := newTestSystem(N)

0 commit comments

Comments
 (0)