channeldb: ensure invoices can't be added with HTLCs

This commit is contained in:
Conner Fromknecht
2021-03-03 09:56:28 -08:00
parent b2234703f6
commit da049ebcf7
2 changed files with 27 additions and 0 deletions

View File

@@ -106,6 +106,10 @@ var (
// ErrInvoicePreimageMismatch is returned when the preimage doesn't
// match the invoice hash.
ErrInvoicePreimageMismatch = errors.New("preimage does not match")
// ErrInvoiceHasHtlcs is returned when attempting to insert an invoice
// that already has HTLCs.
ErrInvoiceHasHtlcs = errors.New("cannot add invoice with htlcs")
)
const (
@@ -588,6 +592,11 @@ func validateInvoice(i *Invoice, paymentHash lntypes.Hash) error {
if i.Terms.PaymentPreimage == nil && !i.HodlInvoice {
return errors.New("non-hodl invoices must have a preimage")
}
if len(i.Htlcs) > 0 {
return ErrInvoiceHasHtlcs
}
return nil
}