Skip to content

odd behaviour of GetDataDir creating wallets/ subdirectory #16220

@markblundeberg

Description

@markblundeberg

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 before GetBlocksDir() but seemingly by accident: the former is called during InitLogging when fetching the default debug.log location, and the latter during AppInitParameterInteraction shortly afterwards. If InitLogging 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) and GetDataDir(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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions