I have been fixing renepay lately and thanks to some insightful discussions and brainstorming with René Pickhardt we have had great improvements.

In summary, the current Mininum Cost Flow algorithm (MCF) cannot allocate fees as part of the payment amount due to the sats conservation assumption that the only source and sink of flow are the sender and recipient nodes. Once fees are added on top this resulted in channels being asked to forward more sats than their probable available liquidity and consequently possibly an infinite loop of failures. To fix this we take the routes computed by the MCF and reduce their sending amount to fit all liquidity constraints:

fee, uncertainty and max_htlc; then deficit in the delivering amount is redistributed among the other routes or reallocated in a new MCF computation if necessary.

More details at this PR: https://github.com/ElementsProject/lightning/pull/6893

before:

after:

Reply to this note

Please Login to reply.

Discussion

How do you get the possible routes to use?

Min. Cost Flow, where the cost function is a combination of uncertainty and fees. This is the implementation of Pickhardt-Richter's idea. https://arxiv.org/abs/2107.05322

I mean are you calling any of the other CLN commands/plugins when you are carrying out the min cost flow process?

No, MCF is done with a model of the network. RPC communication with CLN is needed to send the onions, we call sendpay.

Liquidity Bound Calculation for Lightning Network

1. Inbound Liquidity (IL): The liquidity available for receiving funds.

2. Outbound Liquidity (OL): The liquidity available for sending funds.

3. Transaction Fees (TF): Fees associated with channel transactions.

4. Network Demand Factor (NDF): A factor reflecting network demand and routing.

5. Safety Margin (SM): A buffer for volatility and unexpected scenarios.

We can express the liquidity components as follows:

6. Total Capacity:

TotalCapacity = IL + OL

7. Available Liquidity:

AvailableLiquidity = min(IL, OL)

8. Adjusted Liquidity:

AdjustedLiquidity = AvailableLiquidity - TF

= min(IL, OL) - TF

9. Effective Liquidity:

EffectiveLiquidity = AdjustedLiquidity * NDF

= (min(IL, OL) - TF) * NDF

10. Safe Liquidity Bound:

SafeLiquidityBound = EffectiveLiquidity - SM

= ((min(IL, OL) - TF) * NDF) - SM

Example 1:

11. Inbound Liquidity (IL): 3 BTC

12. Outbound Liquidity (OL): 2 BTC

13. Transaction Fees (TF): 0.01 BTC

14. Network Demand Factor (NDF): 0.9

15. Safety Margin (SM): 0.05 BTC

Calculation:

16. Total Capacity: 3 BTC + 2 BTC = 5 BTC (Not directly needed for the final calculation)

17. Available Liquidity: min(3 BTC, 2 BTC) = 2 BTC

18. Adjusted Liquidity: 2 BTC - 0.01 BTC = 1.99 BTC

19. Effective Liquidity: 1.99 BTC * 0.9 = 1.791 BTC

20. Safe Liquidity Bound: 1.791 BTC - 0.05 BTC = 1.741 BTC

Example 2:

21. Inbound Liquidity (IL): 1.5 BTC

22. Outbound Liquidity (OL): 4 BTC

23. Transaction Fees (TF): 0.02 BTC

24. Network Demand Factor (NDF): 0.8

25. Safety Margin (SM): 0.1 BTC

Calculation:

26. Total Capacity: 1.5 BTC + 4 BTC = 5.5 BTC (Not directly needed for the final calculation)

27. Available Liquidity: min(1.5 BTC, 4 BTC) = 1.5 BTC

28. Adjusted Liquidity: 1.5 BTC - 0.02 BTC = 1.48 BTC

29. Effective Liquidity: 1.48 BTC * 0.8 = 1.184 BTC

30. Safe Liquidity Bound: 1.184 BTC - 0.1 BTC = 1.084 BTC