dashpay / dash

Dash - Reinventing Cryptocurrency
https://www.dash.org
MIT License
1.49k stars 1.2k forks source link

enhancement: separate config files from cache directories #5422

Open coolaj86 opened 1 year ago

coolaj86 commented 1 year ago

Separate Cache from Config

As a general best practice, cache files and directories and config / user data and directories should not be mixed together.

Caches are often Rebuilt

In the specific case of dashd (and dash-qt), it's common to need to delete the blockchain data when it becomes corrupted from:

Using Flags

The -testnet flag already does the right thing by creating a separate testnet3 which can be removed at any time without an issue (I think).

It would make a lot of sense to create a mainnet folder for the mainnet cache rather that putting it alongside dash.conf and settings.json which contain valuable secrets, user config, etc.

I'm not sure which other files also contain valuable data (Wallet Phrase, legacy private keys), but it would be a lot easier to manage the mistakes if there were a clear delineation between what needs to be backup up and what doesn't before blowing away the cache directories - because if they aren't blown away then it seems they just duplicate information rather than resuming from the last good state or pruning the unrecoverable data entirely.

Standards Already Exist

My greatest preference would be to follow the existing standards used by most other CLI tools and switch configuration data to ~/.config/dashcore/ by default, and ~/.local/opt for program files, and other folders in ~/.local for larger important data specific to the user according to standards and best-practice conventions.

coolaj86 commented 1 year ago

Also, -datadir is a misnomer, at least from a user perspective. Perhaps that should be -cachedir and -userdir.

Or there should otherwise be some clear distinction between data that is "NOT unique" and "unique to this instance" and "unique to this user".

In the case of running a Full Node, I assume the purpose is just for creating APIs to interact with transactions and balances, etc, so it's not a big deal - but dashcore as a package doesn't really distinguish between use cases of "User is doing stuff with money" vs "Service provider is providing services" vs "MNO is voting" - everything is everything is everything, which makes it even more important to provide clear distinction at the folder level.

coolaj86 commented 1 year ago

The current behavior is also dangerous because there's no way to future-proof against it.

I can personally change -datadir and -conf, but then later -walletdir comes along and then -settings comes along and so on and so forth.

It needs to be the responsibility of the developers to choose safe defaults, not the responsibility of the user to be constantly vigilant in setting command line options, checking the notes of each release, etc, etc, etc.

Users are dumb. I'm dumb. Computers should protect us from our dumbness, not lead us into traps. People are bad at following rules and guidelines and methodologies, but computers are great at it. Y'know?

thephez commented 1 year ago

The -testnet flag already does the right thing by creating a separate testnet3 which can be removed at any time without an issue (I think).

Fwiw, it is not safe to remove the testnet3 (or regtest or devnet-*) directory at any time. This is because wallet files for each network type are stored within that network's directory.

coolaj86 commented 1 year ago

wallet files for each network type are stored within that network's directory

I found a bug there too: https://github.com/dashpay/dash/issues/5423