Fee selection and coin control: move remaining queries and writes off the GUI thread #974

Open
opened 2026-10-02 17:35:43 +00:00 by johnny9 · 2 comments
johnny9 commented 2026-10-02 17:35:43 +00:00 (Migrated from github.com)

Parent: #923 — Fee selection and coin control.

A transaction notification can refresh the coin list twice, even while its view is hidden. CoinsListModel subscribes to both transaction and balance signals; each refresh scans coins and queries labels and lock state. Locking or unlocking outputs can also write wallet data synchronously.

Selected available-balance reads and custom fee target/rate lookups remain on the GUI thread. The expensive fee-preview calculation already uses a worker, but some preflight and setter queries do not.

Coin views and getters should use cached state. Move remaining queries and persistent lock commands off the GUI thread, avoid redundant backend refreshes, and make completion callbacks apply results only. Preserve selection across reordering, never apply an action to the wrong output, show pending/errors and prevent stale fee results from replacing current values.

Acceptance checks should cover blocked queries and writes with a responsive GUI, repeated notifications, hidden views, changed selections, removed outputs, write failures and stale fee previews.

This was a source-traced risk; the original IBD runs did not measure wallet stalls.

Parent: #923 — Fee selection and coin control. A transaction notification can refresh the coin list twice, even while its view is hidden. [CoinsListModel](https://github.com/bitcoin-core/gui-qml/blob/a91f4b4774f25de061fe1a7c132a91ddde117fca/qml/models/coinslistmodel.cpp#L12) subscribes to both transaction and balance signals; each refresh scans coins and queries labels and lock state. Locking or unlocking outputs can also write wallet data synchronously. Selected available-balance reads and custom fee target/rate lookups remain on the GUI thread. The expensive fee-preview calculation already uses a worker, but some preflight and setter queries do not. Coin views and getters should use cached state. Move remaining queries and persistent lock commands off the GUI thread, avoid redundant backend refreshes, and make completion callbacks apply results only. Preserve selection across reordering, never apply an action to the wrong output, show pending/errors and prevent stale fee results from replacing current values. Acceptance checks should cover blocked queries and writes with a responsive GUI, repeated notifications, hidden views, changed selections, removed outputs, write failures and stale fee previews. This was a source-traced risk; the original IBD runs did not measure wallet stalls.
jarolrod commented 2026-11-05 17:50:49 +00:00 (Migrated from github.com)

Three concrete cases for the selection and refresh work here, recorded on qt6 at d567e3eb2497, macOS / Qt 6.9.0, using disposable regtest wallets.

A temporary reorg snapshot permanently removes a manual selection

  1. Send a payment from a funded wallet and mine its confirming block.
  2. In Send, manually select its change output and one older confirmed coin.
  3. Invalidate the confirming block through RPC.
  4. After the transaction returns to the mempool, inspect listunspent and the GUI selection.
  5. Reconsider the block.

The change output returns as spendable, but Send drops from two selected inputs to one. Reconnecting the block does not restore the selection. Mining an ordinary new block preserves both selections.

With that change output as the only selected coin and Use maximum enabled, losing the selection expands the draft to the wallet-wide maximum. The all-funds warning and final review show the larger amount; nothing was broadcast. This adds a transient-refresh trigger to the empty-selection behavior tracked in #1001.

In the tested code, CoinsListModel::update() removes selections whenever an outpoint is absent from its current coin snapshot. During disconnection, a wallet transaction can briefly be absent before returning to the mempool. Selection intent needs to survive that temporary state, with unavailable inputs handled explicitly rather than broadening the payment’s input scope.

View coins retains bulk marks for spent outputs

  1. In Wallet settings → View coins, mark a confirmed coin for bulk actions without locking it.
  2. Spend it through the normal Send flow.
  3. Return to View coins.

The spent output is gone and the change output is unchecked, but the footer still says 1 selected, with Lock/Unlock enabled. Clicking Lock clears the count without locking anything.

The separate QML markedIds list is not reconciled with removed rows. This is distinct from Send’s manual input selection. An incoming-payment control that merely reordered rows preserved the correct selection.

