WIP: Wallet import descriptors

bitcoin-core/gui-qml: PR #1144

Provider refusals

write_verifier: Provider declined the request because of a cybersecurity restriction. Experiments remain incomplete; static verification can continue.

1 major finding · 6 minor findings · 4 suggestions

Findings

Link

[major] · A crash during import can leave a silently incomplete wallet after restart

An unclean exit during the new historical rescan can leave an automatically loaded view-only wallet with missing transactions and an incorrect balance that ordinary restarts do not repair.

Location: qml/walletqmlcontroller.cpp:725 (head).

Details and suggested fix

A crash or kill after descriptor persistence but before the rescan finishes bypasses the cleanup following importDescriptors(). By then, the pinned backend has enabled startup loading and saved the creation-time tip. ScanFromTime() uses save_progress=false, while the next normal load starts from the saved locator; the birthday check does not rewind it. Relevant transactions in the unscanned historical range therefore remain missing without an incomplete-import warning. Recovery requires an explicit rescanblockchain or recreating the wallet. Persist a pending-import marker before scanning and check it at startup to resume the scan or discard the incomplete wallet. This path is established from source, not a completed crash experiment.


Link

[minor] · GUI active-manager lookups race with descriptor imports

ApplyChangeTypeFallback and the receive-type filter read active-manager maps without cs_wallet, so a concurrent local importdescriptors operation on the same wallet can race with those reads.

Location: qml/models/walletqmlmodel.cpp:180 (head).

Details and suggested fix

CWallet::GetScriptPubKeyMan() directly searches the active-manager maps without acquiring a lock. The new GUI calls occur before backend transaction locking, and the earlier canGetAddresses() call releases its lock before the receive-type loop. Meanwhile, descriptor import activates or deactivates managers under cs_wallet, inserting into or erasing from those same maps. Overlapping operations therefore cause a C++ data race, potentially crashing the GUI or producing inconsistent type decisions. Hold raw_wallet->cs_wallet across the complete fallback decision and receive-type enumeration.


Link

[minor] · Conflicting duplicate descriptors leave a misleading active preview

Conflicting duplicate JSON entries can pass readiness and preview checks yet deactivate the only receive descriptor; no current producer of this hand-built input was identified.

Location: qml/viewonlyimport.cpp:454 (head).

Details and suggested fix

List the same ranged receive descriptor twice, first with active:true and then with active:false, both with timestamp:0. ParseJson() accepts the earlier active request, and DescribeViewOnlyImport() skips the later inactive request when calculating active slots. Core instead processes both requests in order: it permits the matching descriptor update with the same default range, then deactivates its manager. Creation succeeds, but the wallet cannot generate receive addresses despite the active preview. Reject conflicting duplicate descriptor requests before creation.


Link

[minor] · Change fallback overrides Core's recipient-matched legacy change

With only legacy and nested-SegWit change descriptors, default bech32, and no change override, ApplyChangeTypeFallback forces nested-SegWit change for P2PKH payments instead of Core's recipient-matched legacy change.

Location: qml/models/walletqmlmodel.cpp:188 (head).

Details and suggested fix

The helper never examines recipients. In this layout it finds no manager for its computed BECH32 fallback, then selects P2SH_SEGWIT before LEGACY. Core treats that explicit m_change_type as authoritative, bypassing the branch that would match a P2PKH recipient to the available legacy manager. The differing payment and change script types weaken Core's existing mitigation against change-identification heuristics in this manually assembled layout; single-type wallets are unaffected. Pass the recipients to the helper and override only when the type Core would actually select lacks a change manager. Cover the mixed-type case in a regression test.


Link

[minor] · Mixed JSON timestamps receive ineffective pruning recovery advice

Mixed dated/undated JSON can receive ineffective “choose a later date” advice when a fixed timestamp requires pruned blocks; no current producer of this mixed input was identified.

Location: qml/walletqmlcontroller.cpp:714 (head).

Details and suggested fix

On a pruned node, paste JSON containing one descriptor with timestamp:0 and another without a timestamp. The selected creation date changes only the undated request, but ScanBlocksPruned() checks the oldest timestamp across both requests. The fixed timestamp still requires unavailable blocks. Because date_chosen merely records that an undated entry exists, the error recommends a later date even though that cannot succeed. It also offers the valid alternative of using an unpruned node. Check the fixed timestamps separately and select the recovery message according to which requests require pruned blocks.


Link

[minor] · Receive-type filtering does not refresh after descriptor changes

The new active-descriptor filtering extends an existing notification limitation: on an open Receive page, a receive type activated over RPC remains absent until the page or wallet binding is recreated.

Location: qml/models/walletqmlmodel.cpp:1118 (head).

