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

Open
AndreaDiazCorreia wants to merge 17 commits from fix/wallet-work-off-gui-thread into qt6 AGit
AndreaDiazCorreia commented 2026-11-23 00:40:09 +00:00 (Migrated from github.com)

Replaces #990. @johnny9 agreed to hand it over; his five commits keep their authorship, and the rest of this PR rebases them onto current qt6, addresses the open review comments and adds the fixes found while testing.

Depends on #1109. This targets qt6, so the diff includes the three #1109 commits until it is merged. It no longer depends on #985: the wallet commits only shared registration lines with it.

Wallet balance queries, address scans, receive commands, payment reconciliation, message signing, CSV exports and QR file saves could block the GUI while waiting on cs_wallet, cs_main or the disk. A per-wallet backend builds a snapshot of the wallet state on the wallet's worker. GUI getters read that snapshot, refresh requests are coalesced, and stale replies are dropped. Labels, request saves and deletes, address preparation and coin locks run as commands on the same worker.

On top of #990:

  • Tasks use submitTask() from #1109, so each one reports exactly one outcome. Closing a wallet with work in flight no longer leaves pending states set, and a superseded fee estimate is cancelled before it runs.
  • Send reads its balances from the snapshot. The periodic poll also detects coin locks made with lockunspent, which emit no wallet notification.
  • Saving a request or preparing an address reads the wallet once under cs_wallet instead of twice, and releases it before writing settings. The notification from a command's own write no longer triggers another full read, and a failed read is retried after a growing delay.
  • Temporary unlocks of encrypted wallets are serialized, so one operation can neither relock the wallet under another nor let Send skip its password prompt.
  • Results stay in the wallet and view that started them. A delete, a failure, a password prompt or a newly created request that finishes after switching wallets or tabs no longer acts on, or appears over, another wallet.
  • An untouched prefilled note no longer overwrites a newer address label, and an inline edit typed back to its original value leaves no stale draft (#971).
  • A request too long for a QR code shows a notice and disables the QR actions instead of exporting a blank image; the full request can still be copied (#972). A reopened Receive password prompt no longer shows the previous error (#972).
  • The payment request badge follows the current received amount, so a request whose payment was replaced away shows "Awaiting payment" again while its reuse restrictions remain (#1042).

This does not fix #1116 or #1119. Every applied snapshot still resets the Addresses and Coins lists, which those issues track.

Unit, QML and functional tests cover the new cases, and each commit builds and passes the unit and QML suites. Manually tested on regtest with a password-protected wallet: requests, unconfirmed and replaced payments, inline labels while a payment is unconfirmed, coin selection and coin locks made over RPC, message signing and verification, CSV export, a request too long for a QR code, and closing a wallet while a save waits behind keypoolrefill.

Fixes #968
Fixes #969
Fixes #971
Fixes #972
Fixes #1042

Replaces #990. @johnny9 agreed to hand it over; his five commits keep their authorship, and the rest of this PR rebases them onto current `qt6`, addresses the open review comments and adds the fixes found while testing. Depends on #1109. This targets `qt6`, so the diff includes the three #1109 commits until it is merged. It no longer depends on #985: the wallet commits only shared registration lines with it. Wallet balance queries, address scans, receive commands, payment reconciliation, message signing, CSV exports and QR file saves could block the GUI while waiting on `cs_wallet`, `cs_main` or the disk. A per-wallet backend builds a snapshot of the wallet state on the wallet's worker. GUI getters read that snapshot, refresh requests are coalesced, and stale replies are dropped. Labels, request saves and deletes, address preparation and coin locks run as commands on the same worker. On top of #990: - Tasks use `submitTask()` from #1109, so each one reports exactly one outcome. Closing a wallet with work in flight no longer leaves pending states set, and a superseded fee estimate is cancelled before it runs. - Send reads its balances from the snapshot. The periodic poll also detects coin locks made with `lockunspent`, which emit no wallet notification. - Saving a request or preparing an address reads the wallet once under `cs_wallet` instead of twice, and releases it before writing settings. The notification from a command's own write no longer triggers another full read, and a failed read is retried after a growing delay. - Temporary unlocks of encrypted wallets are serialized, so one operation can neither relock the wallet under another nor let Send skip its password prompt. - Results stay in the wallet and view that started them. A delete, a failure, a password prompt or a newly created request that finishes after switching wallets or tabs no longer acts on, or appears over, another wallet. - An untouched prefilled note no longer overwrites a newer address label, and an inline edit typed back to its original value leaves no stale draft (#971). - A request too long for a QR code shows a notice and disables the QR actions instead of exporting a blank image; the full request can still be copied (#972). A reopened Receive password prompt no longer shows the previous error (#972). - The payment request badge follows the current received amount, so a request whose payment was replaced away shows "Awaiting payment" again while its reuse restrictions remain (#1042). This does not fix #1116 or #1119. Every applied snapshot still resets the Addresses and Coins lists, which those issues track. Unit, QML and functional tests cover the new cases, and each commit builds and passes the unit and QML suites. Manually tested on regtest with a password-protected wallet: requests, unconfirmed and replaced payments, inline labels while a payment is unconfirmed, coin selection and coin locks made over RPC, message signing and verification, CSV export, a request too long for a QR code, and closing a wallet while a save waits behind `keypoolrefill`. Fixes #968 Fixes #969 Fixes #971 Fixes #972 Fixes #1042
rreview commented 2026-11-23 01:14:03 +00:00 (Migrated from github.com)

7 additional verified findings in the Review report.

Earlier concerns neither republished nor resolved: 1 minor finding · 2 suggestions. See the Run archive linked from the Review report for their assessments.

🟠 Minor · Signing reads encryption state without synchronization

On an initially unencrypted wallet, background signing can race with GUI encryption because its isCrypted() calls read Core's master-key map without cs_wallet.

Location: qml/models/signverifymessagemodel.cpp:76 (head).

🟠 Minor · Send can use a selected coin while its lock is pending

Locking a manually selected Send input now leaves it selected until worker completion, allowing Review to prepare and sign a transaction containing that coin in the meantime.

Location: qml/components/CoinsList.qml:62 (head).

🟠 Minor · A busy unlock session makes the fee bump impossible to retry

The transient busy path moves BumpTransactionModel to Failed, disabling Update and rejecting password resubmission until the overlay is closed and reopened.

Location: qml/models/bumptransactionmodel.cpp:160 (head).

🟠 Minor · lockunspent can leave the cached Send balance stale

An RPC lock change between the balance read and lock-set checkpoint can leave Send using the old available balance until another refresh trigger; this interleaving was not reproduced.

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

🟠 Minor · Delayed signing opens its password prompt over Verify mode

Switching to Verify while signing is pending can bring up “Unlock and sign” over the Verify form, although submission still signs the previously submitted Sign-tab message.

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

🟠 Minor · A pending verification retains the previous result banner

Although edits already retained the previous banner, asynchronous submission now also leaves it beside the newly submitted inputs until verification completes.

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

Review coverage was incomplete.


Reviewed: 82f801e1302e · Review report

<!-- ralph-major:bitcoin-core/gui-qml --> [7 additional verified findings in the Review report](<https://review.fish.foo/report/gui/1146-82f801e1302e0510696329058e2176e51012c1de-3061-7.html>). Earlier concerns neither republished nor resolved: 1 minor finding · 2 suggestions. See the Run archive linked from the Review report for their assessments. **🟠 Minor · Signing reads encryption state without synchronization** On an initially unencrypted wallet, background signing can race with GUI encryption because its `isCrypted()` calls read Core's master-key map without `cs_wallet`. Location: [qml/models/signverifymessagemodel.cpp:76](<https://github.com/bitcoin-core/gui-qml/blob/82f801e1302e0510696329058e2176e51012c1de/qml/models/signverifymessagemodel.cpp#L76>) (head). **🟠 Minor · Send can use a selected coin while its lock is pending** Locking a manually selected Send input now leaves it selected until worker completion, allowing Review to prepare and sign a transaction containing that coin in the meantime. Location: [qml/components/CoinsList.qml:62](<https://github.com/bitcoin-core/gui-qml/blob/82f801e1302e0510696329058e2176e51012c1de/qml/components/CoinsList.qml#L62>) (head). **🟠 Minor · A busy unlock session makes the fee bump impossible to retry** The transient busy path moves `BumpTransactionModel` to `Failed`, disabling Update and rejecting password resubmission until the overlay is closed and reopened. Location: [qml/models/bumptransactionmodel.cpp:160](<https://github.com/bitcoin-core/gui-qml/blob/82f801e1302e0510696329058e2176e51012c1de/qml/models/bumptransactionmodel.cpp#L160>) (head). **🟠 Minor · `lockunspent` can leave the cached Send balance stale** An RPC lock change between the balance read and lock-set checkpoint can leave Send using the old available balance until another refresh trigger; this interleaving was not reproduced. Location: [qml/models/walletstatesnapshot.cpp:142](<https://github.com/bitcoin-core/gui-qml/blob/82f801e1302e0510696329058e2176e51012c1de/qml/models/walletstatesnapshot.cpp#L142>) (head). **🟠 Minor · Delayed signing opens its password prompt over Verify mode** Switching to Verify while signing is pending can bring up “Unlock and sign” over the Verify form, although submission still signs the previously submitted Sign-tab message. Location: [qml/pages/wallet/SignVerifyMessage.qml:84](<https://github.com/bitcoin-core/gui-qml/blob/82f801e1302e0510696329058e2176e51012c1de/qml/pages/wallet/SignVerifyMessage.qml#L84>) (head). **🟠 Minor · A pending verification retains the previous result banner** Although edits already retained the previous banner, asynchronous submission now also leaves it beside the newly submitted inputs until verification completes. Location: [qml/pages/wallet/SignVerifyMessage.qml:76](<https://github.com/bitcoin-core/gui-qml/blob/82f801e1302e0510696329058e2176e51012c1de/qml/pages/wallet/SignVerifyMessage.qml#L76>) (head). Review coverage was incomplete. <!-- Review tier: sensitive --> --- Reviewed: [`82f801e1302e`](<https://github.com/bitcoin-core/gui-qml/commit/82f801e1302e0510696329058e2176e51012c1de>) · [Review report](<https://review.fish.foo/report/gui/1146-82f801e1302e0510696329058e2176e51012c1de-3061-7.html>)
ValeraFinebits (Migrated from github.com) reviewed 2026-11-24 14:54:26 +00:00
ValeraFinebits (Migrated from github.com) left a comment

Tested ACK b993e67

I ran into two non-blocking issues while testing Send and CSV export on Windows on Regtest.

  1. After the node evicted a low-fee outgoing payment from its mempool, the wallet could no longer spend the change. Its spendable balance was zero, but entering 0.25 BTC in Send showed no warning and the "Review transaction" button stayed enabled. Clicking it correctly reported insufficient funds. Before this PR, the amount field showed the warning as soon as the amount was entered.

  2. In a test wallet with about 25,000 transactions, a payment arrived while Activity was preparing a CSV export. The export was cancelled. With Activity still open, the app showed "Export failed" and prompted me to try again. In the run where the test switched to Send before the export finished, no CSV was written and no message appeared on returning to Activity. It would be helpful to see the retry prompt when coming back to that tab.

Tested ACK b993e67 I ran into two non-blocking issues while testing Send and CSV export on Windows on Regtest. 1. After the node evicted a low-fee outgoing payment from its mempool, the wallet could no longer spend the change. Its spendable balance was zero, but entering 0.25 BTC in Send showed no warning and the "Review transaction" button stayed enabled. Clicking it correctly reported insufficient funds. Before this PR, the amount field showed the warning as soon as the amount was entered. 2. In a test wallet with about 25,000 transactions, a payment arrived while Activity was preparing a CSV export. The export was cancelled. With Activity still open, the app showed "Export failed" and prompted me to try again. In the run where the test switched to Send before the export finished, no CSV was written and no message appeared on returning to Activity. It would be helpful to see the retry prompt when coming back to that tab.
Sign in to join this conversation.
No description provided.