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:
carla
2019-12-20 12:25:08 +02:00
parent 7b5dda0417
commit d2e395d5f2
6 changed files with 54 additions and 36 deletions

View File

@@ -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 {

View File

@@ -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)
}
}

View File

@@ -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.