wallet logger fixes (#2296)

* Fix createdAt in logger context

* Remove duplicate WalletLogEntry field resolver

* Include invoice in wallet logger context if invoice owned by user

* Also only include withdrawal in context if withdrawal owned by user
This commit is contained in:
ekzyis 2025-07-18 21:24:29 +02:00 committed by GitHub
parent d4efacadc0
commit ba370eeda6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 8 additions and 24 deletions

View File

@ -5,7 +5,7 @@ import {
import crypto, { timingSafeEqual } from 'crypto'
import { decodeCursor, LIMIT, nextCursorEncoded } from '@/lib/cursor'
import { SELECT, itemQueryWithMeta } from './item'
import { formatMsats, msatsToSats, msatsToSatsDecimal } from '@/lib/format'
import { msatsToSats, msatsToSatsDecimal } from '@/lib/format'
import {
USER_ID, INVOICE_RETENTION_DAYS,
WALLET_RETRY_AFTER_MS,
@ -22,7 +22,6 @@ import { GqlAuthenticationError, GqlAuthorizationError, GqlInputError } from '@/
import { getNodeSockets } from '../lnd'
import performPaidAction from '../paidAction'
import performPayingAction from '../payingAction'
import { logContextFromBolt11 } from '@/wallets/server'
export async function getInvoice (parent, { id }, { me, models, lnd }) {
const inv = await models.invoice.findUnique({
@ -523,25 +522,6 @@ const resolvers = {
return item
},
sats: fact => msatsToSatsDecimal(fact.msats)
},
WalletLogEntry: {
context: async ({ level, context, invoice, withdrawal }, args, { models }) => {
const isError = ['error', 'warn'].includes(level.toLowerCase())
if (withdrawal) {
return {
...await logContextFromBolt11(withdrawal.bolt11),
...(withdrawal.preimage ? { preimage: withdrawal.preimage } : {}),
...(isError ? { max_fee: formatMsats(withdrawal.msatsFeePaying) } : {})
}
}
// XXX never return invoice as context because it might leak sensitive sender details
// if (invoice) { ... }
return context
}
}
}

View File

@ -14,6 +14,7 @@ export function walletLogger ({
// since logs are created asynchronously and thus might get inserted out of order
// however, millisecond precision is not always enough ...
const createdAt = context?.createdAt ?? new Date()
delete context?.createdAt
const updateStatus = ['OK', 'ERROR', 'WARNING'].includes(level) && (invoiceId || withdrawalId || context.bolt11 || context?.updateStatus)
delete context?.updateStatus

View File

@ -16,11 +16,10 @@ const WalletProtocolConfig = {
}
const WalletLogEntry = {
context: async ({ level, context, withdrawal }) => {
context: async ({ level, context, invoice, withdrawal }, args, { me }) => {
const isError = ['error', 'warn'].includes(level.toLowerCase())
// never return invoice as context because it might leak sensitive sender details
if (withdrawal) {
if (withdrawal && me?.id === withdrawal.userId) {
return {
...await logContextFromBolt11(withdrawal.bolt11),
...(withdrawal.preimage ? { preimage: withdrawal.preimage } : {}),
@ -28,6 +27,10 @@ const WalletLogEntry = {
}
}
if (invoice && me?.id === invoice.userId) {
return await logContextFromBolt11(invoice.bolt11)
}
return context
}
}