Improve LN retry handling and logs

This commit is contained in:
Reckless_Satoshi 2023-03-16 11:11:39 -07:00
parent 8ce26ce213
commit f5853c6e7b
No known key found for this signature in database
GPG Key ID: 9C4585B561315571
2 changed files with 23 additions and 4 deletions

View File

@ -178,7 +178,10 @@ class Command(BaseCommand):
self.stdout.write(f"Ln payment {str(lnpayment)} has no parent order!") self.stdout.write(f"Ln payment {str(lnpayment)} has no parent order!")
return return
order = lnpayment.order_paid_LN order = lnpayment.order_paid_LN
if order.trade_escrow.status == LNPayment.Status.SETLED: if (
order.trade_escrow.status == LNPayment.Status.SETLED
and order.is_swap is False
):
follow_send_payment.delay(lnpayment.payment_hash) follow_send_payment.delay(lnpayment.payment_hash)
def send_onchain_payments(self): def send_onchain_payments(self):
@ -199,6 +202,7 @@ class Command(BaseCommand):
if ( if (
order.trade_escrow.status == LNPayment.Status.SETLED order.trade_escrow.status == LNPayment.Status.SETLED
and order.trade_escrow.num_satoshis >= onchainpayment.num_satoshis and order.trade_escrow.num_satoshis >= onchainpayment.num_satoshis
and order.is_swap is True
): ):
# Sends out onchainpayment # Sends out onchainpayment
LNNode.pay_onchain( LNNode.pay_onchain(

View File

@ -148,7 +148,7 @@ def follow_send_payment(hash):
} }
if response.status == 2: # Status 2 'SUCCEEDED' if response.status == 2: # Status 2 'SUCCEEDED'
print(f"SUCCEEDED. Order: {order.id}. Hash: {hash}") print(f"Order: {order.id} SUCCEEDED. Hash: {hash}")
lnpayment.status = LNPayment.Status.SUCCED lnpayment.status = LNPayment.Status.SUCCED
lnpayment.fee = float(response.fee_msat) / 1000 lnpayment.fee = float(response.fee_msat) / 1000
lnpayment.preimage = response.payment_preimage lnpayment.preimage = response.payment_preimage
@ -184,8 +184,8 @@ def follow_send_payment(hash):
results = {"succeded": False, "context": "The payout invoice has expired"} results = {"succeded": False, "context": "The payout invoice has expired"}
return results return results
if "payment is in transition" in str(e): elif "payment is in transition" in str(e):
print(f"Order: {order.id}. ALREADY IN TRANSITION. Hash: {hash}.") print(f"Order: {order.id} ALREADY IN TRANSITION. Hash: {hash}.")
request = LNNode.routerrpc.TrackPaymentRequest( request = LNNode.routerrpc.TrackPaymentRequest(
payment_hash=bytes.fromhex(hash) payment_hash=bytes.fromhex(hash)
@ -196,6 +196,21 @@ def follow_send_payment(hash):
): ):
handle_response(response) handle_response(response)
elif "invoice is already paid" in str(e):
print(f"Order: {order.id} ALREADY PAID. Hash: {hash}.")
request = LNNode.routerrpc.TrackPaymentRequest(
payment_hash=bytes.fromhex(hash)
)
for response in LNNode.routerstub.TrackPaymentV2(
request, metadata=[("macaroon", MACAROON.hex())]
):
handle_response(response)
else:
print(str(e))
@shared_task(name="payments_cleansing") @shared_task(name="payments_cleansing")
def payments_cleansing(): def payments_cleansing():