htlcswitch: modify the InvoiceDatabase interface to allow specifying final payment amt
In this commit, we modify the InvoiceDatabase slightly to allow the link to record what the final payment about for an invoice was. It may be the case that the invoice actually had no specified value, or that the payer paid more than necessary. As a result, it's important that our on-disk records properly reflect this. To fix this issue, the SettleInvoice method now also accepts the final amount paid. Fixes #856.
This commit is contained in:
parent
edbdcddea1
commit
a32f2b79da
@ -18,7 +18,7 @@ type InvoiceDatabase interface {
|
|||||||
|
|
||||||
// SettleInvoice attempts to mark an invoice corresponding to the
|
// SettleInvoice attempts to mark an invoice corresponding to the
|
||||||
// passed payment hash as fully settled.
|
// 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
|
// ChannelLink is an interface which represents the subsystem for managing the
|
||||||
|
@ -2298,8 +2298,9 @@ func (l *channelLink) processRemoteAdds(fwdPkg *channeldb.FwdPkg,
|
|||||||
}
|
}
|
||||||
|
|
||||||
preimage := invoice.Terms.PaymentPreimage
|
preimage := invoice.Terms.PaymentPreimage
|
||||||
err = l.channel.SettleHTLC(preimage,
|
err = l.channel.SettleHTLC(
|
||||||
pd.HtlcIndex, pd.SourceRef, nil, nil)
|
preimage, pd.HtlcIndex, pd.SourceRef, nil, nil,
|
||||||
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
l.fail(LinkFailureError{code: ErrInternalError},
|
l.fail(LinkFailureError{code: ErrInternalError},
|
||||||
"unable to settle htlc: %v", err)
|
"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
|
// Notify the invoiceRegistry of the invoices we just
|
||||||
// settled with this latest commitment update.
|
// settled (with the amount accepted at settle time)
|
||||||
err = l.cfg.Registry.SettleInvoice(invoiceHash)
|
// with this latest commitment update.
|
||||||
|
err = l.cfg.Registry.SettleInvoice(
|
||||||
|
invoiceHash, pd.Amount,
|
||||||
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
l.fail(LinkFailureError{code: ErrInternalError},
|
l.fail(LinkFailureError{code: ErrInternalError},
|
||||||
"unable to settle invoice: %v", err)
|
"unable to settle invoice: %v", err)
|
||||||
|
@ -3657,6 +3657,13 @@ func TestChannelLinkAcceptOverpay(t *testing.T) {
|
|||||||
t.Fatalf("channel bandwidth incorrect: expected %v, got %v",
|
t.Fatalf("channel bandwidth incorrect: expected %v, got %v",
|
||||||
expectedCarolBandwidth, n.carolChannelLink.Bandwidth())
|
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
|
// chanRestoreFunc is a method signature for functions that can reload both
|
||||||
|
@ -673,7 +673,9 @@ func (i *mockInvoiceRegistry) LookupInvoice(rHash chainhash.Hash) (channeldb.Inv
|
|||||||
return invoice, i.finalDelta, nil
|
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()
|
i.Lock()
|
||||||
defer i.Unlock()
|
defer i.Unlock()
|
||||||
|
|
||||||
@ -687,6 +689,7 @@ func (i *mockInvoiceRegistry) SettleInvoice(rhash chainhash.Hash) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
invoice.Terms.Settled = true
|
invoice.Terms.Settled = true
|
||||||
|
invoice.AmtPaid = amt
|
||||||
i.invoices[rhash] = invoice
|
i.invoices[rhash] = invoice
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
Loading…
Reference in New Issue
Block a user