Add per-mint tracing logs to handleWalletPayInvoice for lightning zap diagnostics
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"VERSION": "v0.7.66",
|
||||
"VERSION_NUMBER": "0.7.66",
|
||||
"BUILD_DATE": "2026-06-30T11:47:22.403Z"
|
||||
"VERSION": "v0.7.67",
|
||||
"VERSION_NUMBER": "0.7.67",
|
||||
"BUILD_DATE": "2026-06-30T11:59:52.299Z"
|
||||
}
|
||||
|
||||
@@ -4568,6 +4568,16 @@ async function handleWalletCreateDeposit(requestId, amount, mint, port) {
|
||||
}
|
||||
|
||||
async function handleWalletPayInvoice(requestId, invoice, mint, port) {
|
||||
const startedAt = Date.now();
|
||||
const traceId = `walletPayInvoice:${requestId}`;
|
||||
const log = (phase, extra = null) => {
|
||||
if (extra === null) {
|
||||
console.log(`[Worker] ${traceId} +${Date.now() - startedAt}ms ${phase}`);
|
||||
} else {
|
||||
console.log(`[Worker] ${traceId} +${Date.now() - startedAt}ms ${phase}`, extra);
|
||||
}
|
||||
};
|
||||
|
||||
try {
|
||||
await ensureDirectWalletLoaded();
|
||||
|
||||
@@ -4580,6 +4590,11 @@ async function handleWalletPayInvoice(requestId, invoice, mint, port) {
|
||||
? [requestedMint, ...knownMints.filter((m) => m !== requestedMint)]
|
||||
: [...knownMints].sort((a, b) => getProofTotal(directProofStore[b]) - getProofTotal(directProofStore[a]));
|
||||
|
||||
log('mint-selection', {
|
||||
requestedMint: requestedMint || null,
|
||||
orderedMints: orderedMints.map((m) => ({ mint: m, proofBalance: getProofTotal(directProofStore[m]) }))
|
||||
});
|
||||
|
||||
let payResult = null;
|
||||
let usedMint = null;
|
||||
let paidAmountSats = 0;
|
||||
@@ -4588,7 +4603,11 @@ async function handleWalletPayInvoice(requestId, invoice, mint, port) {
|
||||
for (const mintUrl of orderedMints) {
|
||||
try {
|
||||
const proofs = Array.isArray(directProofStore[mintUrl]) ? directProofStore[mintUrl] : [];
|
||||
const proofBalance = getProofTotal(proofs);
|
||||
log('mint attempt:start', { mintUrl, proofBalance, proofCount: proofs.length });
|
||||
|
||||
if (proofs.length === 0) {
|
||||
log('mint attempt:no-proofs', { mintUrl });
|
||||
attemptErrors.push({ mint: mintUrl, message: 'No proofs available for mint' });
|
||||
continue;
|
||||
}
|
||||
@@ -4598,13 +4617,16 @@ async function handleWalletPayInvoice(requestId, invoice, mint, port) {
|
||||
const quoteAmount = Number(meltQuote?.amount || 0);
|
||||
const quoteFeeReserve = Number(meltQuote?.fee_reserve || 0);
|
||||
const required = quoteAmount + quoteFeeReserve;
|
||||
log('mint attempt:quote', { mintUrl, quoteAmount, quoteFeeReserve, required });
|
||||
|
||||
if (!Number.isFinite(required) || required <= 0) {
|
||||
log('mint attempt:invalid-quote', { mintUrl, required });
|
||||
attemptErrors.push({ mint: mintUrl, message: 'Invalid melt quote amount' });
|
||||
continue;
|
||||
}
|
||||
|
||||
const proofBalance = getProofTotal(proofs);
|
||||
if (proofBalance < required) {
|
||||
log('mint attempt:insufficient', { mintUrl, proofBalance, required });
|
||||
attemptErrors.push({ mint: mintUrl, message: `Insufficient funds on mint (${proofBalance} sats)` });
|
||||
continue;
|
||||
}
|
||||
@@ -4612,6 +4634,8 @@ async function handleWalletPayInvoice(requestId, invoice, mint, port) {
|
||||
const sendResult = await wallet.send(required, proofs);
|
||||
const keep = Array.isArray(sendResult?.keep) ? sendResult.keep : [];
|
||||
const sendProofs = Array.isArray(sendResult?.send) ? sendResult.send : [];
|
||||
log('mint attempt:send-split', { mintUrl, keepCount: keep.length, sendCount: sendProofs.length });
|
||||
|
||||
const meltResult = await wallet.meltProofs(meltQuote, sendProofs);
|
||||
const change = Array.isArray(meltResult?.change) ? meltResult.change : [];
|
||||
upsertMintProofs(mintUrl, [...keep, ...change]);
|
||||
@@ -4622,19 +4646,25 @@ async function handleWalletPayInvoice(requestId, invoice, mint, port) {
|
||||
? quoteAmount
|
||||
: spentAmount;
|
||||
|
||||
log('mint attempt:success', { mintUrl, paidAmountSats, changeAmount, preimage: meltResult?.preimage || null });
|
||||
|
||||
usedMint = mintUrl;
|
||||
payResult = meltResult;
|
||||
break;
|
||||
} catch (error) {
|
||||
log('mint attempt:error', { mintUrl, message: error?.message || String(error) });
|
||||
attemptErrors.push({ mint: mintUrl, message: error?.message || String(error) });
|
||||
}
|
||||
}
|
||||
|
||||
if (!payResult || !usedMint) {
|
||||
const detail = attemptErrors.map((entry) => `${entry.mint || 'unknown'}: ${entry.message}`).join(' | ');
|
||||
log('all-mints-failed', { attemptErrors });
|
||||
throw new Error(`Failed to pay invoice. ${detail || 'No mint could complete melt'}`);
|
||||
}
|
||||
|
||||
log('paid', { usedMint, paidAmountSats, preimage: payResult?.preimage || null });
|
||||
|
||||
const tx = appendDirectTransaction({
|
||||
type: 'pay',
|
||||
amount: Number.isFinite(paidAmountSats) && paidAmountSats > 0
|
||||
@@ -4680,6 +4710,7 @@ async function handleWalletPayInvoice(requestId, invoice, mint, port) {
|
||||
}
|
||||
})();
|
||||
} catch (error) {
|
||||
log('error', { message: error?.message || String(error), stack: error?.stack || null });
|
||||
port.postMessage({ type: 'response', requestId, error: error.message });
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user