netsync: add TestStartSyncChainCurrent for chain-current noop path
What changed, and why it matters
This commit only adds a new unit test. It does not change any production code, fix a bug, or alter behavior. The test checks that the Bitcoin sync manager does nothing when the local chain is already up to date and no peer has a higher block height. There is no security issue here.
No action needed. This is a routine test-only commit.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The diff adds TestStartSyncChainCurrent to netsync/manager_test.go. The test constructs a sync manager with one recently-mined block, a peer at the same height, and asserts that startSync leaves syncPeer nil and ibdMode false. No implementation code is modified.
Changed components
netsync/manager_test.goInspect captured patch +44 / −0
diff --git a/netsync/manager_test.go b/netsync/manager_test.go
index 164cbe9..becf1a7 100644
--- a/netsync/manager_test.go
+++ b/netsync/manager_test.go
@@ -1169,3 +1169,47 @@ func TestStallNoDisconnectAtSameHeight(t *testing.T) {
require.Nil(t, sm.syncPeer,
"we should have nil syncPeer after handleStallSample")
}
+
+// TestStartSyncChainCurrent verifies that startSync does not set syncPeer
+// or ibdMode when the chain is current and no peer is strictly higher.
+// isInIBDMode sees IsCurrent()==true with no higher peers, returns false,
+// and startSync exits immediately.
+func TestStartSyncChainCurrent(t *testing.T) {
+ t.Parallel()
+
+ params := chaincfg.RegressionNetParams
+ params.Checkpoints = nil
+
+ sm, tearDown := makeMockSyncManager(t, ¶ms)
+ defer tearDown()
+
+ // Mine a single block with a recent timestamp so
+ // IsCurrent() returns true.
+ cb := createTestCoinbase(1, ¶ms)
+ header := wire.BlockHeader{
+ Version: 1,
+ PrevBlock: *params.GenesisHash,
+ MerkleRoot: cb.TxHash(),
+ Timestamp: time.Now().Truncate(time.Second),
+ Bits: params.PowLimitBits,
+ }
+ require.True(t, solveTestBlock(&header, ¶ms))
+
+ block := btcutil.NewBlock(&wire.MsgBlock{
+ Header: header,
+ Transactions: []*wire.MsgTx{cb},
+ })
+ _, _, err := sm.chain.ProcessBlock(block, blockchain.BFNone)
+ require.NoError(t, err)
+ require.True(t, sm.chain.IsCurrent())
+
+ // Peer at our height — not higher.
+ newSyncCandidate(t, sm, 1)
+
+ sm.startSync()
+
+ require.Nil(t, sm.syncPeer,
+ "syncPeer should not be set when chain is already current")
+ require.False(t, sm.ibdMode,
+ "ibdMode should not be activated when chain is already current")
+}
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.