Add invoice expiry paddingas temporary fix for order expire at invoice expire.

This commit is contained in:
Reckless_Satoshi 2022-01-24 10:34:52 -08:00
parent 51d65fd15e
commit 25ab5fdf2e
No known key found for this signature in database
GPG Key ID: 9C4585B561315571
5 changed files with 15 additions and 6 deletions

View File

@ -80,7 +80,7 @@ class LNNode():
memo=description,
value=num_satoshis,
hash=r_hash,
expiry=invoice_expiry,
expiry=int(invoice_expiry*1.15), # actual expiry is padded by 15%
cltv_expiry=cltv_expiry_blocks,
)
response = cls.invoicesstub.AddHoldInvoice(request, metadata=[('macaroon', MACAROON.hex())])
@ -91,6 +91,7 @@ class LNNode():
hold_payment['payment_hash'] = payreq_decoded.payment_hash
hold_payment['created_at'] = timezone.make_aware(datetime.fromtimestamp(payreq_decoded.timestamp))
hold_payment['expires_at'] = hold_payment['created_at'] + timedelta(seconds=payreq_decoded.expiry)
hold_payment['cltv_expiry'] = cltv_expiry_blocks
return hold_payment
@ -103,6 +104,9 @@ class LNNode():
print(response.state)
# TODO ERROR HANDLING
# Will fail if 'unable to locate invoice'. Happens if invoice expiry
# time has passed (but these are 15% padded at the moment). Should catch it
# and report back that the invoice has expired (better robustness)
if response.state == 0: # OPEN
print('STATUS: OPEN')
pass

View File

@ -517,7 +517,8 @@ class Logics():
description = description,
payment_hash = hold_payment['payment_hash'],
created_at = hold_payment['created_at'],
expires_at = hold_payment['expires_at'])
expires_at = hold_payment['expires_at'],
cltv_expiry = hold_payment['cltv_expiry'])
order.save()
return True, {'bond_invoice':hold_payment['invoice'], 'bond_satoshis':bond_satoshis}
@ -597,7 +598,8 @@ class Logics():
description = description,
payment_hash = hold_payment['payment_hash'],
created_at = hold_payment['created_at'],
expires_at = hold_payment['expires_at'])
expires_at = hold_payment['expires_at'],
cltv_expiry = hold_payment['cltv_expiry'])
order.expires_at = timezone.now() + timedelta(seconds=Order.t_to_expire[Order.Status.TAK])
order.save()
@ -663,7 +665,8 @@ class Logics():
description = description,
payment_hash = hold_payment['payment_hash'],
created_at = hold_payment['created_at'],
expires_at = hold_payment['expires_at'])
expires_at = hold_payment['expires_at'],
cltv_expiry = hold_payment['cltv_expiry'])
order.save()
return True, {'escrow_invoice':hold_payment['invoice'],'escrow_satoshis': escrow_satoshis}

View File

@ -71,6 +71,7 @@ class LNPayment(models.Model):
num_satoshis = models.PositiveBigIntegerField(validators=[MinValueValidator(MIN_TRADE*BOND_SIZE), MaxValueValidator(MAX_TRADE*(1+BOND_SIZE+FEE))])
created_at = models.DateTimeField()
expires_at = models.DateTimeField()
cltv_expiry = models.PositiveSmallIntegerField(null=True, default=None, blank=True)
# routing
routing_attempts = models.PositiveSmallIntegerField(null=False, default=0)

View File

@ -52,7 +52,7 @@ export default class OrderPage extends Component {
// Refresh delays according to Order status
this.statusToDelay = {
"0": 2000, //'Waiting for maker bond'
"1": 45000, //'Public'
"1": 25000, //'Public'
"2": 9999999, //'Deleted'
"3": 2000, //'Waiting for taker bond'
"4": 9999999, //'Cancelled'
@ -86,6 +86,7 @@ export default class OrderPage extends Component {
loading: false,
delay: this.setDelay(newStateVars.status),
currencyCode: this.getCurrencyCode(newStateVars.currency),
penalty: newStateVars.penalty, // in case penalty time has finished, it goes back to null
};
var completeStateVars = Object.assign({}, newStateVars, otherStateVars);