Skip to content

let user select wallet file with -wallet=foo.dat#1889

Merged
gavinandresen merged 1 commit intobitcoin:masterfrom
lost-tty:multi-wallet
Jul 25, 2013
Merged

let user select wallet file with -wallet=foo.dat#1889
gavinandresen merged 1 commit intobitcoin:masterfrom
lost-tty:multi-wallet

Conversation

@lost-tty
Copy link

This patch lets a user have multiple wallets within his data directory by selecting a wallet using -wallet=filename. It also allows accessing wallets outside the data directory. In that case, the database environment is still stored in the data directory so both wallet file and data directory must be kept in sync (e.g. when storing the wallet within an encrypted container).

I've been using this patch for a few months now without any troubles and it's proved to be pretty useful.

src/main.cpp Outdated
Copy link

Choose a reason for hiding this comment

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

I would feel better, if this would be a std::string.

Copy link
Member

Choose a reason for hiding this comment

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

Me too, that would make it an owning reference to the underlying data. The memory referenced by .c_str() is deallocated when the underlying std::string goes out of scope, so after the Init() function. Keeping a global reference to it results in use-after-free problems...

@gmaxwell
Copy link
Contributor

gmaxwell commented Oct 1, 2012

Eh. The functionality is desirable, but the ability to filesystem split the wallet and data dir is a surefire way to end up with a corrupted wallet. This is subtle and I suspect hard to warn people out of doing, esp since it would mostly work. (until it eats your keys for lunch).

@BitcoinPullTester
Copy link

Automatic sanity-testing: PASSED, see http://jenkins.bluematt.me/pull-tester/38ff7ee0239d1609a9bafd764f53fb45bbf3ac33 for binaries and test log.

@sipa
Copy link
Member

sipa commented Oct 7, 2012

I agree with @gmaxwell. Can we add a check so only wallet names without / (or other filesystem separation character) are accepted? Maybe even limit to just alphanumeric names, and add ".dat" implicitly?

@gmaxwell
Copy link
Contributor

Now that ultraprune has taken everything else out of the BDB environment, we can now have pluggable wallet locations, but it needs to move the whole db environment too, not just the wallet.dat location.

@lost-tty
Copy link
Author

This patch was never meant to be used to access wallets outside $DATADIR. I've written it to use multiple wallets within the same datadir.

@sipa
Copy link
Member

sipa commented Oct 21, 2012

Maybe not, but then it should either enforce that requirement. Alternatively, it could allow accessing a wallet file anyway, as long as the BDB dir (not the entire datadir) is moved along.

@gmaxwell
Copy link
Contributor

Without one of enforcement or moving the datadir it's a serious footgun that will result in permanent coin loss. I like moving the datadir, since it's viable now— and it would let you have your wallet file on a encrypted/removable volume while the chain resides on some less secure medium (or even a ramdisk).

@BitcoinPullTester
Copy link

Automatic sanity-testing: PASSED, see http://jenkins.bluematt.me/pull-tester/9ccd2da8ad5a1c38db4d3bb73a8638fa6457533a for binaries and test log.

@luke-jr
Copy link
Member

luke-jr commented Nov 13, 2012

@tcatm Any update and/or rebase?

@Diapolo
Copy link

Diapolo commented Jan 1, 2013

I guess in the light of real multiple wallet support coming along, this is not needed anymore?

@laanwj
Copy link
Member

laanwj commented May 19, 2013

Agree with the other posts. This is very useful functionality, but this should either

  1. Enforce the wallet.dat to be inside the data directory or
  2. Open the database environment in the alternative path if a wallet in another path is specified. As the wallet database is the only thing that uses berkelydb now, there is no reason not to.

Personally I like (2) most.

@laanwj
Copy link
Member

laanwj commented Jun 4, 2013

As for (2) we really need a way to set another wallet directory (ie, walletdir=...). There is no reason anymore why the wallet directory and block chain directory would need to be the same.

@luke-jr
Copy link
Member

luke-jr commented Jun 4, 2013

Having been using this for a few months, I have to say I prefer (1).

@laanwj
Copy link
Member

laanwj commented Jun 4, 2013

Why? Are you against setting the wallet directory?

@luke-jr
Copy link
Member

luke-jr commented Jun 4, 2013

