diff options
| author | Adam Soltys <[email protected]> | 2026-07-04 19:29:08 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2026-07-04 19:29:08 -0700 |
| commit | 1d9cac6ca92187718eafbd567562875d25fa772b (patch) | |
| tree | c5ffaa9205d0236fda69ca798d73c33dd9c49a54 /src/ark/manager.js | |
| parent | cc2c05d2a1b7a9601eb3cb0df998483099e590cc (diff) | |
| download | coinosv3-1d9cac6ca92187718eafbd567562875d25fa772b.tar.gz coinosv3-1d9cac6ca92187718eafbd567562875d25fa772b.zip | |
Ark: recover from stale vtxo state
Match captaind's actual 'not spendable' error so a crashed or foreign
spend fails the action instead of retrying forever, and reconcile
locally-spendable vtxos against the server (GetVtxoStatus + ownership
attestation) when an ark address lands in the send form. boardFee now
treats absent proto3 fee fields as zero (Second's signet boards free).
Co-Authored-By: Claude Fable 5 <[email protected]>
Diffstat (limited to 'src/ark/manager.js')
| -rw-r--r-- | src/ark/manager.js | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/src/ark/manager.js b/src/ark/manager.js index bb7eb5f..310bab5 100644 --- a/src/ark/manager.js +++ b/src/ark/manager.js @@ -21,6 +21,7 @@ import { getArkInfo, handshake, encodeAddress, decodeAddress, blindMailboxId, readMailbox, decodeVtxo, arkIdFromServerPubkey, GrpcError, grpcStream, decodeMailboxMessage, mailboxRequestBytes, + getVtxoStatus, VTXO_STATE_SPENT, } from './proto.js'; import { buildArkoorSend, cosignWithServer, buildSignedVtxoBytes, @@ -214,6 +215,27 @@ export class ArkManager { this._streamAbort = null; } + // Check every locally-spendable vtxo against the server's authoritative + // off-chain ledger and flip the ones it reports spent (state drift from the + // same seed active elsewhere, or a restored state snapshot). Trust flows one + // way — spendable -> spent — so a lying server can hide balance from the UI + // but never mint it, and the signed bytes stay held for unilateral exit. + async reconcile() { + const candidates = this.state.vtxos.filter((v) => v.state === 'spendable'); + const states = await Promise.all(candidates.map((v) => + getVtxoStatus(this.arkUrl, this._decoded(v).point.raw, this._keyForVtxo(v).privkey) + .catch(() => null))); // unreachable/erroring server changes nothing + let changed = false; + candidates.forEach((v, i) => { + if (states[i] !== VTXO_STATE_SPENT) return; + v.state = 'spent'; + this._movement({ type: 'reconcile', amountSat: v.amountSat, status: 'complete', vtxoId: v.id, detail: 'spent elsewhere (server vtxo status)' }); + changed = true; + }); + if (changed) this._save(); + return changed; + } + async resumePending() { for (const action of this.pendingActions()) { try { @@ -284,7 +306,7 @@ export class ArkManager { try { sigs = await cosignWithServer(this.arkUrl, build, { input, outputs, vtxoKeys: keys, serverPubkey: this.serverPub }); } catch (e) { - if (e instanceof GrpcError && /already spent/i.test(e.message)) { + if (e instanceof GrpcError && /already spent|not spendable/i.test(e.message)) { // the input is gone (possibly a prior crashed attempt) — don't retry inputRec.state = 'spent'; action.step = 'failed'; |
