@@ -2,7 +2,6 @@ package simplex_test
22
33import (
44 "context"
5- "fmt"
65 "testing"
76 "time"
87
@@ -132,147 +131,146 @@ func TestFinalizeSameSequence(t *testing.T) {
132131 require .Equal (t , uint64 (3 ), e .Metadata ().Round )
133132}
134133
135-
136- func TestFinalizeSameSequenceGap (t * testing.T ) {
137- nodes := []NodeID {{1 }, {2 }, {3 }, {4 }}
138-
139- // for numEmpty := range uint64(5) {
140- // for numNotarizations := range uint64(5) {
141- // leader := LeaderForRound(nodes, 1 + numEmpty + numNotarizations)
142- // if leader.Equals(nodes[0]) {
143- // continue
144- // }
145-
146- // for seqToDoubleFinalize := uint64(1); seqToDoubleFinalize <= numNotarizations; seqToDoubleFinalize++ {
147- // t.Run(fmt.Sprintf("empty=%d notarizations=%d seq=%d", numEmpty, numNotarizations, seqToDoubleFinalize), func(t *testing.T) {
148- // t.Parallel()
149- // testFinalizeSameSequenceGap(t, nodes, numEmpty, numNotarizations, seqToDoubleFinalize)
150- // })
151- // }
152- // }
153- // }
154- testFinalizeSameSequenceGap (t , nodes , 3 , 2 , 2 )
155- }
156-
157- func testFinalizeSameSequenceGap (t * testing.T , nodes []NodeID , numEmptyNotarizations uint64 , numNotarizations uint64 , seqToDoubleFinalize uint64 ) {
158- bb := & testutil.TestBlockBuilder {Out : make (chan * testutil.TestBlock , 1 ), BlockShouldBeBuilt : make (chan struct {}, 1 )}
159- ctx := context .Background ()
160- initialBlock := createBlocks (t , nodes , 1 )[0 ]
161- recordingComm := & recordingComm {Communication : testutil .NewNoopComm (nodes ), BroadcastMessages : make (chan * Message , 100 ), SentMessages : make (chan * Message , 100 )}
162- conf , _ , storage := testutil .DefaultTestNodeEpochConfig (t , nodes [0 ], recordingComm , bb )
163- storage .Index (ctx , initialBlock .VerifiedBlock , initialBlock .Finalization )
164-
165- e , err := NewEpoch (conf )
166- require .NoError (t , err )
167-
168- require .NoError (t , e .Start ())
169- require .Equal (t , uint64 (1 ), e .Metadata ().Seq )
170-
171- finalizeVoteSeqs := make (map [uint64 ]* FinalizeVote )
172- finalizeVoteSeqs [0 ] = & FinalizeVote {
173- Finalization : ToBeSignedFinalization {
174- BlockHeader : initialBlock .VerifiedBlock .BlockHeader (),
175- },
176- }
177- notarizationsLeft := numNotarizations
178-
179- for i := uint64 (0 ); i < numEmptyNotarizations ; i ++ {
180- leader := LeaderForRound (e .Comm .Nodes (), e .Metadata ().Round )
181- if e .ID .Equals (leader ) {
182- require .NotZero (t , notarizationsLeft )
183- fVote := advanceWithFinalizeCheck (t , e , recordingComm , bb )
184- finalizeVoteSeqs [fVote .Finalization .Seq ] = fVote
185- notarizationsLeft --
186- i --
187- continue
188- }
189-
190- advanceRoundFromEmpty (t , e )
191- }
192-
193- for range notarizationsLeft {
194- fmt .Println ("epoch round before notarization:" , e .Metadata ().Round )
195- fmt .Println ("epoch seq before notarization:" , e .Metadata ().Seq )
196- fVote := advanceWithFinalizeCheck (t , e , recordingComm , bb )
197- finalizeVoteSeqs [fVote .Finalization .Seq ] = fVote
198- }
199-
200- // require.Equal(t, 1+numEmptyNotarizations+numNotarizations, e.Metadata().Round)
201- // require.Equal(t, 1 + numNotarizations, e.Metadata().Seq)
202-
203- // // clear the recorded messages
204- // for len(recordingComm.BroadcastMessages) > 0 {
205- // <-recordingComm.BroadcastMessages
206- // }
207-
208- // md := ProtocolMetadata{
209- // Round: 1 + numEmptyNotarizations + numNotarizations,
210- // Seq: seqToDoubleFinalize,
211- // Prev: finalizeVoteSeqs[seqToDoubleFinalize-1].Finalization.Digest,
212- // }
213- // _, ok := bb.BuildBlock(context.Background(), md, simplex.Blacklist{
214- // NodeCount: uint16(len(e.EpochConfig.Comm.Nodes())),
215- // })
216- // require.True(t, ok)
217-
218- // block := <-bb.Out
219- // block.OnVerify = func() {
220- // require.Fail(t, "block should not be verified since we don't have empty notarization for round 1")
221- // }
222-
223- // leader := LeaderForRound(e.Comm.Nodes(), 1 + numEmptyNotarizations + numNotarizations)
224- // require.False(t, e.ID.Equals(leader), "leader should not be the epoch node running the test")
225- // // send block from leader
226- // vote, err := testutil.NewTestVote(block, leader)
227- // require.NoError(t, err)
228- // err = e.HandleMessage(&simplex.Message{
229- // BlockMessage: &simplex.BlockMessage{
230- // Vote: *vote,
231- // Block: block,
232- // },
233- // }, leader)
234- // require.NoError(t, err)
235-
236- // // give some time for block to be (not)verified
237- // time.Sleep(100 * time.Millisecond)
238- // verified := make(chan struct{}, 1)
239- // block.OnVerify = func() {
240- // verified <- struct{}{}
241- // }
242-
243- // // now lets send empty notarizations seqToDoubleFinalize.round - seqToDoubleFinalize-1.round
244- // startMissingNotarizationRound := finalizeVoteSeqs[seqToDoubleFinalize-1].Finalization.Round + 1
245- // for i := startMissingNotarizationRound; i < md.Round; i++ {
246- // emptyNotarization := testutil.NewEmptyNotarization(nodes, i)
247- // err = e.HandleMessage(&simplex.Message{
248- // EmptyNotarization: emptyNotarization,
249- // }, nodes[3])
250- // require.NoError(t, err)
251- // }
252-
253- // // // TODO: test too large of a gap(should not schedule blocks)
254- // <-verified
255-
256- // // drain any finalize votes that were sent
257- // for len(recordingComm.BroadcastMessages) > 0 {
258- // <-recordingComm.BroadcastMessages
259- // }
260-
261- // // create a notarization and now we should send a finalize vote for seqToDoubleFinalize again
262- // notarization, err := testutil.NewNotarization(e.Logger, e.SignatureAggregator, block, nodes[1:])
263- // require.NoError(t, err)
264- // testutil.InjectTestNotarization(t, e, notarization, nodes[1])
265-
266- // wal.AssertNotarization(block.Metadata.Round)
267-
268- // // wait for finalize votes
269- // for {
270- // msg := <-recordingComm.BroadcastMessages
271- // if msg.FinalizeVote != nil {
272- // require.Equal(t, seqToDoubleFinalize, msg.FinalizeVote.Finalization.Seq)
273- // break
274- // }
275- // }
276-
277- // require.Equal(t, 2 + numEmptyNotarizations + numNotarizations, e.Metadata().Round)
278- }
134+ // func TestFinalizeSameSequenceGap(t *testing.T) {
135+ // nodes := []NodeID{{1}, {2}, {3}, {4}}
136+
137+ // // for numEmpty := range uint64(5) {
138+ // // for numNotarizations := range uint64(5) {
139+ // // leader := LeaderForRound(nodes, 1 + numEmpty + numNotarizations)
140+ // // if leader.Equals(nodes[0]) {
141+ // // continue
142+ // // }
143+
144+ // // for seqToDoubleFinalize := uint64(1); seqToDoubleFinalize <= numNotarizations; seqToDoubleFinalize++ {
145+ // // t.Run(fmt.Sprintf("empty=%d notarizations=%d seq=%d", numEmpty, numNotarizations, seqToDoubleFinalize), func(t *testing.T) {
146+ // // t.Parallel()
147+ // // testFinalizeSameSequenceGap(t, nodes, numEmpty, numNotarizations, seqToDoubleFinalize)
148+ // // })
149+ // // }
150+ // // }
151+ // // }
152+ // testFinalizeSameSequenceGap(t, nodes, 3, 2, 2)
153+ // }
154+
155+ // func testFinalizeSameSequenceGap(t *testing.T, nodes []NodeID, numEmptyNotarizations uint64, numNotarizations uint64, seqToDoubleFinalize uint64) {
156+ // bb := &testutil.TestBlockBuilder{Out: make(chan *testutil.TestBlock, 1), BlockShouldBeBuilt: make(chan struct{}, 1)}
157+ // ctx := context.Background()
158+ // initialBlock := createBlocks(t, nodes, 1)[0]
159+ // recordingComm := &recordingComm{Communication: testutil.NewNoopComm(nodes), BroadcastMessages: make(chan *Message, 100), SentMessages: make(chan *Message, 100)}
160+ // conf, _, storage := testutil.DefaultTestNodeEpochConfig(t, nodes[0], recordingComm, bb)
161+ // storage.Index(ctx, initialBlock.VerifiedBlock, initialBlock.Finalization)
162+
163+ // e, err := NewEpoch(conf)
164+ // require.NoError(t, err)
165+
166+ // require.NoError(t, e.Start())
167+ // require.Equal(t, uint64(1), e.Metadata().Seq)
168+
169+ // finalizeVoteSeqs := make(map[uint64]*FinalizeVote)
170+ // finalizeVoteSeqs[0] = &FinalizeVote{
171+ // Finalization: ToBeSignedFinalization{
172+ // BlockHeader: initialBlock.VerifiedBlock.BlockHeader(),
173+ // },
174+ // }
175+ // notarizationsLeft := numNotarizations
176+
177+ // for i := uint64(0); i < numEmptyNotarizations; i++ {
178+ // leader := LeaderForRound(e.Comm.Nodes(), e.Metadata().Round)
179+ // if e.ID.Equals(leader) {
180+ // require.NotZero(t, notarizationsLeft)
181+ // fVote := advanceWithFinalizeCheck(t, e, recordingComm, bb)
182+ // finalizeVoteSeqs[fVote.Finalization.Seq] = fVote
183+ // notarizationsLeft--
184+ // i--
185+ // continue
186+ // }
187+
188+ // advanceRoundFromEmpty(t, e)
189+ // }
190+
191+ // for range notarizationsLeft {
192+ // fmt.Println("epoch round before notarization:", e.Metadata().Round)
193+ // fmt.Println("epoch seq before notarization:", e.Metadata().Seq)
194+ // fVote := advanceWithFinalizeCheck(t, e, recordingComm, bb)
195+ // finalizeVoteSeqs[fVote.Finalization.Seq] = fVote
196+ // }
197+
198+ // // require.Equal(t, 1+numEmptyNotarizations+numNotarizations, e.Metadata().Round)
199+ // // require.Equal(t, 1 + numNotarizations, e.Metadata().Seq)
200+
201+ // // // clear the recorded messages
202+ // // for len(recordingComm.BroadcastMessages) > 0 {
203+ // // <-recordingComm.BroadcastMessages
204+ // // }
205+
206+ // // md := ProtocolMetadata{
207+ // // Round: 1 + numEmptyNotarizations + numNotarizations,
208+ // // Seq: seqToDoubleFinalize,
209+ // // Prev: finalizeVoteSeqs[seqToDoubleFinalize-1].Finalization.Digest,
210+ // // }
211+ // // _, ok := bb.BuildBlock(context.Background(), md, simplex.Blacklist{
212+ // // NodeCount: uint16(len(e.EpochConfig.Comm.Nodes())),
213+ // // })
214+ // // require.True(t, ok)
215+
216+ // // block := <-bb.Out
217+ // // block.OnVerify = func() {
218+ // // require.Fail(t, "block should not be verified since we don't have empty notarization for round 1")
219+ // // }
220+
221+ // // leader := LeaderForRound(e.Comm.Nodes(), 1 + numEmptyNotarizations + numNotarizations)
222+ // // require.False(t, e.ID.Equals(leader), "leader should not be the epoch node running the test")
223+ // // // send block from leader
224+ // // vote, err := testutil.NewTestVote(block, leader)
225+ // // require.NoError(t, err)
226+ // // err = e.HandleMessage(&simplex.Message{
227+ // // BlockMessage: &simplex.BlockMessage{
228+ // // Vote: *vote,
229+ // // Block: block,
230+ // // },
231+ // // }, leader)
232+ // // require.NoError(t, err)
233+
234+ // // // give some time for block to be (not)verified
235+ // // time.Sleep(100 * time.Millisecond)
236+ // // verified := make(chan struct{}, 1)
237+ // // block.OnVerify = func() {
238+ // // verified <- struct{}{}
239+ // // }
240+
241+ // // // now lets send empty notarizations seqToDoubleFinalize.round - seqToDoubleFinalize-1.round
242+ // // startMissingNotarizationRound := finalizeVoteSeqs[seqToDoubleFinalize-1].Finalization.Round + 1
243+ // // for i := startMissingNotarizationRound; i < md.Round; i++ {
244+ // // emptyNotarization := testutil.NewEmptyNotarization(nodes, i)
245+ // // err = e.HandleMessage(&simplex.Message{
246+ // // EmptyNotarization: emptyNotarization,
247+ // // }, nodes[3])
248+ // // require.NoError(t, err)
249+ // // }
250+
251+ // // // // TODO: test too large of a gap(should not schedule blocks)
252+ // // <-verified
253+
254+ // // // drain any finalize votes that were sent
255+ // // for len(recordingComm.BroadcastMessages) > 0 {
256+ // // <-recordingComm.BroadcastMessages
257+ // // }
258+
259+ // // // create a notarization and now we should send a finalize vote for seqToDoubleFinalize again
260+ // // notarization, err := testutil.NewNotarization(e.Logger, e.SignatureAggregator, block, nodes[1:])
261+ // // require.NoError(t, err)
262+ // // testutil.InjectTestNotarization(t, e, notarization, nodes[1])
263+
264+ // // wal.AssertNotarization(block.Metadata.Round)
265+
266+ // // // wait for finalize votes
267+ // // for {
268+ // // msg := <-recordingComm.BroadcastMessages
269+ // // if msg.FinalizeVote != nil {
270+ // // require.Equal(t, seqToDoubleFinalize, msg.FinalizeVote.Finalization.Seq)
271+ // // break
272+ // // }
273+ // // }
274+
275+ // // require.Equal(t, 2 + numEmptyNotarizations + numNotarizations, e.Metadata().Round)
276+ // }
0 commit comments