mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-09-08 14:57:38 +02:00
multi: replace errInvoiceNotFound with resolution result
This commit moves handling of invoice not found errors into NotifyExitHopHtlc and exposes a resolution result to the calling functions. The intention of this change is to make calling functions as naive of the invoice registry's mechanics as possible. When NotifyExitHopHtlc is called and an invoice is not found, calling functions can take action based on the HtlcResolution's InvoiceNotFound outcome rather than having to add a special error check on every call to handle the error.
This commit is contained in:
@@ -758,11 +758,21 @@ func (i *InvoiceRegistry) NotifyExitHopHtlc(rHash lntypes.Hash,
|
||||
return updateDesc, nil
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
debugLog(err.Error())
|
||||
switch err {
|
||||
case channeldb.ErrInvoiceNotFound:
|
||||
// If the invoice was not found, return a failure resolution
|
||||
// with an invoice not found result.
|
||||
return NewFailureResolution(
|
||||
circuitKey, currentHeight, ResultInvoiceNotFound,
|
||||
), nil
|
||||
|
||||
case nil:
|
||||
|
||||
default:
|
||||
debugLog(err.Error())
|
||||
return nil, err
|
||||
}
|
||||
|
||||
debugLog(result.String())
|
||||
|
||||
if updateSubscribers {
|
||||
|
@@ -585,12 +585,16 @@ func TestUnknownInvoice(t *testing.T) {
|
||||
// succeed.
|
||||
hodlChan := make(chan interface{})
|
||||
amt := lnwire.MilliSatoshi(100000)
|
||||
_, err := ctx.registry.NotifyExitHopHtlc(
|
||||
result, err := ctx.registry.NotifyExitHopHtlc(
|
||||
testInvoicePaymentHash, amt, testHtlcExpiry, testCurrentHeight,
|
||||
getCircuitKey(0), hodlChan, testPayload,
|
||||
)
|
||||
if err != channeldb.ErrInvoiceNotFound {
|
||||
t.Fatal("expected invoice not found error")
|
||||
if err != nil {
|
||||
t.Fatal("unexpected error")
|
||||
}
|
||||
if result.Outcome != ResultInvoiceNotFound {
|
||||
t.Fatalf("expected ResultInvoiceNotFound, got: %v",
|
||||
result.Outcome)
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -81,6 +81,10 @@ const (
|
||||
|
||||
// ResultHtlcSetOverpayment is returned when a mpp set is overpaid.
|
||||
ResultHtlcSetOverpayment
|
||||
|
||||
// ResultInvoiceNotFound is returned when an attempt is made to pay an
|
||||
// invoice that is unknown to us.
|
||||
ResultInvoiceNotFound
|
||||
)
|
||||
|
||||
// String returns a human-readable representation of the invoice update result.
|
||||
|
Reference in New Issue
Block a user