Add explicit routing failure reasons for users

This commit is contained in:
Reckless_Satoshi 2022-05-19 07:00:55 -07:00
parent f7b9ca67d4
commit d48ee9ced4
No known key found for this signature in database
GPG Key ID: 9C4585B561315571
5 changed files with 36 additions and 1 deletions

View File

@ -255,6 +255,7 @@ class LNNode:
5 Insufficient local balance.
"""
failure_reason = cls.payment_failure_context[response.failure_reason]
lnpayment.failure_reason = response.failure_reason
lnpayment.status = LNPayment.Status.FAILRO
lnpayment.save()
return False, failure_reason
@ -262,6 +263,7 @@ class LNNode:
if response.status == 2: # STATUS 'SUCCEEDED'
lnpayment.status = LNPayment.Status.SUCCED
lnpayment.fee = float(response.fee_msat)/1000
lnpayment.preimage = response.payment_preimage
lnpayment.save()
return True, None

View File

@ -75,6 +75,14 @@ class LNPayment(models.Model):
SUCCED = 8, "Succeeded"
FAILRO = 9, "Routing failed"
class FailureReason(models.IntegerChoices):
NOTYETF = 0, "Payment isn't failed (yet)"
TIMEOUT = 1, "There are more routes to try, but the payment timeout was exceeded."
NOROUTE = 2, "All possible routes were tried and failed permanently. Or there were no routes to the destination at all."
NONRECO = 3, "A non-recoverable error has occurred."
INCORRE = 4, "Payment details are incorrect (unknown hash, invalid amount or invalid final CLTV delta)."
NOBALAN = 5, "Insufficient unlocked balance in RoboSats' node."
# payment use details
type = models.PositiveSmallIntegerField(choices=Types.choices,
null=False,
@ -85,6 +93,9 @@ class LNPayment(models.Model):
status = models.PositiveSmallIntegerField(choices=Status.choices,
null=False,
default=Status.INVGEN)
failure_reason = models.PositiveSmallIntegerField(choices=FailureReason.choices,
null=True,
default=None)
# payment info
payment_hash = models.CharField(max_length=100,

View File

@ -115,6 +115,7 @@ def follow_send_payment(hash):
lnpayment.status = LNPayment.Status.FAILRO
lnpayment.last_routing_time = timezone.now()
lnpayment.routing_attempts += 1
lnpayment.failure_reason = response.failure_reason
lnpayment.in_flight = False
if lnpayment.routing_attempts > 2:
lnpayment.status = LNPayment.Status.EXPIRE
@ -140,6 +141,7 @@ def follow_send_payment(hash):
print("SUCCEEDED")
lnpayment.status = LNPayment.Status.SUCCED
lnpayment.fee = float(response.fee_msat)/1000
lnpayment.preimage = response.payment_preimage
lnpayment.save()
order.status = Order.Status.SUC
order.expires_at = timezone.now() + timedelta(

View File

@ -379,6 +379,8 @@ class OrderView(viewsets.ViewSet):
data["retries"] = order.payout.routing_attempts
data["next_retry_time"] = order.payout.last_routing_time + timedelta(
minutes=RETRY_TIME)
if order.payout.failure_reason:
data["failure_reason"] = LNPayment.FailureReason(order.payout.failure_reason).label
if order.payout.status == LNPayment.Status.EXPIRE:
data["invoice_expired"] = True

View File

@ -1158,6 +1158,20 @@ handleRatingRobosatsChange=(e)=>{
);
}
};
failureReason=()=>{
const { t } = this.props;
return(
<Grid item xs={12} align="center">
<Typography variant="body2" align="center">
<b>{"Failure reason:"}</b>
</Typography>
<Typography variant="body2" align="center">
{t(this.props.data.failure_reason)}
</Typography>
</Grid>
)
}
showRoutingFailed=()=>{
const { t } = this.props;
@ -1172,10 +1186,11 @@ handleRatingRobosatsChange=(e)=>{
<Grid item xs={12} align="center">
<Typography variant="body2" align="center">
{t("Your invoice has expired or more than 3 payment attempts have been made.")}
<Link href="https://github.com/Reckless-Satoshi/robosats/issues/44"> {t("Check the list of compatible wallets")}</Link>
</Typography>
</Grid>
{this.props.data.failure_reason ? this.failureReason():null}
<Grid item xs={12} align="center">
{this.compatibleWalletsButton()}
</Grid>
@ -1214,6 +1229,9 @@ handleRatingRobosatsChange=(e)=>{
{t("Lightning Routing Failed")}
</Typography>
</Grid>
{this.props.data.failure_reason ? this.failureReason():null}
<Grid item xs={12} align="center">
<Typography variant="body2" align="center">
{t("RoboSats will try to pay your invoice 3 times every 5 minutes. If it keeps failing, you will be able to submit a new invoice. Check whether you have enough inbound liquidity. Remember that lightning nodes must be online in order to receive payments.")}