routing: account for case where final destination send TemporaryChannelFailure
In this commit, we fix an existing bug that could cause lnd to crash if we sent a payment, and the *destination* sent a temp channel failure error message. When handling such a message, we’ll look in the nextHop map to see which channel was *after* the node that sent the payment. However, if the destination sends this error, then there’ll be no entry in this map. To address this case, we now add a prevHop map. If we attempt to lookup a node in the nextHop map, and they don’t have an entry, then we’ll consult the prevHop map. We also update the set of tests to ensure that we’re properly setting both the prevHop map and the nextHop map.
This commit is contained in:
4 files changed
+78
-5
No files matched your search
+15
-2
@@ -1549,6 +1549,10 @@ func (r *ChannelRouter) SendPayment(payment *LightningPayment) ([32]byte, *Route
|
||||
|
||||
errSource := fErr.ErrorSource
|
||||
|
||||
log.Tracef("node=%x reported failure when sending "+
|
||||
"htlc=%x", errSource.SerializeCompressed(),
|
||||
payment.PaymentHash[:])
|
||||
|
||||
switch onionErr := fErr.FailureMessage.(type) {
|
||||
// If the end destination didn't know they payment
|
||||
// hash, then we'll terminate immediately.
|
||||
@@ -1650,13 +1654,22 @@ func (r *ChannelRouter) SendPayment(payment *LightningPayment) ([32]byte, *Route
|
||||
// error was meant to pass the HTLC along to.
|
||||
badChan, ok := route.nextHopChannel(errSource)
|
||||
if !ok {
|
||||
continue
|
||||
// If we weren't able to find the hop
|
||||
// *after* this node, then we'll
|
||||
// attempt to disable the previous
|
||||
// channel.
|
||||
badChan, ok = route.prevHopChannel(
|
||||
errSource,
|
||||
)
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
// If the channel was found, then we'll inform
|
||||
// mission control of this failure so future
|
||||
// attempts avoid this link temporarily.
|
||||
paySession.ReportChannelFailure(badChan)
|
||||
paySession.ReportChannelFailure(badChan.ChannelID)
|
||||
continue
|
||||
|
||||
// If the send fail due to a node not having the
|
||||
|
||||
Reference in new issue
Block a user