It's easier and less disk-bloating to just use simple files, IMO.

@laanwj
Copy link
Member

laanwj commented Jun 4, 2013

How do you mean "just use simple files"? I don't understand you, we aren't changing the wallet format here. BDB will still create a database environment, and it needs to be on the same disk as the .dat file (for reasons gmaxwell mentions). So if the user wants to store the wallet on say, a removable disk, he needs the database environment there as well.

Option 1 would make this impossible (as the database environment is locked in place), and forces the user to always have the wallet in the same directory as the block chain.

@luke-jr
Copy link
Member

luke-jr commented Jun 4, 2013

Different use cases / user preferences, I guess. Maybe if there's a "/" on the end, interpret it as a directory, and if there isn't, make sure there's no "/"s at all?

@laanwj
Copy link
Member

laanwj commented Jun 4, 2013

Or maybe two separate options, instead of trying to parse it from one value:

-walletdir=/dir/etc/   directory of wallet and db env (defaults to datadir)
-wallet=bla.dat         name of wallet (defaults to wallet.dat). Within walletdir, cannot contain '/'.

@luke-jr
Copy link
Member

luke-jr commented Jun 4, 2013

Too much shed painting; let's just merge it as long as the main concern is solved :)

(prefer to append the file extension in code, to ease changing wallet formats later)

@sipa
Copy link
Member

sipa commented Jun 4, 2013

I don't see the problem. Just allow specifying any filename, and use database/ in the directory that file is in as a database dir? If filename doesn't contain any /, use the datadir.

@laanwj
Copy link
Member

laanwj commented Jun 4, 2013

Agree with @sipa

@lost-tty
Copy link
Author

I've updated this request:

  1. strWalletFile is now used for salvage/recover (previously those features were still using wallet.dat)
  2. The supplied wallet file can not contain paths anymore so only plain filenames are allowed now. Even relative paths inside the data directory will be rejected.

@sipa
Copy link
Member

sipa commented Jun 30, 2013

ACK on the semantics, but can you move strWalletFile from main.cpp to init.cpp? (the validation logic has no business knowing where the wallet file is located).

@lost-tty
Copy link
Author

lost-tty commented Jul 3, 2013

Any objections or ACKs?

@sipa
Copy link
Member

sipa commented Jul 3, 2013

ACK, if you squeeze the commits.

use std::string instead of psz for WalletFile

only allow wallets within $DATADIR

Use strWalletFile in salvage/recover

fix: remove unused variable pszWalletFile

move strWalletFile to init.h/init.cpp

avoid conversion of strWalletfile to c-string
@sipa
Copy link
Member

sipa commented Jul 4, 2013

ACK

@BitcoinPullTester
Copy link

Automatic sanity-testing: PASSED, see http://jenkins.bluematt.me/pull-tester/674cb304b376358fdcb17b4a0b16ae7b00cdbedc for binaries and test log.
This test script verifies pulls every time they are updated. It, however, dies sometimes and fails to test properly. If you are waiting on a test, please check timestamps to verify that the test.log is moving at http://jenkins.bluematt.me/pull-tester/current/
Contact BlueMatt on freenode if something looks broken.

gavinandresen added a commit that referenced this pull request Jul 25, 2013
let user select wallet file with -wallet=foo.dat
@gavinandresen gavinandresen merged commit 5e67e12 into bitcoin:master Jul 25, 2013
@lost-tty lost-tty deleted the multi-wallet branch July 26, 2013 09:24
KolbyML pushed a commit to KolbyML/bitcoin that referenced this pull request Dec 5, 2020
… extraction.

b189cc3 Created coldstaking_tests unit test, checking cold staking script keys proper extraction. (furszy)

Pull request description:

  Essentially proving bitcoin#1830 bug and bitcoin#1888 subsequent fix.

ACKs for top commit:
  Fuzzbawls:
    ACK b189cc3
  random-zebra:
    ACK b189cc3 (failing on master, passing on bitcoin#1888). Merging...

Tree-SHA512: 9af3975fe099a0e26feddf2fd52abee12864bf77bb511b2fbed6f39a9ea029cdc057d15157fafe842cd7e2b438447a08dc455c763feeecdc1378af637541eaf1
@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.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants