Skip to content

Commit

Permalink
refactor(core): continue if tx bundle is invalid
Browse files Browse the repository at this point in the history
  • Loading branch information
vindard committed Feb 21, 2024
1 parent 714734d commit 940d7b0
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions core/api/src/services/ledger/facade/update-state.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { Transaction } from "../books"
import { NoTransactionToUpdateStateError, UnknownLedgerError } from "../domain/errors"

import { recordExceptionInCurrentSpan } from "@/services/tracing"

import { LnPaymentStateDeterminator } from "@/domain/ledger/ln-payment-state"

import * as LedgerFacade from "@/services/ledger/facade"
import { ErrorLevel } from "@/domain/shared"

const updateStateByHash = async ({
paymentHash,
Expand All @@ -30,7 +33,7 @@ export const updateLnPaymentState = async ({
}: {
walletIds: WalletId[]
paymentHash: PaymentHash
}): Promise<true | ApplicationError> => {
}): Promise<boolean | ApplicationError> => {
const txns = await LedgerFacade.getTransactionsForWalletsByPaymentHash({
walletIds,
paymentHash,
Expand All @@ -39,7 +42,19 @@ export const updateLnPaymentState = async ({

const lnPaymentState = LnPaymentStateDeterminator(txns).determine()
if (lnPaymentState instanceof Error) {
return lnPaymentState
recordExceptionInCurrentSpan({
error: lnPaymentState,
level: ErrorLevel.Critical,
attributes: {
["error.actionRequired.message"]:
"Check the transaction bundle using the paymentHash and walletIds, " +
"determine the transaction state type, and manually update transactions " +
"with this has to the correct state.",
["error.actionRequired.paymentHash"]: paymentHash,
["error.actionRequired.walletIds"]: JSON.stringify(walletIds),
},
})
return false
}

const markedState = await updateStateByHash({
Expand Down

0 comments on commit 940d7b0

Please sign in to comment.