aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2026-12-04 13:33:15 -0700
committerAdam Soltys <[email protected]>2026-12-06 00:01:59 -0700
commitf15e3b23c94fb36886e5201984d27a2509428cc9 (patch)
tree66c042e5ec85fff102250102b7002d129a6b4a51 /src
parent50ca83a0f21fb8090ba39481cf3d331c331d26ba (diff)
downloadcoinosv3-f15e3b23c94fb36886e5201984d27a2509428cc9.tar.gz
coinosv3-f15e3b23c94fb36886e5201984d27a2509428cc9.zip
ark migrate: batches are the manager's own next coins, so no send goes over the input cap.HEADmaster
The first real sweep (names' old forwarder, 126 coins, many past expiry) failed: a batch of the 48 largest coins was assembled by send() from live coins first, far more than 48. Each batch is now the set _accumulate picks (live coins first, largest first) capped at 48, and its exact total is sent. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01VMan6WoqaQDYdpWkatPCar
Diffstat (limited to 'src')
-rw-r--r--src/ark/migrate.js25
1 files changed, 15 insertions, 10 deletions
diff --git a/src/ark/migrate.js b/src/ark/migrate.js
index 694b692..a05e60d 100644
--- a/src/ark/migrate.js
+++ b/src/ark/migrate.js
@@ -12,13 +12,19 @@
export const MAX_BATCH_INPUTS = 48; // manager.js MAX_SEND_INPUTS
-// Spendable coins the old server will still cosign, largest first.
-// (A coin at the server's exit-depth cap can't be an input; the server refuses
-// to cosign it. Those stay behind and only a unilateral exit can move them.)
-function movableCoins(oldMgr) {
- return oldMgr.vtxos()
- .filter((v) => v.state === 'spendable' && !v.expiryRejected && !oldMgr._capped(v))
- .sort((a, b) => b.amountSat - a.amountSat);
+// The next batch: the coins the manager's own selection would take first,
+// at most maxInputs of them. Sending exactly their total makes send() pick
+// those same coins (it accumulates in the same order: coins still inside
+// their timelock first, largest first), so no batch goes over the input cap.
+// A coin at the server's exit-depth cap is never an input; those stay behind
+// and only a unilateral exit can move them.
+function nextBatch(mgr, maxInputs) {
+ const tip = mgr._tipH || 0;
+ const busy = mgr._remoteBusy();
+ const spendable = mgr.state.vtxos.filter((v) => mgr._free(v, busy) && !mgr._expired(v, tip) && !mgr._capped(v));
+ if (!spendable.length) return null;
+ const n = Math.min(maxInputs, spendable.length);
+ return mgr._accumulate(spendable, tip, (set) => set.length >= n);
}
// Ask the migrator for a deposit address that pays `dest` on the new server.
@@ -44,9 +50,8 @@ export async function migrateWallet(oldMgr, { migratorUrl, dest, fetchFn = fetch
const session = await startMigration(migratorUrl, dest, fetchFn);
let sentSat = 0;
for (let round = 0; round < 50; round++) {
- const coins = movableCoins(oldMgr);
- if (!coins.length) break;
- const batch = coins.slice(0, maxInputs);
+ const batch = nextBatch(oldMgr, maxInputs);
+ if (!batch?.length) break;
const amount = batch.reduce((t, v) => t + v.amountSat, 0);
try {
await oldMgr.send(session.depositAddress, amount);