net: check network activity in ThreadOpenConnections

bitcoin/bitcoin: PR #36956

1 suggestion

Optional improvements

Link

[suggestion] · Offline startup bypasses the addrman-first seed delay

Starting with -networkactive=0 for over 10 seconds lets a configured -seednode be scheduled on the first resumed pass despite a non-empty addrman, without the normal startup grace for existing addresses.

Location: src/net.cpp:2656 (head).

Details and suggested fix

seed_node_timer starts before the loop, so the inactive wait counts toward ADD_NEXT_SEEDNODE. After reactivation, a node below the full-relay threshold sets add_addr_fetch on its first pass and processes the seed on the next, subject to grant availability. Addrman gets at most one pass before that processing, yet the log says it could not connect after 10 seconds. Reset the timer on the inactive-to-active transition to give existing addresses the usual opportunity before contacting a seed, and cover this with a non-empty-addrman reactivation test. Although the existing timer also ages while an active node has enough peers, offline startup has given addrman no connection opportunity; this recommendation selects startup-like behavior for reactivation.


Coverage details

Background

Ralph's summary of historical context for the behaviour affected by this change. The historical record reviewed here is incomplete.

Documented decisions

Starting with networking disabled was introduced to support completely local operations, such as reindexing, without enabling the P2P network.

The merged description of #19473 defines the purpose of -networkactive=0 as offline operation. It does not promise that outbound retry scheduling continues during that period, nor require that scheduling be frozen. This distinguishes the documented user-facing purpose from the automatic loop's previous implementation.

Source 1

Historical anchor handling explicitly treats network deactivation as a temporary interruption that should preserve connection-recovery state, including across shutdown and restart.

#34213 explains that consuming anchors while inactive drops them without a connection attempt, and that losing anchors prevents reconnection on subsequent startup. Its stated solution saves live block-relay-only peers before deactivation and consumes stored anchors only while active. Preserving pending automatic connection opportunities during inactivity therefore has a directly documented precedent, although that proposal addressed anchors rather than every retry task.

Source 1