perf(history): add a transactions revision counter to WalletState

WalletState had no change signal for its transaction list, so a UI
cache had to fingerprint all N transactions every frame to notice an
update. It now carries tx_revision, a counter that only increases;
clear() on disconnect bumps it instead of resetting it, so a cache
built before a reconnect or wallet switch can never match again.

- Every writer of the list bumps it: the full-node refresh, loading the
  cached history, adding, completing and removing a pending send, a
  mining-address relabel, the lite refresh and the screenshot demo
  rows.
- The full-node refresh and the lite refresh (every ~2 s) swap in the
  new list only when it differs field by field, the amount compared
  bit-exactly because -0.0 and +0.0 print differently. An unchanged
  refresh keeps the list and the revision; the compare costs O(N) per
  refresh, not per frame.

Nothing reads the counter yet.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-10 09:50:03 -05:00
co-authored by Claude Opus 5.5
parent 4a2a1bdd54
commit 860916d203
6 changed files with 255 additions and 4 deletions
+5 -1
View File
@@ -1252,6 +1252,7 @@ void App::upsertPendingSendTransaction(const std::string& opid,
} else {
state_.transactions.insert(state_.transactions.begin(), std::move(pending));
}
state_.touchTransactions(); // covers both the in-place replace and the insert
if (newPending) {
applyPendingSendDelta(pendingInfo.from, -pendingInfo.amount, /*includeAggregates*/ true);
}
@@ -1276,6 +1277,7 @@ void App::markPendingSendTransactionSucceeded(const std::string& opid,
pending->confirmations = 0;
if (pending->timestamp == 0) pending->timestamp = static_cast<std::int64_t>(std::time(nullptr));
}
state_.touchTransactions();
state_.last_tx_update = std::time(nullptr);
}
@@ -1299,6 +1301,7 @@ void App::removePendingSendTransactions(const std::vector<std::string>& opids,
}),
state_.transactions.end());
for (const auto& opid : opidSet) pending_send_info_.erase(opid);
state_.touchTransactions();
state_.last_tx_update = std::time(nullptr);
}
@@ -1917,7 +1920,7 @@ void App::loadTransactionHistoryCacheIfAvailable()
state_.sync.best_blockhash);
if (!loaded.loaded) return;
state_.transactions = std::move(loaded.transactions);
state_.replaceTransactions(std::move(loaded.transactions));
shielded_history_scan_heights_ = std::move(loaded.shieldedScanHeights);
pruneShieldedHistoryScanProgress();
state_.last_tx_update = loaded.updatedAt;
@@ -3897,6 +3900,7 @@ void App::setMiningAddress(const std::string& addr, bool mining)
changed = true;
}
}
if (changed) state_.touchTransactions(); // rows relabelled receive<->mined in place: History must rebuild
if (changed) storeTransactionHistoryCacheIfAvailable(data::HistoryStoreMode::Now); // user relabel: persist now
}