qml: Move wallet overview, activity, address and receive work off the GUI thread

bitcoin-core/gui-qml: PR #1146

4 minor findings · 1 suggestion

Findings

Link

[minor] · Newly sampled block tips reset unchanged Addresses and Coins lists

Each newly sampled wallet tip triggers a full snapshot and resets both lists even when their contents are unchanged, interrupting inline label editing and repeating during catch-up.

Location: qml/models/walletstatesnapshot.cpp:224 (head).

Details and suggested fix

When tryGetBalances() reports a different processed-block hash, poll() calls read(node), scanning addresses, coins and wallet transactions. startWalletStateRefresh() applies the returned snapshot, and applyWalletState() always emits walletStateChanged. Both list models now reset on that signal, whereas the base refreshed them through wallet-change notifications. Consequently, even a block unrelated to the wallet rebuilds both lists on the GUI thread. AddressList preserves draft text outside its delegates, but replacing the focused delegate still interrupts its inline editor. Rapid blocks coalesce, so this can repeat on successive one-second polls during catch-up rather than once per connected block. Compare the fields each list uses and notify it only when those fields change, while publishing balance and maturity updates separately. Stall times and crash effects were not measured.


Link

[minor] · A delayed signing password prompt can open over another wallet or page

If signing work finishes after its retained settings page is hidden, the completion opens the original wallet's password prompt over the current screen without checking page visibility.

Location: qml/pages/wallet/SignVerifyMessage.qml:86 (head).

Details and suggested fix

On an encrypted, locked wallet, press Sign while the wallet's serial executor is busy, then switch wallets or leave wallet settings before the task finishes. The settings page remains alive, so its signing generation is still valid. When the worker returns needs_unlock, onSigningFinished calls signPassphrasePopup.open() unconditionally. Because the popup is parented to Overlay.overlay, it appears over the current screen. WalletView.pageHidden() only closes popups that exist when hiding occurs; it does not prevent this later open. Submitting still targets the original wallet and requires its password. Keep the unlock requirement with the originating page and present the prompt only while that page is visible. Cover this with a delayed signing completion after a wallet or section switch.


Link

[minor] · Locking a selected coin no longer notifies selection-count bindings

Locking a selected coin changes coin control without emitting selectedCoinsCountChanged, leaving selection totals and Send's selection-dependent bindings stale.

Location: qml/models/coinslistmodel.cpp:89 (head).

Details and suggested fix

The successful lock completion calls unselectCoin() before applyWalletState() emits walletStateChanged. CoinsListModel::update() then captures the selection after it has already shrunk, so its new comparison is false and selectedCoinsCountChanged is not emitted. Model resets do not notify properties such as selectedCoinsCount, totalSelectedSatoshi and changeAmount, whose NOTIFY signal is specifically selectedCoinsCountChanged. Send's input count and selectedInputsActive can therefore remain stale, and its onSelectedCoinsCountChanged draft-invalidation handler does not run. Locking the last selected input can leave the form describing explicit selection after coin control has no selected inputs. Call refreshSelection() after applying a lock result that changed the selection. Add a signal-spy assertion to the existing selected-coin lock test, which currently checks only the getter.


Link

[minor] · Delayed CSV-export and QR-save results open over another wallet or request

An asynchronous CSV completion or failed QR save can open an overlay dialog after its originating page is hidden or its request modal has been reopened for another request.

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

Details and suggested fix

Start a CSV export or QR save, then switch wallets or leave the page before completion. For QR, closing the modal and opening another request also leaves the card alive. ActivityListPage.onExportFinished always calls exportResultPopup.open(), and ImageSaveModel.onFinished calls showActionFailure() on failure without checking visibility or the request's opening. The QR capture and save-dialog target checks protect submission, not the later write completion. WalletView closes existing popups when hiding a page but cannot catch one opened afterwards. Keep the outcome on its originating view and present it only while that view is shown; for QR, also require the same request opening. Add delayed-completion tests for hiding the page and reopening the modal.


Optional improvements

Link

[suggestion] · QR and CSV models start dedicated workers before any export

ImageSaveModel and ActivityFilterProxyModel eagerly start dedicated worker threads, so retained wallet views carry idle file-writing workers even when the user never saves a QR image or exports CSV.

Location: qml/models/imagesavemodel.h:28 (head).

Details and suggested fix

Every instantiated PaymentRequestCard constructs an ImageSaveModel with a by-value BackendExecutor, and each ActivityFilterProxyModel eagerly constructs another executor. The executor immediately starts a QThread and requests an 8 MiB stack on macOS. Receive cards and retained request modals multiply these idle workers across open wallet views, and each worker must eventually be joined. Create each executor on the first save() or exportCsv() instead. This avoids unused threads while preserving off-thread writes and receiver-guarded completion. Exact thread and memory totals were not measured.


Coverage details

Background

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

Documented decisions

Asynchronous exports must preserve one coherent user-selected view, rather than merely move file writes off the GUI thread.

Issue #969 identified row collection, formatting and file operations as blocking work, while requiring that filter or activity changes not mix unrelated views in one export. It also warned that tryGetTxStatus could still wait for cs_main despite its name. This explains both the worker boundary for CSV export and the need to capture export inputs before delayed execution.

Source 1

Per-wallet views were chosen to make wallet identity structural, accepting additional memory consumption in exchange for fewer context-sensitive authorization mistakes and preserved per-wallet drafts.

PR #1049 explains that selection-following pages could back up, export or sign for a wallet other than the one originally reviewed. It rejected relying exclusively on every popup opting into context guards, and documented the memory cost of retained views. Crucially, it also identified same-wallet replacement and completion screens as cases still needing targeted checks. That distinction explains why the affected delayed Receive results require opening/view identity even when their wallet pointer never changes.

Source 1