fix internal payment check (#1604)

This commit is contained in:
calle
2023-04-03 15:15:34 +02:00
committed by GitHub
parent 8ce84ce592
commit 58c3b05e29
2 changed files with 4 additions and 2 deletions

View File

@@ -597,6 +597,7 @@ async def check_internal(
async def check_internal_pending( async def check_internal_pending(
payment_hash: str, conn: Optional[Connection] = None payment_hash: str, conn: Optional[Connection] = None
) -> bool: ) -> bool:
"""Returns False if the internal payment is not pending anymore (and thus paid), otherwise True"""
row = await (conn or db).fetchone( row = await (conn or db).fetchone(
""" """
SELECT pending FROM apipayments SELECT pending FROM apipayments
@@ -605,7 +606,7 @@ async def check_internal_pending(
(payment_hash,), (payment_hash,),
) )
if not row: if not row:
return False return True
else: else:
return row["pending"] return row["pending"]

View File

@@ -154,10 +154,11 @@ async def pay_invoice(
extra=extra, extra=extra,
) )
# we check if an internal invoice exists that has already been paid (not pending anymore)
if not await check_internal_pending(invoice.payment_hash, conn=conn): if not await check_internal_pending(invoice.payment_hash, conn=conn):
raise PaymentFailure("Internal invoice already paid.") raise PaymentFailure("Internal invoice already paid.")
# check_internal() returns the checking_id of the invoice we're waiting for # check_internal() returns the checking_id of the invoice we're waiting for (pending only)
internal_checking_id = await check_internal(invoice.payment_hash, conn=conn) internal_checking_id = await check_internal(invoice.payment_hash, conn=conn)
if internal_checking_id: if internal_checking_id:
logger.debug(f"creating temporary internal payment with id {internal_id}") logger.debug(f"creating temporary internal payment with id {internal_id}")