Details and suggested fix

ReceivePage.qml binds the picker model to wallet.availableReceiveAddressTypes(). That invokable now filters active receive managers, but the binding has no notifying dependency for manager changes. subscribeToWalletSignals() does not connect handleCanGetAddressesChanged(), although Core emits it on activation and deactivation. For example, adding a legacy receive descriptor to a nested-SegWit-only wallet does not add legacy to the existing picker. Expose the available list as a NOTIFY property and refresh it through a queued handleCanGetAddressesChanged() handler.


Link

[minor] · Historical imports lack progress feedback and an in-form cancel action

A historical import can occupy the creation form for hours without progress or an in-form cancel action; orderly quitting discards the new wallet and forces the scan to start over.

Location: qml/pages/wallet/CreateWalletForm.qml:462 (head).

Details and suggested fix

creating hides Back and Close while the worker waits for importDescriptors(), including its rescan. The form displays only a static scanning note, even though the earliest-date option warns that scanning can take hours. Connect handleShowProgress() to visible progress and offer a Cancel action using abortRescan(). An aborted import already returns an error, so cancellation can retain the existing discard-on-error behavior instead of requiring the user to quit the application.


Optional improvements

Link

[suggestion] · Receive-only imports do not explain missing change coverage

A lone wpkh(.../0/*) import has no change coverage or active change manager, so it can miss the source wallet's change and cannot prepare sends requiring change, without an explicit warning.

Location: qml/viewonlyimport.cpp:264 (head).

Details and suggested fix

ParseLines() accepts a single ranged receive descriptor because its completeness check only requires an active request. Unlike the previous xpub import, it does not also import /1/*. The row says “receive”, but does not explain that activity on the source wallet's separate change branch will be absent or that transaction preparation can fail when it needs a change address. Show an explicit missing-change warning in the import summary while keeping intentional receive-only imports possible.


Link

[suggestion] · Cleanup tests bypass the wait-and-delete path in DiscardCreatedWallet

The cleanup tests use a loader with null context, so they cannot detect regressions in waiting for wallet destruction, deleting database files, or reusing the failed import's name.

Location: qml/walletqmlcontroller.cpp:117 (head).

Details and suggested fix

FakeWalletLoader does not override context(), whose interface default returns null. Consequently, DiscardCreatedWallet() returns at if (!shared) after mocked removal, before WaitForDeleteWallet() and fs::remove(). The functional pruning case also cannot cover this path because it rejects the import before creating the wallet. Add a real-database case that fails after creation, such as cancellation during a rescan, and assert that the error appears, the database files and empty directory disappear, and the same name can be reused.


Link

[suggestion] · Non-default wallet imports precede their receive/change support

Intermediate commits can create nested-SegWit or legacy-only wallets before the model can select their available receive/change types; the later support commit removes this intermediate failure, so this is a sequencing concern.

Location: qml/models/walletqmlmodel.cpp:176 at 6cdcb04133d8 (commit) (commit).

Details and suggested fix

eb6759aeb143def4effd8ee2ffec23f935687d2e accepts pkh and sh(wpkh) descriptors, and cdc203d12f51e1a7c9bdf6d26d0aa4680fa50950 adds corresponding key imports and type choices. Their receive/change model support arrives only in 6cdcb04133d879992e2e915d2f77872ad2538896, after fef4427bff86677c9f37fb77c1cbcd55faeefb7b. Move that model-support commit immediately after the shared-label refactor bbce2b0f4d7bc6ffbfc98de09da3498135fc2629. Its tests construct wallets with AddActiveDescriptor() directly, so they do not require the import parser. This keeps the same final tree while allowing the import commits to be validated without those intervening receive/send failures.


Link

[suggestion] · Import choices precede the reset that binds them to a key

Intermediate commits reuse an earlier key's address type and birth date after a different key is pasted; the final reset fixes this, but reviewers must validate the choice workflow without its invariant first.

Location: qml/pages/wallet/CreateWalletForm.qml:119 at 35841cebc6fd (commit) (commit).

Details and suggested fix

At cdc203d12f51e1a7c9bdf6d26d0aa4680fa50950, addressTypeChoice and birthChoice feed readiness and submission without being cleared when the imported key changes. A second xpub can therefore inherit the wrong address type or a scan date that misses older transactions. 35841cebc6fd02438edb52c63dd430a797201d9e adds importId, the reset handler, and test assertions. Fold that identity plumbing and reset into cdc203d12f51e1a7c9bdf6d26d0aa4680fa50950, with the birth-date protection optionally introduced in eb6759aeb143def4effd8ee2ffec23f935687d2e. This is a series-validation improvement, not a remaining head defect.


Coverage details