Skip to content

Conversation

@achow101
Copy link
Member

@achow101 achow101 commented Jan 7, 2026

As pointed out in #34156 (comment), it is possible for createfromdump to also accidentally delete the entire wallets directory if the wallet name is the empty string and the dumpfile contains a checksum error.

This is also fixed by removing the files created by only removing the directory for named wallets, and avoiding the use of fs::remove_all.

@DrahtBot
Copy link
Contributor

DrahtBot commented Jan 7, 2026

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

Code Coverage & Benchmarks

For details see: https://corecheck.dev/bitcoin/bitcoin/pulls/34215.

Reviews

See the guideline for information on the review process.

Type Reviewers
ACK waketraindev, polespinasa, rkrux, willcl-ark, pablomartin4btc
Approach ACK w0xlt

If your review is incorrectly listed, please copy-paste <!--meta-tag:bot-skip--> into the comment that the bot should ignore.

Copy link
Contributor

@w0xlt w0xlt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approach ACK

@waketraindev
Copy link
Contributor

lgtm ACK f78f6f1

tested manually, datadir no longer removed.

$ ./bitcoin-wallet -datadir=./local-datadir -dumpfile=test.dump createfromdump; ls local-datadir
Error: Got key that was not hex: malformedData13370776657273696f6e
test-wallet

@DrahtBot DrahtBot requested a review from w0xlt January 7, 2026 01:14
Copy link
Member

@polespinasa polespinasa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

code review and tACK f78f6f1

Unlike #34156 this one should be backported as v29.x is also affected by this bug.
It can easily be tested with the commands shared here #34156 (comment)

Copy link
Contributor

@rkrux rkrux left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code review and tACK f78f6f1

I can see the following error in the latest functional test if the cpp changes are reverted.

    assert self.nodes[0].wallets_path.exists()
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^
AssertionError


wallet.reset(); // The pointer deleter will close the wallet for us.

// Remove the wallet dir if we have a failure
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

- // Remove the wallet dir if we have a failure
+ // If we have a failure, remove the wallet files and optionally the wallet dir if a named wallet

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or perhaps add the if a named wallet bit in the comment above about the gathering...

if (!ret) {
fs::remove_all(wallet_path);
for (const auto& p : paths_to_remove) {
fs::remove(p);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One remaining unhandled case is that fs::remove() of the wallet_path fails (silently, as currently implemented) as the directory contains another file.

I can't think how that would be problematic, nor do I think it should be a blocker for this fix.

Copy link
Member

@willcl-ark willcl-ark left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK f78f6f1

We now safely gather paths to remove, and by dropping fs::remove_all() usage only remove files and non-empty directories.

Copy link
Member

@pablomartin4btc pablomartin4btc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK f78f6f1

@fanquake fanquake merged commit cd6e4c9 into bitcoin:master Jan 7, 2026
27 checks passed
fanquake pushed a commit to fanquake/bitcoin that referenced this pull request Jan 7, 2026
@fanquake
Copy link
Member

fanquake commented Jan 7, 2026

Backported to 30.x in #34209.

Copy link
Contributor

@janb84 janb84 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Post merge)
code review ACK f78f6f1

on failure a specific list of files and folders is removed not just the wallet_path, which was a bit harsh. Agree with the remarks of rkrux and willcl-ark

fanquake added a commit that referenced this pull request Jan 7, 2026
483d158 doc: update manual pages for v30.2rc1 (fanquake)
747a863 build: bump version to v30.2rc1 (fanquake)
cc3cdbe doc: update release notes for v30.2rc1 (fanquake)
c4082a4 wallettool: do not use fs::remove_all in createfromdump cleanup (Ava Chow)
185ca0e test: coverage for migration failure when last sync is beyond prune height (furszy)
bc71372 wallet: migration, fix watch-only and solvables wallets names (furszy)
bef4b1f wallet: improve post-migration logging (furszy)
ac940ac test: restorewallet, coverage for existing dirs, unnamed wallet and prune failure (furszy)
8e5c02a test: add coverage for unnamed wallet migration failure (furszy)
ac4d095 wallet: fix unnamed wallet migration failure (furszy)
454ac8e wallet: RestoreWallet failure, erase only what was created (furszy)

Pull request description:

  Backports:
  * #34156
  * #34215

ACKs for top commit:
  darosior:
    ACK 483d158
  willcl-ark:
    tACK 483d158
  janb84:
    ACK 483d158
  w0xlt:
    ACK 483d158
  marcofleon:
    lgtm ACK 483d158

Tree-SHA512: b43485a8745a663d3a031113a6a266af699b3e70b77f72a0e69ea1986adcaa0ee0d4ce51aacd0fde91611cb4bdba9b6be52e5dca59ff8b12135715b8b1ed5ef2
achow101 added a commit to achow101/bitcoin that referenced this pull request Jan 7, 2026
achow101 added a commit to achow101/bitcoin that referenced this pull request Jan 7, 2026
achow101 added a commit to achow101/bitcoin that referenced this pull request Jan 7, 2026
achow101 added a commit to achow101/bitcoin that referenced this pull request Jan 7, 2026
achow101 added a commit to achow101/bitcoin that referenced this pull request Jan 7, 2026
achow101 added a commit to achow101/bitcoin that referenced this pull request Jan 8, 2026
@polespinasa
Copy link
Member

Just checked and 28.x is also affected by this issue.
Should it be backported? The release is in "Maintenance End" untill v31.0.

@fanquake
Copy link
Member

fanquake commented Jan 8, 2026

It is being backported to 28.x in #34223.

@fanquake
Copy link
Member

fanquake commented Jan 8, 2026

Being backported to 29.x in #34222.

achow101 added a commit to achow101/bitcoin that referenced this pull request Jan 8, 2026
achow101 added a commit to achow101/bitcoin that referenced this pull request Jan 9, 2026
achow101 added a commit to achow101/bitcoin that referenced this pull request Jan 9, 2026
glozow added a commit that referenced this pull request Jan 12, 2026
76cdeb7 wallet: test: Failed migration cleanup (David Gumberg)
9405e91 test: coverage for migration failure when last sync is beyond prune height (furszy)
5e8ad98 wallet: migration, fix watch-only and solvables wallets names (furszy)
a7e2d10 wallet: improve post-migration logging (furszy)
9ea84c0 test: restorewallet, coverage for existing dirs, unnamed wallet and prune failure (furszy)
833848e test: add coverage for unnamed wallet migration failure (furszy)
a074d36 wallet: fix unnamed wallet migration failure (furszy)
d91f56e wallet: RestoreWallet failure, erase only what was created (furszy)
cc324aa wallettool: do not use fs::remove_all in createfromdump cleanup (Ava Chow)
01c04d3 wallet: introduce method to return all db created files (furszy)
abaf1e3 refactor: remove sqlite dir path back-and-forth conversion (furszy)

Pull request description:

  Backports:
  * #34215
  * #34156
  * #34226
  * 2 required commits from #31423

  Note that this backport is unclean and several changes have to be made to most commits to accommodate BDB and the differences in migration cleanup behavior.

ACKs for top commit:
  furszy:
    Code review ACK 76cdeb7
  brunoerg:
    light code review ACK 76cdeb7 + backported the functional tests without the fixes and all of them failed accordingly.
  glozow:
    light review ACK 76cdeb7.

Tree-SHA512: 432268117783fc9a221d895a6f6601b6a2a5031c76d1443cf804cc1d486b40fcded982409d548acd1c01a13c7b378b840fcc3fbe823d6ba5ffc4ebe017d4e13c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants