net: don't perform network activity when networkactive=0#34467
net: don't perform network activity when networkactive=0#34467saksham-1304 wants to merge 1 commit intobitcoin:masterfrom
Conversation
When starting bitcoind with -networkactive=0, various network activities should not occur, including: - Address selection from addrman - NAT-PMP port mapping attempts - Tor control socket connection attempts Fix this by: 1. Adding a check in ThreadOpenConnections to pause the main outbound connection loop when fNetworkActive is false, preventing unnecessary addrman selections and connection attempts 2. Making StartMapPort conditional on -networkactive flag 3. Making StartTorControl conditional on -networkactive flag Fixes bitcoin#34190
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ReviewsSee the guideline for information on the review process. ConflictsReviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first. |
|
Those aren't strictly P2P network activity, but I guess it makes sense. |
|
@luke-jr Sir can you please guide me what should i do further wrt this PR? |
|
In my opinion this PR attemps to solve the log spam issue far too literally, without consideration of how the fix should integrate with our software on a larger scale. Whilst it does "fix the spam" (hooray, mission complete!), it breaks how If bitcoind from PR is started with I also believe my approach in #34486 is wired up in a much more logical way. The only downside of my own approach in my opinion, is that its adding more libevent code, which I know we are angling to drop at some point... I will add this rationale to #34486 |
|
I agree with willcl-ark here, this PR is not comprehensive enough, while its alternative PR has already managed to get conceptual buy in. In order to keep our review resources focused I think this PR should be closed in favour of #34466. |
Problem
When starting bitcoind with
-networkactive=0, the node still performs various network activities despite the user explicitly requesting that the P2P network be inactive. This results in unnecessary log messages and network overhead:[addrman] Selected IP:PORT from tried- Address manager selections[net:error] Could not get best interface for default route- Gateway detection attempts[tor] Error connecting to Tor control socket- Tor control connection attempts[tor] Not connected to Tor control port- Tor reconnection attempts[net] portmap: Could not determine IPv4/IPv6 default gateway- UPnP/NAT-PMP attemptsThis defeats the purpose of the
-networkactiveflag, which is documented as "Enable all P2P network activity (default: 1)".Steps to Reproduce
bitcoind.exe -networkactive=0Expected Behavior
No network activity should occur when
-networkactive=0is set at startup. The node should remain idle until network is activated via RPC commandsetnetworkactive true.Solution
This PR ensures that when
networkactive=0, no network initialization or activity occurs by:1. ThreadOpenConnections (src/net.cpp)
Added a check at the beginning of the main while loop to pause all outbound connection logic when
fNetworkActiveis false. This prevents:This check follows the existing pattern used for DNS seed querying (lines 2345-2349) and uses the same synchronization mechanism (
fNetworkActiveatomic flag andsleep_forwith interruption support).2. StartMapPort (src/init.cpp)
Made NAT-PMP port mapping startup conditional on
-networkactivebeing true. This prevents:3. StartTorControl (src/init.cpp)
Made Tor control thread startup conditional on
-networkactivebeing true. This prevents:Testing
The fix has been verified to:
args.GetBoolArg("-networkactive", true))Manual Testing
Affected Code Paths
src/net.cpp: CConnman::ThreadOpenConnections()- Main connection management loopsrc/init.cppBitcoin Core initialization - MapPort and TorControl startupNotes
This change is backward compatible - default behavior (networkactive=1) is unchanged
Dynamic network activation via setnetworkactive true RPC will resume ThreadOpenConnections activity
MapPort and TorControl remain stopped if started with networkactive=0 (can be addressed in follow-up if needed for dynamic activation)
Fixes #34190