Use channel balance in path-finding #1395
The path finding algorithm uses channel capacity instead of htlcMaximumMsat. It also takes into account channel balance when available and excludes channels that don't have enough funds to relay the payment. This change also fixes an off-by-one error in weight computation: we were incorrectly applying a channel's fee to the amount that needs to be relayed through that channel (whereas this is instead what the node needs to receive to collect enough fee *before* relaying).
There were a couple confusing steps in the implementation of Yen's algorithm. The first one was the computation of the `edgesToIgnore` and the specific handling of the case i = 0. This specific case wasn't needed and made the code a bit hard to read. The second one was the weight provided to dijkstra for spur paths. The weight of the root path was applied to the target node. It was probably an attempt to take into account the fact that dijkstra wasn't computing a complete path and that fees may not match, but it couldn't really work. I removed that and added a fee check at the end of the path-finding.
That's a reasonable argument indeed, the thing that lead me to that refactoring was mostly the
EDIT: done in 702493f, let me know what you think (I can revert that commit if needed).
This is handled by the added call to
If you have a current shortest path
I think it's better to do a "normal" dijkstra to find