Skip to content

FIX: resume scanning when switching back to a network - #181

Open
chaitika wants to merge 1 commit into
CypherCommons:masterfrom
chaitika:fix/resume-scan-after-network-switch
Open

chaitika wants to merge 1 commit into
CypherCommons:masterfrom
chaitika:fix/resume-scan-after-network-switch

Conversation

@chaitika

@chaitika chaitika commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

After switching from Mainnet to Signet and back, the mainnet wallet stopped scanning for silent payments until the app was restarted:

  • pull-to-refresh and background polling did nothing
  • Track a payment said "No payment found" for real silent payments
  • the switch dialog promises the scan "will resume from where it left off when you switch back"

The switch cancels the outgoing wallet's scan but keeps the wallet object, and nothing ever cleared the cancel flag again.

  • add allowScanning() to undo cancelScan(), and remove the reset in scanForPayments that could never run
  • switchNetwork re-enables and restarts the scan for the incoming wallets once the indexer points at their chain, and for the outgoing wallets when a switch fails. Switching to a network for the first time in a session now also starts its wallet's scan right away, instead of waiting for pull-to-refresh
  • fix the networkPreference.ts comment that said the caller reloads wallets from storage
  • tests: the provider restarts the scan after switching away and back and after a failed switch, without scanning Signet while parked

The failing unit test (sendDetails) is unrelated and also fails on master; #234 fixes it.

Copilot AI balanced review requested due to automatic review settings October 7, 2026 17:07

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@thevaibhav-dixit

Copy link
Copy Markdown
Contributor

Tested locally — the fix works.

Unit / CI: ran the new network-switch.test.tsx against master's source (test file kept) → all 4 fail; the provider tests fail with Expected number of calls: 1 / Received: 0. With the PR they pass. tsc, lint (no new warnings), unit (374 tests) and integration are green.

Android emulator (debug build of this branch): created a mainnet and a Signet wallet, switched Mainnet → Signet → Mainnet, then hot-swapped master's versions of the changed files into the same build and repeated.

After switching back to Mainnet Before (master) After (this PR)
Scan restarts on its own ❌ no scan ✅ resumes from lastScanned=970642 to tip 970643 (block mined while parked)
30s background polling ❌ nothing for 40s ✅
Pull-to-refresh ❌ onRefresh fires, no SP scan ✅ scan runs
Track a payment (indexed taproot txid) ❌ fetches the tx but skips the check (cancelFlag=true) → "No payment to your wallet" ✅ runs the SP check (Scanned 1 txs, 1 outputs)
Mainnet wallet idle while on Signet ✅ ✅

Code review notes:

  • Removing the reset in scanForPayments is correct: it sat right after if (this.cancelScanCallbackScan) return 0;, so it only ever set an already-false flag.
  • allowScanning() is only called from the switch path; the only other cancelScan caller is deleteWallet, and deleted wallets never come back as incoming wallets.
  • Tightening isScannable is safe: HDSilentPaymentsWallet is the only IScannableWallet implementer and has both new methods.
  • No race with a quick follow-up switch: scanForPayments sets activeScanPromise before its first await, so cancelScanAndWait() always sees the restarted scan.
  • Scans restart only after switchNetworkBackends / rollbackNetworkSwitch and attachWalletCallbacks, so they hit the right chain's indexer and their state reaches the UI.

Not covered: iOS (change is JS-only), and a Track-a-payment match (test wallet had no incoming silent payment).

LGTM 👍

A network switch cancels the outgoing wallet's scan but keeps the wallet
object, and nothing cleared the cancel flag again. After switching to
Signet and back, the mainnet wallet stopped scanning for silent payments
until the app restarted: pull-to-refresh and polling did nothing, and
Track a payment reported "No payment found" for real silent payments.

- Add allowScanning() to undo cancelScan(), and remove the reset in
  scanForPayments that could never run.
- switchNetwork re-enables and restarts the scan for the incoming wallets
  once the indexer points at their chain, and for the outgoing wallets
  when a switch fails.
- Correct the networkPreference comment that said the caller reloads
  wallets from storage.
@chaitika
chaitika force-pushed the fix/resume-scan-after-network-switch branch from 5592a90 to 99e0ea9 Compare November 15, 2026 07:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants