netsync: add TestStallNoDisconnectAtSameHeight for stall handler
What changed, and why it matters
This commit only adds a new unit test. It does not change any production code, so it cannot introduce a security vulnerability or fix one directly. The test checks that the sync manager does not disconnect a peer that is at the same block height when a stall is sampled.
No security action needed. Review the related production code only if this test was added to guard a recent behavior change.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The diff adds TestStallNoDisconnectAtSameHeight in netsync/manager_test.go. The test constructs a mock sync manager, sets an inbound peer whose advertised height equals the local chain height, marks the peer as the sync peer, enables IBD mode, sets lastProgressTime beyond maxStallDuration, and calls handleStallSample. It then asserts the peer is not disconnected and syncPeer is cleared. No production logic is modified.
Changed components
netsync/manager_test.goInspect captured patch +28 / −0
diff --git a/netsync/manager_test.go b/netsync/manager_test.go
index bafeb9b..164cbe9 100644
--- a/netsync/manager_test.go
+++ b/netsync/manager_test.go
@@ -1141,3 +1141,31 @@ func TestStartSyncBlockFallback(t *testing.T) {
require.NotEmpty(t, sm.requestedBlocks,
"blocks should be requested via fetchHeaderBlocks")
}
+
+// TestStallNoDisconnectAtSameHeight verifies that handleStallSample does
+// not disconnect a sync peer whose advertised height equals our own.
+func TestStallNoDisconnectAtSameHeight(t *testing.T) {
+ t.Parallel()
+
+ params := chaincfg.RegressionNetParams
+ params.Checkpoints = nil
+
+ sm, tearDown := makeMockSyncManager(t, ¶ms)
+ defer tearDown()
+
+ p := peer.NewInboundPeer(&peer.Config{})
+ p.UpdateLastBlockHeight(0) // Same height as our genesis chain.
+ sm.peerStates[p] = &peerSyncState{}
+ sm.syncPeer = p
+ sm.ibdMode = true
+ sm.lastProgressTime = time.Now().Add(
+ -(maxStallDuration + time.Minute))
+
+ sm.handleStallSample()
+
+ _, tracked := sm.peerStates[p]
+ require.True(t, tracked,
+ "peer at same height should not be disconnected")
+ require.Nil(t, sm.syncPeer,
+ "we should have nil syncPeer after handleStallSample")
+}
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.