Skip to content

Conversation

ajtowns
Copy link
Contributor

@ajtowns ajtowns commented Aug 5, 2017

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.

@laanwj
Copy link
Member

laanwj commented Aug 5, 2017

Concept ACK

@@ -22,6 +22,10 @@ This help message
.IP
Specify configuration file (default: bitcoin.conf)
.HP
\fB\-netconf=\fR<file>
Copy link
Member

@laanwj laanwj Aug 5, 2017

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).

Copy link
Contributor Author

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...

Copy link
Contributor

@meshcollider meshcollider Sep 15, 2017

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

Copy link
Contributor Author

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.

@ajtowns
Copy link
Contributor Author

ajtowns commented Aug 6, 2017

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().

@ajtowns
Copy link
Contributor Author

ajtowns commented Aug 6, 2017

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
Copy link
Contributor

jnewbery commented Aug 6, 2017

I've wanted to rebase and revive #9402 for some time, but I was waiting for #10267, both because this conflicts heavily with that PR, and also because I think once #10267 is merged, then this PR becomes more straightforward.

@ajtowns
Copy link
Contributor Author

ajtowns commented Aug 7, 2017

@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).

@ajtowns ajtowns force-pushed the netconf branch 3 times, most recently from 7d7eea2 to e3fe835 Compare August 25, 2017 05:21
@ajtowns
Copy link
Contributor Author

ajtowns commented Aug 25, 2017

Squashed most of the commits, and rebased to current master.

@ajtowns ajtowns force-pushed the netconf branch 2 times, most recently from 262abf1 to e609aba Compare October 10, 2017 05:18
@ajtowns
Copy link
Contributor Author

ajtowns commented Oct 10, 2017

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.

@ajtowns ajtowns changed the title [WIP] Add per-network config file network.conf Add per-network config file network.conf Oct 10, 2017
@laanwj laanwj added the Feature label Nov 9, 2017
@ajtowns
Copy link
Contributor Author

ajtowns commented Nov 21, 2017

Rebased to fix test_runner conflicts

@meshcollider
Copy link
Contributor

meshcollider commented Nov 21, 2017

Big concept ACK on the default network specific config files. EDIT: utACK 8da2270
Will test it out shortly
It does seem a bit weird though having both conf and netconf. What if netconf was just a boolean to decide whether to look for conf in the net specific datadir or not? I'm worried about user confusion over the interaction between both those parameters, will discuss on IRC

@ajtowns
Copy link
Contributor Author

ajtowns commented Nov 21, 2017

@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.

@meshcollider
Copy link
Contributor

meshcollider commented Nov 21, 2017

Upon discussion on IRC: I suggested using network.conf if -conf is not specified but using the -conf if it is and not using network.conf at all. This removes the need for the netconf argument. Reasoning is that if a user specified a config file they probably want to use it on the network they specify as well, so we really only need to change the default behaviour. But unsure if that's too limiting

@sipa
Copy link
Member

sipa commented Nov 21, 2017

Concept ACK

@ajtowns
Copy link
Contributor Author

ajtowns commented Nov 22, 2017

@meshcollider see ajtowns#2 . not a big fan of repeating the conditionals still, but it's not too bad.

Copy link
Contributor

@promag promag left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Meanwhile some nits.


# otherwise loads specified network conf
self.stop_node(0)
self.start_node(0, ["-conf=bitcoin-altnet.conf"])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use restart_node.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed.


# netconf on command line overrides specification in bitcoin.conf
self.stop_node(0)
self.start_node(0, ["-conf=bitcoin-altnet.conf", "-netconf=network.conf"])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed.


# if file doesn't exist, everything is fine
self.stop_node(0)
self.start_node(0, ["-netconf=no-network.conf"])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed.

# 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
Copy link
Contributor

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."""

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed.

import os
from test_framework.test_framework import BitcoinTestFramework

class IncludeConfTest(BitcoinTestFramework):
Copy link
Contributor

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?

Copy link
Contributor Author

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);
Copy link
Contributor

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);
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

@ajtowns
Copy link
Contributor Author

ajtowns commented Nov 27, 2017

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.
@ajtowns
Copy link
Contributor Author

ajtowns commented Dec 5, 2017

Rebased to fix test_runner.py conflict, renamed test case to conform to naming convention of #11796

@meshcollider
Copy link
Contributor

This is now superseded by #11862

@ajtowns
Copy link
Contributor Author

ajtowns commented Mar 6, 2018

Abandoning in favour of #11862

@ajtowns ajtowns closed this Mar 6, 2018
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Sep 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants