WIP: qml: update model design

bitcoin-core/gui-qml: PR #1142

1 major finding · 7 minor findings · 3 suggestions

Earlier concerns neither republished nor resolved: 13 minor findings · 10 suggestions. See the Run archive for their assessments.

Findings

Link

[major] · ENABLE_WALLET=OFF still links wallet-dependent WalletManager code

The recorded wallet-disabled application build fails to link because walletmanager.cpp remains selected while the wallet implementations it requires are excluded.

Location: CMakeLists.txt:141 (head).

Details and suggested fix

The recursive QML_SOURCES glob retains qml/walletmanager.cpp/.h, but the node-only exclusions remove WalletModel and still name the obsolete walletregistry and receiptreconciliationmodel files. walletmanager.h includes walletmodel.h and declares the Q_OBJECT class OpenWalletListModel, so its moc and implementation introduce references to excluded wallet code. The recorded head build with ENABLE_WALLET=OFF, BUILD_APP_TESTS=OFF and ENABLE_IPC=OFF fails at the final link with undefined WalletModel references from walletmanager.cpp.o. Update the node-only source partition to the final wallet-only filenames, including their moc inputs, and add a wallet-disabled configure/build check.


Link

[minor] · The same pasted passphrase no longer round-trips through creation and unlock

Creation removes pasted CR/LF, but unlock preserves them, so pasting the same clipboard fails authorization; typing the visible passphrase still works.

Location: qml/controls/PasswordTextField.qml:20 (head).

Details and suggested fix

Creating a wallet with pasted pw\n now encrypts it with pw, because the new-passphrase fields enable dropsLineEndings. The unlock field deliberately preserves pw\n for compatibility with older wallets, and the backend passes those bytes directly to wallet.unlock(). This breaks the paste-at-creation, paste-at-unlock workflow. After an exact unlock fails, retry once with CR/LF removed when present. Trying the exact text first keeps wallets encrypted under the previous behavior accessible.


Link

[minor] · Return defaults to replacing the current payment details

For an imported request awaiting confirmation, Return outside the alert's buttons chooses Replace rather than Cancel; spending still requires Review and Send.

Location: qml/pages/wallet/SendCreate.qml:496 (head).

Details and suggested fix

paymentUriOverwritePopup supplies a Cancel action and a Replace action, but no returnAction. Since AlertAction.role defaults to Normal, AlertPopup.acceptAction() selects Replace and calls imports.replace(). An incidental Return can therefore discard the existing payment details without explicitly selecting Replace. Give the Cancel action an ID and set it as this alert's returnAction, as the other irreversible confirmations now do.


Link

[minor] · Send applies avoid_reuse without its paired partial-spend policy

With avoid_reuse enabled and default -avoidpartialspends, Send can spend only some outputs at an address, leaving the rest dirty and excluded from its balance and maximum.

Location: qml/models/coinselection.h:33 (head).

Details and suggested fix

ApplyInputPolicy() enables m_avoid_address_reuse but leaves m_avoid_partial_spends at its default. Core's sendtoaddress explicitly enables partial-spend avoidance when reuse avoidance is active. Its optional grouped retry does not guarantee grouping, because it can retain the ungrouped transaction when grouping costs too much. Enable m_avoid_partial_spends for wallets using avoid_reuse, and cover a payment that would otherwise consume only one of two outputs at the same address.


Link

[minor] · Core workers lose the explicit macOS stack size

The new std::thread workers drop the previous 8 MiB macOS stack safeguard for Core work and initialization; no resulting stack overflow has been observed.

Location: qml/executor.cpp:26 (head).

Details and suggested fix

Base's BackendExecutor set an 8 MiB stack on macOS because Core startup could exceed the 512 KiB secondary-thread default, particularly under sanitizers. QmlInitExecutor previously submitted initialization through that executor. Head constructs both its lifecycle thread and the shared workers with plain std::thread, losing that explicit allowance. Preserve the 8 MiB stack for these threads on macOS, or establish why the former requirement no longer applies.


Link

[minor] · The Activity position handler undoes its final clamp

When the held position lies outside the final content range, the settle callback restores that out-of-range value instead of keeping the clamp.

Location: qml/pages/wallet/ActivityListPage.qml:383 (head).

Details and suggested fix

