-
Notifications
You must be signed in to change notification settings - Fork 36.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
net: Add -networkactive option #19473
Conversation
There was an idea to overload No opinion on that, though. Concept ACK on adding the functionality. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice PR! I tested various combinations:
bitcoind -networkactive
bitcoind -networkactive=1
bitcoind -networkactive=0
bitcoind -nonetworkactive
and the behavior was as expected (the first two enabled and the second two disabled networking). I also verified that after disabling networking on the command line, I could change it in both directions using the setnetworkactive
RPC.
I think it's okay that there's no unit test, because this is test code anyway, and there's no easy place to add one. The only thing bad that could happen is networking isn't enabled by default, and that would be noticed right away!
If you can fix that tiny quote problem, I'd be happy to approve.
I think it is enabled by default :) |
Yes, sorry, my comment wasn't clear; I just meant that without a test, a bug in this PR could conceivably make networking disabled by default. But, as I said, that would be pretty obvious, so I'm not worried! Plus, now that I think about it, there are numerous existing tests that would fail. So never mind. I was just trying to support your decision not to include a test. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested in the gui:
$ ./src/qt/bitcoin-qt -? |grep -A1 networka
-networkactive
Enable all p2p network activity (default: 1). Could be changed by the
setnetworkactive RPC command
ACK e9a9c97 🎈
Show signature and timestamp
Signature:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512
ACK e9a9c9712f 🎈
-----BEGIN PGP SIGNATURE-----
iQGzBAEBCgAdFiEE+rVPoUahrI9sLGYTzit1aX5ppUgFAlwqrYAACgkQzit1aX5p
pUiw8wwAhcByYIf/MRTpljoUpnyyQOh2M2qMLBv5ECseJmHeC9Tq1n/04FTVnguB
C6AjlPujp1jmIpyA1QLMp5j7hMjjBeRSE9t/xH5Tt1Lc5NpzmYucK6/JXU8+P7jN
EB/FpW2QAsAIBc7Hqyh+Cjq4aJegeNQn/j0zBgGKoiEjZtw2wSNgeOZ4QfezXGFT
iUJrlszz+FYQY4lPijAjIJcyVtWwMNuNG4N1T/gC9fi7vF8sZZCtyDdgZgl4VmDe
0IRKXKRz3HCcSe4o8lkB4AnEzqhhUwyORziMcxqkj8eNDYNhzDCfnHiRXZAnQYbk
whHxEHq68P6eRbnbPy+9MSs3HsE9Gu9jLZavZ6sjzdhHkqQXz06J6Irku/2hvEPa
oGygTwLyv2cvpP1kOW8FoE6ddpCCrCFWC9TkQZyJRhnTsoShcxAix5cp38VEVz9c
0KZNkNQZNZC1xsjN8RKkYKbXi72OziL9dPr2oX1ISTdbrzz+c2u7cP6cuo5a5oty
HclCb1NB
=2rnx
-----END PGP SIGNATURE-----
Timestamp of file with hash 289aaa99e8660b4dd3573b6eabcfd374fdeaf85e793ebd854168b6684124745b -
Though, I used the following diff:
diff --git a/src/init.cpp b/src/init.cpp
index a726c5e062..615f3929d4 100644
--- a/src/init.cpp
+++ b/src/init.cpp
@@ -455,7 +455,7 @@ void SetupServerArgs(NodeContext& node)
gArgs.AddArg("-proxy=<ip:port>", "Connect through SOCKS5 proxy, set -noproxy to disable (default: disabled)", ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
gArgs.AddArg("-proxyrandomize", strprintf("Randomize credentials for every proxy connection. This enables Tor stream isolation (default: %u)", DEFAULT_PROXYRANDOMIZE), ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
gArgs.AddArg("-seednode=<ip>", "Connect to a node to retrieve peer addresses, and disconnect. This option can be specified multiple times to connect to multiple nodes.", ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
- gArgs.AddArg("-networkactive", "Enable all p2p network activity (default: 1). Could be changed by the `setnetworkactive' RPC command", ArgsManager::ALLOW_BOOL | ArgsManager::DEBUG_ONLY, OptionsCategory::CONNECTION);
+ gArgs.AddArg("-networkactive", "Enable all p2p network activity (default: 1). Could be changed by the setnetworkactive RPC command", ArgsManager::ALLOW_BOOL, OptionsCategory::CONNECTION);
gArgs.AddArg("-timeout=<n>", strprintf("Specify connection timeout in milliseconds (minimum: 1, default: %d)", DEFAULT_CONNECT_TIMEOUT), ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
gArgs.AddArg("-peertimeout=<n>", strprintf("Specify p2p connection timeout in seconds. This option determines the amount of time a peer may be inactive before the connection to it is dropped. (minimum: 1, default: %d)", DEFAULT_PEER_CONNECT_TIMEOUT), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::CONNECTION);
gArgs.AddArg("-torcontrol=<ip>:<port>", strprintf("Tor control port to use if onion listening enabled (default: %s)", DEFAULT_TOR_CONTROL), ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
@@ -1373,7 +1373,7 @@ bool AppInitMain(const util::Ref& context, NodeContext& node)
assert(!node.banman);
node.banman = MakeUnique<BanMan>(GetDataDir() / "banlist.dat", &uiInterface, gArgs.GetArg("-bantime", DEFAULT_MISBEHAVING_BANTIME));
assert(!node.connman);
- node.connman = std::unique_ptr<CConnman>(new CConnman(GetRand(std::numeric_limits<uint64_t>::max()), GetRand(std::numeric_limits<uint64_t>::max()), gArgs.GetBoolArg("-networkactive", true)));
+ node.connman = MakeUnique<CConnman>(GetRand(std::numeric_limits<uint64_t>::max()), GetRand(std::numeric_limits<uint64_t>::max()), gArgs.GetBoolArg("-networkactive", true));
// Make mempool generally available in the node context. For example the connection manager, wallet, or RPC threads,
// which are all started after this, may use it from the node context.
assert(!node.mempool);
Mind adding test coverage? |
Updated e9a9c97 -> a323249 (pr19473.01 -> pr19473.02, diff):
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. 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. |
src/init.cpp
Outdated
@@ -456,6 +456,7 @@ void SetupServerArgs(NodeContext& node) | |||
gArgs.AddArg("-proxy=<ip:port>", "Connect through SOCKS5 proxy, set -noproxy to disable (default: disabled)", ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION); | |||
gArgs.AddArg("-proxyrandomize", strprintf("Randomize credentials for every proxy connection. This enables Tor stream isolation (default: %u)", DEFAULT_PROXYRANDOMIZE), ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION); | |||
gArgs.AddArg("-seednode=<ip>", "Connect to a node to retrieve peer addresses, and disconnect. This option can be specified multiple times to connect to multiple nodes.", ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION); | |||
gArgs.AddArg("-networkactive", "Enable all p2p network activity (default: 1). Can be changed by the setnetworkactive RPC command", ArgsManager::ALLOW_BOOL, OptionsCategory::CONNECTION); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please capitalize P2P
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
utACK otherwise |
The `setnetworkactive' RPC command is already present. This new option allows to start the client with disabled p2p network activity for testing or reindexing.
Updated a323249 -> 2aac093 (pr19473.02 -> pr19473.03, diff):
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK 2aac093
re-ACK 2aac093 🏠 Show signature and timestampSignature:
Timestamp of file with hash |
The `setnetworkactive' RPC command is already present. This new option allows to start the client with disabled p2p network activity for testing or reindexing. Github-Pull: bitcoin#19473 Rebased-From: aabc6af
Github-Pull: bitcoin#19473 Rebased-From: e9a9c97
Summary: Some Bitcoin activity is completely local (offline), e.g., reindexing. The `setnetworkactive` RPC command is already present. This PR adds the corresponding command-line argument / config option, and allows to start the client with disabled p2p network by providing `-networkactive=0` or `-nonetworkactive`. Commit message #1: > net: Add -networkactive option > > The `setnetworkactive' RPC command is already present. > This new option allows to start the client with disabled p2p network > activity for testing or reindexing. Commit message #2: >net: Log network activity status change unconditionally Commit message #3: > test: Add test coverage for -networkactive option This is a backport of [[bitcoin/bitcoin#19473 | core#19473]] Test Plan: `ninja all check-all` Reviewers: #bitcoin_abc, majcosta Reviewed By: #bitcoin_abc, majcosta Subscribers: Fabien Differential Revision: https://reviews.bitcoinabc.org/D9713
Some Bitcoin Core activity is completely local (offline), e.g., reindexing.
The
setnetworkactive
RPC command is already present. This PR adds the corresponding command-line argument / config option, and allows to start the client with disabled p2p network by providing-networkactive=0
or-nonetworkactive
.This was done while reviewing #16981.