Prevent unencrypted private keys from being written to wallet.dat #635
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Unencrypted private keys could remain in the wallet.dat file (and other berkely db database files) after wallet encryption.
This pull request does several things to fix the problem:
Completely rewrites the wallet.dat file upon encryption.
Removes all keys from the keypool so they will not be used for new transactions (they are encrypted and stored in the new wallet, in case any bitcoins are sent to them).
Modifies the database code so temporary database files are cleaned up when bitcoin shuts down
Successful encryption of the wallet is now followed by a shutdown, so old unencrypted private keys that might have been in the database's caches will not be written to the new, encrypted wallet file.