Improve response time of confirm fiat receive; improve failure routing handling

This commit is contained in:
Reckless_Satoshi 2022-02-03 17:37:24 -08:00
parent b39529d91e
commit 3f6731d3e0
No known key found for this signature in database
GPG Key ID: 9C4585B561315571
6 changed files with 43 additions and 26 deletions

View File

@ -49,7 +49,7 @@ class Logics():
return False, {'bad_request':'You are already taker of an active order'}, queryset[0]
# Edge case when the user is in an order that is failing payment and he is the buyer
queryset = Order.objects.filter( Q(maker=user) | Q(taker=user), status__in=Order.Status.FAI)
queryset = Order.objects.filter( Q(maker=user) | Q(taker=user), status=Order.Status.FAI)
if queryset.exists():
order = queryset[0]
if cls.is_buyer(order, user):
@ -794,13 +794,20 @@ class Logics():
# RETURN THE BONDS // Probably best also do it even if payment failed
cls.return_bond(order.taker_bond)
cls.return_bond(order.maker_bond)
is_payed, context = follow_send_payment(order.payout) ##### !!! KEY LINE - PAYS THE BUYER INVOICE !!!
if is_payed:
##### !!! KEY LINE - PAYS THE BUYER INVOICE !!!
##### Backgroun process "follow_invoices" will try to pay this invoice until success
order.status = Order.Status.PAY
order.payout.status = LNPayment.Status.FLIGHT
order.payout.save()
order.save()
return True, context
else:
# error handling here
return False, context
return True, None
# is_payed, context = follow_send_payment(order.payout) ##### !!! KEY LINE - PAYS THE BUYER INVOICE !!!
# if is_payed:
# order.save()
# return True, context
# else:
# # error handling here
# return False, context
else:
return False, {'bad_request':'You cannot confirm the fiat payment at this stage'}

View File

@ -27,7 +27,7 @@ class Command(BaseCommand):
try:
self.follow_hold_invoices()
self.retry_payments()
self.send_payments()
except Exception as e:
if 'database is locked' in str(e):
self.stdout.write('database is locked')
@ -117,15 +117,25 @@ class Command(BaseCommand):
self.stdout.write(str(timezone.now()))
self.stdout.write(str(debug))
def retry_payments(self):
''' Checks if any payment is due for retry, and tries to pay it'''
def send_payments(self):
'''
Checks for invoices that are due to pay; i.e., INFLIGHT status and 0 routing_attempts.
Checks if any payment is due for retry, and tries to pay it.
'''
queryset = LNPayment.objects.filter(type=LNPayment.Types.NORM,
status=LNPayment.Status.FLIGHT,
routing_attempts=0)
queryset_retries = LNPayment.objects.filter(type=LNPayment.Types.NORM,
status__in=[LNPayment.Status.VALIDI, LNPayment.Status.FAILRO],
routing_attempts__lt=4,
last_routing_time__lt=(timezone.now()-timedelta(minutes=int(config('RETRY_TIME')))))
queryset = queryset.union(queryset_retries)
for lnpayment in queryset:
success, _ = follow_send_payment(lnpayment)
success, _ = follow_send_payment(lnpayment) # Do follow_send_payment.delay() for further concurrency.
# If already 3 attempts and last failed. Make it expire (ask for a new invoice) an reset attempts.
if not success and lnpayment.routing_attempts == 3:

View File

@ -77,7 +77,6 @@ def follow_send_payment(lnpayment):
order.save()
context = {'routing_failed': LNNode.payment_failure_context[response.failure_reason]}
print(context)
# Call a retry in 5 mins here?
return False, context
if response.status == 2 : # Status 2 'SUCCEEDED'

View File

@ -227,11 +227,9 @@ export default class BookPage extends Component {
render() {
return (
<Grid className='orderBook' container spacing={1} sx={{minWidth:400}}>
<Grid item xs={12} align="center">
<Typography component="h2" variant="h2">
Order Book
</Typography>
</Grid>
{/* <Grid item xs={12} align="center">
<Typography component="h4" variant="h4">ORDER BOOK</Typography>
</Grid> */}
<Grid item xs={6} align="right">
<FormControl >

View File

@ -153,12 +153,12 @@ export default class MakerPage extends Component {
render() {
return (
<Grid container xs={12} align="center" spacing={1}>
<Grid item xs={12} align="center" sx={{minWidth:380}}>
<Typography component="h2" variant="h2">
Order Maker
<Grid container xs={12} align="center" spacing={1} sx={{minWidth:380}}>
{/* <Grid item xs={12} align="center" sx={{minWidth:380}}>
<Typography component="h4" variant="h4">
ORDER MAKER
</Typography>
</Grid>
</Grid> */}
<Grid item xs={12} align="center" spacing={1}>
<Paper elevation={12} style={{ padding: 8, width:240, align:'center'}}>
<Grid item xs={12} align="center" spacing={1}>

View File

@ -67,16 +67,19 @@ body {
filter: drop-shadow(0.5px 0.5px 0.5px #000000);
}
.phoneFlippedSmallAvatar {
.phoneFlippedSmallAvatar img{
transform: scaleX(-1);
border: 1.3px solid #555;
filter: drop-shadow(0.7px 0.7px 0.7px #000000);
border: 1.3px solid #1976d2;
-webkit-filter: grayscale(100%);
filter: grayscale(100%) brightness(150%) contrast(150%) drop-shadow(0.7px 0.7px 0.7px #000000);
}
.phoneFlippedSmallAvatar:after {
content: '';
position: absolute;
top: 0; left: 0; bottom: 0; right: 0;
border-radius: 50%;
border: 2.4px solid #1976d2;
box-shadow: inset 0px 0px 35px rgb(255, 255, 255);
}