-
Notifications
You must be signed in to change notification settings - Fork 88
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(backend): improve ilp connector logs #2680
Changes from 4 commits
69944cc
ec6b3b9
8f68b1a
04c31e3
9ccf935
0b7a5d2
9843d05
65976bd
1e0cd23
2b84f94
5ab763c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,9 +29,11 @@ export function createAccountMiddleware(serverAddress: string): ILPMiddleware { | |
) | ||
} catch (err) { | ||
// Don't complain if liquidity account already exists. | ||
if (err instanceof AccountAlreadyExistsError) { | ||
// Do nothing. | ||
} else { | ||
if (!(err instanceof AccountAlreadyExistsError)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can't comment on the exact line where this could be added, but in the spirit of the directive in #2489 for "more is more", might it be useful for a debug or trace-level log when liquidity accounts are successfully created There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good idea, added: 5ab763c |
||
ctx.services.logger.error( | ||
{ account, accountType, err }, | ||
'Failed to create liquidity account' | ||
) | ||
throw err | ||
} | ||
} | ||
|
@@ -56,7 +58,15 @@ export function createAccountMiddleware(serverAddress: string): ILPMiddleware { | |
IncomingPaymentState.Expired | ||
].includes(incomingPayment.state) | ||
) { | ||
throw new Errors.UnreachableError('destination account is disabled') | ||
const errorMessage = 'destination account is disabled' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe "destination account is in an incorrect state" makes more sense? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ya thats better, updated |
||
ctx.services.logger.error( | ||
{ | ||
incomingPayment, | ||
streamDestination: ctx.state.streamDestination | ||
}, | ||
errorMessage | ||
) | ||
throw new Errors.UnreachableError(errorMessage) | ||
} | ||
|
||
// Create the tigerbeetle account if not exists. | ||
|
@@ -67,6 +77,7 @@ export function createAccountMiddleware(serverAddress: string): ILPMiddleware { | |
LiquidityAccountType.INCOMING | ||
) | ||
} | ||
ctx.services.logger.trace('got account from incoming payment') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe "destination account is incoming payment"? maybe we can also log the id of the account? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm interpreting "id of the account" to mean I updated this and similar to log this message and the underlying account id (in this case incoming payment). |
||
return incomingPayment | ||
} | ||
// Open Payments SPSP fallback account | ||
|
@@ -80,12 +91,14 @@ export function createAccountMiddleware(serverAddress: string): ILPMiddleware { | |
LiquidityAccountType.WEB_MONETIZATION | ||
) | ||
} | ||
ctx.services.logger.trace('got account from wallet address') | ||
return walletAddress | ||
} | ||
} | ||
const address = ctx.request.prepare.destination | ||
const peer = await peers.getByDestinationAddress(address) | ||
if (peer) { | ||
ctx.services.logger.trace('got account from peer') | ||
return peer | ||
} | ||
if ( | ||
|
@@ -106,7 +119,15 @@ export function createAccountMiddleware(serverAddress: string): ILPMiddleware { | |
|
||
const outgoingAccount = await getAccountByDestinationAddress() | ||
if (!outgoingAccount) { | ||
throw new Errors.UnreachableError('unknown destination account') | ||
const errorMessage = 'unknown destination account' | ||
ctx.services.logger.error( | ||
{ | ||
streamDestination: ctx.state.streamDestination, | ||
destinationAddress: ctx.request.prepare.destination | ||
}, | ||
errorMessage | ||
) | ||
throw new Errors.UnreachableError(errorMessage) | ||
} | ||
ctx.accounts = { | ||
get incoming(): IncomingAccount { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe we can have a log if we fail to get the incomingAccount as well (on L44) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah that makes sense, missed that |
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import { Errors } from 'ilp-packet' | ||
import { ILPContext, ILPMiddleware } from '../rafiki' | ||
import { ILPContext, ILPMiddleware, TransferOptions } from '../rafiki' | ||
BlairCurrey marked this conversation as resolved.
Show resolved
Hide resolved
|
||
import { | ||
isTransferError, | ||
TransferError | ||
|
@@ -35,6 +35,15 @@ export function createBalanceMiddleware(): ILPMiddleware { | |
}) | ||
if (typeof destinationAmountOrError !== 'bigint') { | ||
// ConvertError | ||
services.logger.error( | ||
{ | ||
amount, | ||
destinationAmountOrError, | ||
sourceAsset: accounts.incoming.asset, | ||
destinationAsset: accounts.outgoing.asset | ||
}, | ||
'Could not get rates' | ||
) | ||
throw new CannotReceiveError( | ||
`Exchange rate error: ${destinationAmountOrError}` | ||
) | ||
|
@@ -51,20 +60,35 @@ export function createBalanceMiddleware(): ILPMiddleware { | |
const createPendingTransfer = async (): Promise< | ||
Transaction | undefined | ||
> => { | ||
const trxOrError = await services.accounting.createTransfer({ | ||
const transferOptions = { | ||
sourceAccount: accounts.incoming, | ||
destinationAccount: accounts.outgoing, | ||
sourceAmount, | ||
destinationAmount: destinationAmountOrError, | ||
timeout: 5 | ||
}) | ||
} | ||
const trxOrError = | ||
await services.accounting.createTransfer(transferOptions) | ||
|
||
if (isTransferError(trxOrError)) { | ||
const safeLogTransferError = (transferOptions: TransferOptions) => { | ||
if (transferOptions.destinationAccount?.http?.outgoing.authToken) { | ||
// @ts-expect-error - "The operand of a 'delete' operator must be optional" | ||
delete transferOptions.destinationAccount.http.outgoing.authToken | ||
} | ||
services.logger.error( | ||
{ transferOptions }, | ||
'Could not create transfer' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should we also log the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you want, you can also use redaction in pino on a global level (to avoid needing to delete keys and such) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will try to use that instead - looks handy. I found this surprisingly cumbersome. Although I dont love the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. updated to log the |
||
) | ||
} | ||
|
||
switch (trxOrError) { | ||
case TransferError.InsufficientBalance: | ||
case TransferError.InsufficientLiquidity: | ||
safeLogTransferError(transferOptions) | ||
throw new InsufficientLiquidityError(trxOrError) | ||
default: | ||
safeLogTransferError(transferOptions) | ||
// TODO: map transfer errors to ILP errors | ||
ctxThrow(500, destinationAmountOrError.toString()) | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,7 +23,7 @@ export function createIncomingErrorHandlerMiddleware( | |
if (!err || typeof err !== 'object') { | ||
err = new Error('Non-object thrown: ' + e) | ||
} | ||
ctx.services.logger.debug({ err }, 'Error thrown in incoming pipeline') | ||
ctx.services.logger.info({ err }, 'Error thrown in incoming pipeline') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I figured we don't want to limit the error logs to development so I changed to info (which matches what we do in the open payments server error handler as well.) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe we should have an error log in the unexpected internal error case down below? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. there is one but it looks like its basically null if its not an |
||
if (ctx.revertTotalReceived) { | ||
await ctx.revertTotalReceived() | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,7 +22,7 @@ export function createIldcpMiddleware(serverAddress: string): ILPMiddleware { | |
|
||
const clientAddress = incoming.staticIlpAddress | ||
if (!clientAddress) { | ||
logger.warn( | ||
logger.error( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For logging where there are errors, I generally made them error level like this. There were a few exceptions like the rate limiting errors. Those are currently warnings and I left them alone - warning felt appropriate there. |
||
{ | ||
peerId: incoming.id | ||
}, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,7 @@ export function createIncomingMaxPacketAmountMiddleware(): ILPMiddleware { | |
if (maxPacketAmount) { | ||
const amount = request.prepare.intAmount | ||
if (amount > maxPacketAmount) { | ||
logger.warn( | ||
logger.error( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was back and forth on this one, but I think error is correct here, since it would probably require actioning to update the configuration for the peer |
||
{ maxPacketAmount: maxPacketAmount.toString(), request }, | ||
'rejected a packet due to amount exceeding maxPacketAmount' | ||
) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,7 +24,7 @@ function getDestinationExpiry( | |
const sourceExpiryTime = request.expiresAt.getTime() | ||
|
||
if (sourceExpiryTime < Date.now()) { | ||
log.trace('incoming packet has already expired', { request }) | ||
log.debug({ request }, 'incoming packet has already expired') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. pino doesnt complain, but |
||
throw new InsufficientTimeoutError( | ||
'source transfer has already expired.' + | ||
' sourceExpiry=' + | ||
|
@@ -42,9 +42,15 @@ function getDestinationExpiry( | |
) | ||
|
||
if (destinationExpiryTime < Date.now() + minExpirationWindow) { | ||
log.trace('incoming packet expires too soon to complete payment', { | ||
request | ||
}) | ||
log.debug( | ||
{ | ||
expectedDestinationExpiryTime, | ||
maxHoldTime, | ||
request, | ||
minExpirationWindow | ||
}, | ||
'incoming packet expires too soon to complete payment' | ||
) | ||
throw new InsufficientTimeoutError( | ||
'source transfer expires too soon to complete payment.' + | ||
' actualSourceExpiry=' + | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no error actually being throw here, so I changed the wording