I think this is subtly “wrong” fwiw: if you have [main] includeconf=foo.conf
in bitcoin.conf, and then set testnet=1
in foo.conf, you’ll have foo.conf included, and be running testnet not mainnet, so you “shouldn’t” have included foo.conf (and any other settings from the [main] section won’t have been used). That might be too subtle to worry about though.
It’s perhaps less subtly wrong in that if you said includeconf=force-testnet.conf [testnet] includeconf=testnet-params.conf
, with force-testnet.conf setting testnet=1
, you would not end up including testnet-params.conf, whereas if you set -testnet
on the command line, you would.
The easiest approach might be to not allow [regtest] includeconf=rt.conf
at all, but that would probably be annoying (particularly with custom chains).
A thought I had was that maybe [regtest] includeconf=rt.conf
should treat all the options in rt.conf as being network-specific, so if rt.conf says connect=10.10.10.10 [main] connect=10.10.10.20 [regtest] connect=10.10.10.30
, that would get interpreted as if it was [regtest] connect=10.10.10.10 connect=10.10.10.30
. That would avoid the inconsistency above, in that it would turn [main] includeconf=foo.conf
into essentially [main] testnet=1
which would just be ignored.
I think it might be better to do it as four phases though: (1) read “-conf”, (2) read the includeconfs that aren’t under a section, (3) work out the chain based on everything noted so far, and (4) read the “-chain.includeconf” options from -conf (but not letting that change the chain).