aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ark/manager.js11
-rw-r--r--src/features/ark.js12
2 files changed, 21 insertions, 2 deletions
diff --git a/src/ark/manager.js b/src/ark/manager.js
index 9731dd6..a190480 100644
--- a/src/ark/manager.js
+++ b/src/ark/manager.js
@@ -187,7 +187,16 @@ export class ArkManager {
});
return true;
}
- _decoded(v) { return decodeVtxo(hex.decode(v.bytes)); }
+ _decoded(v) {
+ // vtxo bytes are immutable per id — parse once. The depth advisory and
+ // fee estimates decode every coin on every render without this.
+ const hit = this._decodeCache && this._decodeCache.get(v.id);
+ if (hit) return hit;
+ const d = decodeVtxo(hex.decode(v.bytes));
+ (this._decodeCache ||= new Map()).set(v.id, d);
+ if (this._decodeCache.size > 200) this._decodeCache.delete(this._decodeCache.keys().next().value);
+ return d;
+ }
// ---- chain adapter (esplora REST, same API the wallet already speaks) ----
//
diff --git a/src/features/ark.js b/src/features/ark.js
index 72624b4..140eeb0 100644
--- a/src/features/ark.js
+++ b/src/features/ark.js
@@ -1929,16 +1929,26 @@ export function arkFeature(ctx) {
// What a unilateral exit will need from Savings, BEFORE it starts: every
// chain hop is a zero-fee tx bumped by a ~130 vB CPFP child, plus the
// final claim. Priced at today's feerate — the driver reprices per hop.
+ // Memoized on the coin set + feerate: signedExitTxs rebuilds every hop of
+ // every coin's exit chain with an elliptic-curve tweak per hop — profiled
+ // at ~200ms of secp256k1 per call on a phone with depth-13 coins — and
+ // the depth advisory asked for it on EVERY wallet render. Same coins at
+ // the same feerate price the same, so pay once per change instead.
+ let _exitFeeMemo = { key: null, val: 0 };
function estimateExitFeeSat(mgr) {
const feeRate = Math.max(1, (wallet.feeRates && wallet.feeRates.halfHourFee) || 2);
+ const coins = mgr.vtxos().filter((x) => x.state === 'spendable');
+ const key = feeRate + '|' + coins.map((v) => v.id).join(',');
+ if (_exitFeeMemo.key === key) return _exitFeeMemo.val;
let total = 0;
- for (const v of mgr.vtxos().filter((x) => x.state === 'spendable')) {
+ for (const v of coins) {
try {
for (const txi of signedExitTxs(mgr._decoded(v), mgr.serverPub))
total += Math.ceil((txi.vsize + 130) * feeRate);
total += Math.ceil(150 * feeRate); // the claim tx
} catch {}
}
+ _exitFeeMemo = { key, val: total };
return total;
}