invoices+htlcswitch+lnrpc: cancel invoice

This commit is contained in:
Joost Jager
2019-01-11 11:19:16 +01:00
parent 9cd88a04b7
commit 1b87fbfab2
13 changed files with 1020 additions and 590 deletions

View File

@@ -20,6 +20,10 @@ type InvoiceDatabase interface {
// SettleInvoice attempts to mark an invoice corresponding to the
// passed payment hash as fully settled.
SettleInvoice(payHash lntypes.Hash, paidAmount lnwire.MilliSatoshi) error
// CancelInvoice attempts to cancel the invoice corresponding to the
// passed payment hash.
CancelInvoice(payHash lntypes.Hash) error
}
// ChannelLink is an interface which represents the subsystem for managing the

View File

@@ -2337,6 +2337,23 @@ func (l *channelLink) processRemoteAdds(fwdPkg *channeldb.FwdPkg,
continue
}
// Reject htlcs for canceled invoices.
if invoice.Terms.State == channeldb.ContractCanceled {
l.errorf("Rejecting htlc due to canceled " +
"invoice")
failure := lnwire.NewFailUnknownPaymentHash(
pd.Amount,
)
l.sendHTLCError(
pd.HtlcIndex, failure, obfuscator,
pd.SourceRef,
)
needUpdate = true
continue
}
// If the invoice is already settled, we choose to
// accept the payment to simplify failure recovery.
//

View File

@@ -18,7 +18,7 @@ import (
"github.com/btcsuite/btcd/txscript"
"github.com/btcsuite/btcd/wire"
"github.com/go-errors/errors"
"github.com/lightningnetwork/lightning-onion"
sphinx "github.com/lightningnetwork/lightning-onion"
"github.com/lightningnetwork/lnd/chainntnfs"
"github.com/lightningnetwork/lnd/channeldb"
"github.com/lightningnetwork/lnd/contractcourt"
@@ -735,6 +735,25 @@ func (i *mockInvoiceRegistry) SettleInvoice(rhash lntypes.Hash,
return nil
}
func (i *mockInvoiceRegistry) CancelInvoice(payHash lntypes.Hash) error {
i.Lock()
defer i.Unlock()
invoice, ok := i.invoices[payHash]
if !ok {
return channeldb.ErrInvoiceNotFound
}
if invoice.Terms.State == channeldb.ContractCanceled {
return nil
}
invoice.Terms.State = channeldb.ContractCanceled
i.invoices[payHash] = invoice
return nil
}
func (i *mockInvoiceRegistry) AddInvoice(invoice channeldb.Invoice) error {
i.Lock()
defer i.Unlock()