Skip to content

Commit c5c4477

Browse files
committed
remove printf
1 parent e710a92 commit c5c4477

File tree

4 files changed

+45
-22
lines changed

4 files changed

+45
-22
lines changed

epoch.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,8 @@ func (e *Epoch) HandleMessage(msg *Message, from NodeID) error {
135135
return e.handleEmptyVoteMessage(msg.EmptyVoteMessage, from)
136136
case msg.Notarization != nil:
137137
return e.handleNotarizationMessage(msg.Notarization, from)
138-
//case msg.EmptyNotarization != nil:
139-
// return e.handleEmptyNotarizationMessage(msg.EmptyNotarization, from)
138+
// case msg.EmptyNotarization != nil:
139+
// return e.handleEmptyNotarizationMessage(msg.EmptyNotarization, from)
140140
case msg.Finalization != nil:
141141
return e.handleFinalizationMessage(msg.Finalization, from)
142142
case msg.FinalizationCertificate != nil:
@@ -1561,6 +1561,7 @@ func (e *Epoch) triggerProposalWaitTimeExpired(round uint64) {
15611561
}
15621562
e.Logger.Debug("Persisted empty vote to WAL",
15631563
zap.Uint64("round", round),
1564+
zap.Uint64("round from metadata", e.metadata().Round),
15641565
zap.Int("size", len(emptyVoteRecord)))
15651566

15661567
emptyVotes := e.getOrCreateEmptyVoteSetForRound(round)
@@ -1583,7 +1584,6 @@ func (e *Epoch) monitorProgress(round uint64) {
15831584
proposalWaitTimeExpired := func() {
15841585
e.lock.Lock()
15851586
defer e.lock.Unlock()
1586-
15871587
e.triggerProposalWaitTimeExpired(round)
15881588
}
15891589

epoch_multinode_test.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"simplex/wal"
1414
"sync"
1515
"testing"
16+
"time"
1617

1718
"github.com/stretchr/testify/require"
1819
)
@@ -102,6 +103,7 @@ func defaultTestNodeEpochConfig(t *testing.T, nodeID NodeID, net *inMemNetwork,
102103
BlockDeserializer: &blockDeserializer{},
103104
QCDeserializer: &testQCDeserializer{t: t},
104105
ReplicationEnabled: replicationEnabled,
106+
StartTime: time.Now(),
105107
}
106108
return conf
107109
}
@@ -278,20 +280,20 @@ func (c *testComm) Broadcast(msg *Message) {
278280
}
279281

280282
type inMemNetwork struct {
281-
t *testing.T
282-
nodes []NodeID
283-
instances []*testNode
284-
lock sync.Mutex
283+
t *testing.T
284+
nodes []NodeID
285+
instances []*testNode
286+
lock sync.Mutex
285287
disconnected map[string]struct{}
286288
}
287289

288290
// newInMemNetwork creates an in-memory network. Node IDs must be provided before
289291
// adding instances, as nodes require prior knowledge of all participants.
290292
func newInMemNetwork(t *testing.T, nodes []NodeID) *inMemNetwork {
291293
net := &inMemNetwork{
292-
t: t,
293-
nodes: nodes,
294-
instances: make([]*testNode, 0),
294+
t: t,
295+
nodes: nodes,
296+
instances: make([]*testNode, 0),
295297
disconnected: make(map[string]struct{}),
296298
}
297299
return net
@@ -353,7 +355,7 @@ func newTestControlledBlockBuilder(t *testing.T) *testControlledBlockBuilder {
353355
return &testControlledBlockBuilder{
354356
t: t,
355357
control: make(chan struct{}, 1),
356-
testBlockBuilder: testBlockBuilder{out: make(chan *testBlock, 1)},
358+
testBlockBuilder: testBlockBuilder{out: make(chan *testBlock, 1), blockShouldBeBuilt: make(chan struct{}, 1)},
357359
}
358360
}
359361

@@ -366,7 +368,6 @@ func (t *testControlledBlockBuilder) triggerNewBlock() {
366368
}
367369

368370
func (t *testControlledBlockBuilder) BuildBlock(ctx context.Context, metadata ProtocolMetadata) (Block, bool) {
369-
require.Equal(t.t, metadata.Seq, metadata.Round)
370371
<-t.control
371372
return t.testBlockBuilder.BuildBlock(ctx, metadata)
372373
}

epoch_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -734,6 +734,7 @@ func (t *testBlockBuilder) IncomingBlock(ctx context.Context) {
734734
case <-t.blockShouldBeBuilt:
735735
case <-ctx.Done():
736736
}
737+
737738
}
738739

