Skip to content

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

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

kiwidream wants to merge 13 commits 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

kiwidream and others added 10 commits November 19, 2026 15:04
The transaction list resolved each row's label through
AddressTableModel::labelForAddress, which asked 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 waited whenever the
wallet held its lock, for example for each block it connects. Only
during a wallet encryption did it answer from the model's own rows.

The transaction table now always answers from the address table
model's rows through the new cachedLabelForAddress(), which normalises
the address the way the wallet lookup does. The rows match the wallet's
labels: they are built from getAddresses(), which lists exactly the
non-change entries getAddress() finds, and every address book
notification updates them. The other labelForAddress() callers, which
are dialog actions, keep reading the wallet, as does purposeForAddress().

Because nothing reads the wallet on repaint any more, an address book
change must invalidate the rows that show it. WalletModel::
updateAddressBook() now has the transaction table emit dataChanged for
those rows only, so views, label searches and sorts follow the address
book whichever of a payment and its label is delivered first.

The message signing dialog replaces the address table model with one
that lists only legacy addresses. That model now keeps the entries it
leaves out of its rows, and keeps them current, so label lookups stay
complete whatever model is displayed.

Refs #445

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The lock-holding threads in the new label tests gave up after five
seconds, and some checks waited five seconds for queued notifications,
so a CI runner that stalls the process for several seconds could fail
them. The synthetic wallet now wakes the holder as soon as the GUI
thread asks it for an address, so that test fails at once without
depending on time; the remaining bounds only end a GUI thread that
waits for the lock. Queued notifications are delivered directly once
the thread that raised them has ended, instead of waiting for them.

Refs #445

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Review of the first commit found that keeping the entries a
pk_hash_only address table model leaves out of its rows in a second
list let new non-legacy entries into its rows, left the transaction
list reading a model that refresh() swaps out without telling the rows,
and kept a full copy of the address book in every model the message
signing dialog creates.

Instead, the transaction table keeps reading the address table model
the wallet model was created with, which lists every address, and
WalletModel::updateAddressBook() keeps every address table model it
has handed out current. That model is also the one the address book
pages show, so they no longer stop following the address book after
the message signing dialog has called refresh(). The pk_hash_only model
is as before.

updateAddressLabel() now collects the rows first and stops emitting if
a listener deletes the model or changes its rows.

Refs #445

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
WalletModel's constructor built the address table model, which reads
the address book, before subscribeToCoreSignals() registered the
address book handler, and the transaction history loads in between,
which takes seconds for a long history. A change made meanwhile, such
as a setlabel or getnewaddress RPC while the wallet opens or a
receiving address the wallet files while it syncs, never reached the
GUI. The transaction list now shows labels from that model, so it
would have kept the stale label until the GUI restarted.

Register only the address book handler before the address table model
reads the address book. Notifications from other threads are queued
and applied after the constructor has returned; one for a change the
read already includes is skipped, or applied again with the state the
read found. The other handlers are registered where they were.

Refs #445

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
WalletModel::updateAddressBook() sent each address book change to
every address table model refresh() had ever created. The message
signing dialog has refresh() create one each time it opens its address
book, and nothing shows the earlier ones, so each change cost more the
more often the dialog had been opened, and each legacy-only model
logged a warning for every change to another address.

Keep the model created with the wallet model in a member and update it
and the one getAddressTableModel() currently returns. The member says
which model is the complete one, where finding the first child would
rely on child order, which Qt leaves undefined for findChild(), and
would also find a model that is still reading the address book. A
change raised on the GUI thread is delivered at once, so one raised
during that read would have been applied there and then read again,
listing the address twice. The constructor raises none, but nothing
now depends on that.

Share the lookup of an address table entry by destination between
cachedLabelForAddress() and the encryption-in-progress branch of
getAddressData(), and drop a header sentence that did not hold: a
pk_hash_only model takes in a new entry for any address, as before.

In the label tests, release the lock-holding thread from a scope guard,
so a failed check no longer waits out the thread's 60 second bound.

Refs #445

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Finding and notifying the transaction rows that show a changed label
ran inside the wallet's address book notification. A change made on
the GUI thread, such as an edit on the address book page, calls
WalletModel::updateAddressBook() directly while the wallet holds
cs_wallet, and for a deletion an open database transaction, so the
scan over the history and the proxies' re-filtering, which read
transaction statuses, ran under that lock. Each notification also made
its own pass over the history, and an address shown by many rows sent
a signal for every range of its rows, each for every column.

The address table models still take a change at once. The transaction
table now notes the address and queues a pass, which runs once the
event loop is reached and covers every address changed meanwhile, so a
burst of K changes over N rows costs one pass of N rows instead of K.
The pass sends one dataChanged() for the address column, from the
first row that shows a changed label to the last. One signal is not
only cheaper: a proxy sorts the rows of a signal again among its other
rows, which it takes to be in order, and the labels of all the rows
have already changed, so with a signal per range a list sorted by the
address column misplaced them. Only the address column shows the
label, so a list sorted by date is no longer sorted again; filters
still look at every row the signal covers. If a listener adds or
removes rows while the signal is delivered, the pass is queued again
instead of dropping the rows.

