How does lnd make sure it does not reuse the same route twice for a retry after the first payment failed?

2

Suppose LND node A wants to send a payment to another node D. The pathfind algorithm based on Dijkstra found a route through B and C and initiates the payment. It fails, as B -> C does not have sufficient balance/bandwidth.

Will LND just fail the payment or try another time with a different route? How does it remember the failed route?

Follow-up question: Can node A figure out, which edge failed?


Edit: To be more clear, in my example, all channels have 0.5BTC as capacity, and all of them have an equal balance distribution of this capacity (0.25, 0.25), except for B -> C, which has (0, 0.5), so B currently cannot send any payments to C.

The balance state (here: (0, 0.5)) is private, but the capacity of all channels is public.

As the routing computation is done in A (source routing), the algorithm initially has no knowledge of the balances. If A just wants to send 0.001BTC, the routing algorithm will find the route, but it cannot reach the target.

wtho

Posted 2019-10-18T15:42:59.833

Reputation: 23

Answers

0

So I went ahead and looked at the LND implementation here: https://github.com/lightningnetwork/lnd/blob/master/routing/pathfind.go and this is the comment block above the function findPath:

findPath attempts to find a path from the source node within the ChannelGraph to the target node that's capable of supporting a payment of amt value. The current approach implemented is modified version of Dijkstra's algorithm to find a single shortest path between the source node and the destination. The distance metric used for edges is related to the time-lock+fee costs along a particular edge. If a path is found, this function returns a slice of ChannelHop structs which encoded the chosen path from the target to the source. The search is performed backwards from destination node back to source. This is to properly accumulate fees that need to be paid along the path and accurately check the amount to forward at every node against the available bandwidth.

If this is the case then I don't think your scenario would play out. It appears LND wouldn't return the path A --> B --> C --> D because it does not have sufficient balance/bandwidth.

Matthew Cruz

Posted 2019-10-18T15:42:59.833

Reputation: 74

Yeah, that is the general aim of findPath, but as long as bandwidthHints is not set, it has no "available bandwidth". bandwidthHints usually is only set for the outgoing channel of A. I also extended my problem description. If it actually sets bandwidth hints from e. g. failed routes, that would exactly be what I am interested in!wtho 2019-10-27T15:04:23.167

The distribution of the balance in a channel is not public information, so lnd wouldn't know that the funds are all on the side of C in B->C before attempting to route the payment through the channel.Murch 2019-10-27T17:25:43.757