mirror of
https://github.com/RoboSats/robosats.git
synced 2025-07-18 16:53:16 +00:00
Rework concurrent payments. in_flight true/false
This commit is contained in:
@ -139,13 +139,14 @@ class Command(BaseCommand):
|
|||||||
queryset = LNPayment.objects.filter(
|
queryset = LNPayment.objects.filter(
|
||||||
type=LNPayment.Types.NORM,
|
type=LNPayment.Types.NORM,
|
||||||
status=LNPayment.Status.FLIGHT,
|
status=LNPayment.Status.FLIGHT,
|
||||||
|
in_flight=False,
|
||||||
routing_attempts=0,
|
routing_attempts=0,
|
||||||
)
|
)
|
||||||
|
|
||||||
queryset_retries = LNPayment.objects.filter(
|
queryset_retries = LNPayment.objects.filter(
|
||||||
type=LNPayment.Types.NORM,
|
type=LNPayment.Types.NORM,
|
||||||
status__in=[LNPayment.Status.VALIDI, LNPayment.Status.FAILRO],
|
status__in=[LNPayment.Status.VALIDI, LNPayment.Status.FAILRO],
|
||||||
routing_attempts__lt=5,
|
in_flight=False,
|
||||||
last_routing_time__lt=(
|
last_routing_time__lt=(
|
||||||
timezone.now() - timedelta(minutes=int(config("RETRY_TIME")))),
|
timezone.now() - timedelta(minutes=int(config("RETRY_TIME")))),
|
||||||
)
|
)
|
||||||
@ -153,9 +154,9 @@ class Command(BaseCommand):
|
|||||||
queryset = queryset.union(queryset_retries)
|
queryset = queryset.union(queryset_retries)
|
||||||
|
|
||||||
for lnpayment in queryset:
|
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:
|
if not success:
|
||||||
LNNode.resetmc()
|
LNNode.resetmc()
|
||||||
|
|
||||||
|
@ -125,7 +125,7 @@ class LNPayment(models.Model):
|
|||||||
last_routing_time = models.DateTimeField(null=True,
|
last_routing_time = models.DateTimeField(null=True,
|
||||||
default=None,
|
default=None,
|
||||||
blank=True)
|
blank=True)
|
||||||
|
in_flight = models.BooleanField(default=False, null=False, blank=False)
|
||||||
# involved parties
|
# involved parties
|
||||||
sender = models.ForeignKey(User,
|
sender = models.ForeignKey(User,
|
||||||
related_name="sender",
|
related_name="sender",
|
||||||
|
11
api/tasks.py
11
api/tasks.py
@ -95,11 +95,13 @@ def follow_send_payment(hash):
|
|||||||
]):
|
]):
|
||||||
if response.status == 0: # Status 0 'UNKNOWN'
|
if response.status == 0: # Status 0 'UNKNOWN'
|
||||||
# Not sure when this status happens
|
# Not sure when this status happens
|
||||||
pass
|
lnpayment.in_flight = False
|
||||||
|
lnpayment.save()
|
||||||
|
|
||||||
if response.status == 1: # Status 1 'IN_FLIGHT'
|
if response.status == 1: # Status 1 'IN_FLIGHT'
|
||||||
print("IN_FLIGHT")
|
print("IN_FLIGHT")
|
||||||
lnpayment.status = LNPayment.Status.FLIGHT
|
lnpayment.status = LNPayment.Status.FLIGHT
|
||||||
|
lnpayment.in_flight = True
|
||||||
lnpayment.save()
|
lnpayment.save()
|
||||||
order.status = Order.Status.PAY
|
order.status = Order.Status.PAY
|
||||||
order.save()
|
order.save()
|
||||||
@ -109,6 +111,7 @@ def follow_send_payment(hash):
|
|||||||
lnpayment.status = LNPayment.Status.FAILRO
|
lnpayment.status = LNPayment.Status.FAILRO
|
||||||
lnpayment.last_routing_time = timezone.now()
|
lnpayment.last_routing_time = timezone.now()
|
||||||
lnpayment.routing_attempts += 1
|
lnpayment.routing_attempts += 1
|
||||||
|
lnpayment.in_flight = False
|
||||||
lnpayment.save()
|
lnpayment.save()
|
||||||
order.status = Order.Status.FAI
|
order.status = Order.Status.FAI
|
||||||
order.expires_at = timezone.now() + timedelta(
|
order.expires_at = timezone.now() + timedelta(
|
||||||
@ -116,7 +119,8 @@ def follow_send_payment(hash):
|
|||||||
order.save()
|
order.save()
|
||||||
context = {
|
context = {
|
||||||
"routing_failed":
|
"routing_failed":
|
||||||
LNNode.payment_failure_context[response.failure_reason]
|
LNNode.payment_failure_context[response.failure_reason],
|
||||||
|
"IN_FLIGHT":False,
|
||||||
}
|
}
|
||||||
print(context)
|
print(context)
|
||||||
return False, context
|
return False, context
|
||||||
@ -130,13 +134,14 @@ def follow_send_payment(hash):
|
|||||||
order.expires_at = timezone.now() + timedelta(
|
order.expires_at = timezone.now() + timedelta(
|
||||||
seconds=order.t_to_expire(Order.Status.SUC))
|
seconds=order.t_to_expire(Order.Status.SUC))
|
||||||
order.save()
|
order.save()
|
||||||
return True, None
|
return True, {"IN_FLIGHT":False}
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
if "invoice expired" in str(e):
|
if "invoice expired" in str(e):
|
||||||
print("INVOICE EXPIRED")
|
print("INVOICE EXPIRED")
|
||||||
lnpayment.status = LNPayment.Status.EXPIRE
|
lnpayment.status = LNPayment.Status.EXPIRE
|
||||||
lnpayment.last_routing_time = timezone.now()
|
lnpayment.last_routing_time = timezone.now()
|
||||||
|
lnpayment.in_flight = False
|
||||||
lnpayment.save()
|
lnpayment.save()
|
||||||
order.status = Order.Status.FAI
|
order.status = Order.Status.FAI
|
||||||
order.expires_at = timezone.now() + timedelta(
|
order.expires_at = timezone.now() + timedelta(
|
||||||
|
Reference in New Issue
Block a user