mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-09-22 15:57:49 +02:00
channeldb+invoices: make htlc cancelation stricter
Previously it was possible to cancel a canceled htlc. This would subtract the htlc amount from the invoice amount again.
This commit is contained in:
@@ -640,7 +640,21 @@ func (i *InvoiceRegistry) CancelInvoice(payHash lntypes.Hash) error {
|
||||
canceledHtlcs := make(
|
||||
map[channeldb.CircuitKey]*channeldb.HtlcAcceptDesc,
|
||||
)
|
||||
for key := range invoice.Htlcs {
|
||||
for key, htlc := range invoice.Htlcs {
|
||||
switch htlc.State {
|
||||
|
||||
// If we get here, there shouldn't be any settled htlcs.
|
||||
case channeldb.HtlcStateSettled:
|
||||
return nil, errors.New("cannot cancel " +
|
||||
"invoice with settled htlc(s)")
|
||||
|
||||
// Don't cancel htlcs that were already cancelled,
|
||||
// because it would incorrectly modify the invoice paid
|
||||
// amt.
|
||||
case channeldb.HtlcStateCancelled:
|
||||
continue
|
||||
}
|
||||
|
||||
canceledHtlcs[key] = nil
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user