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:
Carla Kirk-Cohen 2023-10-30 15:29:38 -04:00
parent b82478a7e7
commit 7ce3a152a1
No known key found for this signature in database
GPG Key ID: 4CA7FE54A6213C91

View File

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