holdPositionTimer calls restorePosition(true) before clearing heldContentY. Assigning the clamped contentY synchronously invokes onContentYChanged, which calls restorePosition(false) and writes the original, unclamped held value back. The timer then clears the hold, leaving contentY outside the settled range. Compute the clamped target, clear heldContentY, and only then assign contentY.


Link

[minor] · A blank -addresstype= overrides the Taproot default

An explicitly blank -addresstype= makes Receive choose Bech32 instead of Taproot; no configuration producing a blank value by default was found.

Location: qml/walletopening.cpp:43 (head).

Details and suggested fix

For a Taproot-capable wallet with no saved receive preference, Core ignores an empty -addresstype and leaves its native Bech32 default unchanged. The application instead tests IsArgSet("-addresstype") and treats that native default as an explicit user choice, bypassing its Taproot fallback. Use Core's nonempty-value test, !gArgs.GetArg("-addresstype", "").empty(), wherever the application decides whether this option supplies an explicit receive type.


Link

[minor] · SendRecipient::SameText compares storage rather than text

Setting an unchanged nonempty label or message from separate QString storage advances validation unnecessarily; no current caller producing that input was identified.

Location: qml/models/sendrecipient.cpp:19 (head).

Details and suggested fix

SameText() considers equal-length nonempty strings equal only when their constData() pointers match. Consequently, setLabel() or setMessage() given identical text in separate storage treats it as an edit, emits inputEdited and requests a new validation revision, invalidating work keyed to the previous revision. Compare contents with a == b and add an idempotence test using equal text held in separate storage.


Optional improvements

Link

[suggestion] · Wallet creation retains an unwiped passphrase capture

secretinput::Input retains plaintext in an ordinary QString, and wallet creation keeps that capture in its immutable request for the operation's lifetime.

Location: qml/secretinput.cpp:34 (head).

Details and suggested fix

Input stores const QString m_text and has no cleansing destructor; materialize() wipes only its temporary UTF-8 buffer. WalletCreationController assigns the capture to both request.passphrase and request.confirmation, and the creation service retains const Request m_request, so materializing a SecureString does not release the original capture. Keep consumable credentials in owned secure or wipeable storage outside the immutable request and release them after their last use. Conversion can remain worker-side.


Link

[suggestion] · Speed Up omits the avoid_reuse filter now used by Send

Speed Up retains the pre-existing bumpfee behavior: in an avoid_reuse wallet, a bump needing another input can add a dirty output that Send now excludes.

Location: qml/walletbump.cpp:106 (head).

Details and suggested fix

walletbump::Prepare() initializes CCoinControl without m_avoid_address_reuse. Core's bump builder permits additional inputs and passes that control into transaction construction, so the extra inputs do not receive Send's reuse filter. Set control.m_avoid_address_reuse = true here as Send does, allowing Core to apply the filter when the wallet has opted into avoid_reuse.


Link

[suggestion] · The cleanup-worker test can hang after its assertion fails

A lane-isolation regression makes this test block during cleanup instead of returning after its failed assertion.

Location: test/test_executor.cpp:330 (head).

Details and suggested fix

In cleanupUtilityWorkerIsSeparateFromIoAndJoinedOnStop(), the cleanup task waits on release_future, but several assertions precede release_cleanup.set_value(). If cleanup and IO accidentally share a worker, the IO readiness assertion returns early and the executor's destructor joins the still-blocked worker. Record the check results, release the barrier and join before asserting, following the pattern in the preceding test.


Coverage details

Earlier concerns

Earlier reports raised these, with the titles and severities shown there. This review neither republished nor resolved them.

Background

Ralph's summary of historical context for the behaviour affected by this change. The historical record reviewed here is incomplete.

Documented decisions

Per-wallet pages were deliberately chosen as a structural authorization boundary, at a memory cost. Earlier GUI-QML PR #1049 explains that retargeting shared pages could make an existing dialog back up, export, replace a draft or sign for a different wallet. Keeping each page bound to one wallet avoided requiring every popup to opt into context-token checks, while retaining per-wallet navigation and drafts. Its description explicitly acknowledged the additional memory consumption.

The head WalletPageController rejects rebinding to a second wallet, and the architecture retains one-wallet-per-page scopes. This continues an earlier safety decision rather than introducing ownership solely as a naming or presentation convention. The earlier proposal also distinguished cross-wallet substitution from same-wallet replacement, which still required separate handling.

Source 1

Shutdown ordering historically had to interrupt backend work before waiting on objects whose destruction could wait for that work. A 2019 change moved the node shutdown request earlier specifically so long operations such as wallet rescans could abort, and documented that disconnecting node signals was necessary to avoid a deadlock when no event loop was running.

