diff options
| -rw-r--r-- | names/server.js | 64 |
1 files changed, 54 insertions, 10 deletions
diff --git a/names/server.js b/names/server.js index 683702c..a7424f8 100644 --- a/names/server.js +++ b/names/server.js @@ -374,7 +374,23 @@ if (CFG.forwarder?.mnemonic) { // between syncs) lives there, and balance() only counts what state has seen. await fwd.sync().catch(() => {}); log(`forwarder ark wallet ready — float ${fwd.balance().spendableSat} sat, receive ${fwd.address().slice(0, 24)}…`); + // A float send never picks a coin at the server's exit-depth cap. Each + // arkoor hop adds one to a coin's depth and only a round flattens it; at + // the cap the ASP refuses every cosign. The float's wallet code (the + // coinosv3 submodule, from 10-16) predates its own cap check, so the + // smallest coin covering a send — a 13,661-sat change chain at depth 100 — + // was picked for every forward under 13,661 sat and refused, from + // 2026-11-24 00:09Z until this went out ("reports of missing deposits", + // Adam). floatUpkeep refreshes such coins; until that round settles they + // are just left out here. + const select = fwd._selectInputs.bind(fwd), free = fwd._free.bind(fwd); + let selecting = false; + fwd._free = (v, busy) => free(v, busy) && !(selecting && floatCapped(v)); + fwd._selectInputs = (...a) => { selecting = true; try { return select(...a); } finally { selecting = false; } }; } +function floatDepth(v) { try { return fwd._decoded(v).genesis.length; } catch { return 0; } } +const floatDepthCap = () => fwd?.info?.maxVtxoExitDepth || 100; +function floatCapped(v) { return floatDepth(v) >= floatDepthCap(); } // Is this name's wallet on another network than this registrar's node? Then // nothing payable may be minted for it here: a mainnet offer for a mutinynet @@ -963,23 +979,51 @@ async function autoTopupFloat() { // its expiry into a fresh round output. let floatRefreshAt = 0; const REFRESH_MARGIN_BLOCKS = 144; +// A send the server cosigned and registered whose mailbox notice is refused +// for good (status 3, e.g. "invalid a blinded VTXO mailbox identifier") is as +// done as it will ever be: the coins went. forwardOnce closes the ones made +// for a payment; these close the rest (five 1-sat sends from 2026-10-27 sat +// 'registered' for four weeks and held every upkeep and consolidation round). +function closeRefusedSends() { + let n = 0; + for (const a of fwd.state.actions || []) { + if (a.type === 'send' && a.step === 'registered' && /PostArkoorMessage: status 3\b/.test(a.lastError || '')) { + a.step = 'done'; a.undelivered = a.lastError; n++; + } + } + if (n) { fwd._save(); log(`float upkeep: closed ${n} sends whose mailbox notice was refused for good`); } +} + async function floatUpkeep() { - if (!fwd || Date.now() - floatRefreshAt < 30 * 60_000) return; + if (!fwd) return; + closeRefusedSends(); const spendables = (fwd.state?.vtxos || []).filter((v) => v.state === 'spendable'); // never start a round while another action is still in flight if (!spendables.length || (fwd.state.actions || []).some((a) => !['done', 'failed'].includes(a.step))) return; const tip = await fwd.chain.tipHeight(); - // not one already past it: the server's sweeper has taken that coin, and a - // refresh of it never settles — it sat 'submitted' from 2026-09-16 (a large - // coin, swept two blocks after expiry) and blocked every round after it + // not one already past its expiry: the server's sweeper has taken that + // coin, and a refresh of it never settles — it sat 'submitted' from + // 2026-09-16 (a large coin, swept two blocks after expiry) and blocked + // every round after it + const live = (v) => !(v.expiryHeight && v.expiryHeight <= tip); + // coins at or near the depth cap can't be sent (see floatCapped): flatten + // them as soon as they get there, not on the 30-minute expiry cadence. + // Deep dust rides along with a bigger deep coin; alone it can't make a round. + const deep = spendables.filter((v) => live(v) && floatDepth(v) >= floatDepthCap() - 8); + const deepSat = deep.reduce((n, v) => n + v.amountSat, 0); + if (Date.now() - floatRefreshAt < (deepSat >= 330 ? 2 * 60_000 : 30 * 60_000)) return; const expiring = spendables.filter((v) => - v.expiryHeight && v.expiryHeight > tip && v.expiryHeight - tip < REFRESH_MARGIN_BLOCKS && v.amountSat >= 330); - if (!expiring.length) return; + live(v) && v.expiryHeight && v.expiryHeight - tip < REFRESH_MARGIN_BLOCKS && v.amountSat >= 330); + const ids = new Set(expiring.map((v) => v.id)); + if (deepSat >= 330) for (const v of deep) ids.add(v.id); + if (!ids.size) return; floatRefreshAt = Date.now(); - const sat = expiring.reduce((n, v) => n + v.amountSat, 0); - log(`float upkeep: refreshing ${expiring.length} coins (${sat} sat) nearing expiry`); - await fwd.refresh(expiring.map((v) => v.id)); - log(`float upkeep: refresh round complete — float now ${fwd.balance().spendableSat} sat`); + const coins = spendables.filter((v) => ids.has(v.id)); + const sat = coins.reduce((n, v) => n + v.amountSat, 0); + const nDeep = coins.filter((v) => floatDepth(v) >= floatDepthCap() - 8).length; + log(`float upkeep: refreshing ${coins.length} coins (${sat} sat; ${nDeep} at depth ≥ ${floatDepthCap() - 8}, ${expiring.length} nearing expiry)`); + await fwd.refresh([...ids]); + log(`float upkeep: refresh submitted — float now ${fwd.balance().spendableSat} sat`); } // A float fed by many small receives can hold enough sats yet too many coins |
