From b90c11bc1b27fede9595c851ab0a0ebccd753778 Mon Sep 17 00:00:00 2001 From: Matthias <5011972+fasmat@users.noreply.github.com> Date: Wed, 28 Aug 2024 17:23:14 +0000 Subject: [PATCH] Cleanup --- fetch/wire_types.go | 19 ++++++++++--------- hare3/hare_test.go | 10 +++++----- hare4/hare_test.go | 20 +++++++++----------- 3 files changed, 24 insertions(+), 25 deletions(-) diff --git a/fetch/wire_types.go b/fetch/wire_types.go index bd5ce8cc280..964d491289e 100644 --- a/fetch/wire_types.go +++ b/fetch/wire_types.go @@ -120,15 +120,16 @@ type MaliciousIDs struct { } type EpochData struct { - // When changing this value also check - // - the size of `ResponseMessage.Data` above - // - the size of `Response.Data` in `p2p/server/server.go` - // - the size of `NodeIDs` in `MaliciousIDs` above - // - the size of `Set` in `EpochActiveSet` in common/types/activation.go - // - the size of `EligibilityProofs` in the type `Ballot` in common/types/ballot.go - // - the size of `Rewards` in the type `InnerBlock` in common/types/block.go - // - the size of `Ballots` in the type `LayerData` below - // - the size of `Proposals` in the type `Value` in hare3/types.go + // When changing this value also check the size of + // - `ResponseMessage.Data` above + // - `Response.Data` in `p2p/server/server.go` + // - `NodeIDs` in `MaliciousIDs` above + // - `Set` in `EpochActiveSet` in common/types/activation.go + // - `EligibilityProofs` in the type `Ballot` in common/types/ballot.go + // - `Rewards` in the type `InnerBlock` in common/types/block.go + // - `Ballots` in the type `LayerData` below + // - `Proposals` in the type `Value` in hare3/types.go + // - `Proposals` and `CompactProposals` in the type `Value` in hare4/types.go AtxIDs []types.ATXID `scale:"max=8000000"` } diff --git a/hare3/hare_test.go b/hare3/hare_test.go index b53d19e5274..e281034be5e 100644 --- a/hare3/hare_test.go +++ b/hare3/hare_test.go @@ -276,7 +276,7 @@ func withProposals(fraction float64) clusterOpt { } // withSigners creates N signers in addition to regular active nodes. -// this signeres will be partitioned in fair fashion across regular active nodes. +// this signers will be partitioned in fair fashion across regular active nodes. func withSigners(n int) clusterOpt { return func(cluster *lockstepCluster) { cluster.signersCount = n @@ -316,9 +316,7 @@ type lockstepCluster struct { func (cl *lockstepCluster) addNode(n *node) { n.hare.Start() - cl.t.Cleanup(func() { - n.hare.Stop() - }) + cl.t.Cleanup(n.hare.Stop) cl.nodes = append(cl.nodes, n) } @@ -912,7 +910,9 @@ func TestProposals(t *testing.T) { atxsdata.AddFromAtx(&atx, false) } for _, proposal := range tc.proposals { - proposals.Add(proposal) + if err := proposals.Add(proposal); err != nil { + panic(err) + } } for _, id := range tc.malicious { require.NoError(t, identities.SetMalicious(db, id, []byte("non empty"), time.Time{})) diff --git a/hare4/hare_test.go b/hare4/hare_test.go index c0cd80e36d9..48b1ffb27ca 100644 --- a/hare4/hare_test.go +++ b/hare4/hare_test.go @@ -45,8 +45,6 @@ import ( const layersPerEpoch = 4 -var wait = 10 * time.Second - func TestMain(m *testing.M) { types.SetLayersPerEpoch(layersPerEpoch) res := m.Run() @@ -323,7 +321,7 @@ func withProposals(fraction float64) clusterOpt { } // withSigners creates N signers in addition to regular active nodes. -// this signeres will be partitioned in fair fashion across regular active nodes. +// this signers will be partitioned in fair fashion across regular active nodes. func withSigners(n int) clusterOpt { return func(cluster *lockstepCluster) { cluster.signersCount = n @@ -451,7 +449,7 @@ func (cl *lockstepCluster) genProposalNode(lid types.LayerID, node int) { active := cl.activeSet() n := cl.nodes[node] if n.atx == nil { - panic("shouldnt happen") + panic("shouldn't happen") } proposal := &types.Proposal{} proposal.Layer = lid @@ -655,15 +653,15 @@ func sendWithTimeout[T any](t testing.TB, value T, ch chan<- T, timeout time.Dur } func (t *testTracer) waitStopped() types.LayerID { - return waitForChan(t.TB, t.stopped, wait, "didn't stop") + return waitForChan(t.TB, t.stopped, 10*time.Second, "didn't stop") } func (t *testTracer) waitEligibility() []*types.HareEligibility { - return waitForChan(t.TB, t.eligibility, wait, "no eligibility") + return waitForChan(t.TB, t.eligibility, 10*time.Second, "no eligibility") } func (t *testTracer) waitSent() *Message { - return waitForChan(t.TB, t.sent, wait, "no message") + return waitForChan(t.TB, t.sent, 10*time.Second, "no message") } func (*testTracer) OnStart(types.LayerID) {} @@ -676,21 +674,21 @@ func (t *testTracer) OnStop(lid types.LayerID) { } func (t *testTracer) OnActive(el []*types.HareEligibility) { - sendWithTimeout(t.TB, el, t.eligibility, wait, "eligibility can't be sent") + sendWithTimeout(t.TB, el, t.eligibility, 10*time.Second, "eligibility can't be sent") } func (t *testTracer) OnMessageSent(m *Message) { - sendWithTimeout(t.TB, m, t.sent, wait, "message can't be sent") + sendWithTimeout(t.TB, m, t.sent, 10*time.Second, "message can't be sent") } func (*testTracer) OnMessageReceived(*Message) {} func (t *testTracer) OnCompactIdRequest(*CompactIdRequest) { - sendWithTimeout(t.TB, struct{}{}, t.compactReq, wait, "compact req can't be sent") + sendWithTimeout(t.TB, struct{}{}, t.compactReq, 10*time.Second, "compact req can't be sent") } func (t *testTracer) OnCompactIdResponse(*CompactIdResponse) { - sendWithTimeout(t.TB, struct{}{}, t.compactResp, wait, "compact resp can't be sent") + sendWithTimeout(t.TB, struct{}{}, t.compactResp, 10*time.Second, "compact resp can't be sent") } func testHare(t *testing.T, active, inactive, equivocators int, opts ...clusterOpt) {