Repository navigation
Description
Summary
Core transaction records persisted by platform-wallet (transactions / PersistentTransaction) can carry a net_amount and direction that ignore the wallet's own spent inputs. A self-spend with change is stored as Incoming, +change, and an asset lock that spent the whole Core balance is stored as Internal, 0.0, while the TXO layer of the same store correctly links those inputs as spent by that very transaction. The record is never recomputed afterwards.
Balances are NOT affected (they come from TXOs, verified against Insight), but transaction history shows large phantom "Received" entries. On one testnet wallet the stored nets sum to +287.66 tDASH against a real balance of 10.05 tDASH.
This is the most plausible explanation for the "396 tDASH available, funds vanished after send, physically still there" report from @lklimek on the same E2E wallet (dash-evo-tool): the funds never existed as a balance, only as mis-netted history rows.
Environment
- platform
v4.2-dev@ c83c2c0 (rs-platform-wallet 4.2.0-beta.5), key-wallet / dash-spv 0.45.0 (rust-dashcore rev e4208c90786a) - dashwallet-ios
develop@ a345cc852, iOS Simulator (iPhone 17, iOS 26.5), testnet, fresh import of the E2E wallet (E2E_WALLET_MNEMONIC, seed known to @lklimek; not pasted here)
Evidence 1 — historical rows on a fresh import (2026-09-28)
After a full SPV sync of the E2E wallet, ZPERSISTENTTRANSACTION holds 723 rows:
| direction | n | Σ net_amount |
|---|---|---|
| 0 incoming | 214 | +723.26 |
| 1 outgoing | 405 | −425.67 |
| 2 internal | 104 | −9.94 |
| total | 723 | +287.66 tDASH |
ZPERSISTENTTXO: 36 unspent = 10.05056269 tDASH. Insight (/insight-api/addrs/…/utxo over all 1026 derived addresses) returns the same 36 UTXOs / 10.05056269, so the TXO layer is right and the tx records are wrong.
Joining each record with the TXOs it received and the TXOs that name it as spendingTransaction (Σreceived − Σspent) flags 26 rows (16 stored incoming, 10 outgoing) whose stored net differs from the TXO-derived net by +277.61 tDASH in total. Two checked on-chain:
| txid (display order) | height | on-chain | stored |
|---|---|---|---|
adf034c8385359fc8dae87b8b7825afcea3b4d9269a05201fa5db01ed13f2744 |
1474835 | 1 input 61.98792994 (ours), out 2.0 → ySaahczAy9…, change 59.98792768 → net −2.00000226 | direction=incoming, net=+59.98792768 |
1278141c23bd2a2746108f342251d3d2781c2aac57038cb5059ca0cee9fb296c |
1474845 | 1 input 59.98692542 (ours), out 2.0 → yNqxGXUFEM…, change 57.98692316 → net −2.00000226 | direction=incoming, net=+57.98692316 |
In both cases ZPERSISTENTTXO.ZSPENDINGTRANSACTION of the input already points at the row with the wrong net.
Evidence 2 — live reproduction (same day)
Internal transfer Core → Platform (AssetLockAddressTopUp, Max), app killed 2.5 s after the PIN = 2 s after the SPV broadcast of the asset lock, 0.5 s after its InstantSend lock, while wait_for_proof was still pending. After relaunch the funding completed (Platform addresses credited, no funds lost), but the record the relaunched process created for the lock is wrong:
| txid (display order) | inputs (ours) | outputs | TXO-derived net | stored |
|---|---|---|---|---|
fb5190500819704bb7b8ebcb514199cdbbf0daa7a24424f1f021db628aa47cdf (type 8, h 1562326) |
2 = 5.00002666 | lock 5.00002105, no change | −5.00002666 | direction=internal (2), net=0.0 |
Control: the identical route without the kill, 9ebc2e1cc3a1e500cb3531a73f005ff84670eb2d0e5e8b027b4286b3ad4377e2 (36 inputs = 10.05056269, lock 10.0504816, change 0.00002666), is stored correctly as internal, −10.05053603. Both rows' inputs are linked as spent (ZISSPENT=1, ZSPENDINGTRANSACTION = the row) in the same store.
Side effect of the same kill: the ZPERSISTENTASSETLOCK row for fb519050… stays at status 2 (instantSendLocked) for > 2 min after the address funding landed; the control lock reached 4 (consumed) within seconds.
Where it comes from (reading the code)
- key-wallet
managed_core_funds_account.rs:814setsnet_amount = account_match.received − account_match.sent;sentonly counts inputs whose parent outpoint is in the account'sutxosat check time (self.utxos.get(&input.previous_output), ~L206/L277). - platform-wallet
changeset/changeset.rs::fold_same_txid_recordssums those per-account slices and derivesdirectionfrom the mergedinput_details/output_details. - swift-sdk
PlatformWalletPersistenceHandler.swift(~L2525–2563) writes whatevertx.net_amount/tx.directionthe changeset carries; nothing recomputes a record once its inputs are later recognised as ours.
So when a transaction is checked while the parent outputs it spends are not (yet, or no longer) in the account UTXO set — rescan order, relaunch mid-flow, parent already removed by a wallet-level observed_spent reconcile — the record is born with empty input_details, net = +our outputs, direction = Incoming (or Internal/0 for a lock), and stays that way even though the TXO seam later attributes the spend to it.
Expected
net_amount / direction of a persisted transaction record reconcile with the TXOs the store links to it: when TXOs later name the record as their spending transaction, the record is recomputed (Σreceived − Σspent, direction by the fold rule), or the record is derived from the TXO seam in the first place.
Repro (iOS, testnet)
- Fresh import of the E2E wallet, full SPV sync → compare
SUM(ZNETAMOUNT)withSUM(ZAMOUNT) WHERE ZISSPENT=0inDocuments/SwiftDashSDK/Platform/testnet/DashModel.sqlite(+287.66 vs 10.05). - Or: Internal → Transparent→Platform → Max → PIN,
xcrun simctl terminate~2.5 s later, relaunch → the new lock's row hasnet=0.0while its inputs areZISSPENT=1withZSPENDINGTRANSACTIONpointing at it.
SQL used for the diff (works on the SwiftData store):
WITH outs AS (SELECT ZTRANSACTION tx, SUM(ZAMOUNT) received FROM ZPERSISTENTTXO GROUP BY ZTRANSACTION),
ins AS (SELECT ZSPENDINGTRANSACTION tx, SUM(ZAMOUNT) spent FROM ZPERSISTENTTXO
WHERE ZSPENDINGTRANSACTION IS NOT NULL GROUP BY ZSPENDINGTRANSACTION)
SELECT t.Z_PK, t.ZDIRECTION, t.ZNETAMOUNT, COALESCE(o.received,0)-COALESCE(i.spent,0) AS txo_net, hex(t.ZTXID)
FROM ZPERSISTENTTRANSACTION t LEFT JOIN outs o ON o.tx=t.Z_PK LEFT JOIN ins i ON i.tx=t.Z_PK
WHERE t.ZNETAMOUNT <> COALESCE(o.received,0)-COALESCE(i.spent,0);cc @lklimek
Activity