diff --git a/htlcswitch/interfaces.go b/htlcswitch/interfaces.go index 196dad4c0..60c400f06 100644 --- a/htlcswitch/interfaces.go +++ b/htlcswitch/interfaces.go @@ -18,7 +18,7 @@ type InvoiceDatabase interface { // SettleInvoice attempts to mark an invoice corresponding to the // passed payment hash as fully settled. - SettleInvoice(chainhash.Hash) error + SettleInvoice(payHash chainhash.Hash, paidAmount lnwire.MilliSatoshi) error } // ChannelLink is an interface which represents the subsystem for managing the diff --git a/htlcswitch/link.go b/htlcswitch/link.go index 68261ca26..467a8a735 100644 --- a/htlcswitch/link.go +++ b/htlcswitch/link.go @@ -2298,8 +2298,9 @@ func (l *channelLink) processRemoteAdds(fwdPkg *channeldb.FwdPkg, } preimage := invoice.Terms.PaymentPreimage - err = l.channel.SettleHTLC(preimage, - pd.HtlcIndex, pd.SourceRef, nil, nil) + err = l.channel.SettleHTLC( + preimage, pd.HtlcIndex, pd.SourceRef, nil, nil, + ) if err != nil { l.fail(LinkFailureError{code: ErrInternalError}, "unable to settle htlc: %v", err) @@ -2307,8 +2308,11 @@ func (l *channelLink) processRemoteAdds(fwdPkg *channeldb.FwdPkg, } // Notify the invoiceRegistry of the invoices we just - // settled with this latest commitment update. - err = l.cfg.Registry.SettleInvoice(invoiceHash) + // settled (with the amount accepted at settle time) + // with this latest commitment update. + err = l.cfg.Registry.SettleInvoice( + invoiceHash, pd.Amount, + ) if err != nil { l.fail(LinkFailureError{code: ErrInternalError}, "unable to settle invoice: %v", err) diff --git a/htlcswitch/link_test.go b/htlcswitch/link_test.go index c42c6e508..a97da2311 100644 --- a/htlcswitch/link_test.go +++ b/htlcswitch/link_test.go @@ -3657,6 +3657,13 @@ func TestChannelLinkAcceptOverpay(t *testing.T) { t.Fatalf("channel bandwidth incorrect: expected %v, got %v", expectedCarolBandwidth, n.carolChannelLink.Bandwidth()) } + + // Finally, we'll ensure that the amount we paid is properly reflected + // in the stored invoice. + if invoice.AmtPaid != amount { + t.Fatalf("expected amt paid to be %v, is instead %v", amount, + invoice.AmtPaid) + } } // chanRestoreFunc is a method signature for functions that can reload both diff --git a/htlcswitch/mock.go b/htlcswitch/mock.go index e0016188e..7f86c049f 100644 --- a/htlcswitch/mock.go +++ b/htlcswitch/mock.go @@ -673,7 +673,9 @@ func (i *mockInvoiceRegistry) LookupInvoice(rHash chainhash.Hash) (channeldb.Inv return invoice, i.finalDelta, nil } -func (i *mockInvoiceRegistry) SettleInvoice(rhash chainhash.Hash) error { +func (i *mockInvoiceRegistry) SettleInvoice(rhash chainhash.Hash, + amt lnwire.MilliSatoshi) error { + i.Lock() defer i.Unlock() @@ -687,6 +689,7 @@ func (i *mockInvoiceRegistry) SettleInvoice(rhash chainhash.Hash) error { } invoice.Terms.Settled = true + invoice.AmtPaid = amt i.invoices[rhash] = invoice return nil