mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-09-26 20:26:34 +02:00
channeldb: split cancel and add htlc updates
Previously the cancel and add actions were combined in a single map. Nil values implictly signaled cancel actions. This wasn't very obvious. Furthermore this split prepares for processing the adds and cancels separately, which is more efficient if there are already two maps.
This commit is contained in:
@@ -598,7 +598,7 @@ func (i *InvoiceRegistry) CancelInvoice(payHash lntypes.Hash) error {
|
||||
|
||||
// Mark individual held htlcs as canceled.
|
||||
canceledHtlcs := make(
|
||||
map[channeldb.CircuitKey]*channeldb.HtlcAcceptDesc,
|
||||
map[channeldb.CircuitKey]struct{},
|
||||
)
|
||||
for key, htlc := range invoice.Htlcs {
|
||||
switch htlc.State {
|
||||
@@ -615,13 +615,13 @@ func (i *InvoiceRegistry) CancelInvoice(payHash lntypes.Hash) error {
|
||||
continue
|
||||
}
|
||||
|
||||
canceledHtlcs[key] = nil
|
||||
canceledHtlcs[key] = struct{}{}
|
||||
}
|
||||
|
||||
// Move invoice to the canceled state.
|
||||
return &channeldb.InvoiceUpdateDesc{
|
||||
Htlcs: canceledHtlcs,
|
||||
State: channeldb.ContractCanceled,
|
||||
CancelHtlcs: canceledHtlcs,
|
||||
State: channeldb.ContractCanceled,
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
@@ -130,7 +130,9 @@ func updateInvoice(ctx *invoiceUpdateCtx, inv *channeldb.Invoice) (
|
||||
},
|
||||
}
|
||||
|
||||
update := channeldb.InvoiceUpdateDesc{Htlcs: newHtlcs}
|
||||
update := channeldb.InvoiceUpdateDesc{
|
||||
AddHtlcs: newHtlcs,
|
||||
}
|
||||
|
||||
// Don't update invoice state if we are accepting a duplicate payment.
|
||||
// We do accept or settle the HTLC.
|
||||
|
Reference in New Issue
Block a user