Handle the duplicate fileid exception thrown at CheckUniqueFileid in tow cases:
- when duplicate wallets are set on the command line - catch in
LoadWallets; - when a duplicate wallet is loaded dynamically - catch in
LoadWallet.
Fixes #16776.
To backport?
I don't know if that's a thing here but there is no function at the end which returns something (In practice it is). Probably some compilers will give a warning or errer so you might should add a return false; at the end
Thanks @promag for working on this.
Note: the PR description should be updated to suggest reviewing with git show -w 8b8964e
Functional test wallet_multiwallet.py --usecli is failing for me with AssertionError: [node 0] Expected message "BerkeleyBatch: Can't open database w8_copy \(duplicates fileid \w+ from w8\)" does not partially match stderr: ""
Here are the results at 8b8964e of loading 2 identical wallets in ~/.bitcoin/testnet3/wallets/ named t7 and t8:
$ ./src/qt/bitcoin-qt -debug -testnet
terminate called after throwing an instance of 'std::runtime_error'
what(): BerkeleyBatch: Can't open database wallet.dat (duplicates fileid 99059e0100fe00005cbe4ae945270e0000000000 from wallet.dat)
Aborted
$ ./src/bitcoind -testnet -wallet=t7.dat -wallet=t8.dat
2019-09-20T17:55:40Z Bitcoin Core version v0.18.99.0-8b8964e872 (debug build)
...
2019-09-20T17:55:40Z Using data directory /home/jon/.bitcoin/testnet3
2019-09-20T17:55:40Z Using wallet directory /home/jon/.bitcoin/testnet3/wallets
2019-09-20T17:55:40Z init message: Verifying wallet(s)...
2019-09-20T17:55:40Z Using BerkeleyDB version Berkeley DB 4.8.30: (April 9, 2010)
2019-09-20T17:55:40Z Using wallet /home/jon/.bitcoin/testnet3/wallets/t7.dat
2019-09-20T17:55:40Z BerkeleyEnvironment::Open: LogDir=/home/jon/.bitcoin/testnet3/wallets/t7.dat/database
ErrorFile=/home/jon/.bitcoin/testnet3/wallets/t7.dat/db.log
2019-09-20T17:55:40Z scheduler thread start
2019-09-20T17:55:40Z Using BerkeleyDB version Berkeley DB 4.8.30: (April 9, 2010)
2019-09-20T17:55:40Z Using wallet /home/jon/.bitcoin/testnet3/wallets/t8.dat
2019-09-20T17:55:40Z BerkeleyEnvironment::Open: LogDir=/home/jon/.bitcoin/testnet3/wallets/t8.dat/database
ErrorFile=/home/jon/.bitcoin/testnet3/wallets/t8.dat/db.log
<!--e57a25ab6845829454e8d69fc972939a-->
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.
<!--174a7506f384e20aa4161008e828411d-->
Reviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.
Dynamically loading a duplicate wallet doesn't result in the same problem.
That's not the case, unfortunately. Tested on Linux Mint 19.2:
2019-11-20T09:42:58Z [] Using BerkeleyDB version Berkeley DB 4.8.30: (April 9, 2010)
2019-11-20T09:42:58Z [] Using wallet /home/hebasto/.bitcoin/testnet3/wallets/w20191015
2019-11-20T09:42:58Z [] BerkeleyEnvironment::Open: LogDir=/home/hebasto/.bitcoin/testnet3/wallets/w20191015/database ErrorFile=/home/hebasto/.bitcoin/testnet3/wallets/w20191015/db.log
2019-11-20T09:42:58Z [] init message: Loading wallet...
2019-11-20T09:42:58Z [] BerkeleyEnvironment::Open: LogDir=/home/hebasto/.bitcoin/testnet3/wallets/w20191015/database ErrorFile=/home/hebasto/.bitcoin/testnet3/wallets/w20191015/db.log
2019-11-20T09:42:58Z [] [w20191015] Wallet File Version = 169900
2019-11-20T09:42:58Z [] [w20191015] Keys: 2003 plaintext, 0 encrypted, 2003 w/ metadata, 2003 total. Unknown wallet records: 0
2019-11-20T09:42:58Z [] [w20191015] Wallet completed loading in 29ms
...
2019-11-20T09:43:16Z [] Using BerkeleyDB version Berkeley DB 4.8.30: (April 9, 2010)
2019-11-20T09:43:16Z [] Using wallet /home/hebasto/.bitcoin/testnet3/wallets/w20191015 (copy)
2019-11-20T09:43:16Z [] BerkeleyEnvironment::Open: LogDir=/home/hebasto/.bitcoin/testnet3/wallets/w20191015 (copy)/database ErrorFile=/home/hebasto/.bitcoin/testnet3/wallets/w20191015 (copy)/db.log
2019-11-20T09:43:16Z [] init message: Loading wallet...
2019-11-20T09:43:16Z [] BerkeleyEnvironment::Open: LogDir=/home/hebasto/.bitcoin/testnet3/wallets/w20191015 (copy)/database ErrorFile=/home/hebasto/.bitcoin/testnet3/wallets/w20191015 (copy)/db.log
terminate called after throwing an instance of 'std::runtime_error'
what(): BerkeleyBatch: Can't open database wallet.dat (duplicates fileid f78d2600020800008513f6218301020000000000 from wallet.dat)
Aborted (core dumped)
I don't know if that's a thing here but there is no function at the end which returns something (In practice it is). Probably some compilers will give a warning or errer so you might should add a
return false;at the end @emilengler I think you mean inLoadWallets, note that all branches have a return value.
@hebasto IIRC I tried with no success to hit that, prolly I've done something wrong.
I can confirm that the fix does not work, unfortunately.
Steps to reproduce:
$ ls ~/.bitcoin/testnet3/wallets/ | grep w20191015
w20191015
w20191015 (copy)
on master:
$ ./src/qt/bitcoin-qt -testnet
terminate called after throwing an instance of 'std::runtime_error'
what(): BerkeleyBatch: Can't open database wallet.dat (duplicates fileid f78d2600020800008513f6218301020000000000 from wallet.dat)
Aborted (core dumped)
with this pr:
$ ./src/qt/bitcoin-qt -testnet
terminate called after throwing an instance of 'std::runtime_error'
what(): BerkeleyBatch: Can't open database wallet.dat (duplicates fileid f78d2600020800008513f6218301020000000000 from wallet.dat)
Aborted (core dumped)
Literally, I did steps as described in #16776 (comment)
Tested 4deb8fa32e4f40b2f63ac8aa5b6fff76101af40c on Linux Mint 19.3:

