perf(migrate): gate the seed-migration confirming balance scan
While the seed migration sits on the Confirming gate it polled the sweep's confirmations and a full wallet balance together on every pass. That balance call is the expensive one, and it only matters once the sweep is mined and we do not yet have a post-mine figure, yet it ran every poll even mid-sync when it cannot move the gate. - The confirmation count is still read on every poll. - The balance scan now runs only when it can actually advance the adopt gate: the sweep is mined, no post-mine balance has been recorded yet, and no sync is in progress. The manual Refresh button forces it regardless. - The decision lives in a small pure helper, and the poller snapshots the main-thread state it needs rather than reading members off the worker thread. - The Confirming screen now claims a leftover remainder (and offers the re-sweep button) only once the balance has actually been measured; while it is still unknown it keeps waiting instead of prompting on a sentinel. Tests cover the gate helper across the forced, syncing, and mined cases. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
+15
-8
@@ -33,6 +33,7 @@
|
||||
#include "rpc/rpc_client.h"
|
||||
#include "rpc/rpc_worker.h"
|
||||
#include "rpc/connection.h"
|
||||
#include "services/seed_migration_poll.h" // migrationWantsBalanceScan: gate the Confirming balance scan
|
||||
#include "services/lowest_block_search.h" // detectLowestAvailableBlockHeight: pure search + probe classification
|
||||
#include "chat/chat_identity.h" // deriveChatIdentityFromSecret for HushChat identity provisioning
|
||||
#include "ui/windows/chat_tab.h" // ui::ResetChatTab — wipe chat UI plaintext on a wallet switch
|
||||
@@ -6338,30 +6339,36 @@ std::function<void(bool, const std::string&)> App::makeSweepCompletionCallback(b
|
||||
// adopt step is gated on the tx being mined (confs >= 1) AND the legacy balance being ~0, so we
|
||||
// never swap wallet.dat while the funds could still bounce back (dropped/reorged tx) or while a
|
||||
// remainder is left behind (a sweep too big for one transaction).
|
||||
void App::pollSweepStatus()
|
||||
void App::pollSweepStatus(bool forceBalance)
|
||||
{
|
||||
if (capture_mode_) return; // no live ops during a UI sweep
|
||||
if (!rpc_ || !worker_ || !state_.connected) return;
|
||||
if (seed_migration_confirm_in_flight_ || seed_migration_sweep_txid_.empty()) return;
|
||||
seed_migration_confirm_in_flight_ = true;
|
||||
const std::string txid = seed_migration_sweep_txid_;
|
||||
worker_->post([this, txid]() -> rpc::RPCWorker::MainCb {
|
||||
int confs = 0; double remaining = -1.0; bool ok = false;
|
||||
// Snapshot main-thread state for the worker - never read members off the worker thread.
|
||||
const bool syncing = effectivelySyncing();
|
||||
const double priorRemaining = seed_migration_legacy_remaining_;
|
||||
worker_->post([this, txid, forceBalance, syncing, priorRemaining]() -> rpc::RPCWorker::MainCb {
|
||||
int confs = 0; double remaining = -1.0; bool ok = false; bool scanned = false;
|
||||
rpc::RPCClient::TraceScope trace("Migrate / confirm");
|
||||
try {
|
||||
auto tx = rpc_->call("gettransaction", {txid});
|
||||
if (tx.contains("confirmations") && tx["confirmations"].is_number())
|
||||
confs = tx["confirmations"].get<int>();
|
||||
auto bal = rpc_->call("z_gettotalbalance");
|
||||
if (bal.contains("total") && bal["total"].is_string())
|
||||
remaining = std::stod(bal["total"].get<std::string>());
|
||||
if (services::migrationWantsBalanceScan(forceBalance, syncing, confs, priorRemaining)) {
|
||||
auto bal = rpc_->call("z_gettotalbalance");
|
||||
if (bal.contains("total") && bal["total"].is_string())
|
||||
remaining = std::stod(bal["total"].get<std::string>());
|
||||
scanned = true;
|
||||
}
|
||||
ok = true;
|
||||
} catch (...) {}
|
||||
return [this, confs, remaining, ok]() {
|
||||
return [this, confs, remaining, ok, scanned]() {
|
||||
seed_migration_confirm_in_flight_ = false;
|
||||
if (ok) {
|
||||
seed_migration_sweep_confs_ = confs;
|
||||
seed_migration_legacy_remaining_ = remaining;
|
||||
if (scanned) seed_migration_legacy_remaining_ = remaining;
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user