aboutsummaryrefslogtreecommitdiffstats
path: root/src/ark/manager.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/ark/manager.js')
-rw-r--r--src/ark/manager.js30
1 files changed, 22 insertions, 8 deletions
diff --git a/src/ark/manager.js b/src/ark/manager.js
index 24a2478..8be9d58 100644
--- a/src/ark/manager.js
+++ b/src/ark/manager.js
@@ -41,7 +41,7 @@ import {
} from './board.js';
import {
submitRoundParticipation, roundParticipationStatus, parseTx,
- cosignHarkLeaf, requestForfeitNonces, forfeitBundle, forfeitVtxos,
+ cosignHarkLeaf, requestForfeitNonces, forfeitBundle, forfeitVtxos, checkRoundOutputs,
encodeVtxoFromDecoded,
} from './refresh.js';
import {
@@ -577,6 +577,8 @@ export class ArkManager {
// chain gets there in four days), so such a coin is money only a refresh
// can free — and it refreshes without the base fee at `deepWaiverDepth`.
exitDepth(v) { try { return this._decoded(v).genesis.length; } catch { return 0; } }
+ // a server before 0.9.0 wants the old dust split (see isolateDust)
+ _legacyDust() { return !(this.info && this.info.maxRoundParticipationOutputs); }
_capDepth() { return (this.info && this.info.maxVtxoExitDepth) || 0; }
_waiverDepth() { return (this.info && this.info.refreshFees && this.info.refreshFees.deepWaiverDepth) || 0; }
_capped(v) { const cap = this._capDepth(); return !!cap && this.exitDepth(v) >= cap; }
@@ -1379,7 +1381,7 @@ export class ArkManager {
const decoded = inputRecs.map((r) => this._decoded(r));
const keysList = inputRecs.map((r) => this._keyForVtxo(r));
await registerVtxoTransactions(this.arkUrl, decoded.map((d) => d._raw.bytes));
- const builds = parts.map((p, i) => buildArkoorSend({
+ const builds = parts.map((p, i) => buildArkoorSend({ legacyDust: this._legacyDust(),
input: decoded[i],
outputs: [
{ amountSat: p.destSat, userPubkey: hex.decode(action.destPubkey) },
@@ -1708,7 +1710,7 @@ export class ArkManager {
const htlcKey = this._key(action.htlcKeyIndex);
// every part locks its own HTLC vtxo under the SAME payment hash and
// key — the server sums them into one payment (htlc_vtxo_sum)
- const builds = parts.map((p, i) => buildArkoorSend({
+ const builds = parts.map((p, i) => buildArkoorSend({ legacyDust: this._legacyDust(),
input: decoded[i],
outputs: [
{
@@ -1908,7 +1910,7 @@ export class ArkManager {
const revKey = this._key(action.revKeyIndex);
const inputs = (action.htlcBytesList || [action.htlcBytes])
.map((b) => decodeVtxo(hex.decode(b)));
- const builds = inputs.map((input) => buildArkoorSend({
+ const builds = inputs.map((input) => buildArkoorSend({ legacyDust: this._legacyDust(),
input,
outputs: [{ amountSat: input.amountSat, userPubkey: revKey.pubkey }],
serverPubkey: this.serverPub, vtxoKeys: keys,
@@ -2170,7 +2172,7 @@ export class ArkManager {
return;
}
}
- const builds = decoded.map((input) => buildArkoorSend({
+ const builds = decoded.map((input) => buildArkoorSend({ legacyDust: this._legacyDust(),
input,
outputs: [{ amountSat: input.amountSat, userPubkey: keys.pubkey }],
serverPubkey: this.serverPub, vtxoKeys: keys,
@@ -2240,7 +2242,7 @@ export class ArkManager {
if (changeSat > 0) outputs.push({ amountSat: changeSat, userPubkey: this._key(refundIndex).pubkey });
await registerVtxoTransactions(this.arkUrl, [decoded._raw.bytes]);
- const build = buildArkoorSend({ input: decoded, outputs, serverPubkey: this.serverPub, vtxoKeys: keys });
+ const build = buildArkoorSend({ legacyDust: this._legacyDust(), input: decoded, outputs, serverPubkey: this.serverPub, vtxoKeys: keys });
const sigs = await cosignWithServer(this.arkUrl, build, {
input: decoded, vtxoKeys: keys, serverPubkey: this.serverPub,
});
@@ -2281,7 +2283,7 @@ export class ArkManager {
? (typeof destPubkey === 'string' ? hex.decode(destPubkey) : destPubkey)
: this._key(outIndex).pubkey;
await registerVtxoTransactions(this.arkUrl, [input._raw.bytes]).catch(() => {});
- const build = buildArkoorSend({
+ const build = buildArkoorSend({ legacyDust: this._legacyDust(),
input, outputs: [{ amountSat: input.amountSat, userPubkey: outPub }],
serverPubkey: this.serverPub, vtxoKeys: keys,
});
@@ -2313,7 +2315,7 @@ export class ArkManager {
const keys = this._key(claimKeyIndex);
if (input.policy.claimPubkey !== hex.encode(keys.pubkey)) throw new Error('htlc not held by this key');
await registerVtxoTransactions(this.arkUrl, [input._raw.bytes]).catch(() => {});
- const build = buildArkoorSend({
+ const build = buildArkoorSend({ legacyDust: this._legacyDust(),
input,
outputs: [{ amountSat: input.amountSat, userPubkey: hex.decode(input.policy.refundPubkey) }],
serverPubkey: this.serverPub, vtxoKeys: keys,
@@ -2689,6 +2691,18 @@ export class ArkManager {
const fundingTx = parseTx(hex.decode(action.fundingTxHex));
const unlockHash = hex.decode(action.unlockHash);
const newVtxos = action.outputVtxos.map((b) => decodeVtxo(hex.decode(b)));
+ // nothing is signed for coins we couldn't unlock (bark !2803): the
+ // action stays 'issued' with the reason, and no forfeit goes out
+ try {
+ checkRoundOutputs(newVtxos, {
+ unlockHash: action.unlockHash, fundingTxid: fundingTx.txid,
+ ownerPubkey: outKeys.pubkey ? hex.encode(outKeys.pubkey) : null, minTotalSat: action.outAmountSat || 0,
+ });
+ } catch (e) {
+ if (action.lastError !== e.message) { action.lastError = e.message; this._save(); }
+ console.warn('ark: refusing to forfeit for this round —', e.message);
+ return;
+ }
// leaf cosign + forfeit are both idempotent server-side
const leafSigs = [];
for (const v of newVtxos) {