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

Bitcoin Asked by wtho on December 14, 2021

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.

In fact, finding a route in LND can be described as the process of finding the "shortest path" on a weighted graph. In LND, the weight of each channel is composed of three parts, fee, CLTV_DELTA and the probability. You'll understand the first two factors if you are familiar with the Lightning Network, and the last factor is the probability that this channel can afford the payments from a local perspective.

If a route fails, then the node with insufficient capacity will actively include this information in the return message, which can only be unlocked and seen by the payer. For example, Then the payer will reduce the probability of this channel in the local view and find the route again (you can treat it as setting the weight of this edge to very large).

You can find detailed information here.

Answered by Zhichun Lu on December 14, 2021

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.

Answered by Matthew Cruz on December 14, 2021

## Related Questions

### What makes cross input signature aggregation complicated to implement?

1  Asked on January 2, 2021

### In a Proof of Stake (PoS) mining scheme what prevents miners from producing many more blocks or inflating the currency?

1  Asked on December 25, 2020 by kristopher-ives

### What kinds of wallets are there?

3  Asked on December 23, 2020 by karlito

### From Edge to Poloniex

1  Asked on December 22, 2020 by don-myers

### In theory could we skip the proposed Taproot soft fork, activate Simplicity instead and use Simplicity to write the equivalent of Taproot scripts?

1  Asked on December 20, 2020 by michael-folkson

### i have 0.10096 mbtc (0.00010096 BTC) in my btc wallet but when ever i try to send bitcoins it always says your balance is low to pay the fee

2  Asked on December 20, 2020 by noor-siddiq

### Create Raw Transaction in BitcoinJ offline starting from UTXO info

1  Asked on December 19, 2020 by andrean

### How do I calculate transaction fee for call to createpsbt()?

1  Asked on December 18, 2020

### What is the longest firstbits?

1  Asked on December 17, 2020 by lurf-jurv

1  Asked on December 15, 2020 by theruss

### Bip39 tool – BIP32 Extended Private Key vs BIP32 Root Key

1  Asked on December 14, 2020 by guillaume07

### How to configure bitcoind to wait for X confirmations to make the payment submitted

1  Asked on December 13, 2020 by valometrics-com

### Stale block verification at node level

2  Asked on December 10, 2020 by user87441

### How to import address with private key using importmulti

1  Asked on December 8, 2020 by kimon

### What is the program in Python that print information about the current block?

1  Asked on December 6, 2020 by roofnos

### What exactly is the relation between Bisq and Bitcoin Core?

1  Asked on December 5, 2020 by j-lotz

### How to automatically get transaction while sending BTC?

0  Asked on December 2, 2020 by abhishek-pandey