Skip to content

qt: serve transaction-list labels from the address table's rows - #449

Open
kiwidream wants to merge 1 commit into
1.x.xfrom
kiwidream/qt445-label-cache
Open

kiwidream wants to merge 1 commit into
1.x.xfrom
kiwidream/qt445-label-cache

Conversation

@kiwidream

@kiwidream kiwidream commented Nov 19, 2026 •

Copy link
Copy Markdown
Member

The transaction list resolved each row's label with AddressTableModel::labelForAddress, which asks the wallet under a blocking cs_wallet lock. That ran on every repaint of a visible row and on every filter or sort pass over the history, and it waited whenever the wallet held its lock, for example for each connected block. On a wallet with a long history this freezes the GUI while the node catches up.

The transaction table now reads labels from the address table model's rows (cachedLabelForAddress). It keeps the decode-then-encode normalisation of the wallet lookup and gives no label to an address that does not decode, as the wallet does. Its label source is the address table model the wallet model was created with, which lists every address, and the wallet model passes it explicitly. That holds after the Sign Message dialog has had WalletModel::refresh() hand out a legacy-only model. WalletModel registers for address-book changes before its address table model reads the address book, so changes made while the history loads are no longer lost, and it updates the complete model and the current one only.

Because nothing reads the wallet on repaint any more, an address-book change invalidates the transaction rows that show that address. Notifications can arrive in another order than the writes they report (CWallet::SetAddressBookWithDB notifies after releasing the wallet lock), so each one is also followed by a comparison of the entries it named with the wallet. That comparison runs from the event loop and uses a new non-blocking read, interfaces::Wallet::tryGetAddresses(), a single TRY_LOCK(cs_wallet) for every recorded address. Where the complete address table model's row differs from the wallet's entry, it applies the wallet's state the way a notification would. An address whose encoding does not decode to a destination the wallet can look up is left as its notifications left it, and if a listener delivers a newer notification while a correction is applied, the remaining entries are read again rather than overwritten with the older read. While the lock is busy, as while a block is connected or the wallet is being encrypted, it retries after 250 ms and never waits. However the notifications were ordered, the models end at the wallet's state. The address table models still take a change at once, inside the wallet's notification; for a change made on the GUI thread, CWallet::DelAddressBook and CWallet::GetNewDestination raise it with the wallet lock held. The transaction table only records the address there, and only if its label changed: the unlabelled receiving entries the wallet files while it syncs or rescans, purpose-only changes and the removal of unlabelled entries cost nothing. It makes one pass over the history from the event loop, after the notification has returned. That one pass covers every address changed meanwhile, so a burst of changes costs one pass instead of one per change.

The pass sends a single dataChanged() for the address column, from the first affected row to the last. A single signal is needed for correctness: QSortFilterProxyModel sorts the rows of each signal against the rest, assuming the rest is in order, so per-range signals left a list sorted by label wrong. Filters still see every covered row, and a list sorted by date is not sorted again. If a listener adds or removes rows meanwhile, the pass is repeated instead of dropping rows.

Dialog actions (coin control, send entries, the edit-address duplicate check) and purposeForAddress still read the wallet.

Tests use the synthetic wallet and a real descriptor wallet. They cover:

  • no getAddress call and no wait while another thread holds the wallet lock;
  • equivalence with the wallet across address-book states and a pk_hash_only refresh;
  • both delivery orders of a payment and its label;
  • changes during model construction;
  • no row signal inside the wallet's notification;
  • one pass for a burst;
  • one signal for scattered rows, with search and address sort following;
  • re-notification after a row change;
  • stored address text in upper case or with white space;
  • undecodable addresses;
  • no pass for a change that leaves the label as it was;
  • reordered notifications (relabel, add and delete) converging on the wallet's state, for the table, the rows, a search and an address sort;
  • the comparison not blocking while the wallet lock is held, and retrying;
  • one wallet read per burst;
  • no change when the notifications were in order;
  • deletion of the wallet model with a comparison pending;
  • an entry the wallet holds under a destination its address does not name left alone;
  • a newer notification delivered during the comparison not overwritten;
  • the legacy-only model for entries relabelled, added and removed.