Both the pinned base and head shutdown coordinators distinguish work before and after node interruption. The head adds admission-stop hooks and changes executor ownership. The historical constraint explains why draining, interruption, signal disconnection and destruction are distinct lifecycle stages rather than interchangeable cleanup steps.

Source 1

Moving wallet work to a worker does not itself settle QObject lifetime safety. GUI PR #693 documented shutdown during wallet opening: queued completions and an explicit processEvents call could resume after wallet controllers and models had been deleted. Its minimal resolution avoided the reentrant event-processing call and cleared dangling controller references; the author identified guarded or shared ownership as a more extensive approach.

This history directly motivates the head's distinction between backend completion, outcome delivery and observing pages, together with guarded callbacks and staged shutdown. It also explains why completion after wallet closure matters even when the backend operation itself finishes successfully.

Source 1 · Source 2

PSBT fee presentation has an adversarial-input constraint: a supplied input amount is not necessarily authenticated merely because it is sufficient to calculate a fee. The 2020 Electrum/Trezor proposal described an attack using false SegWit input amounts to induce unexpectedly high fees and required full previous transactions so the amounts could be checked. The discussion separately warned against signing legacy inputs without validating the previous transaction.

The base application used AnalyzePSBT's fee to determine review and broadcast capabilities. At the unchanged Core pin, AnalyzePSBT obtains input values through GetUTXO and sums them. The head's psbtfee adapter instead distinguishes authenticated previous-output evidence from unsupported claims, checks consistency, and binds the fee evidence to the reviewed transaction. The history explains this trust distinction without establishing a defect in Core or proving the adapter complete.

Source 1 · Source 2 · Source 3

External-signer hardening distinguishes adding signatures and metadata from replacing the approved transaction. Upstream PR #36114 explicitly proposed merging signer responses rather than replacing the original PSBT, rejecting changed outputs and unsafe sighash types, while permitting omission of unnecessary metadata. It also explicitly limited its threat model: it did not claim full protection against a malicious signer or a same-user malicious HWI process.

The head application compares unsigned transaction terms before accepting signing results and rechecks fee evidence and signatures afterward. This is the same approval-preservation concern, but the inspected proposal is design context, not evidence that its guarantees are present in the pinned Core implementation or that application-side checks create a sandbox around the signer process.

Source 1

GUI-created PSBT file compatibility and external-signer compatibility were treated as separate decisions. Issue #36518 described version-2 files failing on pre-v32 Core nodes and disrupting existing cosigning workflows. PR #36539 moved GUI file exports back to version 0; avoiding new translated controls during a backport was an explicit implementation constraint. The subsequent discussion retained version 2 for external signers rather than applying version 0 indiscriminately.

The head ExportReview creates new export documents as version 0 while preserving an imported document's version. This matches the historical distinction between broadly interoperable files and a separately managed signer handoff, rather than implying that version 2 is intrinsically unsuitable for all wallet operations.

Source 1 · Source 2 · Source 3 · Source 4 · Source 5

Ralph's inferences

Object identity and revisioned review data address different kinds of stale intent. A permanently wallet-bound page isolates actions from wallet selection changes; a distinct review object and captured transaction terms isolate authorization from later changes within that same wallet. Operation ownership therefore has a security role beyond organizing asynchronous code.

The head architecture gives controllers their own operations and makes each review carry its transaction, PSBT, fee proof and originating draft version. Read alongside #1049's explicit statement that per-wallet pages cannot address same-wallet replacement, this explains why fixed wallet scope alone is insufficient to preserve what the user reviewed. This is an interpretation of the combined design, not a claim that every action path satisfies it.

Source 1

Unresolved disagreements

The inspected asynchronous-GUI discussion did not establish a universal choice between continuation-style APIs and nested event loops. Russell Yanofsky described nested loops as a way to preserve existing control flow with fewer rewrites, while preferring event-driven requests generally; João Barbosa disputed their usefulness here, and Wladimir van der Laan warned about escaped pointers and lifetime surprises.

This records the historical tension between migration cost and reentrancy/lifetime complexity behind the move away from monolithic synchronous controllers. The head architecture's promise to keep Qt processing events during final joins does not, by itself, resolve that historical lifetime question.

Source 1 · Source 2 · Source 3 · Source 4 · Source 5