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, memo=description,
value=num_satoshis, value=num_satoshis,
hash=r_hash, hash=r_hash,
expiry=invoice_expiry, expiry=int(invoice_expiry*1.15), # actual expiry is padded by 15%
cltv_expiry=cltv_expiry_blocks, cltv_expiry=cltv_expiry_blocks,
) )
response = cls.invoicesstub.AddHoldInvoice(request, metadata=[('macaroon', MACAROON.hex())]) 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['payment_hash'] = payreq_decoded.payment_hash
hold_payment['created_at'] = timezone.make_aware(datetime.fromtimestamp(payreq_decoded.timestamp)) 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['expires_at'] = hold_payment['created_at'] + timedelta(seconds=payreq_decoded.expiry)
hold_payment['cltv_expiry'] = cltv_expiry_blocks
return hold_payment return hold_payment
@ -103,6 +104,9 @@ class LNNode():
print(response.state) print(response.state)
# TODO ERROR HANDLING # 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 if response.state == 0: # OPEN
print('STATUS: OPEN') print('STATUS: OPEN')
pass pass

View File

@ -517,7 +517,8 @@ class Logics():
description = description, description = description,
payment_hash = hold_payment['payment_hash'], payment_hash = hold_payment['payment_hash'],
created_at = hold_payment['created_at'], 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() order.save()
return True, {'bond_invoice':hold_payment['invoice'], 'bond_satoshis':bond_satoshis} return True, {'bond_invoice':hold_payment['invoice'], 'bond_satoshis':bond_satoshis}
@ -597,7 +598,8 @@ class Logics():
description = description, description = description,
payment_hash = hold_payment['payment_hash'], payment_hash = hold_payment['payment_hash'],
created_at = hold_payment['created_at'], 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.expires_at = timezone.now() + timedelta(seconds=Order.t_to_expire[Order.Status.TAK])
order.save() order.save()
@ -663,7 +665,8 @@ class Logics():
description = description, description = description,
payment_hash = hold_payment['payment_hash'], payment_hash = hold_payment['payment_hash'],
created_at = hold_payment['created_at'], 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() order.save()
return True, {'escrow_invoice':hold_payment['invoice'],'escrow_satoshis': escrow_satoshis} 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))]) num_satoshis = models.PositiveBigIntegerField(validators=[MinValueValidator(MIN_TRADE*BOND_SIZE), MaxValueValidator(MAX_TRADE*(1+BOND_SIZE+FEE))])
created_at = models.DateTimeField() created_at = models.DateTimeField()
expires_at = models.DateTimeField() expires_at = models.DateTimeField()
cltv_expiry = models.PositiveSmallIntegerField(null=True, default=None, blank=True)
# routing # routing
routing_attempts = models.PositiveSmallIntegerField(null=False, default=0) routing_attempts = models.PositiveSmallIntegerField(null=False, default=0)
@ -183,7 +184,7 @@ class Order(models.Model):
13 : 24*60*60, # 'Sending satoshis to buyer' 13 : 24*60*60, # 'Sending satoshis to buyer'
14 : 24*60*60, # 'Sucessful trade' 14 : 24*60*60, # 'Sucessful trade'
15 : 24*60*60, # 'Failed lightning network routing' 15 : 24*60*60, # 'Failed lightning network routing'
16 : 10*24*60*60, # 'Wait for dispute resolution' 16 : 10*24*60*60, # 'Wait for dispute resolution'
17 : 24*60*60, # 'Maker lost dispute' 17 : 24*60*60, # 'Maker lost dispute'
18 : 24*60*60, # 'Taker lost dispute' 18 : 24*60*60, # 'Taker lost dispute'
} }

View File

@ -52,7 +52,7 @@ export default class OrderPage extends Component {
// Refresh delays according to Order status // Refresh delays according to Order status
this.statusToDelay = { this.statusToDelay = {
"0": 2000, //'Waiting for maker bond' "0": 2000, //'Waiting for maker bond'
"1": 45000, //'Public' "1": 25000, //'Public'
"2": 9999999, //'Deleted' "2": 9999999, //'Deleted'
"3": 2000, //'Waiting for taker bond' "3": 2000, //'Waiting for taker bond'
"4": 9999999, //'Cancelled' "4": 9999999, //'Cancelled'
@ -86,6 +86,7 @@ export default class OrderPage extends Component {
loading: false, loading: false,
delay: this.setDelay(newStateVars.status), delay: this.setDelay(newStateVars.status),
currencyCode: this.getCurrencyCode(newStateVars.currency), 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); var completeStateVars = Object.assign({}, newStateVars, otherStateVars);