Currently, the salvagewallet function sets the DB_AGGRESSIVE
flag when calling BDB’s Db::verify()
and then tries to load the output back into a database. Here’s the documentation for that flag:
Output all the key/data pairs in the file that can be found. By default, Db::verify() does not assume corruption. For example, if a key/data pair on a page is marked as deleted, it is not then written to the output file. When DB_AGGRESSIVE is specified, corruption is assumed, and any key/data pair that can be found is written. In this case, key/data pairs that are corrupted or have been deleted may appear in the output (even if the file being salvaged is in no way corrupt), and the output will almost certainly require editing before being loaded into a database.
We should not be setting the DB_AGGRESSIVE flag and then immediately trying to load the output into a database.
For more technical details see #7463 (comment).
Running with aggressive mode can lead to full database corruption and loss of private keys (#7379). The wallet is backed up to wallet.timestamp.bak, but the original wallet.dat file will lose some or all of its key-value pairs. That’s obviously a very serious usability issue for users. Many will not know about the existence of the wallet.timestamp.bak backup files.
I think in almost all cases it’s better to run Db::verify()
without the aggressive flag set. There perhaps should be a tool to run Db::verify() with the aggressive flag. If the database has been badly corrupted, it may be the only way to recover key-value pairs. However, this should be done in an external tool as the output will almost certainly require editing before being reloaded. #8745 (bitcoin-wallet-tool) is the right place for this.
This PR removes the DB_AGGRESSIVE flag from calls to Db::verify()
. It also re-enables the -salvagewallet
incidental test in wallet.py. I’ve also included a commit which cleans up that test, which can be omitted if it’s not wanted.
I’ve run wallet.py 100 times and not yet hit the salvagewallet issue in #7463. That was intermittent, so I may just be getting lucky, but I think this is an improvement.
Fixes #7463