Problem
When a node is shut down while network activity is disabled (e.g. via -networkactive=0 or setnetworkactive false), anchors.dat is overwritten with an empty list. This happens because StopNodes() collects anchors via GetCurrentBlockRelayOnlyConns(), which returns nothing when there are no active connections. The node then loses its anchors and cannot reconnect to them on the next startup.
Fix
- In
SetNetworkActive(false), save the current block-relay-only connections intom_anchorsbefore the connections are closed, so the anchor list is preserved even after the network is deactivated. - In
StopNodes(), if the network is inactive and m_anchors is non-empty, use those stored anchors as the source for anchors.dat instead of the (empty) live connection list. Also skipDumpAnchorsentirely when the network is inactive and there is nothing to write.
Also, log that “X anchors will be tried for connections” only if network is active.