Skip to content

Commit 01aa635

Browse files
authored
*: qbft flakey test (#4267)
Possible fix for qbft flakey test. Also included golangci-lint changes that appear again and again. category: fixbuild ticket: none
1 parent d92d999 commit 01aa635

File tree

8 files changed

+39
-9
lines changed

8 files changed

+39
-9
lines changed

app/app.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ func Run(ctx context.Context, conf Config) (err error) {
239239
if err != nil {
240240
return err
241241
}
242+
242243
labels["cluster_peer"] = p2p.PeerName(peerID)
243244

244245
// Update cluster_peer label for Loki

app/eth2wrap/cache.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,23 +288,27 @@ func (c *DutiesCache) InvalidateCache(ctx context.Context, epoch eth2p0.Epoch) {
288288
defer c.mu.Unlock()
289289

290290
invalidated := false
291+
291292
for e := range c.proposerDuties {
292293
if e > epoch {
293294
invalidated = true
295+
294296
delete(c.proposerDuties, e)
295297
}
296298
}
297299

298300
for e := range c.attesterDuties {
299301
if e > epoch {
300302
invalidated = true
303+
301304
delete(c.attesterDuties, e)
302305
}
303306
}
304307

305308
for e := range c.syncDuties {
306309
if e > epoch {
307310
invalidated = true
311+
308312
delete(c.syncDuties, e)
309313
}
310314
}
@@ -336,6 +340,7 @@ func (c *DutiesCache) ProposerDutiesCache(ctx context.Context, epoch eth2p0.Epoc
336340
}
337341

338342
missedCacheCount.WithLabelValues("proposer_duties").Inc()
343+
339344
c.mu.Lock()
340345
defer c.mu.Unlock()
341346

@@ -385,6 +390,7 @@ func (c *DutiesCache) AttesterDutiesCache(ctx context.Context, epoch eth2p0.Epoc
385390
}
386391

387392
missedCacheCount.WithLabelValues("attester_duties").Inc()
393+
388394
c.mu.Lock()
389395
defer c.mu.Unlock()
390396

@@ -422,6 +428,7 @@ func (c *DutiesCache) SyncCommDutiesCache(ctx context.Context, epoch eth2p0.Epoc
422428
}
423429

424430
missedCacheCount.WithLabelValues("sync_committee_duties").Inc()
431+
425432
c.mu.Lock()
426433
defer c.mu.Unlock()
427434

@@ -467,10 +474,12 @@ func (c *DutiesCache) cachedProposerDuties(epoch eth2p0.Epoch, vidxs []eth2p0.Va
467474
}
468475

469476
dutiesFiltered := []*eth2v1.ProposerDuty{}
477+
470478
for _, d := range duties {
471479
if !slices.Contains(vidxs, d.ValidatorIndex) {
472480
continue
473481
}
482+
474483
dutiesFiltered = append(dutiesFiltered, d)
475484
}
476485

@@ -492,10 +501,12 @@ func (c *DutiesCache) cachedAttesterDuties(epoch eth2p0.Epoch, vidxs []eth2p0.Va
492501
}
493502

494503
dutiesFiltered := []*eth2v1.AttesterDuty{}
504+
495505
for _, d := range duties {
496506
if !slices.Contains(vidxs, d.ValidatorIndex) {
497507
continue
498508
}
509+
499510
dutiesFiltered = append(dutiesFiltered, d)
500511
}
501512

@@ -517,10 +528,12 @@ func (c *DutiesCache) cachedSyncDuties(epoch eth2p0.Epoch, vidxs []eth2p0.Valida
517528
}
518529

519530
dutiesFiltered := []*eth2v1.SyncCommitteeDuty{}
531+
520532
for _, d := range duties {
521533
if !slices.Contains(vidxs, d.ValidatorIndex) {
522534
continue
523535
}
536+
524537
dutiesFiltered = append(dutiesFiltered, d)
525538
}
526539

app/monitoringapi.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,13 +284,15 @@ func beaconNodeVersionMetric(ctx context.Context, eth2Cl eth2wrap.Client, beacon
284284
if err != nil {
285285
log.Warn(ctx, "Failed to fetch beacon node version", err,
286286
z.Str("beacon_node_address", addr))
287+
287288
continue
288289
}
289290

290291
response, err := scopedClient.NodeIdentity(ctx, &eth2api.NodeIdentityOpts{})
291292
if err != nil {
292293
log.Warn(ctx, "Failed to fetch beacon node identity", err,
293294
z.Str("beacon_node_address", addr))
295+
294296
continue
295297
}
296298

cmd/test_internal_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ func TestBeaconBasicAuth(t *testing.T) {
2323

2424
// Create a test server that validates basic auth
2525
authValidated := false
26+
2627
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
2728
// Check if Authorization header is present
2829
auth := r.Header.Get("Authorization")

core/consensus/qbft/qbft_test.go

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -76,17 +76,22 @@ func testQBFTConsensus(t *testing.T, threshold, nodes int) {
7676
lock, p2pkeys, _ := cluster.NewForT(t, 1, threshold, nodes, seed, random)
7777

7878
var (
79-
peers []p2p.Peer
80-
hosts []host.Host
81-
hostsInfo []peer.AddrInfo
82-
components []*qbft.Consensus
83-
results = make(chan core.UnsignedDataSet, threshold)
84-
runErrs = make(chan error, threshold)
85-
sniffed = make(chan int, threshold)
86-
ctx, cancel = context.WithCancel(context.Background())
79+
peers []p2p.Peer
80+
hosts []host.Host
81+
hostsInfo []peer.AddrInfo
82+
components []*qbft.Consensus
83+
results = make(chan core.UnsignedDataSet, threshold)
84+
runErrs = make(chan error, threshold)
85+
sniffed = make(chan int, threshold)
86+
deadlineChan = make(chan core.Duty)
87+
ctx, cancel = context.WithCancel(context.Background())
8788
)
8889
defer cancel()
8990

91+
// Add a test timeout to fail fast instead of waiting for CI's 10-minute timeout
92+
testCtx, testCancel := context.WithTimeout(ctx, 30*time.Second)
93+
defer testCancel()
94+
9095
// Create hosts and enrs (only for threshold).
9196
for i := range threshold {
9297
addr := testutil.AvailableAddr(t)
@@ -127,7 +132,7 @@ func testQBFTConsensus(t *testing.T, threshold, nodes int) {
127132

128133
deadliner := coremocks.NewDeadliner(t)
129134
deadliner.On("Add", mock.Anything).Return(true)
130-
deadliner.On("C").Return(nil)
135+
deadliner.On("C").Return((<-chan core.Duty)(deadlineChan))
131136

132137
// Create a mock beacon client for test
133138
// Use zero genesis time so timer uses relative timing instead of absolute slot-based timing
@@ -165,6 +170,8 @@ func testQBFTConsensus(t *testing.T, threshold, nodes int) {
165170

166171
for {
167172
select {
173+
case <-testCtx.Done():
174+
t.Fatal("test timed out waiting for consensus")
168175
case err := <-runErrs:
169176
testutil.RequireNoError(t, err)
170177
case res := <-results:

core/consensus/timer/roundtimer.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,7 @@ func (t *doubleEagerLinearRoundTimer) Timer(round int64) (<-chan time.Time, func
265265
} else {
266266
deadline = t.clock.Now().Add(timeout)
267267
}
268+
268269
t.firstDeadlines[round] = deadline
269270
}
270271

core/tracker/tracker.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ func countAttestations(duty core.Duty, events []event) int {
228228

229229
// Count fetcher events
230230
count := 0
231+
231232
for _, e := range events {
232233
if e.step == fetcher && e.pubkey != "" {
233234
count++

core/validatorapi/validatorapi.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1123,10 +1123,12 @@ func (c Component) ProposerDuties(ctx context.Context, opts *eth2api.ProposerDut
11231123
// Replace root public keys with public shares.
11241124
// Duties are copied into new slice, as otherwise the cached duties would be modified.
11251125
dutiesShareKey := []*eth2v1.ProposerDuty{}
1126+
11261127
for _, d := range cachedResp {
11271128
if d == nil {
11281129
return nil, errors.New("nil proposer duty from cache")
11291130
}
1131+
11301132
duty := *d
11311133

11321134
pubshare, ok := c.getPubShareFunc(duty.PubKey)
@@ -1158,6 +1160,7 @@ func (c Component) AttesterDuties(ctx context.Context, opts *eth2api.AttesterDut
11581160
// Replace root public keys with public shares.
11591161
// Duties are copied into new slice, as otherwise the cached duties would be modified.
11601162
dutiesShareKey := []*eth2v1.AttesterDuty{}
1163+
11611164
for _, d := range cachedResp {
11621165
if d == nil {
11631166
return nil, errors.New("attester duty cannot be nil")
@@ -1187,6 +1190,7 @@ func (c Component) SyncCommitteeDuties(ctx context.Context, opts *eth2api.SyncCo
11871190
// Replace root public keys with public shares.
11881191
// Duties are copied into new slice, as otherwise the cached duties would be modified.
11891192
dutiesShareKey := []*eth2v1.SyncCommitteeDuty{}
1193+
11901194
for _, d := range cachedResp {
11911195
if d == nil {
11921196
return nil, errors.New("sync committee duty cannot be nil")

0 commit comments

Comments
 (0)