Rework concurrent payments. in_flight true/false

This commit is contained in:
Reckless_Satoshi 2022-04-18 06:57:03 -07:00
parent 2f1f82f1a6
commit f00bafb5d8
No known key found for this signature in database
GPG Key ID: 9C4585B561315571
3 changed files with 13 additions and 7 deletions

View File

@ -139,13 +139,14 @@ class Command(BaseCommand):
queryset = LNPayment.objects.filter(
type=LNPayment.Types.NORM,
status=LNPayment.Status.FLIGHT,
in_flight=False,
routing_attempts=0,
)
queryset_retries = LNPayment.objects.filter(
type=LNPayment.Types.NORM,
status__in=[LNPayment.Status.VALIDI, LNPayment.Status.FAILRO],
routing_attempts__lt=5,
in_flight=False,
last_routing_time__lt=(
timezone.now() - timedelta(minutes=int(config("RETRY_TIME")))),
)
@ -153,9 +154,9 @@ class Command(BaseCommand):
queryset = queryset.union(queryset_retries)
for lnpayment in queryset:
success, _ = follow_send_payment.delay(lnpayment.payment_hash)
success, _ = follow_send_payment(lnpayment.payment_hash)
# If failed, reset mision control. (This won't scale well, just a temporary fix)
# If failed, reset mission control. (This won't scale well, just a temporary fix)
if not success:
LNNode.resetmc()

View File

@ -125,7 +125,7 @@ class LNPayment(models.Model):
last_routing_time = models.DateTimeField(null=True,
default=None,
blank=True)
in_flight = models.BooleanField(default=False, null=False, blank=False)
# involved parties
sender = models.ForeignKey(User,
related_name="sender",

View File

@ -95,11 +95,13 @@ def follow_send_payment(hash):
]):
if response.status == 0: # Status 0 'UNKNOWN'
# Not sure when this status happens
pass
lnpayment.in_flight = False
lnpayment.save()
if response.status == 1: # Status 1 'IN_FLIGHT'
print("IN_FLIGHT")
lnpayment.status = LNPayment.Status.FLIGHT
lnpayment.in_flight = True
lnpayment.save()
order.status = Order.Status.PAY
order.save()
@ -109,6 +111,7 @@ def follow_send_payment(hash):
lnpayment.status = LNPayment.Status.FAILRO
lnpayment.last_routing_time = timezone.now()
lnpayment.routing_attempts += 1
lnpayment.in_flight = False
lnpayment.save()
order.status = Order.Status.FAI
order.expires_at = timezone.now() + timedelta(
@ -116,7 +119,8 @@ def follow_send_payment(hash):
order.save()
context = {
"routing_failed":
LNNode.payment_failure_context[response.failure_reason]
LNNode.payment_failure_context[response.failure_reason],
"IN_FLIGHT":False,
}
print(context)
return False, context
@ -130,13 +134,14 @@ def follow_send_payment(hash):
order.expires_at = timezone.now() + timedelta(
seconds=order.t_to_expire(Order.Status.SUC))
order.save()
return True, None
return True, {"IN_FLIGHT":False}
except Exception as e:
if "invoice expired" in str(e):
print("INVOICE EXPIRED")
lnpayment.status = LNPayment.Status.EXPIRE
lnpayment.last_routing_time = timezone.now()
lnpayment.in_flight = False
lnpayment.save()
order.status = Order.Status.FAI
order.expires_at = timezone.now() + timedelta(