background process debugging

This commit is contained in:
Reckless_Satoshi 2022-01-20 09:30:29 -08:00
parent 300a385589
commit 4eaad57475
No known key found for this signature in database
GPG Key ID: 9C4585B561315571
5 changed files with 21 additions and 9 deletions

View File

@ -33,7 +33,7 @@ class OrderAdmin(AdminChangeLinksMixin, admin.ModelAdmin):
@admin.register(LNPayment) @admin.register(LNPayment)
class LNPaymentAdmin(AdminChangeLinksMixin, admin.ModelAdmin): class LNPaymentAdmin(AdminChangeLinksMixin, admin.ModelAdmin):
list_display = ('hash','concept','status','num_satoshis','type','expires_at','sender_link','receiver_link','order_made','order_taken','order_escrow','order_paid') list_display = ('hash','concept','status','num_satoshis','type','expires_at','sender_link','receiver_link','order_made','order_taken','order_escrow','order_paid')
list_display_links = ('hash','concept','order_made','order_taken','order_escrow','order_paid') list_display_links = ('hash','concept')
change_links = ('sender','receiver') change_links = ('sender','receiver')
list_filter = ('type','concept','status') list_filter = ('type','concept','status')

View File

@ -220,7 +220,7 @@ class Logics():
@classmethod @classmethod
def open_dispute(cls, order, user=None): def open_dispute(cls, order, user=None):
# Always settle the escrow during a dispute (same as with 'Fiat Sent') # Always settle the escrow during a dispute
# Dispute winner will have to submit a new invoice. # Dispute winner will have to submit a new invoice.
if not order.trade_escrow.status == LNPayment.Status.SETLED: if not order.trade_escrow.status == LNPayment.Status.SETLED:
@ -235,7 +235,10 @@ class Logics():
if not user == None: if not user == None:
profile = user.profile profile = user.profile
profile.num_disputes = profile.num_disputes + 1 profile.num_disputes = profile.num_disputes + 1
profile.orders_disputes_started = list(profile.orders_disputes_started).append(str(order.id)) if profile.orders_disputes_started == None:
profile.orders_disputes_started = [str(order.id)]
else:
profile.orders_disputes_started = list(profile.orders_disputes_started).append(str(order.id))
profile.save() profile.save()
return True, None return True, None
@ -325,7 +328,7 @@ class Logics():
''' adds a new rating to a user profile''' ''' adds a new rating to a user profile'''
# TODO Unsafe, does not update ratings, it adds more ratings everytime a new rating is clicked. # TODO Unsafe, does not update ratings, it adds more ratings everytime a new rating is clicked.
profile.total_ratings = profile.total_ratings + 1 profile.total_ratings += 1
latest_ratings = profile.latest_ratings latest_ratings = profile.latest_ratings
if latest_ratings == None: if latest_ratings == None:
profile.latest_ratings = [rating] profile.latest_ratings = [rating]
@ -633,6 +636,7 @@ class Logics():
'''returns the trade escrow''' '''returns the trade escrow'''
if LNNode.cancel_return_hold_invoice(order.trade_escrow.payment_hash): if LNNode.cancel_return_hold_invoice(order.trade_escrow.payment_hash):
order.trade_escrow.status = LNPayment.Status.RETNED order.trade_escrow.status = LNPayment.Status.RETNED
order.trade_escrow.save()
return True return True
def cancel_escrow(order): def cancel_escrow(order):
@ -640,6 +644,7 @@ class Logics():
# Same as return escrow, but used when the invoice was never LOCKED # Same as return escrow, but used when the invoice was never LOCKED
if LNNode.cancel_return_hold_invoice(order.trade_escrow.payment_hash): if LNNode.cancel_return_hold_invoice(order.trade_escrow.payment_hash):
order.trade_escrow.status = LNPayment.Status.CANCEL order.trade_escrow.status = LNPayment.Status.CANCEL
order.trade_escrow.save()
return True return True
def return_bond(bond): def return_bond(bond):
@ -649,10 +654,12 @@ class Logics():
try: try:
LNNode.cancel_return_hold_invoice(bond.payment_hash) LNNode.cancel_return_hold_invoice(bond.payment_hash)
bond.status = LNPayment.Status.RETNED bond.status = LNPayment.Status.RETNED
bond.save()
return True return True
except Exception as e: except Exception as e:
if 'invoice already settled' in str(e): if 'invoice already settled' in str(e):
bond.status = LNPayment.Status.SETLED bond.status = LNPayment.Status.SETLED
bond.save()
return True return True
else: else:
raise e raise e
@ -665,10 +672,12 @@ class Logics():
try: try:
LNNode.cancel_return_hold_invoice(bond.payment_hash) LNNode.cancel_return_hold_invoice(bond.payment_hash)
bond.status = LNPayment.Status.CANCEL bond.status = LNPayment.Status.CANCEL
bond.save()
return True return True
except Exception as e: except Exception as e:
if 'invoice already settled' in str(e): if 'invoice already settled' in str(e):
bond.status = LNPayment.Status.SETLED bond.status = LNPayment.Status.SETLED
bond.save()
return True return True
else: else:
raise e raise e
@ -705,11 +714,11 @@ class Logics():
order.status = Order.Status.SUC order.status = Order.Status.SUC
order.buyer_invoice.status = LNPayment.Status.SUCCED order.buyer_invoice.status = LNPayment.Status.SUCCED
order.expires_at = timezone.now() + timedelta(seconds=Order.t_to_expire[Order.Status.SUC]) order.expires_at = timezone.now() + timedelta(seconds=Order.t_to_expire[Order.Status.SUC])
order.save()
# RETURN THE BONDS # RETURN THE BONDS
cls.return_bond(order.taker_bond) cls.return_bond(order.taker_bond)
cls.return_bond(order.maker_bond) cls.return_bond(order.maker_bond)
order.save()
return True, context return True, context
else: else:
# error handling here # error handling here

