While backporting some things to Bitcoin ABC, I notice that GetDataDir
is a bit awkward since it not only creates the directory in question, it also creates the wallets/ subdirectory … but only if it was the first time creating the datadir (see #11466).
Why this is a bit weird:
- If something else during initialization happens to create the directory in question first (like
GetBlocksDir
), the wallets/ directory won’t get created. This is particularly relevant for the net-specific case. In Bitcoin Core,GetDataDir(true)
gets called beforeGetBlocksDir()
but seemingly by accident: the former is called duringInitLogging
when fetching the default debug.log location, and the latter duringAppInitParameterInteraction
shortly afterwards. IfInitLogging
were changed slightly, it could inadvertently cause testnet/regtest to stop creating wallets/ directory. - If someone creates the ~/.bitcoin directory just to host the bitcoin.conf before running first time, it won’t create the mainnet wallets/ subdirectory.
- If running in -nowallet mode, it still creates the wallets/ directory. If running -regtest and -nowallet, it creates two wallets/ directories (the mainnet one and net-specific one) since both
GetDataDir(false)
andGetDataDir(true)
get called during init. - If a user were to run in -nowallet, then deleted the empty and apparently superfluous wallets/ directory, it will not get recreated if later run with wallet enabled. Then bitcoind will instead create wallet.dat in the bare directory.
- If bitcoind is compiled without wallet support, it still creates wallets/ directory (sometimes).
I think a more elegant solution would be to have wallets/ directory created in the wallet initialization, however I’m not an expert on the wallet part of the code and how this ought to behave.
(pinging @meshcollider from original PR)