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:
Joost Jager
2019-11-27 14:19:15 +01:00
parent c45891ecf7
commit a4a3c41924
4 changed files with 31 additions and 28 deletions

View File

@@ -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
}

View File

@@ -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.