From 7ce3a152a132405704edb4ece8cdaf02160cf09e Mon Sep 17 00:00:00 2001 From: Carla Kirk-Cohen Date: Mon, 30 Oct 2023 15:29:38 -0400 Subject: [PATCH] routing/refactor: add failNode helper to final outcome processing Note: this refactor updates the inequality used from >= 2 to > 1 to align with the rest of this file so that we express this concept consistently throughout the code. --- routing/result_interpretation.go | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/routing/result_interpretation.go b/routing/result_interpretation.go index 1534ba6de..ad7f7d2fd 100644 --- a/routing/result_interpretation.go +++ b/routing/result_interpretation.go @@ -201,6 +201,17 @@ func (i *interpretedResult) processPaymentOutcomeFinal( n := len(route.Hops) + failNode := func() { + i.failNode(route, n) + + // Other channels in the route forwarded correctly. + if n > 1 { + i.successPairRange(route, 0, n-2) + } + + i.finalFailureReason = &reasonError + } + // If a failure from the final node is received, we will fail the // payment in almost all cases. Only when the penultimate node sends an // incorrect htlc, we want to retry via another route. Invalid onion @@ -256,18 +267,11 @@ func (i *interpretedResult) processPaymentOutcomeFinal( // destination correctly. Continue the payment process. i.successPairRange(route, 0, n-1) + // All other errors are considered terminal if coming from the + // final hop. They indicate that something is wrong at the + // recipient, so we do apply a penalty. default: - // All other errors are considered terminal if coming from the - // final hop. They indicate that something is wrong at the - // recipient, so we do apply a penalty. - i.failNode(route, n) - - // Other channels in the route forwarded correctly. - if n >= 2 { - i.successPairRange(route, 0, n-2) - } - - i.finalFailureReason = &reasonError + failNode() } }