739740
type testBlock struct {

replication_test.go

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"simplex"
1010
"simplex/testutil"
1111
"simplex/wal"
12+
"time"
1213

1314
"testing"
1415

@@ -181,17 +182,22 @@ func TestReplicationAfterNodeDisconnects(t *testing.T) {
181182
net := newInMemNetwork(t, nodes)
182183
startDisconnect := uint64(5)
183184
endDisconnect := uint64(18)
184-
185-
normalNode1 := newSimplexNode(t, nodes[0], net, bb, true)
186-
normalNode2 := newSimplexNode(t, nodes[1], net, bb, true)
187-
normalNode3 := newSimplexNode(t, nodes[2], net, bb, true)
188-
laggingNode := newSimplexNode(t, nodes[3], net, bb, true)
185+
normalNode1 := newSimplexNode(t, nodes[0], net, bb, false)
186+
normalNode2 := newSimplexNode(t, nodes[1], net, bb, false)
187+
normalNode3 := newSimplexNode(t, nodes[2], net, bb, false)
188+
laggingNode := newSimplexNode(t, nodes[3], net, bb, false)
189189

190190
require.Equal(t, uint64(0), normalNode1.storage.Height())
191191
require.Equal(t, uint64(0), normalNode2.storage.Height())
192192
require.Equal(t, uint64(0), normalNode3.storage.Height())
193193
require.Equal(t, uint64(0), laggingNode.storage.Height())
194194

195+
epochTimes := make([]time.Time, 0, 4)
196+
for _, n := range net.instances {
197+
epochTimes = append(epochTimes, n.e.StartTime)
198+
n.start()
199+
}
200+
195201
bb.triggerNewBlock()
196202

197203
net.startInstances()
@@ -212,13 +218,17 @@ func TestReplicationAfterNodeDisconnects(t *testing.T) {
212218
// lagging node disconnects
213219
net.Disconnect(nodes[3])
214220

221+
missedSeqs := uint64(0)
215222
// normal nodes continue to make progress
216223
for i := startDisconnect; i < endDisconnect; i++ {
217-
if bytes.Equal(simplex.LeaderForRound(nodes, i), nodes[3]) {
218-
// TODO: build empty block
219-
}
220-
for _, n := range net.instances[:3] {
221-
n.storage.waitForBlockCommit(i)
224+
emptyRound := bytes.Equal(simplex.LeaderForRound(nodes, i), nodes[3])
225+
if emptyRound {
226+
advanceWithoutLeader(t, net, bb, epochTimes)
227+
missedSeqs++
228+
} else {
229+
for _, n := range net.instances[:3] {
230+
n.storage.waitForBlockCommit(i - missedSeqs)
231+
}
222232
}
223233
bb.triggerNewBlock()
224234
}
@@ -239,6 +249,17 @@ func TestReplicationAfterNodeDisconnects(t *testing.T) {
239249
require.Equal(t, endDisconnect+1, normalNode3.storage.Height())
240250
}
241251

252+
func advanceWithoutLeader(t *testing.T, net *inMemNetwork, bb *testControlledBlockBuilder, epochTimes []time.Time) {
253+
for range net.instances {
254+
bb.blockShouldBeBuilt <- struct{}{}
255+
}
256+
257+
for i, n := range net.instances[:3] {
258+
// advance the round without a leader
259+
waitForBlockProposerTimeout(t, n.e, epochTimes[i])
260+
}
261+
}
262+
242263
func createBlocks(t *testing.T, nodes []simplex.NodeID, bb simplex.BlockBuilder, seqCount uint64) []simplex.FinalizedBlock {
243264
logger := testutil.MakeLogger(t, int(0))
244265
ctx := context.Background()

0 commit comments

Comments
 (0)