netsync: avoid clock tick race in sync state test
What changed, and why it matters
This change only fixes a flaky test. It does not change any production code, so it has no security impact on real users or the network.
No security action needed. Treat as a normal test reliability fix.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit modifies netsync/manager_test.go to eliminate a race in TestSyncStateMachine where two time.Now() calls could fall within the same clock tick. The test previously compared timestamps to verify that handleHeadersMsg updated lastProgressTime; now it resets the field to the zero value and asserts it becomes non-zero. No runtime behavior of btcd is changed.
Changed components
netsync/manager_test.goInspect captured patch +5 / −4
diff --git a/netsync/manager_test.go b/netsync/manager_test.go
index 4d304fc..1e40dd8 100644
--- a/netsync/manager_test.go
+++ b/netsync/manager_test.go
@@ -869,9 +869,10 @@ func syncSendHeaders(t *testing.T, sm *SyncManager,
t.Helper()
- // Record the progress time set by startIBD so we can verify
- // that handleHeadersMsg advances it.
- progressBefore := sm.lastProgressTime
+ // Reset the progress time to a zero sentinel so the assertion below
+ // verifies that handleHeadersMsg writes it without depending on the
+ // system clock advancing between calls to time.Now.
+ sm.lastProgressTime = time.Time{}
headers := wire.NewMsgHeaders()
for _, block := range blocks {
@@ -887,7 +888,7 @@ func syncSendHeaders(t *testing.T, sm *SyncManager,
_, bestHeaderHeight := sm.chain.BestHeader()
require.Equal(t, int32(totalBlocks), bestHeaderHeight)
- require.True(t, sm.lastProgressTime.After(progressBefore),
+ require.False(t, sm.lastProgressTime.IsZero(),
"handleHeadersMsg should update lastProgressTime")
wantRequested := make(map[chainhash.Hash]struct{}, len(blocks))
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.