i.e., the exception is handled, but the client keeps trying to load the duplicated wallet forever.
i.e., the exception is handled, but the client keeps trying to load the duplicated wallet forever.
Forever how?
i.e., the exception is handled, but the client keeps trying to load the duplicated wallet forever.
Forever how?
Run test again: it lasts 2 minutes and keeps going...
Does the progress go away when you press "OK" on the "Open wallet failed" dialog?
No.
On osx the error dialog shows on top.
On Linux Mint 19.3 the sequence of events is as follows:
ACK a7f81a9f98113a92de515bd13e59052885b42541, tested on Linux Mint 19.3.
ACK 68e0ff0e1 tested rebased on master 5f9cd62f33fb4
(origin/pr/16923) $ uname -a
Linux 4.19.0-5-amd64 [#1](/bitcoin-bitcoin/1/) SMP Debian 4.19.37-5+deb10u2 (2019-08-08) x86_64 GNU/Linux
(origin/pr/16923) $ ./src/bitcoind -testnet -wallet=t8-copy.dat -wallet=t8.dat
...
2020-03-30T13:04:17Z Using wallet directory /home/jon/.bitcoin/testnet3/wallets
2020-03-30T13:04:17Z init message: Verifying wallet(s)...
2020-03-30T13:04:17Z Using BerkeleyDB version Berkeley DB 4.8.30: (April 9, 2010)
2020-03-30T13:04:17Z Using wallet /home/jon/.bitcoin/testnet3/wallets/t8-copy.dat
2020-03-30T13:04:17Z BerkeleyEnvironment::Open:
LogDir=/home/jon/.bitcoin/testnet3/wallets/t8-copy.dat/database
ErrorFile=/home/jon/.bitcoin/testnet3/wallets/t8-copy.dat/db.log
2020-03-30T13:04:17Z Using BerkeleyDB version Berkeley DB 4.8.30: (April 9, 2010)
2020-03-30T13:04:17Z Using wallet /home/jon/.bitcoin/testnet3/wallets/t8.dat
2020-03-30T13:04:17Z BerkeleyEnvironment::Open:
LogDir=/home/jon/.bitcoin/testnet3/wallets/t8.dat/database
ErrorFile=/home/jon/.bitcoin/testnet3/wallets/t8.dat/db.log
Attempting to load wallet t8-copy after loading wallet t8:

In a follow-up, it might be helpful if the error message stated the conflicting wallet names.
In a follow-up, it might be helpful if the error message stated the conflicting wallet names.
But It says :) yeah display the wallet name, not the underlying filename which is useless for directory based wallets.
Re-ACK 9eefc6e92fa1acef6eddd87886ed80510b439a57 no change since last review 68e0ff0e1f530c942721aab49cf67ffc07104628

Tested on macOS 10.14.6 as well (preceding test was on Debian).

re-ACK 9eefc6e92fa1acef6eddd87886ed80510b439a57
Milestone
0.20.0