From cb4cd49dc8d3b0255afe9ff29af9c46c2dbb2c98 Mon Sep 17 00:00:00 2001 From: Joost Jager Date: Wed, 25 Mar 2020 14:59:08 +0100 Subject: [PATCH] routing: map insufficient local bandwidth error to no path With mpp it isn't possible anymore for findPath to determine that there isn't enough local bandwidth. The full payment amount isn't known at that point. In a follow-up, this payment outcome can be reintroduced on a higher level (payment lifecycle). --- channeldb/payments.go | 3 +++ routing/pathfind.go | 2 +- routing/pathfind_test.go | 31 ------------------------------- routing/payment_session.go | 10 ---------- 4 files changed, 4 insertions(+), 42 deletions(-) diff --git a/channeldb/payments.go b/channeldb/payments.go index 7c5f49a2..16497dcd 100644 --- a/channeldb/payments.go +++ b/channeldb/payments.go @@ -116,6 +116,9 @@ const ( // FailureReasonInsufficientBalance indicates that we didn't have enough // balance to complete the payment. + // + // This reason isn't assigned anymore, but may still exist for older + // payments. FailureReasonInsufficientBalance FailureReason = 4 // TODO(halseth): cancel state. diff --git a/routing/pathfind.go b/routing/pathfind.go index 1365958c..3241fb12 100644 --- a/routing/pathfind.go +++ b/routing/pathfind.go @@ -478,7 +478,7 @@ func findPathInternal( return nil, err } if max < amt { - return nil, errInsufficientBalance + return nil, errNoPathFound } } diff --git a/routing/pathfind_test.go b/routing/pathfind_test.go index 68662119..deaa4ea5 100644 --- a/routing/pathfind_test.go +++ b/routing/pathfind_test.go @@ -2809,37 +2809,6 @@ func TestRouteToSelf(t *testing.T) { ctx.assertPath(path, []uint64{1, 3, 2}) } -// TestInsufficientBalance tests that a dedicated error is returned for -// insufficient local balance. -func TestInsufficientBalance(t *testing.T) { - t.Parallel() - - testChannels := []*testChannel{ - symmetricTestChannel("source", "target", 100000, &testChannelPolicy{ - Expiry: 144, - FeeBaseMsat: 500, - }, 1), - } - - ctx := newPathFindingTestContext(t, testChannels, "source") - defer ctx.cleanup() - - paymentAmt := lnwire.NewMSatFromSatoshis(100) - target := ctx.keyFromAlias("target") - - ctx.graphParams.bandwidthHints = map[uint64]lnwire.MilliSatoshi{ - 1: lnwire.NewMSatFromSatoshis(50), - } - - // Find the best path to self. We expect this to be source->a->source, - // because a charges the lowest forwarding fee. - _, err := ctx.findPath(target, paymentAmt) - if err != errInsufficientBalance { - t.Fatalf("expected insufficient balance error, but got: %v", - err) - } -} - type pathFindingTestContext struct { t *testing.T graphParams graphParams diff --git a/routing/payment_session.go b/routing/payment_session.go index 6a597ff0..b439420f 100644 --- a/routing/payment_session.go +++ b/routing/payment_session.go @@ -26,10 +26,6 @@ const ( // not exist in the graph. errNoPathFound - // errInsufficientLocalBalance is returned when none of the local - // channels have enough balance for the payment. - errInsufficientBalance - // errEmptyPaySession is returned when the empty payment session is // queried for a route. errEmptyPaySession @@ -50,9 +46,6 @@ func (e noRouteError) Error() string { case errEmptyPaySession: return "empty payment session" - case errInsufficientBalance: - return "insufficient local balance" - default: return "unknown no-route error" } @@ -69,9 +62,6 @@ func (e noRouteError) FailureReason() channeldb.FailureReason { return channeldb.FailureReasonNoRoute - case errInsufficientBalance: - return channeldb.FailureReasonInsufficientBalance - default: return channeldb.FailureReasonError }