wallet: Handle duplicate fileid exception #16923

pull promag wants to merge 2 commits into bitcoin:master from promag:2019-09-fix-duplicate-exception changing 5 files +43 −25
  1. promag commented at 2:55 pm on September 20, 2019: member

    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.

  2. promag commented at 2:56 pm on September 20, 2019: member
    To backport?
  3. promag force-pushed on Sep 20, 2019
  4. emilengler commented at 4:28 pm on September 20, 2019: contributor
    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
  5. DrahtBot added the label Wallet on Sep 20, 2019
  6. jonatack commented at 6:19 pm on September 20, 2019: member

    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
    
  7. promag force-pushed on Sep 29, 2019
  8. laanwj added the label Bug on Sep 30, 2019
  9. DrahtBot commented at 3:02 pm on October 7, 2019: member

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #16224 (gui: Bilingual GUI error messages by hebasto)

    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.

  10. DrahtBot added the label Needs rebase on Oct 21, 2019
  11. promag force-pushed on Nov 3, 2019
  12. DrahtBot removed the label Needs rebase on Nov 4, 2019
  13. hebasto commented at 10:03 am on November 20, 2019: member

    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)
    
  14. promag commented at 3:45 pm on January 9, 2020: member

    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 in LoadWallets, note that all branches have a return value.

  15. promag commented at 3:47 pm on January 9, 2020: member
    @hebasto IIRC I tried with no success to hit that, prolly I’ve done something wrong.
  16. hebasto commented at 5:01 pm on January 9, 2020: member

    @promag

    @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:

    1. prepare a copy of a wallet:
    0$ ls ~/.bitcoin/testnet3/wallets/ | grep w20191015
    1w20191015
    2w20191015 (copy)
    
    1. load wallets one by one

    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)

  17. hebasto commented at 9:13 pm on March 27, 2020: member
    @promag are you still working on this pr?
  18. promag force-pushed on Mar 28, 2020
  19. promag renamed this:
    wallet: Fix duplicates fileid exception on start
    wallet: Handle duplicates fileid exception
    on Mar 28, 2020
  20. promag renamed this:
    wallet: Handle duplicates fileid exception
    wallet: Handle duplicate fileid exception
    on Mar 28, 2020
  21. promag force-pushed on Mar 28, 2020
  22. promag commented at 11:08 am on March 28, 2020: member
    @hebasto updated OP, thanks for the remind!
  23. hebasto commented at 6:17 pm on March 28, 2020: member

    Tested 4deb8fa32e4f40b2f63ac8aa5b6fff76101af40c on Linux Mint 19.3:

    Screenshot from 2020-03-28 20-14-25

    i.e., the exception is handled, but the client keeps trying to load the duplicated wallet forever.

  24. promag commented at 6:30 pm on March 28, 2020: member

    i.e., the exception is handled, but the client keeps trying to load the duplicated wallet forever.

    Forever how?

  25. hebasto commented at 6:33 pm on March 28, 2020: member

    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…

  26. promag commented at 1:00 am on March 30, 2020: member
    @hebasto I fail to reproduce your case on osx. Does the progress go away when you press “OK” on the “Open wallet failed” dialog? On osx the error dialog shows on top.
  27. hebasto commented at 7:33 am on March 30, 2020: member

    @promag

    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:

  28. hebasto commented at 11:52 am on March 30, 2020: member
    ACK a7f81a9f98113a92de515bd13e59052885b42541, tested on Linux Mint 19.3.
  29. promag force-pushed on Mar 30, 2020
  30. promag commented at 12:03 pm on March 30, 2020: member
    @hebasto improved last commit, no longer wip.
  31. hebasto approved
  32. hebasto commented at 12:06 pm on March 30, 2020: member

    ACK 68e0ff0e1f530c942721aab49cf67ffc07104628 @promag your last changes were on my tongue ;)

    nit: #include <cassert>

  33. jonatack commented at 1:25 pm on March 30, 2020: member

    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:

    Screenshot from 2020-03-30 15-03-30

    In a follow-up, it might be helpful if the error message stated the conflicting wallet names.

  34. promag commented at 4:51 pm on March 30, 2020: member

    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.

  35. wallet: Handle duplicate fileid exception ee9e88ba27
  36. gui: Delete progress dialog instead of hidding it 9eefc6e92f
  37. promag force-pushed on Mar 31, 2020
  38. promag commented at 1:25 pm on March 31, 2020: member
    Rebased after merging #18338.
  39. jonatack commented at 3:30 pm on March 31, 2020: member

    Re-ACK 9eefc6e92fa1acef6eddd87886ed80510b439a57 no change since last review 68e0ff0e1f530c942721aab49cf67ffc07104628

    Screenshot from 2020-03-31 17-23-57

  40. laanwj added this to the milestone 0.20.0 on Mar 31, 2020
  41. jonatack commented at 5:37 pm on March 31, 2020: member

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

    Screen Shot 2020-03-31 at 7 28 54 PM

  42. hebasto commented at 9:10 pm on March 31, 2020: member
    re-ACK 9eefc6e92fa1acef6eddd87886ed80510b439a57
  43. laanwj merged this on Apr 2, 2020
  44. laanwj closed this on Apr 2, 2020

  45. promag deleted the branch on Apr 2, 2020
  46. sidhujag referenced this in commit fb46b04c87 on Apr 2, 2020
  47. Fabcien referenced this in commit 3fcc6ed32b on Jan 13, 2021
  48. DrahtBot locked this on Feb 15, 2022

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2024-11-17 12:12 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me