Each fails without its part of the change.

Measured on 100,000 synthetic rows with two proxies:

  • a relabel of an address shown by half the rows: about 0.35 s, none of it under the wallet lock (before: 0.3 s, all of it inside the notification);
  • a burst of 1,000 relabels: about 0.35 s (before: 1.1 to 1.7 s);
  • a relabel of a rarely used address now costs one filter pass over the span of its rows (about 0.35 s here).

Known limits: a failed address-book database write sends no notification, so the list keeps the old label until the next change to that address or a restart. While the wallet lock is busy, a label from notifications that arrived out of order can show until the next retry finds the lock free (every 250 ms). The non-blocking read calls IsMine, which can wait on the wallet's descriptor locks as tryGetTxStatus can. A row inserted between a label change made on the GUI thread and the following label pass can be placed wrongly in a list sorted on the address column if its own label did not change; the next sort corrects it. Each lookup still decodes and re-encodes the address.

Proposed release note

GUI: The transaction list now takes labels from the GUI's copy of the address book instead of asking the wallet on every repaint, so scrolling, searching and sorting a long history no longer stall while the wallet is busy, for example while the node catches up. When a label changes, the list updates the affected rows once the change has been applied, in a single pass for any number of changes made together (such as a rescan or a script that sets many labels), and a list sorted by label is re-sorted correctly. On a wallet with a very long history, changing a label can take a fraction of a second while the list filters its rows again. A label changed from the RPC console or another RPC client appears in the list as soon as the GUI processes the change, also when several clients change the same label at once. The Sending and Receiving addresses windows also keep updating after the Sign Message dialog's address book has been used. (#445)

Refs #445

🤖 Generated with Claude Code

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-30T18:51:07.458288Z 448872f New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@kiwidream

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4bae798f19

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/qt/transactiontablemodel.cpp Resolved
@kiwidream

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Delightful!

Reviewed commit: 4afa5dbf8f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

The transaction list resolved each row's label with `AddressTableModel::labelForAddress`, which asks the wallet under a blocking `cs_wallet` lock. That ran on every repaint of a visible row and on every filter or sort pass over the history, and it waited whenever the wallet held its lock, for example for each connected block. On a wallet with a long history this freezes the GUI while the node catches up.

The transaction table now reads labels from the address table model's rows (`cachedLabelForAddress`). It keeps the decode-then-encode normalisation of the wallet lookup and gives no label to an address that does not decode, as the wallet does. Its label source is the address table model the wallet model was created with, which lists every address, and the wallet model passes it explicitly. That holds after the Sign Message dialog has had `WalletModel::refresh()` hand out a legacy-only model. `WalletModel` registers for address-book changes before its address table model reads the address book, so changes made while the history loads are no longer lost, and it updates the complete model and the current one only.

Because nothing reads the wallet on repaint any more, an address-book change invalidates the transaction rows that show that address. Notifications can arrive in another order than the writes they report (`CWallet::SetAddressBookWithDB` notifies after releasing the wallet lock), so each one is also followed by a comparison of the entries it named with the wallet. That comparison runs from the event loop and uses a new non-blocking read, `interfaces::Wallet::tryGetAddresses()`, a single `TRY_LOCK(cs_wallet)` for every recorded address. Where the complete address table model's row differs from the wallet's entry, it applies the wallet's state the way a notification would. An address whose encoding does not decode to a destination the wallet can look up is left as its notifications left it, and if a listener delivers a newer notification while a correction is applied, the remaining entries are read again rather than overwritten with the older read. While the lock is busy, as while a block is connected or the wallet is being encrypted, it retries after 250 ms and never waits. However the notifications were ordered, the models end at the wallet's state. The address table models still take a change at once, inside the wallet's notification; for a change made on the GUI thread, `CWallet::DelAddressBook` and `CWallet::GetNewDestination` raise it with the wallet lock held. The transaction table only records the address there, and only if its label changed: the unlabelled receiving entries the wallet files while it syncs or rescans, purpose-only changes and the removal of unlabelled entries cost nothing. It makes one pass over the history from the event loop, after the notification has returned. That one pass covers every address changed meanwhile, so a burst of changes costs one pass instead of one per change.

The pass sends a single `dataChanged()` for the address column, from the first affected row to the last. A single signal is needed for correctness: `QSortFilterProxyModel` sorts the rows of each signal against the rest, assuming the rest is in order, so per-range signals left a list sorted by label wrong. Filters still see every covered row, and a list sorted by date is not sorted again. If a listener adds or removes rows meanwhile, the pass is repeated instead of dropping rows.

Dialog actions (coin control, send entries, the edit-address duplicate check) and `purposeForAddress` still read the wallet.

Tests use the synthetic wallet and a real descriptor wallet. They cover:
- no `getAddress` call and no wait while another thread holds the wallet lock;
- equivalence with the wallet across address-book states and a `pk_hash_only` refresh;
- both delivery orders of a payment and its label;
- changes during model construction;
- no row signal inside the wallet's notification;
- one pass for a burst;
- one signal for scattered rows, with search and address sort following;
- re-notification after a row change;
- stored address text in upper case or with white space;
- undecodable addresses;
- no pass for a change that leaves the label as it was;
- reordered notifications (relabel, add and delete) converging on the wallet's state, for the table, the rows, a search and an address sort;
- the comparison not blocking while the wallet lock is held, and retrying;
- one wallet read per burst;
- no change when the notifications were in order;
- deletion of the wallet model with a comparison pending;
- an entry the wallet holds under a destination its address does not name left alone;
- a newer notification delivered during the comparison not overwritten;
- the legacy-only model for entries relabelled, added and removed.

Each fails without its part of the change.

Measured on 100,000 synthetic rows with two proxies:
- a relabel of an address shown by half the rows: about 0.35 s, none of it under the wallet lock (before: 0.3 s, all of it inside the notification);
- a burst of 1,000 relabels: about 0.35 s (before: 1.1 to 1.7 s);
- a relabel of a rarely used address now costs one filter pass over the span of its rows (about 0.35 s here).

Known limits: a failed address-book database write sends no notification, so the list keeps the old label until the next change to that address or a restart. While the wallet lock is busy, a label from notifications that arrived out of order can show until the next retry finds the lock free (every 250 ms). The non-blocking read calls `IsMine`, which can wait on the wallet's descriptor locks as `tryGetTxStatus` can. A row inserted between a label change made on the GUI thread and the following label pass can be placed wrongly in a list sorted on the address column if its own label did not change; the next sort corrects it. Each lookup still decodes and re-encodes the address.

**Proposed release note**

> GUI: The transaction list now takes labels from the GUI's copy of the address book instead of asking the wallet on every repaint, so scrolling, searching and sorting a long history no longer stall while the wallet is busy, for example while the node catches up. When a label changes, the list updates the affected rows once the change has been applied, in a single pass for any number of changes made together (such as a rescan or a script that sets many labels), and a list sorted by label is re-sorted correctly. On a wallet with a very long history, changing a label can take a fraction of a second while the list filters its rows again. A label changed from the RPC console or another RPC client appears in the list as soon as the GUI processes the change, also when several clients change the same label at once. The Sending and Receiving addresses windows also keep updating after the Sign Message dialog's address book has been used. (#445)

Refs #445

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Squashed commits:
c9202a4 qt: serve transaction-list labels from the address table's rows
fdc77b3 qt: keep the label tests independent of host pauses
35fae9f qt: keep transaction labels on the complete address table model
88065de qt: register for address book changes before reading the address book
8964afe qt: update only the address table models in use
a634bd5 qt: notify changed labels' rows once per event-loop pass
51e2985 qt: give no label to an address that does not decode
5cf0dc1 qt: hand the transaction table its label source
ad5224b qt: reserve the label tests' vectors before filling them
4bae798 qt: skip the label pass when an entry's label stays the same
0efeeda qt, wallet: add a try-lock read of address book entries
5803d8f qt: compare notified address book entries with the wallet
4afa5db qt: leave unaddressable entries alone and reread after nested changes

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Squashed-from: 4afa5db
@kiwidream
kiwidream force-pushed the kiwidream/qt445-label-cache branch from 4afa5db to 448872f Compare November 30, 2026 18:48

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant