channeldb: optimize updateInvoice for AMP by only reading relevant HTLCs
In this commit, we update the logic in `updateInvoice` to allow callers to pass in either a hint, or the setID in the update callback. This makes things more efficient for AMP invoices with thousands of recurring payments, as we no longer need to read out _all_ the invoices each time we go to update the state of a few HTLCs.
This commit is contained in:
3 files changed
+117
-34
No files matched your search
@@ -688,7 +688,7 @@ func (i *InvoiceRegistry) cancelSingleHtlc(invoiceRef channeldb.InvoiceRef,
|
||||
// Intercept the update descriptor to set the local updated variable. If
|
||||
// no invoice update is performed, we can return early.
|
||||
var updated bool
|
||||
invoice, err := i.cdb.UpdateInvoice(invoiceRef,
|
||||
invoice, err := i.cdb.UpdateInvoice(invoiceRef, nil,
|
||||
func(invoice *channeldb.Invoice) (
|
||||
*channeldb.InvoiceUpdateDesc, error) {
|
||||
|
||||
@@ -979,6 +979,7 @@ func (i *InvoiceRegistry) notifyExitHopHtlcLocked(
|
||||
)
|
||||
invoice, err := i.cdb.UpdateInvoice(
|
||||
ctx.invoiceRef(),
|
||||
(*channeldb.SetID)(ctx.setID()),
|
||||
func(inv *channeldb.Invoice) (
|
||||
*channeldb.InvoiceUpdateDesc, error) {
|
||||
|
||||
@@ -1181,7 +1182,7 @@ func (i *InvoiceRegistry) SettleHodlInvoice(preimage lntypes.Preimage) error {
|
||||
|
||||
hash := preimage.Hash()
|
||||
invoiceRef := channeldb.InvoiceRefByHash(hash)
|
||||
invoice, err := i.cdb.UpdateInvoice(invoiceRef, updateInvoice)
|
||||
invoice, err := i.cdb.UpdateInvoice(invoiceRef, nil, updateInvoice)
|
||||
if err != nil {
|
||||
log.Errorf("SettleHodlInvoice with preimage %v: %v",
|
||||
preimage, err)
|
||||
@@ -1265,7 +1266,7 @@ func (i *InvoiceRegistry) cancelInvoiceImpl(payHash lntypes.Hash,
|
||||
}
|
||||
|
||||
invoiceRef := channeldb.InvoiceRefByHash(payHash)
|
||||
invoice, err := i.cdb.UpdateInvoice(invoiceRef, updateInvoice)
|
||||
invoice, err := i.cdb.UpdateInvoice(invoiceRef, nil, updateInvoice)
|
||||
|
||||
// Implement idempotency by returning success if the invoice was already
|
||||
// canceled.
|
||||
|
||||
Reference in new issue
Block a user