invoices: refactor - update timestamp expiry to use specific names
This commit is contained in:
parent
d29f2fe4f9
commit
039e9f439c
@ -116,9 +116,25 @@ func (ew *InvoiceExpiryWatcher) Stop() {
|
|||||||
func makeInvoiceExpiry(paymentHash lntypes.Hash,
|
func makeInvoiceExpiry(paymentHash lntypes.Hash,
|
||||||
invoice *channeldb.Invoice) invoiceExpiry {
|
invoice *channeldb.Invoice) invoiceExpiry {
|
||||||
|
|
||||||
if invoice.State != channeldb.ContractOpen {
|
switch invoice.State {
|
||||||
|
// If we have an open invoice with no htlcs, we want to expire the
|
||||||
|
// invoice based on timestamp
|
||||||
|
case channeldb.ContractOpen:
|
||||||
|
return makeTimestampExpiry(paymentHash, invoice)
|
||||||
|
|
||||||
|
default:
|
||||||
log.Debugf("Invoice not added to expiry watcher: %v",
|
log.Debugf("Invoice not added to expiry watcher: %v",
|
||||||
paymentHash)
|
paymentHash)
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// makeTimestampExpiry creates a timestamp-based expiry entry.
|
||||||
|
func makeTimestampExpiry(paymentHash lntypes.Hash,
|
||||||
|
invoice *channeldb.Invoice) *invoiceExpiryTs {
|
||||||
|
|
||||||
|
if invoice.State != channeldb.ContractOpen {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -150,9 +166,10 @@ func (ew *InvoiceExpiryWatcher) AddInvoices(invoices ...invoiceExpiry) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// nextExpiry returns a Time chan to wait on until the next invoice expires.
|
// nextTimestampExpiry returns a Time chan to wait on until the next invoice
|
||||||
// If there are no active invoices, then it'll simply wait indefinitely.
|
// expires. If there are no active invoices, then it'll simply wait
|
||||||
func (ew *InvoiceExpiryWatcher) nextExpiry() <-chan time.Time {
|
// indefinitely.
|
||||||
|
func (ew *InvoiceExpiryWatcher) nextTimestampExpiry() <-chan time.Time {
|
||||||
if !ew.timestampExpiryQueue.Empty() {
|
if !ew.timestampExpiryQueue.Empty() {
|
||||||
top := ew.timestampExpiryQueue.Top().(*invoiceExpiryTs)
|
top := ew.timestampExpiryQueue.Top().(*invoiceExpiryTs)
|
||||||
return ew.clock.TickAfter(top.Expiry.Sub(ew.clock.Now()))
|
return ew.clock.TickAfter(top.Expiry.Sub(ew.clock.Now()))
|
||||||
@ -217,21 +234,21 @@ func (ew *InvoiceExpiryWatcher) mainLoop() {
|
|||||||
|
|
||||||
select {
|
select {
|
||||||
|
|
||||||
case invoicesWithExpiry := <-ew.newInvoices:
|
case newInvoices := <-ew.newInvoices:
|
||||||
// Take newly forwarded invoices with higher priority
|
// Take newly forwarded invoices with higher priority
|
||||||
// in order to not block the newInvoices channel.
|
// in order to not block the newInvoices channel.
|
||||||
ew.pushInvoices(invoicesWithExpiry)
|
ew.pushInvoices(newInvoices)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
default:
|
default:
|
||||||
select {
|
select {
|
||||||
|
|
||||||
case <-ew.nextExpiry():
|
case <-ew.nextTimestampExpiry():
|
||||||
// Wait until the next invoice expires.
|
// Wait until the next invoice expires.
|
||||||
continue
|
continue
|
||||||
|
|
||||||
case invoicesWithExpiry := <-ew.newInvoices:
|
case newInvoices := <-ew.newInvoices:
|
||||||
ew.pushInvoices(invoicesWithExpiry)
|
ew.pushInvoices(newInvoices)
|
||||||
|
|
||||||
case <-ew.quit:
|
case <-ew.quit:
|
||||||
return
|
return
|
||||||
|
Loading…
Reference in New Issue
Block a user