Repeated label scans cause measurable GUI stalls

With Activity open and no coin view visible, an incoming payment to a synthetic wallet containing 5,000 coins and 1,668 receiving addresses blocked GUI responses for approximately 5.5 seconds offscreen and 5.8–5.9 seconds with Cocoa. Labeling the same wallet’s receiving addresses reduced the offscreen stall to about 0.43 seconds.

CoinsListModel::update() asks for every coin’s label. An empty label triggers getAddressLabel() to scan the full address book, although that fallback cannot supply information missing from the direct lookup. Repeated notifications multiply the work.

The tested #990 build’s cached label lookup substantially reduced this cost. The selection cases above still need independent coverage when changing refresh scheduling, particularly temporary absence, actual removal, and reordered rows.

Three concrete cases for the selection and refresh work here, recorded on `qt6` at `d567e3eb2497`, macOS / Qt 6.9.0, using disposable regtest wallets. **A temporary reorg snapshot permanently removes a manual selection** 1. Send a payment from a funded wallet and mine its confirming block. 2. In Send, manually select its change output and one older confirmed coin. 3. Invalidate the confirming block through RPC. 4. After the transaction returns to the mempool, inspect `listunspent` and the GUI selection. 5. Reconsider the block. The change output returns as spendable, but Send drops from two selected inputs to one. Reconnecting the block does not restore the selection. Mining an ordinary new block preserves both selections. With that change output as the only selected coin and **Use maximum** enabled, losing the selection expands the draft to the wallet-wide maximum. The all-funds warning and final review show the larger amount; nothing was broadcast. This adds a transient-refresh trigger to the empty-selection behavior tracked in #1001. In the tested code, `CoinsListModel::update()` removes selections whenever an outpoint is absent from its current coin snapshot. During disconnection, a wallet transaction can briefly be absent before returning to the mempool. Selection intent needs to survive that temporary state, with unavailable inputs handled explicitly rather than broadening the payment’s input scope. **View coins retains bulk marks for spent outputs** 1. In **Wallet settings → View coins**, mark a confirmed coin for bulk actions without locking it. 2. Spend it through the normal Send flow. 3. Return to View coins. The spent output is gone and the change output is unchecked, but the footer still says **1 selected**, with Lock/Unlock enabled. Clicking Lock clears the count without locking anything. The separate QML `markedIds` list is not reconciled with removed rows. This is distinct from Send’s manual input selection. An incoming-payment control that merely reordered rows preserved the correct selection. **Repeated label scans cause measurable GUI stalls** With Activity open and no coin view visible, an incoming payment to a synthetic wallet containing 5,000 coins and 1,668 receiving addresses blocked GUI responses for approximately 5.5 seconds offscreen and 5.8–5.9 seconds with Cocoa. Labeling the same wallet’s receiving addresses reduced the offscreen stall to about 0.43 seconds. `CoinsListModel::update()` asks for every coin’s label. An empty label triggers `getAddressLabel()` to scan the full address book, although that fallback cannot supply information missing from the direct lookup. Repeated notifications multiply the work. The tested #990 build’s cached label lookup substantially reduced this cost. The selection cases above still need independent coverage when changing refresh scheduling, particularly temporary absence, actual removal, and reordered rows.
jarolrod commented 2026-11-10 22:52:33 +00:00 (Migrated from github.com)

Since #1049 a display-unit change runs this coin-list refresh for every open wallet, including hidden ones.

To reproduce:

  1. Open two wallets: a small one, selected, and a large one that stays hidden. Mine had 3,000 coins and 601 unlabeled receiving addresses.
  2. In the small wallet, open Send and click the unit button in the Amount field.

Each click leaves the window unresponsive for 0.52 to 0.67 s, offscreen and native. Other measurements with the same wallets:

  • Two such hidden wallets: 1.06 to 1.16 s.
  • The large wallet closed from the wallet picker: 0.01 to 0.09 s. Reopening it brings the stall back.
  • The large wallet selected instead of hidden: the same 0.5 to 0.7 s.
  • A hidden wallet with 5,000 coins and 1,668 addresses: 2.1 to 2.6 s, offscreen only.
  • At startup with sats saved as the unit, a profile shows about 0.4 s on the GUI thread under WalletQmlModel::setDisplayUnit while the wallet views are created. With BTC saved there is none.

