diff options
| author | Adam Soltys <[email protected]> | 2026-06-25 00:08:18 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2026-06-25 00:08:18 -0700 |
| commit | a1c20acc78df310e1d805e14c649bc1731e60e9d (patch) | |
| tree | 4182b7eee23d2c033603894cf444f093f4b4266f /src | |
| parent | 26a5d52cd11adb22cd3cd3de4ead1b1f3fff38e6 (diff) | |
| download | coinosv3-a1c20acc78df310e1d805e14c649bc1731e60e9d.tar.gz coinosv3-a1c20acc78df310e1d805e14c649bc1731e60e9d.zip | |
Faster WS reconnect; stop double-running the held-coin reconcile
- _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) <[email protected]>
Diffstat (limited to 'src')
| -rw-r--r-- | src/wallet.js | 10 |
1 files changed, 9 insertions, 1 deletions
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. |
