fix(lite): refresh the sidebar unconfirmed badge on confirmations

The sidebar unconfirmed-tx badge was recomputed only when the tx list
changed, keyed on last_tx_update plus the list size. That missed the
one case that matters most: a transaction confirming without the list
count changing. last_tx_update did not move for a same-second content
change, and lite never stamped it at all, so the badge stuck on a
stale 0-conf count until some unrelated refresh happened to shift the
list size.

- The badge now keys on tx_revision, which the state bumps on every
  content change - including a confirmation flip at an unchanged tx
  count - and which lite stamps too, so the count tracks confirmations
  on both the full node and the lite wallet.
- The sentinel starts at 0, which tx_revision never takes (it starts
  at 1), so the first frame always computes once.
- The recompute still runs only when the revision actually moved, so
  the per-frame work the previous guard avoided is still avoided.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-10-14 07:51:34 -05:00
co-authored by Claude Opus 4.8
parent 25ad23aee4
commit e2210cf5d3
2 changed files with 7 additions and 9 deletions
+4 -5
View File
@@ -2163,10 +2163,10 @@ void App::render()
// long confirmed (the other leg holds the real count). So: a txid with ANY confirmed leg is
// confirmed, and we count UNIQUE unconfirmed txids — otherwise the badge sticks on stale 0-conf
// legs of already-confirmed transactions and double-counts multi-leg ones.
// Recompute only when the tx list actually changed (last_tx_update is bumped on every tx refresh;
// size() catches same-second content changes). Otherwise this built two unordered_sets over the whole
// Recompute only when the tx list actually changed. tx_revision moves on EVERY content change (incl. a
// confirmation flip at equal tx count) and, unlike last_tx_update, lite stamps it. Otherwise this built two unordered_sets over the whole
// wallet tx list every frame just to size a badge.
if (state_.last_tx_update != sb_unconf_key_ts_ || state_.transactions.size() != sb_unconf_key_n_) {
if (state_.tx_revision != sb_unconf_key_rev_) {
std::unordered_set<std::string> confirmedTxids;
for (const auto& tx : state_.transactions) {
if (tx.confirmations >= 1) confirmedTxids.insert(tx.txid);
@@ -2178,8 +2178,7 @@ void App::render()
}
}
sb_unconf_count_ = static_cast<int>(unconfirmedTxids.size());
sb_unconf_key_ts_ = state_.last_tx_update;
sb_unconf_key_n_ = state_.transactions.size();
sb_unconf_key_rev_ = state_.tx_revision;
}
sbStatus.unconfirmedTxCount = sb_unconf_count_;
+3 -4
View File
@@ -1006,10 +1006,9 @@ private:
mutable std::uint64_t chat_unread_rev_ = ~0ull; // ~0 forces the first compute
mutable int chat_unread_cached_ = 0;
mutable double chat_unread_computed_at_ = 0.0;
// Sidebar unconfirmed-tx badge — recomputed only when the tx list changes (keyed on last_tx_update +
// size), not every frame. See App::render().
std::int64_t sb_unconf_key_ts_ = -1;
std::size_t sb_unconf_key_n_ = 0;
// Sidebar unconfirmed-tx badge — recomputed only when the tx list changes (keyed on tx_revision),
// not every frame. See App::render().
std::uint64_t sb_unconf_key_rev_ = 0; // sentinel 0 never matches: tx_revision starts at 1
int sb_unconf_count_ = 0;
// Daemon-memory probe is expensive (/proc scan on Linux, popen on macOS): it runs on this sampler's own
// thread, at most once per 3 s and only while a reader asks (Mining tab memory bar, Peers tab Memory cell).