-
Notifications
You must be signed in to change notification settings - Fork 37.7k
Add per-network config file network.conf #10996
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
Conversation
Concept ACK |
doc/man/bitcoin-cli.1
Outdated
@@ -22,6 +22,10 @@ This help message | |||
.IP | |||
Specify configuration file (default: bitcoin.conf) | |||
.HP | |||
\fB\-netconf=\fR<file> |
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.
I wonder - is there any practical point in being able to override this?
If not, it's a waste of an option (and help translation).
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.
It could be useful if you wanted to temporarily restart bitcoind without using the network.conf file. You could have a bitcoin-alt.conf that specified netconf=network-alt.conf so that you could load bitcoind with -conf=bitcoin-alt.conf and have that load network specific alternative configurations too. Not sure how realistic/valuable those are, though. Not having the option would be inconsistent; and having the option makes the name of the config file at least a little discoverable...
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.
Aren't the doc/man/ files automatically generated anyway so shouldn't be modified directly? Or is this information out of date
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.
@meshcollider Yep, that's correct; worse the help text for bitcoin-cli is missing. Will fix.
Commit 7a71b09 adds basic functional tests; it makes use of -netconf being a modifiable parameter to point bitcoind at different files in different ways and checks that has different results. Commit 8b48aa5 cleans up the code a little, but also allows you to specify an absolute path for network.conf if you want to for some reason (not that doing so actually makes a lot of sense). Commit 70f5388 removes the default for fNetSpecific for calls to Get/ReadConfigFile, which seems sensible since the default would need to be false to be backwards compatible with the old calls for bitcoin.conf, but is the opposite to the default for the same parameter for GetDataDir(). |
One possibly confusing behaviour: possible to set "-testnet" or "-regtest" in a network.conf where those parameters would be wrong; if you do so, they won't take effect or cause problems because ChainNameFromCommandLine() has already been called and isn't called again; but if some future change to the code does try to call ChainNameFromCommandLine() sometime after startup, and a network.conf sets a wrong parameter, it could blow up in your face. I'm not sure if this is worth fixing... (Adding a "static const string *result;" to ChainNameFromCommandLine() to memoise it at first call, and just reuse the result without reexamining the arguments later seems to be sufficient to fix the problem if it is worth fixing. Giving an error if regtest/testnet is specified in network.conf would probably be better, but seems like it violates the abstraction layer a fair bit...) |
@jnewbery Hmm, looking at #10267 in a bit more detail, the current patch seems to only allow a single includeconf directive to have an effect anyway, rather than multiple includes or recursive includes; so you could actually get the same effect as that patch with this one by just giving an absolute path to the netconf directory here. It doesn't look to me like there's really much difficulty in combining the two patches either once one or the other gets merged (I'm not seeing much room for either to get much simpler, though -- you still have to finish loading bitcoin.conf then load the chain params to work out which network you're on before you can load the right network.conf). |
7d7eea2
to
e3fe835
Compare
Squashed most of the commits, and rebased to current master. |
262abf1
to
e609aba
Compare
Rebased to current master. Also: no longer committing changes to manpages, functional test updated due to API changes on master, help text for bitcoin-cli added, and minor code style fixes. |
Rebased to fix test_runner conflicts |
Big concept ACK on the default network specific config files. EDIT: utACK 8da2270 |
@meshcollider In normal usage, -netconf isn't needed -- you just add the network.conf file to .bitcoin/testnet3/ (or wherever) if you want to use it, and you don't if you don't want to use it. The main benefits to having the option are (a) it makes it easier to test (can just specify different config files to check different behaviour, rather than having to move files around), and (b) it means it shows up when you say --help so people have some chance of knowing it exists. I think that's enough to justify having the option, but happy to drop it if people think that makes it simpler. |
Upon discussion on IRC: I suggested using network.conf if |
Concept ACK |
@meshcollider see ajtowns#2 . not a big fan of repeating the conditionals still, but it's not too bad. |
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.
Meanwhile some nits.
test/functional/netconf.py
Outdated
|
||
# otherwise loads specified network conf | ||
self.stop_node(0) | ||
self.start_node(0, ["-conf=bitcoin-altnet.conf"]) |
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.
Use restart_node
.
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.
Changed.
test/functional/netconf.py
Outdated
|
||
# netconf on command line overrides specification in bitcoin.conf | ||
self.stop_node(0) | ||
self.start_node(0, ["-conf=bitcoin-altnet.conf", "-netconf=network.conf"]) |
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.
Same as above.
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.
Changed.
test/functional/netconf.py
Outdated
|
||
# if file doesn't exist, everything is fine | ||
self.stop_node(0) | ||
self.start_node(0, ["-netconf=no-network.conf"]) |
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.
Same as above.
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.
Changed.
test/functional/netconf.py
Outdated
# Distributed under the MIT software license, see the accompanying | ||
# file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||
""" | ||
Tests the network-specific config file |
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.
Nit, missing period. One line?
"""Tests the network-specific config file."""
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.
Changed.
test/functional/netconf.py
Outdated
import os | ||
from test_framework.test_framework import BitcoinTestFramework | ||
|
||
class IncludeConfTest(BitcoinTestFramework): |
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.
Should mirror the filename? class NetconfTest
?
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.
Changed.
@@ -200,7 +201,7 @@ class ArgsManager | |||
std::map<std::string, std::vector<std::string>> mapMultiArgs; | |||
public: | |||
void ParseParameters(int argc, const char*const argv[]); | |||
void ReadConfigFile(const std::string& confPath); | |||
void ReadConfigFile(const std::string& confPath, bool fNetSpecific); |
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.
Same as above.
@@ -171,7 +172,7 @@ bool TryCreateDirectories(const fs::path& p); | |||
fs::path GetDefaultDataDir(); | |||
const fs::path &GetDataDir(bool fNetSpecific = true); | |||
void ClearDatadirCache(); | |||
fs::path GetConfigFile(const std::string& confPath); | |||
fs::path GetConfigFile(const std::string& confPath, bool fNetSpecific); |
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.
Set default value bool fNetSpecific = false
? In that case remove changes where it's false.
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.
The "Be explicit whether config file is net specific" commit removes the fNetSpecific=false default argument, because otherwise it would have the opposite default to GetDataDir() which seems confusing to me.
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.
Err, the implication being that just dropping/not merging that commit is how you'd get the fNetSpecific=false default.
Rebased, small improvements to test case, nit fixes. |
Remove the default for whether GetConfigFile and ReadConfigFile expects the file to be network specific or not, requiring true or false to be passed in for fNetworkSpecific on any call.
Rebased to fix test_runner.py conflict, renamed test case to conform to naming convention of #11796 |
This is now superseded by #11862 |
Abandoning in favour of #11862 |
Adds a per-net network.conf as per #9374 ; this is pretty much the same as #9402 which was closed for lack of interest.
It's somewhat interesting in the context of #10994 because it provides somewhere to stick the network-specific vbignore settings. Unless I'm missing something, I don't think #10267 provides an easy way of doing per-network config files, so wouldn't work well for that particular use case.
This patch doesn't include any tests, so is marked as WIP. There's some test code in #10267 that would presumably be able to be adapted pretty easily.