fix(btc-only): purge phantom multi-chain balances on connect#351
Merged
Conversation
Diagnosis: the balance cache is keyed by hardware deviceId alone (getCachedBalances(deviceId) → all chain rows), and deviceId is stable across firmware variants. A device reflashed from multi-chain to bitcoin-only keeps its old multi-chain balance rows, so the dashboard sums phantom balances — incl. an ETH balance at an address the btc-only firmware physically cannot derive — into 'All Chains'. (Reproduced: device 343737340F...3B00, ETH $91.36 at 0x9f5f2e60…, Bitcoin $0.00, total $101.17; rows dated 4 days pre-flash.) The user's assumption that the cache is keyed by an ETH address is inverted — it's keyed by deviceId, which has no address in it, so nothing stops the stale multi-chain data from loading. Fix: a btc-only seed is locked to BTC (storage band 10017) and can never hold another chain, so on connect purge every non-'bitcoin' cached balance for the device (clearNonBitcoinBalances). Removes the phantom at the source, so every read path (dashboard, audit, ledger, swap) is correct.
This was referenced Jul 12, 2026
Collaborator
Author
|
Backed out of |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Diagnosis (live btc-only testing): dashboard showed
All Chains $101.17butBitcoin No balance. The balance cache is keyed by hardwaredeviceIdalone (getCachedBalances(deviceId)returns every chain row), anddeviceIdis stable across firmware variants. A device reflashed multi-chain → btc-only keeps its old rows, so the dashboard sums phantom balances — including ETH $91.36 at0x9f5f2e60…, an address btc-only firmware can't derive — into the total. (Rows dated 2026-07-08, 4 days pre-flash — stale table, not a live refetch.)The intuition that the cache needs an ETH address in its identifier is inverted: it's keyed by
deviceId, so nothing gates the stale data.Fix: a btc-only seed is locked to BTC (storage band 10017) and can never hold another chain, so on connect purge every non-
bitcoincached balance for the device. Source-level fix → dashboard, audit, ledger, and swap all read correct. Verified on the live DB: 16 phantom rows removed, 1 BTC row kept, total → $0.00.