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.
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:
0$ ./src/qt/bitcoin-qt -debug -testnet
1terminate called after throwing an instance of 'std::runtime_error'
2 what(): BerkeleyBatch: Can't open database wallet.dat (duplicates fileid 99059e0100fe00005cbe4ae945270e0000000000 from wallet.dat)
3Aborted
0$ ./src/bitcoind -testnet -wallet=t7.dat -wallet=t8.dat
12019-09-20T17:55:40Z Bitcoin Core version v0.18.99.0-8b8964e872 (debug build)
2...
32019-09-20T17:55:40Z Using data directory /home/jon/.bitcoin/testnet3
42019-09-20T17:55:40Z Using wallet directory /home/jon/.bitcoin/testnet3/wallets
52019-09-20T17:55:40Z init message: Verifying wallet(s)...
62019-09-20T17:55:40Z Using BerkeleyDB version Berkeley DB 4.8.30: (April 9, 2010)
72019-09-20T17:55:40Z Using wallet /home/jon/.bitcoin/testnet3/wallets/t7.dat
82019-09-20T17:55:40Z BerkeleyEnvironment::Open: LogDir=/home/jon/.bitcoin/testnet3/wallets/t7.dat/database
9 ErrorFile=/home/jon/.bitcoin/testnet3/wallets/t7.dat/db.log
102019-09-20T17:55:40Z scheduler thread start
112019-09-20T17:55:40Z Using BerkeleyDB version Berkeley DB 4.8.30: (April 9, 2010)
122019-09-20T17:55:40Z Using wallet /home/jon/.bitcoin/testnet3/wallets/t8.dat
132019-09-20T17:55:40Z BerkeleyEnvironment::Open: LogDir=/home/jon/.bitcoin/testnet3/wallets/t8.dat/database
14 ErrorFile=/home/jon/.bitcoin/testnet3/wallets/t8.dat/db.log
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.
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:
02019-11-20T09:42:58Z [] Using BerkeleyDB version Berkeley DB 4.8.30: (April 9, 2010)
12019-11-20T09:42:58Z [] Using wallet /home/hebasto/.bitcoin/testnet3/wallets/w20191015
22019-11-20T09:42:58Z [] BerkeleyEnvironment::Open: LogDir=/home/hebasto/.bitcoin/testnet3/wallets/w20191015/database ErrorFile=/home/hebasto/.bitcoin/testnet3/wallets/w20191015/db.log
32019-11-20T09:42:58Z [] init message: Loading wallet...
42019-11-20T09:42:58Z [] BerkeleyEnvironment::Open: LogDir=/home/hebasto/.bitcoin/testnet3/wallets/w20191015/database ErrorFile=/home/hebasto/.bitcoin/testnet3/wallets/w20191015/db.log
52019-11-20T09:42:58Z [] [w20191015] Wallet File Version = 169900
62019-11-20T09:42:58Z [] [w20191015] Keys: 2003 plaintext, 0 encrypted, 2003 w/ metadata, 2003 total. Unknown wallet records: 0
72019-11-20T09:42:58Z [] [w20191015] Wallet completed loading in 29ms
8...
92019-11-20T09:43:16Z [] Using BerkeleyDB version Berkeley DB 4.8.30: (April 9, 2010)
102019-11-20T09:43:16Z [] Using wallet /home/hebasto/.bitcoin/testnet3/wallets/w20191015 (copy)
112019-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
122019-11-20T09:43:16Z [] init message: Loading wallet...
132019-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
14terminate called after throwing an instance of 'std::runtime_error'
15 what(): BerkeleyBatch: Can't open database wallet.dat (duplicates fileid f78d2600020800008513f6218301020000000000 from wallet.dat)
16Aborted (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:
0$ ls ~/.bitcoin/testnet3/wallets/ | grep w20191015
1w20191015
2w20191015 (copy)
on master:
0$ ./src/qt/bitcoin-qt -testnet
1terminate called after throwing an instance of 'std::runtime_error'
2 what(): BerkeleyBatch: Can't open database wallet.dat (duplicates fileid f78d2600020800008513f6218301020000000000 from wallet.dat)
3Aborted (core dumped)
with this pr:
0$ ./src/qt/bitcoin-qt -testnet
1terminate called after throwing an instance of 'std::runtime_error'
2 what(): BerkeleyBatch: Can't open database wallet.dat (duplicates fileid f78d2600020800008513f6218301020000000000 from wallet.dat)
3Aborted (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 68e0ff0e1 tested rebased on master 5f9cd62f33fb4
0(origin/pr/16923) $ uname -a
1Linux 4.19.0-5-amd64 [#1](/bitcoin-bitcoin/1/) SMP Debian 4.19.37-5+deb10u2 (2019-08-08) x86_64 GNU/Linux
2(origin/pr/16923) $ ./src/bitcoind -testnet -wallet=t8-copy.dat -wallet=t8.dat
3...
42020-03-30T13:04:17Z Using wallet directory /home/jon/.bitcoin/testnet3/wallets
52020-03-30T13:04:17Z init message: Verifying wallet(s)...
62020-03-30T13:04:17Z Using BerkeleyDB version Berkeley DB 4.8.30: (April 9, 2010)
72020-03-30T13:04:17Z Using wallet /home/jon/.bitcoin/testnet3/wallets/t8-copy.dat
82020-03-30T13:04:17Z BerkeleyEnvironment::Open:
9 LogDir=/home/jon/.bitcoin/testnet3/wallets/t8-copy.dat/database
10 ErrorFile=/home/jon/.bitcoin/testnet3/wallets/t8-copy.dat/db.log
112020-03-30T13:04:17Z Using BerkeleyDB version Berkeley DB 4.8.30: (April 9, 2010)
122020-03-30T13:04:17Z Using wallet /home/jon/.bitcoin/testnet3/wallets/t8.dat
132020-03-30T13:04:17Z BerkeleyEnvironment::Open:
14 LogDir=/home/jon/.bitcoin/testnet3/wallets/t8.dat/database
15 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).