Each open wallet now has its own view (DesktopWallets.qml#L444-L452), and each view's Activity list binds the global unit into its wallet whether or not the view is active (ActivityList.qml#L88-L93). setDisplayUnit emits balanceChanged (walletqmlmodel.cpp#L3187-L3201), which is connected to CoinsListModel::update (coinslistmodel.cpp#L16-L18). That is the per-coin label scan measured above for incoming payments. A unit change does not alter any coin, so it should not need the coin list rebuilt.

Before #1049 there was a single Activity list bound to the selected wallet, so a unit change refreshed that wallet only. That comparison is by source; I did not run a build from before #1049.

The cached label lookup tested with #990 should cut the cost of each refresh. I have not checked that branch for the per-wallet binding.

Reproduced on merged qt6 at eed1f426fcb6, macOS / Qt 6.9, isolated regtest, offscreen and native. Clicks went through the test bridge. Timing was noisy on a loaded machine: one native session's closed-wallet control read 0.13 to 0.58 s, and some native runs were several times slower than the figures above for reasons I could not isolate. I have left those out.

Since #1049 a display-unit change runs this coin-list refresh for every open wallet, including hidden ones. To reproduce: 1. Open two wallets: a small one, selected, and a large one that stays hidden. Mine had 3,000 coins and 601 unlabeled receiving addresses. 2. In the small wallet, open **Send** and click the unit button in the Amount field. Each click leaves the window unresponsive for 0.52 to 0.67 s, offscreen and native. Other measurements with the same wallets: - Two such hidden wallets: 1.06 to 1.16 s. - The large wallet closed from the wallet picker: 0.01 to 0.09 s. Reopening it brings the stall back. - The large wallet selected instead of hidden: the same 0.5 to 0.7 s. - A hidden wallet with 5,000 coins and 1,668 addresses: 2.1 to 2.6 s, offscreen only. - At startup with sats saved as the unit, a profile shows about 0.4 s on the GUI thread under `WalletQmlModel::setDisplayUnit` while the wallet views are created. With BTC saved there is none. Each open wallet now has its own view ([DesktopWallets.qml#L444-L452](https://github.com/bitcoin-core/gui-qml/blob/eed1f426fcb64daa61b004590335a03afe376274/qml/pages/wallet/DesktopWallets.qml#L444-L452)), and each view's Activity list binds the global unit into its wallet whether or not the view is active ([ActivityList.qml#L88-L93](https://github.com/bitcoin-core/gui-qml/blob/eed1f426fcb64daa61b004590335a03afe376274/qml/pages/wallet/ActivityList.qml#L88-L93)). `setDisplayUnit` emits `balanceChanged` ([walletqmlmodel.cpp#L3187-L3201](https://github.com/bitcoin-core/gui-qml/blob/eed1f426fcb64daa61b004590335a03afe376274/qml/models/walletqmlmodel.cpp#L3187-L3201)), which is connected to `CoinsListModel::update` ([coinslistmodel.cpp#L16-L18](https://github.com/bitcoin-core/gui-qml/blob/eed1f426fcb64daa61b004590335a03afe376274/qml/models/coinslistmodel.cpp#L16-L18)). That is the per-coin label scan measured above for incoming payments. A unit change does not alter any coin, so it should not need the coin list rebuilt. Before #1049 there was a single Activity list bound to the selected wallet, so a unit change refreshed that wallet only. That comparison is by source; I did not run a build from before #1049. The cached label lookup tested with #990 should cut the cost of each refresh. I have not checked that branch for the per-wallet binding. Reproduced on merged `qt6` at `eed1f426fcb6`, macOS / Qt 6.9, isolated regtest, offscreen and native. Clicks went through the test bridge. Timing was noisy on a loaded machine: one native session's closed-wallet control read 0.13 to 0.58 s, and some native runs were several times slower than the figures above for reasons I could not isolate. I have left those out.
Sign in to join this conversation.
No description provided.