wallet: warn when encryption cleanup fails #36793

Closed
l0rinc wants to merge 2 commits from l0rinc/wallet-encryption-rewrite-warning into master AGit
l0rinc commented 2026-11-06 18:17:35 +00:00 (Migrated from github.com)

Problem: Wallet encryption ignores a failed database rewrite after encrypted key records have been committed.
Old plaintext key material can remain in unused pages without a warning.

Fix: Log the cleanup failure while preserving the successful encryption result.
The warning advises moving funds to a newly created wallet before relying on at-rest encryption.

**Problem:** Wallet encryption ignores a failed database rewrite after encrypted key records have been committed. Old plaintext key material can remain in unused pages without a warning. **Fix:** Log the cleanup failure while preserving the successful encryption result. The warning advises moving funds to a newly created wallet before relying on at-rest encryption.
DrahtBot commented 2026-11-06 18:17:49 +00:00 (Migrated from github.com)

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

External sites

Reviews

See the guideline and AI policy for information on the review process.
A summary of reviews will appear here.

<!--e57a25ab6845829454e8d69fc972939a--> The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. <!--006a51241073e994b41acfe9ec718e94--> ### External sites * Code coverage & benchmarks: https://corecheck.dev/bitcoin/bitcoin/pulls/36793 * Ralph review <img src=https://review.fish.foo/assets/bitcoin/bitcoin/36793.png alt="Ralph review status"> https://git.fish.foo/bitcoin/bitcoin/pulls/36793#author-ralph <!--021abf342d371248e50ceaed478a90ca--> ### Reviews See [the guideline](https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#code-review) and [AI policy](https://github.com/bitcoin/bitcoin/blob/master/doc/AI_POLICY.md) for information on the review process. A summary of reviews will appear here. <!--5faf32d7da4f0f540f40219e4f7537a3-->
First-time contributor

🔵 Suggestion · Encryption callers do not receive the cleanup warning

When cleanup fails, the encryptwallet RPC and GUI encryption dialog still show their normal success messages without the move-funds advice.

Location: src/wallet/wallet.cpp:901 (head).

🔵 Suggestion · Cleanup advice unnecessarily alarms born-encrypted wallets

A rewrite failure during passphrase-protected wallet creation triggers unnecessary move-funds advice, and the advice does not specify creating the replacement with a passphrase.

Location: src/wallet/wallet.cpp:901 (head).

🔵 Suggestion · Rewrite-failure test omits committed key-record assertions

The new test checks cached wallet state after rewrite failure but does not directly check the committed key records that justify returning success.

Location: src/wallet/test/wallet_tests.cpp:203 (head).

Review coverage was incomplete.


Reviewed: 5f7f18b07a1c · Full review report · Previous reports

permalink

<!-- forgejo-review-bot:bitcoin/bitcoin --> <!-- ralph-engine:current:df0443dc5cff1224f58cf2f0af2a814b52ac77c4fa18c64584a637f43b36d781:adfdaf6241fe97209d62717f4b34912a3f3c05551d5eb04e28ec078dd3f7e4f2 --> <!-- ralph-base:5bf3bc5e263407a252c14a17afe04fc3bf24a889 --> <!-- ralph-head:5f7f18b07a1ca15e95a74ea80e4b09343ba879dc --> <!-- ralph-case:4552b645aa3db5c4b16bdaeb66997d32127eaaae660df201512c604877bd43ad --> **🔵 Suggestion · Encryption callers do not receive the cleanup warning** When cleanup fails, the encryptwallet RPC and GUI encryption dialog still show their normal success messages without the move-funds advice. Location: [`src/wallet/wallet.cpp:901`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/5f7f18b07a1ca15e95a74ea80e4b09343ba879dc/src/wallet/wallet.cpp#L901>) (head). **🔵 Suggestion · Cleanup advice unnecessarily alarms born-encrypted wallets** A rewrite failure during passphrase-protected wallet creation triggers unnecessary move-funds advice, and the advice does not specify creating the replacement with a passphrase. Location: [`src/wallet/wallet.cpp:901`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/5f7f18b07a1ca15e95a74ea80e4b09343ba879dc/src/wallet/wallet.cpp#L901>) (head). **🔵 Suggestion · Rewrite-failure test omits committed key-record assertions** The new test checks cached wallet state after rewrite failure but does not directly check the committed key records that justify returning success. Location: [`src/wallet/test/wallet_tests.cpp:203`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/5f7f18b07a1ca15e95a74ea80e4b09343ba879dc/src/wallet/test/wallet_tests.cpp#L203>) (head). Review coverage was incomplete. <!-- Review tier: sensitive --> --- Reviewed: [`5f7f18b07a1c`](<https://git.fish.foo/bitcoin/bitcoin/commit/5f7f18b07a1ca15e95a74ea80e4b09343ba879dc>) · [Full review report](<https://review.fish.foo/traces/36793-5f7f18b07a1ca15e95a74ea80e4b09343ba879dc-2330-1.html>) · [Previous reports](<https://review.fish.foo/traces/36793/>) [permalink](<https://review.fish.foo/traces/36793-5f7f18b07a1ca15e95a74ea80e4b09343ba879dc-2330-1.html>)
achow101 commented 2026-11-06 23:44:14 +00:00 (Migrated from github.com)

I prefer that we simply drop this code once encryptwallet is dropped altogether.

Or alternatively, we do a RAII thing that turns on/off secure_delete as needed, rather than requiring the caller to use VACUUM afterwards which can fail.

I prefer that we simply drop this code once `encryptwallet` is dropped altogether. Or alternatively, we do a RAII thing that turns on/off `secure_delete` as needed, rather than requiring the caller to use `VACUUM` afterwards which can fail.
achow101 commented 2026-11-07 02:13:15 +00:00 (Migrated from github.com)

Prefer #36796

Prefer #36796
vicjuma commented 2026-11-07 13:27:55 +00:00 (Migrated from github.com)

Agree with @achow101. Resolving #36027 will remove most of these "post-commit" arms including #35966

Agree with @achow101. Resolving #36027 will remove most of these "post-commit" arms including #35966
l0rinc commented 2026-11-07 16:20:22 +00:00 (Migrated from github.com)

Thanks for the comments!

Thanks for the comments!
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
bitcoin/bitcoin!36793
No description provided.