From a1c20acc78df310e1d805e14c649bc1731e60e9d Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Thu, 25 Jun 2026 00:08:18 -0700 Subject: Faster WS reconnect; stop double-running the held-coin reconcile MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - _scheduleReconnect now backs off exponentially from ~0.6s (was a flat 4s), so a first socket attempt that's transiently rejected retries fast — the wallet reaches Live in well under a second instead of ~4s. Backoff resets on open. - refreshLive now stamps _lastPoll at its start, so a socket-open refresh and the poll-timer tick don't both fire reconcileHeld back-to-back on load. A cached load does one held-coin reconcile (verify coins still unspent + frontier check) instead of ~3x. Co-Authored-By: Claude Opus 4.8 (1M context) --- src/wallet.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'src/wallet.js') diff --git a/src/wallet.js b/src/wallet.js index 6b8be9f..ec1141e 100644 --- a/src/wallet.js +++ b/src/wallet.js @@ -291,6 +291,8 @@ export class Wallet { async refreshLive() { if (this.offline || this._refreshing || this._polling) return; this._polling = true; + this._lastPoll = Date.now(); // any refresh (poll OR socket-open) resets the + // poll clock, so the two don't both fire back-to-back on load. let changed = false; try { const fresh = []; // frontier addresses found to be active this pass @@ -1229,6 +1231,7 @@ export class Wallet { this._ws = ws; ws.onopen = () => { this.live = true; + this._wsBackoff = 0; // healthy again — reset the reconnect backoff this._lastMsg = Date.now(); this.retrack(); this.emit(); @@ -1353,7 +1356,12 @@ export class Wallet { _scheduleReconnect() { if (!this._wsWant) return; clearTimeout(this._wsRetry); - this._wsRetry = setTimeout(() => this._connectWs(), 4000); + // Exponential backoff starting small, so a first attempt that's transiently + // rejected (e.g. a stale rate-limit) retries in ~0.6s instead of a flat 4s — + // the wallet reaches Live quickly. Reset to 0 on a successful open. + this._wsBackoff = Math.min((this._wsBackoff || 0) + 1, 6); + const delay = Math.min(600 * 2 ** (this._wsBackoff - 1), 15000); + this._wsRetry = setTimeout(() => this._connectWs(), delay); } // Debounced: a payment may touch several of our addresses in one go. -- cgit v1.2.3