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.
This commit is contained in:
1 file changed
+15
-11
@@ -201,6 +201,17 @@ func (i *interpretedResult) processPaymentOutcomeFinal(
|
|||||||
|
|
||||||
n := len(route.Hops)
|
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
|
// 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
|
// payment in almost all cases. Only when the penultimate node sends an
|
||||||
// incorrect htlc, we want to retry via another route. Invalid onion
|
// 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.
|
// destination correctly. Continue the payment process.
|
||||||
i.successPairRange(route, 0, n-1)
|
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:
|
default:
|
||||||
// All other errors are considered terminal if coming from the
|
failNode()
|
||||||
// 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
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user