rc6 crashes trying to rewrite wallet #644

issue dooglus opened this issue on November 19, 2011
  1. dooglus commented at 1:06 AM on November 19, 2011: contributor

    I've been testing the release candidates. rc1 through rc3 seem OK, but rc4 through rc6 all crash when I try to start them with my existing excrypted wallet:

    $ ./bitcoin-qt QGtkStyle was unable to detect the current GTK+ theme.


    EXCEPTION: 11DbException
    Db::open: Invalid argument
    bitcoin in Runaway exception

    terminate called after throwing an instance of 'DbException' what(): Db::open: Invalid argument Aborted $

    The exception is thrown by the "ret = pdbCopy->open(NULL, ...) in CDB::Rewrite() in db.cpp

    I'm running a 64 bit archlinux, and am linking against package Berkeley DB ('db') version 5.2.36-2 because I couldn't find a version 4.

    Is that likely to be causing this problem?

    I'm pretty sure I had rc4 manage to open my wallet one time, but can't get it to work now.

  2. dooglus commented at 1:10 AM on November 19, 2011: contributor

    I found a version 4.8 of db, so will try building against that.

    It's here:

    http://aur.archlinux.org/packages.php?ID=43907

  3. gavinandresen commented at 4:26 PM on November 19, 2011: contributor

    Cannot reproduce using Ubuntu 10.10 server.

  4. dooglus commented at 6:04 PM on November 19, 2011: contributor

    I've been able to reproduce it several times, but not reliably.

    It does seem to trash my wallet when I do, however. Luckily I made a backup before running rc6 for the first time so didn't lose any funds. I wonder if it would be good to always have bitcoin keep a copy of the previous version of the wallet in case this or other bugs cause wallet corruption. If we only update the backup each time we successfully load a wallet we should never have the user be without any working copy of their wallet.

    I'll try again to find a reliable way to reproduce this problem.

  5. dooglus commented at 6:55 PM on November 19, 2011: contributor

    OK, this seems to do it:

    /bin/rm -fr ~/.bitcoin; rc1-db4/bitcoin-qt -keypool=3; rc6-db4/bitcoin-qt -keypool=3; rc6-db4/bitcoin-qt -keypool=3

    Remove .bitcoind, create it using rc1 and immediately encrypt the wallet, then quit. Then run rc6, it will rewrite the wallet and exit. Run it again, and it fails to start. Here's the output. I put some debugging printf()s in db4.8.

    chris@chris:~/Programs/bitcoin$ /bin/rm -fr ~/.bitcoin; rc1-db4/bitcoin-qt -keypool=3; rc6-db4/bitcoin-qt -keypool=3; rc6-db4/bitcoin-qt -keypool=3 QGtkStyle was unable to detect the current GTK+ theme. __db_open_pp('addr.dat') __db_open_pp('addr.dat') returning 0 __db_open_pp('blkindex.dat') __db_open_pp('blkindex.dat') returning 0 __db_open_pp('wallet.dat') __db_open_pp('wallet.dat') returning 0 QGtkStyle was unable to detect the current GTK+ theme. subdb exists __db_open_pp('addr.dat') subdb exists __db_open_pp('addr.dat') returning 0 __db_open_pp('blkindex.dat') subdb exists __db_open_pp('blkindex.dat') returning 0 __db_open_pp('wallet.dat') subdb exists __db_open_pp('wallet.dat') returning 0 __db_open_pp('wallet.dat') subdb exists __db_open_pp('wallet.dat') returning 0 __db_open_pp('wallet.dat.rewrite') __db_open_pp('wallet.dat.rewrite') returning 0 QGtkStyle was unable to detect the current GTK+ theme. __db_open_pp('addr.dat') subdb exists __db_open_pp('addr.dat') returning 0 __db_open_pp('blkindex.dat') subdb exists __db_open_pp('blkindex.dat') returning 0 __db_open_pp('wallet.dat') __db_open_pp('wallet.dat') returning 22


    EXCEPTION: 11DbException
    Db::open: Invalid argument
    bitcoin in Runaway exception

    terminate called after throwing an instance of 'DbException' what(): Db::open: Invalid argument Aborted chris@chris:~/Programs/bitcoin$

    I've uploaded the resulting .bitcoin folder here: http://replay.marpirc.net/chris/bitcoin.tgz

    It fails to load up in rc6 for me. How about you?

  6. dooglus commented at 8:01 PM on November 19, 2011: contributor

    I did some more testing of this.

    If I create and encrypt the wallet using rc3 and rewrite it using rc4, the wallet got corrupted only 1 in 5 trials.

    Rather than writing this out in full for each case, here's a summary:

    (encrypt using -> rewrite using = corrupted) 3 -> 4 = 1 of 5 1 -> 4 = 1 of 5 3 -> 5 = 0 of 3 1 -> 5 = 0 of 3 1 -> 6 = 6 of 6 3 -> 6 = 6 of 6

    so it seems that creating the wallet with rc1 or rc3 then loading it into rc6 is the least safe rc4 and rc5 mostly are able to rewrite old wallets correctly, but rc6 always corrupts them.

  7. dooglus commented at 8:27 PM on November 19, 2011: contributor

    If I comment out line 34 of db.cpp (rc6): // fRemoveLogFiles = fIn; then creating and encrypting a wallet in rc3 and rewriting it in rc6 doesn't corrupt the wallet (0 of 2 trials caused corruption).

  8. dooglus commented at 8:41 PM on November 19, 2011: contributor

    This has allowed me to load my original wallet backup. Just commenting line 1157 of wallet.cpp (rc6) fixes the problem for me: // RemoveLogFilesOnShutdown(true);

    Also, would it be possible to load the wallet first? Having to wait several minutes for the addresses and blockchain to load only to have the wallet be rewritten causing bitcoin to need restarting is annoying:

    Loading addresses... dbenv.open strLogDir=/home/chris/.bitcoin/database strErrorFile=/home/chris/.bitcoin/db.log Loaded 150885 addresses addresses 44139ms Loading block index... LoadBlockIndex(): hashBestChain=0000000000000ac25d05 height=153983 block index 87077ms Loading wallet...

  9. dooglus commented at 9:05 PM on November 19, 2011: contributor

    http://pybsddb.sourceforge.net/ref/transapp/logfile.html tells me:

    "you cannot remove the current log files simply because you have created a database snapshot"

    "Log files may be removed at any time, as long as:

    the log file is not involved in an active transaction. at least two checkpoints have been written subsequent to the log file's creation. the log file is not the only log file in the environment."

    In my test cases, bitcoin is removing the only log file in the environment. Is this the problem?

  10. gavinandresen commented at 2:16 AM on November 20, 2011: contributor

    Could be, although the log file is only removed after the new wallet is successfully written and the environment has been closed.

    The problem is the log file can contain old, unencrypted private keys; suggestions on how to get bdb to completely clean up after itself very welcome...

  11. dooglus commented at 7:05 AM on November 20, 2011: contributor

    If I comment out the actual 'delete log file' line only, I can create a wallet in rc3 and have rc6 rewrite it, then load it successfully. If I have it rewrite the wallet, then wait a minute and delete the logfile from .bitcoin/databases while no bitcoin process is running, it won't later load up the wallet again.

    So it seems that the log files can contain something necessary even when the process is stopped.

    This file: http://replay.marpirc.net/chris/bitcoin2.tgz contains just 2 files: wallet.dat and database/log.0000000001

    If you extract it, the wallet loads. If you blow it away, extract it again, and "rm .bitcoin/database/log.0000000001", it doesn't load. If you blow it away, extract again, run bitcoin and quit, the log.001 has gone, but log.002 has appeared, which also breaks things if you delete it after closing bitcoin.

    It's as if there's something in the logfiles that makes the wallet work. Deleting them willy-nilly seems kind of dangerous.

  12. gavinandresen commented at 4:08 PM on November 20, 2011: contributor

    OK... Plan E : Leave the log file alone.

    That means encrypting your wallet gets you a good wallet.dat file, but old private keys will hang around in the database/log.* file for a while, but will eventually be removed when you cleanly shutdown bitcoin.

  13. dooglus commented at 5:00 PM on November 20, 2011: contributor

    What will be removed when you shutdown bitcoin?

    The logfiles aren't removed when I shut down. And I don't know if it's safe to assume the keys will be removed from the logfile either.

  14. gavinandresen commented at 5:31 PM on November 20, 2011: contributor

    BDB closes the old logfile and opens a new one when it get close to 10megabytes big.

    When bitcoin shuts down cleanly, it asks BDB to remove any unused log files, and BDB will remove all but one file from database/log.*

    So: if you encrypt your wallet, unencrypted private keys will be in the old part of the log file. But after running for a day or two, BDB will close that old log file and open a new one. Then, the next time you restart bitcoin, the old log file containing the unencrypted keys is removed.

    This seems like a reasonable compromise between security and safety for now; a better wallet encryption solution for the next version of bitcoin (one that doesn't require shutting down and restarting after encrypting the wallet) is a good idea, but out of scope for this release.

  15. dooglus commented at 5:37 PM on November 20, 2011: contributor

    OK. Thanks for explaining that.

  16. gavinandresen commented at 8:47 PM on November 20, 2011: contributor

    Thanks very much for helping test! rc7 binaries are available now.

  17. dooglus commented at 1:43 AM on November 21, 2011: contributor

    For the fun of it I just tested sipa's 'resilver' change. It fixes this whole issue. So I think you can go back to deleting the logfiles.

    To be clear, git revision f47dfa5a works for me.

  18. sipa commented at 5:40 PM on February 19, 2012: member

    So this issue can be closed?

  19. laanwj closed this on Sep 21, 2012

  20. ptschip referenced this in commit c3ea564c5a on Jun 11, 2017
  21. dexX7 referenced this in commit 2cfb7ebcb1 on Jul 16, 2018
  22. elichai referenced this in commit 461acf5c6c on Aug 22, 2019
  23. elichai referenced this in commit 69b0efd59f on Aug 22, 2019
  24. sipa referenced this in commit 6b9cd1520b on Sep 24, 2019
  25. sipa referenced this in commit 544c1f35e7 on Nov 6, 2019
  26. sipa referenced this in commit d5cd9db7a3 on Nov 19, 2019
  27. sipa referenced this in commit de659898b6 on Jan 21, 2020
  28. sipa referenced this in commit 36362dfb90 on Jan 23, 2020
  29. jnewbery referenced this in commit 85e7d06351 on Mar 17, 2020
  30. sipa referenced this in commit 4977ac14d3 on Mar 18, 2020
  31. sipa referenced this in commit 5bf7fb5baa on Mar 18, 2020
  32. sipa referenced this in commit fb2a05e468 on Mar 19, 2020
  33. sipa referenced this in commit 497fad6f09 on Mar 21, 2020
  34. sipa referenced this in commit eae016f117 on Mar 22, 2020
  35. sipa referenced this in commit 4e37a7c2cb on Mar 27, 2020
  36. jnewbery referenced this in commit 9696dea839 on Apr 16, 2020
  37. jnewbery referenced this in commit a541fd0e87 on Apr 19, 2020
  38. sipa referenced this in commit c308759ea5 on Apr 19, 2020
  39. sipa referenced this in commit 4eaec32f1c on May 2, 2020
  40. sipa referenced this in commit ef7117193c on May 22, 2020
  41. sipa referenced this in commit 67f232b5d8 on Jun 9, 2020
  42. stackman27 referenced this in commit 78cde6f8c7 on Jun 26, 2020
  43. MarcoFalke locked this on Sep 8, 2021

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: 2026-04-16 00:15 UTC

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