diff options
| author | Adam Soltys <[email protected]> | 2026-11-25 08:33:00 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2026-11-25 08:33:00 -0700 |
| commit | b23b02bdaae233f51b543bc60fa38a025e07a743 (patch) | |
| tree | 10e20e92b97d4942663007b6365e995b3f856d42 /tools/ark/dust-shapes-test.js | |
| parent | 2cd42f811d33a74c3ca28094176c009c0388da9b (diff) | |
| download | coinosv3-master.tar.gz coinosv3-master.zip | |
Ark sends follow server-0.9.0's dust rule, and a renewal checks its new coins before forfeiting for them. "yes go ahead" (Adam, 2026-11-25, on fixing the send code and the refresh check before rehearsing captaind 0.9.0).HEADmaster
Dust: 0.9.0 (!2822) refuses a cosign whose checkpoint carries an output under 330 sat unless the input itself is dust. Our split, a port of bark ≤0.8's new_isolate_dust, "accepted the mix" in two cases 0.9.0 now isolates: every output dust (100 sent from a 400-sat coin, 300 change), and dust no output can pad (100 from 500, the 400 change isolated whole). isolateDust now matches 0.9.0 case for case (upstream's eight isolate_dust tests ported). 0.8.0 refuses exactly those two new shapes instead ("At least one output is required"), so the split follows the server it talks to: a server advertising ArkInfo field 23 (max_round_participation_outputs, new in 0.9.0 and never 0 there) gets the new rule, any other the old one. Every arkoor build (sends, Lightning HTLC sends, refunds, sweeps, claims) passes it through.
Renewals: bark !2803 (reported by MrHodl) — bark didn't check that the unlock hash of its forfeits matched the one locking its new round coins; neither did we. A round's coins are now checked before the leaf cosign and the forfeit: a hash-locked round leaf locked by our unlock hash, anchored in this round's funding transaction, paid to our output key, worth at least what we asked for. On any mismatch nothing is signed, and the action keeps the reason.
Regtest: new dust-shapes-test sends all four shapes (all dust, isolate whole, pad, dust input) from single-coin wallets, delivers them and spends the change onward — passes on captaind 0.8.0 and on 0.9.0 (master's code fails the two new shapes on 0.9.0). manager, dust-gift, refresh-reprice, rescue-claimed, expired-dust, send-failure, custody, offboard-split and board tests pass on 0.9.0; ln-test and ln-e2e (25-sat zap-size sends, receives) pass on 0.9.0 with CLN v26.06.9; manager and dust-gift pass on 0.8.0. send, refresh, receive, scheduled-refresh and ln-pending-history fail the same way on master (stale fixtures). New isolate-dust-test (upstream vectors, 200k random payments against both servers' ported checks) and round-outputs-check-test pass; rescue-claimed-test stubs the new check (its fake rounds carry no coins). features-smoke and feature-registry-check pass.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01VMan6Upic5L6MMJzkTn8zg
Diffstat (limited to 'tools/ark/dust-shapes-test.js')
| -rw-r--r-- | tools/ark/dust-shapes-test.js | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/tools/ark/dust-shapes-test.js b/tools/ark/dust-shapes-test.js new file mode 100644 index 0000000..d5a9f5f --- /dev/null +++ b/tools/ark/dust-shapes-test.js @@ -0,0 +1,59 @@ +// The arkoor shapes whose dust isolation changed for server-0.9.0 (!2822), +// sent through a real server: each from a wallet holding ONE coin, so the +// split is exactly the one named. +// 400 → 100 (+300 change) every output dust: both isolated +// 500 → 100 (+400 change) the change can't pad the dust: isolated whole +// 1000 → 100 (+900 change) the change pads the dust (unchanged) +// 300 → 100 (+200 change) dust input: nothing isolated (unchanged) +// Each payment arrives, and the change is spent onward (the coin is real). +// Usage: bun tools/ark/dust-shapes-test.js (ARK_URL to point at another captaind) +import { execSync } from 'node:child_process'; +import { generateMnemonic, mnemonicToSeedSync } from '@scure/bip39'; +import { wordlist } from '@scure/bip39/wordlists/english'; +import { HDKey } from '@scure/bip32'; +import { ArkManager } from '../../src/ark/manager.js'; + +const ARK = process.env.ARK_URL || 'http://127.0.0.1:3535'; +const ESPLORA = 'http://127.0.0.1:30002'; +const ALICE = `${process.env.HOME}/bark/target/debug/bark --datadir ${process.env.HOME}/ark-regtest/alice`; +const sleep = (ms) => new Promise((r) => setTimeout(r, ms)); +let ok = true; +const check = (name, cond, detail = '') => { console.log(` ${cond ? '✓' : '✗'} ${name}${detail ? ' — ' + detail : ''}`); if (!cond) ok = false; }; + +const newWallet = async () => { + let raw = null; + const account = HDKey.fromMasterSeed(mnemonicToSeedSync(generateMnemonic(wordlist))).derive("m/86'/0'/9'"); + return new ArkManager({ account, storage: { load: () => (raw ? JSON.parse(raw) : null), save: (s) => { raw = JSON.stringify(s); } }, arkUrl: ARK, esploraUrl: ESPLORA }).init(); +}; +const waitBalance = async (m, want, tries = 15) => { + for (let i = 0; i < tries && m.balance().spendableSat < want; i++) { await m.sync(); await sleep(1500); } + return m.balance().spendableSat; +}; + +const sink = await newWallet(); +let sunk = 0; +// a bank of ours with one big coin pays each wallet: one coin each, always +// (alice's CLI wallet pays from whatever coins it holds, sometimes several) +const bank = await newWallet(); +execSync(`${ALICE} -q send ${bank.address()} "20000 sat"`); +check('bank funded', (await waitBalance(bank, 20000)) >= 20000); +if (bank.state.vtxos.filter((v) => v.state === 'spendable').length > 1) { await bank.refresh(); for (let i = 0; i < 40 && bank.state.vtxos.filter((v) => v.state === 'spendable').length !== 1; i++) { execSync('docker exec bc bitcoin-cli -rpcwallet=coinos -generate 1'); await bank.sync(); await sleep(2000); } } +check('...in one coin', bank.state.vtxos.filter((v) => v.state === 'spendable').length === 1); +for (const [coin, pay, shape] of [[400, 100, 'all dust'], [500, 100, 'change isolated whole'], [1000, 100, 'change pads the dust'], [300, 100, 'dust input']]) { + console.log(`\n[${coin} → ${pay}] ${shape}`); + const w = await newWallet(), to = await newWallet(); + await bank.send(w.address(), coin); + check(`funded with one ${coin}-sat coin`, (await waitBalance(w, coin)) === coin && w.state.vtxos.filter((v) => v.state === 'spendable').length === 1); + let err = null; + try { await w.send(to.address(), pay); } catch (e) { err = e.message; } + check(`${pay} sent, server cosigned`, !err, err || ''); + check(`${pay} arrived`, (await waitBalance(to, pay)) === pay); + const change = coin - pay; + check(`${change} change spendable`, (await waitBalance(w, change)) === change); + let err2 = null; + try { await w.send(sink.address(), change); sunk += change; } catch (e) { err2 = e.message; } + check(`...and spent onward`, !err2, err2 || ''); +} +check('every onward spend arrived', (await waitBalance(sink, sunk)) === sunk, `${sink.balance().spendableSat}/${sunk}`); +console.log(ok ? '\n✅ every dust shape goes through ' + ARK : '\n❌ a dust shape failed on ' + ARK); +process.exit(ok ? 0 : 1); |
