Currently, when we make deletions or updates to the database that require records to be fully deleted and to not persist in free pages afterwards, we need to explicitly call WalletDatabase::Rewrite. This behavior was introduced in #635 to ensure that unencrypted private keys are erased from the database after encrypting a wallet, and initial encryption is the only consumer of this function.
However, initial encryption is not the only functionality that requires secure deletion. l0rinc's LLMs recently found changing the passphrase can leave the original that encryption key record in free pages. We should want to ensure that those records are also deleted, although I do not consider that the presence of such records in free space to actually be a problem. Note that this behavior appears to be present since wallet encryption was initially introduced in #352.
Fortunately, SQLite offers a secure_delete flag that can be enabled on each connection to a database. If set, all deletes or updates will ensure that any data that was deleted or overwritten actually are overwritten with 0's. It is one of the 2 methods in SQLite's documentation for ensuring that records do not persist in free pages, the other method being to call VACUUM after deletions or updates, which is what Rewrite does.
The downside is that secure_delete will increase CPU and disk I/O, which is why this was not set previously. However, it seems like several distros ship with secure_delete enabled by default: Debian, Ubuntu, Fedora, Arch, and NixOS all set SQLite's compile time option to default secure_delete to enabled, and these are just the ones I've looked at. This suggests to me that the performance penalty is not actually that bad. As I run Arch and often do not use depends builds, I had not noticed that secure_delete was always on and did not experience any particularly poor wallet performance that could be attributed to that behavior. In the grand scheme of things, erases and updates are fairly infrequent in the wallet.
This PR enables secure_delete when the database is opened, and also enables it by default in the sqlite depends package. There are also a couple tests to check that all records we want deleted actually are being deleted from the database. WalletDatabase::Rewrite is removed as it it is no longer used.