Rows whose address is text the wallet stored are compared through the
address book key the label lookup uses, against all changed addresses
at once.

Refs #445

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
cachedLabelForAddress() decodes an address and looks up its encoding.
An address that does not decode, or a transaction row without one,
became a lookup of the empty string, which an entry whose encoding is
empty would answer. The wallet finds no entry for such a destination,
so the shared lookup by destination now finds none either; it also
serves the encryption-in-progress branch of getAddressData().

Refs #445

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
TransactionTableModel took the address table model it reads labels
from with parent->getAddressTableModel() in its initialiser list, which
gives the complete model only because the WalletModel constructor
creates the transaction table before anything can call refresh().
Reordering that constructor could have left the transaction list
reading a model that lists only legacy addresses. The wallet model now
passes the complete model explicitly.

Also correct two comments: getAddressData() is no longer where the
transaction list looks up its labels, and only a change made on
another thread is queued while the wallet model's constructor runs.

Refs #445

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
clang-tidy's performance-inefficient-vector-operation, which the tidy
job treats as an error, flagged two loops in the new label tests that
grow a vector one element at a time.

Refs #445

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
WalletModel::updateAddressBook() queued a pass over the transaction
history for every address book notification, including the many that
change no label: the unlabelled receiving entry the wallet files for
each address it finds used while it connects blocks or rescans, a
change of purpose only, and the removal of an unlabelled entry. The
transaction list shows nothing of an entry but its label, so compare
the label the complete address table model gives for the address
before and after the update, and queue the pass only if it changed. An
entry no address decodes to, which no row can show, no longer pulls
every row without an address into the pass.

Also state which wallet paths notify with the wallet lock held: for a
change made on the GUI thread, CWallet::DelAddressBook (inside a
database transaction) and CWallet::GetNewDestination do, while
CWallet::SetAddressBookWithDB notifies after releasing it. The test
for the deferred pass now removes an entry, as DelAddressBook does.

Refs #445

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@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-20T01:09:10.311799Z 4afa5db Manual request
ℹ️ 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 and others added 3 commits November 19, 2026 19:10
The GUI keeps the address book in its address table models and
updates them from the wallet's address book notifications. Those can
arrive in another order than the writes they report, so the GUI needs
to compare the entries a notification named with the wallet, without
waiting for the wallet lock on its thread.

interfaces::Wallet::tryGetAddresses() reads the entries for a list of
destinations under one TRY_LOCK(cs_wallet), as tryGetBalances() and
tryGetTxStatus() do, and gives up if the lock is busy. Each entry is
what getAddresses() lists for that destination, with the same purpose
fallback for old wallets, or none if the wallet has no entry other than
a change one. The synthetic test wallet gains the counterpart, which
counts its calls and gives up while its lock stand-in excludes the
caller.

Refs #445

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
CWallet::SetAddressBookWithDB() notifies after releasing cs_wallet,
so when two writers change one entry the notifications can arrive in
the opposite order to the writes. WalletModel::updateAddressBook()
applied them in arrival order and kept the older label. Before the
transaction list read labels from the address table model, its rows
read the wallet on every repaint and recovered; now the rows, label
searches and sorts kept the older label until another change to that
address or a restart.

Each notification is still applied to the address table models at
once. The address it names is also recorded, and one queued step per
event-loop pass reads the wallet's entries for every recorded address
with tryGetAddresses(), which never waits for the wallet lock: while
the lock is busy, as while a block is connected or the wallet is being
encrypted, the addresses are kept and the step runs again after
MODEL_UPDATE_DELAY. Where the complete address table model's row
differs from the wallet's entry (missing, extra, another label or
another type), the step applies the wallet's state through the same
updateEntry() path a notification takes, to the complete model and the
current one, and queues a label pass if the label shown changed. As
every notification is followed by such a step, the models end at the
wallet's state whatever order the notifications arrived in.

Refs #445

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Review of the address book reconcile found two cases it got wrong,
neither of which today's wallet writers reach.

An entry the wallet holds under a destination its encoding does not
name, such as one that encodes to the empty string, or an address the
chain does not decode, cannot be looked up by that encoding. The
wallet read found no entry, and the reconcile removed the row. Such
addresses are now skipped, and the row stays as its notifications
left it.

The reconcile reads every recorded entry and then applies the
differences one by one. If a listener ran a nested event loop that
delivered a newer notification for an address still to come, the
older read was applied over it and nothing recorded the address again.
A count of the notifications applied now shows that this happened, and
the remaining addresses are read again in another reconcile, as the
label pass does when its rows change under it.

Also test the reconcile while the legacy-only model is current, for a
legacy entry relabelled and for entries it adds and removes, and share
the WalletAddress construction, with its purpose fallback for old
wallets, between getAddresses() and tryGetAddresses().

Refs #445

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@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".

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