View File

@ -40,11 +40,13 @@ class Command(BaseCommand):
if Logics.order_expires(order): # Order send to expire here if Logics.order_expires(order): # Order send to expire here
debug['expired_orders'].append({idx:context}) debug['expired_orders'].append({idx:context})
# If it cannot locate the hold invoice, make it expire anywway # It should not happen, but if it cannot locate the hold invoice
# it probably was cancelled by another thread, make it expire anyway.
except Exception as e: except Exception as e:
if 'unable to locate invoice' in str(e): if 'unable to locate invoice' in str(e):
self.stdout.write(str(e)) self.stdout.write(str(e))
order.status = Order.Status.EXP order.status = Order.Status.EXP
order.save()
debug['expired_orders'].append({idx:context}) debug['expired_orders'].append({idx:context})

View File

@ -57,7 +57,6 @@ class LNPayment(models.Model):
FLIGHT = 7, 'In flight' FLIGHT = 7, 'In flight'
SUCCED = 8, 'Succeeded' SUCCED = 8, 'Succeeded'
FAILRO = 9, 'Routing failed' FAILRO = 9, 'Routing failed'
# payment use details # payment use details
type = models.PositiveSmallIntegerField(choices=Types.choices, null=False, default=Types.HOLD) type = models.PositiveSmallIntegerField(choices=Types.choices, null=False, default=Types.HOLD)
@ -141,7 +140,7 @@ class Order(models.Model):
last_satoshis = models.PositiveBigIntegerField(null=True, validators=[MinValueValidator(0), MaxValueValidator(MAX_TRADE*2)], blank=True) # sats last time checked. Weird if 2* trade max... last_satoshis = models.PositiveBigIntegerField(null=True, validators=[MinValueValidator(0), MaxValueValidator(MAX_TRADE*2)], blank=True) # sats last time checked. Weird if 2* trade max...
# order participants # order participants
maker = models.ForeignKey(User, related_name='maker', on_delete=models.CASCADE, null=True, default=None) # unique = True, a maker can only make one order maker = models.ForeignKey(User, related_name='maker', on_delete=models.SET_NULL, null=True, default=None) # unique = True, a maker can only make one order
taker = models.ForeignKey(User, related_name='taker', on_delete=models.SET_NULL, null=True, default=None, blank=True) # unique = True, a taker can only take one order taker = models.ForeignKey(User, related_name='taker', on_delete=models.SET_NULL, null=True, default=None, blank=True) # unique = True, a taker can only take one order
is_pending_cancel = models.BooleanField(default=False, null=False) # When collaborative cancel is needed and one partner has cancelled. is_pending_cancel = models.BooleanField(default=False, null=False) # When collaborative cancel is needed and one partner has cancelled.
is_fiat_sent = models.BooleanField(default=False, null=False) is_fiat_sent = models.BooleanField(default=False, null=False)

2
clean_orders Normal file
View File

@ -0,0 +1,2 @@
2022-01-20 12:59:13.516882+00:00
{'num_expired_orders': 1, 'expired_orders': [{0: 'Order 56: SELL BTC for 40.0 USD was Public'}]}