Research/Bitcoin Dev Archive / lightning-dev list
Code for sub second runtime of piecewise linarization to quickly approximate the minimum convex cost flow problem (makes fast multi part payments with large amounts possible)
9 messages, Mar 11 to 21, 2022. Started by René Pickhardt.
René Pickhardt (3), Carsten Otto (2), Martin (2), ZmnSCPxj, Stefan Richter
Dear fellow Lightning Developers,
I am pleased (and a bit proud) to be able to inform you that I finally found a quick way to approximate the slow minimum convex cost flow computation. This is necessary for optimally reliable and cheap payment flows [0] to deliver large multi part payments over the Lightning Network. The proposed solution happens via piecewise linearization [1] of the min cost flow problem on the uncertainty network which we face in order to compute the optimal split and planning of large amount multi part payments. The notion of "optimal" is obviously subjective with respect to the chosen cost function. As known we suggest to include the negative logarithm of success probabilities based on the likelihood that enough liquidity is available on a channel as a dominant feature of the used cost function. We give the background for this in [2] which since then has already been picked up by c-lightning and LDK. The c-lightning team even published benchmarks showing significant improvement in payment speed over their previously used cost function [2b].
Let me recall that one of the largest criticisms and concerns of our approach to use minimum cost flows for payment delivery back in July / August last year (especially by the folks from lightning labs) was that the min cost flow approach would be impractical due to run time constrains. Thus I am delighted that with the now published code [3] (which has exactly 100 lines including data import and parsing and ignoring comments) we are able to compute a reasonable looking approximation to the optimal solution in a sub second run time on the complete public channel graph of the Lightning Network. This is achieved via piecewise linearization of the convex cost function and invoking of a standard linear min cost flow solver [4] for the linearized problem. This works quickly despite the fact that the piecewise linearization adds a significant higher amount of arcs to the network and blows up the size of the network on which we solve the min cost flow problem. This makes me fairly certain that with proper pruning of the graph we might even reach the 100 millisecond runtime frontier, which would be far faster than what I dreamed & hoped to be possible.
The currently widely deployed Dijkstra search to generate a single candidate path takes roughly 100ms of runtime. It seems that with the runtime of the piecewise linearized problem the min cost flow approach is now competitive from a runtime perspective. The flow computation is still a bit slower than Dijkstra in both theory and practice. However the piecewise linearized min cost flow has the huge advantage that it generates several candidate paths for a solid approximation of the optimal MPP split. Remember the exact min cost flow corresponds to the optimal MPP split. The later was not used so far as the min cost flow was considered to be too slow. Yet the question how to split seems to be addressed as issues in implementations [5][6][7] and acknowledged to be complicated (especially with respect to fees) in [8]. This result is btw of particular interest for LSPs. If an LSP has to schedule x payments per second it can just do one flow computation with several sink nodes and plan all of those payments with a single min cost flow computation. This globally optimizes the potentially heavy load that LSPs might have even if all payments were so small that no splitting was necessary.
The iPython notebook which I shared contains about 1 page to explain how to conduct a piecewise linear approximation. The quality of the approximation is not the major goal here as I am just focused to demonstrate the run time of the approach and the principle how to achieve this runtime. Thus I do the piecewise linear approximation very roughly in the published code. Selecting the optimal piecewise approximation [9] will not change the the runtime of flow computation but only blows up the code to prepare the solver. This is why I decided to keep the code as simple and short as possible even if that means that the approximation will be not as close to the optimum as it could be in practice. For the same reason I did not include any code to update the uncertainty network from previously failed or successful attempts by using conditional success probabilities P(X>a | min_liquidity < X < max_liquidity ). People who are interested might look at my hands on instructions and explanations for coders in this rust-lightning issue [10]. The folks from LDK have picked this up and implemented this already for single path payments in [11] which might be relevant for people who prefer code over math papers. An obvious optimization of the piece wise linearization would be to chose the first segment of the piecewise linear approximation with a capacity of the certain liquidity and a unit cost of 0 for that piece.
Our original papers describe everything only from a theoretical point of view and with simulations. However our mainnet experiments from July last year [12] indicated that we easily have been able to deliver for example 0.3679 BTC via a couple rounds of min cost flow computations through the Lightning Network (given we accept the computational waiting time). This experiment was too slow to be used in practice but confirmed our model and approach to deliver such large amounts. Given that the min cost flow computation is now significantly below the median onion round trip times it is my understanding that with these newly introduced techniques we should be able to deliver substantial monetary amounts over the Lightning Network within a couple of seconds despite the uncertainty about the Liquidity in remote channels. While I am very excited about the result I think some principle roadblocks of the protocol are becoming more and more visible:
1. The well known issue of hanging HTLCs. As of now I believe onion messages would be great to acknowledge incoming HTLCs of multipart payments but I certainly believe this will not be sufficient if we don't go for a cancelable & stuckless payment protocol as suggested in [13]. 2. I believe the Lightning Network Protocol should be able to handle redundant overpayments as suggested in [14] and [15] (The later paper derives independently of us the same success probabilities and tries to maximize them!). This would allow to transform the problem of finding a flow that maximizes the success probability to a flow that expects to deliver the amount of the invoice (when redundancy is applied) with a single round of min cost flow computation on average.
Last but not least, please allow me to make a short remark on the (still to me very surprisingly controversial) base fee discussion: For simplicity I did not include any fee considerations to the published code (besides a fee report on how expensive the computed flow is). However in practice we wish to optimize at least for high reliability (via neg log success probabilities) and cheap fees which in particular with the ppm is very easily possible to be included to the piece wise linearized cost function. While for small base fees it seems possible to encode the base fee into the first segment of the piecewise linearized approximation I think the base fee will still be tricky to be handled in practice (even with this approximation). For example if the base fee is too high the "base fee adjusted" unit cost of the first segment of the piecewise linearized problem might be higher than the unit cost of the second segment which effectively would break the convexity. Thus I reiterate my earlier point that from the perspective of the year long pursued goal of optimizing for fees (which all Dijkstra based single path implementations do) it seems to be best if the non linearity that is introduced by the base fee would be removed at all. According to discussions with people who crate Lightning Network explorer (and according to my last check of gossip) about 90% of channels have a base fee of 1 sat or lower and ~38% of all channels already set their base fee away from the default value to 0 [16].
I hope this mail was useful for you. Feel free to ask me anything if there should be questions or if you need help to integrate those results into your software!
With kind regards Rene Pickhardt
[0]: https://arxiv.org/abs/2107.05322 [1]: https://en.wikipedia.org/wiki/Piecewise_linear_function [2]: https://arxiv.org/abs/2103.08576 [2b]: https://medium.com/blockstream/c-lightning-v0-10-2-bitcoin-dust-consensus-rule-33e777d58657
[3]: https://github.com/renepickhardt/mpp-splitter/blob/master/Minimal%20Linearized%20min%20cost%20flow%20example%20for%20MPP.ipynb [4]: https://developers.google.com/optimization/flow/mincostflow [5]: https://github.com/lightningnetwork/lnd/issues/4203 [6]: https://github.com/lightningdevkit/rust-lightning/issues/1276 [7]: https://github.com/ElementsProject/lightning/issues/4753 [8]: https://github.com/ACINQ/eclair/pull/1427 [9]: http://www.iaeng.org/publication/WCECS2008/WCECS2008_pp1191-1194.pdf [10]: https://github.com/lightningdevkit/rust-lightning/issues/1170#issuecomment-972396747 [11]: https://github.com/lightningdevkit/rust-lightning/pull/1227 [12]: https://twitter.com/renepickhardt/status/1418849788531990530 [13]: https://www.learnbitcoin.com/archive/lists/lightning-dev/t/2019/proposal-for-stuckless-payment#m-a66b0308 [14]: https://berkeley-defi.github.io/assets/material/1910.01834.pdf [15]: https://dl.acm.org/doi/10.1145/3479722.3480997 [16]: https://lnrouter.app/graph/zero-base-fee
Hi Rene,
thanks a lot for your contribution! This is exactly what I needed to start coding again :) I intend to release a somewhat usable version of your approach in lnd-manageJ [1] soon. Preliminary results indicate that results (i.e. MPPs to try) can be computed in less than a second, which is great!
Important remark: my code can only be used for real MPPs once a usable MPP gRPC call is made available, see lnd issue #5746 [2].
While working on my implementation, a few questions came to mind:
1) What's the reasoning behind combining parallel channels?
I agree that parallel channels make things a lot more complicated, but I also see the benefit from a node operator's point of view. That being said, wouldn't it suffice to treat parallel channels individually?
1.1) A payment of size 2 needs to be split into 1+1 to fit through parallel channels of size 1+1. Combining the 1+1 channels into a virtual channel of size 2 only complicates the code that has to do come up with a MPP that doesn't over-saturate the actual channels. On the other hand, I don't think the probability for the virtual channel of size 2 is more realistic than reasoning about two individual channels and their probabilities - but I didn't even try to see the math behind that. Please prove me wrong? :)
1.2) The Mission Control information provided by lnd can be used to place a minimum available balance on each of the parallel channels. If we know that node A isn't able to forward N sats to node B, we can treat all parallel channels between A and B (in that direction) to have a capacity of at most N-1 sats. How would this look like if we combined the parallel channels into a virtual one? Note that it may still be possible to route two individual payments/onions of size N-1 sats from A to B, given two parallel channels with that many sats on A's side.
2) Optimal Piecewise Linearization
See Twitter [3].
Is it worth it cutting a channel into pieces of different sizes, instead of just having (as per your example) 5 pieces of the same size? If it makes a noticeable difference, adding some complexity to the code might be worth it.
3) Size of Piecewise Linearization
My gut feeling is that cutting a 1 BTC channel into 5 pieces is different from cutting a 0.01 BTC channel into 5 pieces. Would it make sense to use different values of N depending on the channel size?
4) Leftovers after Piecewise Linearization
If I cut some channel into N pieces, I might end up with up to N-1 sats that don't end up in any of the N pieces, effectively making the channel look smaller than it is. For smaller values of N that's obviously not an issue (given the uncertainty we're dealing with), but it might be more problematic if quantization is used with larger values. Any thoughts on this?
5) Fees (and other properties?)
How can we integrate fees into the function? I must admit, I haven't even thought about that, yet. A copy-paste answer would be great, though! :) Maybe it's also a good idea to punish channels based on their CLTV delta? Ratio of enabled channels? Age? Manual punishment score? ...
6) Non-Zero Base Fee
See Twitter [4].
According to Stefan [5] it should be possible to integrate ZmnSCPxj's ideas to make this work with non-zero base fees. How? Simpler approach: Twitter [6].
7) Private Channels
[very niche topic, not really that interesting nor urgent]
I'm a fan of adding private channels to provide more outbound liquidity, mainly to reduce gossip and hide my intentions. If my total liquidity to some peer is below the amount announced in public channels, I don't see any meaningful complication. However, I might have a public channel of size N and several private channels bringing my local liquidity to some value >N. It's rather obvious that not announcing this fact is a bad idea, as any #pickhardtpayments implementation would think I have 0-N on my side of the channel(s). Assuming I'm willing to accept this tradeoff, do you see other complications or issues with hidden liquidity?
My gut feeling is that this isn't an issue, at all, as channel balances change all the time, which is something the algorithm already has to deal with.
8) Quality of Approximation
There are some problems in computer science that are hard/impossible to approximate, in the sense that any kind of deviation from the optimum could cause the computed results to be extremely bad. Do you have some idea (or proof) that your kind of approximation isn't causing a major issue? I guess a piece-wise linearization with an infinite number of pieces corresponds to the optimal result. Given a finite number of pieces, how large is the difference to the optimum?
Bye, Carsten
1: https://github.com/C-Otto/lnd-manageJ/issues/6 2: https://github.com/lightningnetwork/lnd/issues/5746 3: https://twitter.com/c_otto83/status/1502329970349248521 4: https://twitter.com/c_otto83/status/1502329271964033027 5: https://twitter.com/stefanwouldgo/status/1502681455918473217 6: https://twitter.com/c_otto83/status/1502330558793363464
Dear Carsten, Martin and fellow lightning developers,
first of all thank you very much for independently verifying and acknowledging my recent findings about the runtime of finding a pieceweise linearized approximation to the min cost flow problem, for working on integrating them into lnd-manageJ and for your excellent questions & thoughts.
On Sun, Mar 13, 2022 at 8:17 PM Carsten Otto via Lightning-dev < lightning-dev at lists.linuxfoundation.org> wrote:
Quoted text (2 lines)
> 1) What's the reasoning behind combining parallel channels? >
Generally speaking this is pure pragmatism on my end to simplify my life as handling parallel channels in some cases blows up complexity of code and simulations. However I think from a probabilistic point of view ( see below ) the combination is more accurate to reflect the actual likelihood that the liquidity is available.
Quoted text (4 lines)
I agree that parallel channels make things a lot more complicated, but I > also see the benefit from a node operator's point of view. That being > said, wouldn't it suffice to treat parallel channels individually? >
I think that should work and especially when including fees to the cost function and considering how nodes handle routing requests on parallel channels we might have to do so anyway. The suggested flows will probably change in a way that disfavors parallel channels even if their virtual capacity is larger than an alternative single channel (see below)
Quoted text (9 lines)
1.1) A payment of size 2 needs to be split into 1+1 to fit through > parallel channels of size 1+1. Combining the 1+1 channels into a virtual > channel of size 2 only complicates the code that has to do come up with > a MPP that doesn't over-saturate the actual channels. On the other hand, > I don't think the probability for the virtual channel of size 2 is more > realistic than reasoning about two individual channels and their > probabilities - but I didn't even try to see the math behind that. > Please prove me wrong? :) >
* The likelihood that a 1 Satoshi capacity channel has 1 Satoshi to route is 1/2. * The likelihood that 2 channels of capacity 1 have each 1 satoshi available to route is 1/2*1/2 = 1/4 * Combining both parallel channels to one virtual channel of capacity 2 and asking if 2 satoshis are available to route gives a likelihood of 1/3 which is larger than 1/4.
However I believe in practice one cannot just send a 2 satoshi onion and expect the routing node to split the amount correctly / accordingly between the two parallel channels. (I might be wrong here). So in that case modelling and computing probabilities for parallel channels might be necessary anyway though the math indicates that splitting liquidity in parallel channels will get you selected less frequently for routing.
Quoted text (9 lines)
1.2) The Mission Control information provided by lnd can be used to > place a minimum available balance on each of the parallel channels. If > we know that node A isn't able to forward N sats to node B, we can treat > all parallel channels between A and B (in that direction) to have a > capacity of at most N-1 sats. How would this look like if we combined > the parallel channels into a virtual one? Note that it may still be > possible to route two individual payments/onions of size N-1 sats from A > to B, given two parallel channels with that many sats on A's side. >
I think you talk a about a maximum available balance of a channel (and not min available balance)? In the case of parallel channels I am not even sure if such information is accurate as it is my understanding that the routing node may decide to use the parallel channel to forward the amount even though the other channel was specified in the onion. Assuming that routing nodes indeed do so we would have learnt that neither channel has an effective capacity of N. So the combined virtual channel could be seen as 2N-1. However if routing nodes don't locally split a forwarding request across both channels we would know that calaculating with 2N-1 is bad as a request of N could not be fulfilled. I guess it is for the implementations that support parallel channels to figure out the details here.
Quoted text (9 lines)
2) Optimal Piecewise Linearization > > See Twitter [3]. > > Is it worth it cutting a channel into pieces of different sizes, instead > of just having (as per your example) 5 pieces of the same size? If it > makes a noticeable difference, adding some complexity to the code might > be worth it. >
I will certainly do experiments or be happy if others are faster to do them which compare the quality of the approximation with optimal piecewise linearization to my choice of fixed intervals and the selection of various numbers of segments. As long as we don't have numbers it is hard to guess if it is worthwhile adding the complexity. Looking at the current results it seems that my (geometricly motivated but) arbitrary choice might end up to be good and easy enough. However we might very well see quite an improvement of the approximation if we find better piecewise linearizations.
Quoted text (6 lines)
> 3) Size of Piecewise Linearization > > My gut feeling is that cutting a 1 BTC channel into 5 pieces is > different from cutting a 0.01 BTC channel into 5 pieces. Would it make > sense to use different values of N depending on the channel size? >
The main difference here is that a channel of 1 BTC is highly preferable from a probabilistic payment delivery perspective over a channel of 0.01 BTC. Even approximating the 1 BTC channel with 1000 intervalls of 0.001 BTC should still have a lower unit cost in all pieces of the first 0.01 BTC of the liquidity than the first piece of the 0.01 BTC channel. So I think splitting all channels in the equal number of pieces is pretty well motivated but let me elaborate on this:
The motivation of splitting all channels into the same number of pieces comes from the observation that from a probabilistic point of view (and very roughly speaking!) we want to find a flow that puts the same (high) success probability on all edges. Using 20% of the capacity gives an 80% probability that the liquidity is available. This in turn has a 51.2% chance to be successful on a three hop path which in my experience is a good probability to aim for as on average one is expected to need two attempts. Since the linearized pieces - if included in the flow - tend to be fully saturated I decided that it makes sense to put them in 5 buckets of 20% each. If you read the code carefully I don't even approximate the cost correctly at the 2nd, 3rd, 4th and 5th piece. I just multiplied the linearized unit cost of the first piece with 2,3,4 and 5 respectively Which approximates the negative log probability with a quadratic cost function. But as we can see those geometrically motivated choices work already pretty well. Again I plan to invest more time to find a better approximation and we might end up using it. But I don't expect too much gain from doing so.
If you look at the output of the flow in the iPython notebook (Which I will copy to the end of the mail for your convenience) you see that most channels did not fully saturate the first piece and have a likelihood between 80% and 100% where as some channels saturated the first piece producing a likelihood of 80% and few channels saturated also the second piece giving a likelihood of 60%.
Thus I expect that the real value from studying the optimal piece wise linear approximation will give us a better understanding of where to prune segments away. If we note that in this flow not a single channel used the third, forth and fifth piece we could have removed 60% of all edges and doubled the runtime and still compute the same resulting flow.
Quoted text (9 lines)
> 4) Leftovers after Piecewise Linearization > > If I cut some channel into N pieces, I might end up with up to N-1 sats > that don't end up in any of the N pieces, effectively making the channel > look smaller than it is. For smaller values of N that's obviously not an > issue (given the uncertainty we're dealing with), but it might be more > problematic if quantization is used with larger values. Any thoughts on > this? >
I am not sure if I understand your question / issue here. The splitting works by selecting N points on the domain of the function and splitting the domain into segments at those points. This should never leave sats over. The quantization which doesn't boost the runtime too much anyway happens before piecewise linearization. So as long as the domain is larger than N the piecewiese linearization should not bring up a situation where sats are left over. If the quantization however makes a channel so small that we cannot even create 5 (or N) disjoint segments then I guess the likelihood for being included into the final result is too small anyway. But I agree that an actual implementation might have to watch out for such edge cases.
Again this yield interesting pruning opportunities to reduce the seize of the network before doing the expensive min cost flow computation. For example I could prune channels with high unit costs on the first segment. Especially if they are further away from the source and destination node. This would overall reduce the size of the graph and improve runtime. Already last July I had a pretty well working heurist that was able to through away about 90% of all channels and would pretty much always find the same flow in the pruned network as on the full network. I should really prioritize the pruning work again now that we have fast solvers.
Quoted text (7 lines)
5) Fees (and other properties?) > > How can we integrate fees into the function? I must admit, I haven't > even thought about that, yet. A copy-paste answer would be great, > though! :) Maybe it's also a good idea to punish channels based on their > CLTV delta? Ratio of enabled channels? Age? Manual punishment score? ... >
plugging in fees (assuming only channels that set a base fee of zero) is very easy and straight forward.
Let's recall from the code that the piecewise linearized unit cost is computed as follows
unit_cost = int(max_cap/cap)for i in range(N):
#arc format is src, dest, capacity, unit_cost
arcs.append((src,dest,int(cap/(N*QUANTIZATION)),(i+1)*unit_cost))
As described in our paper for a good (and to be determined) value of \mu we could just create the linear combination between the two features which would change the line to:
arcs.append((src,dest,int(cap/(N*QUANTIZATION)),(i+1)*unit_cost + mu*fee_rate_ppm))
Note two things: 1. the only requirement for the solver to work is that \mu*fee_rate_ppm needs to be an integer. So in case \mu was smaller than 1 we could also scale the term from the linearized log probabilities by putting a larger mu to the feature arising from the cost of the uncertainty.
arcs.append((src,dest,int(cap/(N*QUANTIZATION)),mu*(i+1)*unit_cost + fee_rate_ppm))
2. the cost from the routing fees is the same on each segment of the piecewise linearization which makes a lot of sense because the current feerate is indeed a unit cost that does not change with how heavily you plan to use a channel independently how the cost that comes from the probability grows.
With respect to other features I guess the entire topic of feature engineering for our cost function should be a separate threat / topic and line of research but as you asked I will give you some short thoughts on this here:
As pointed out to the c-lightning team in https://github.com/ElementsProject/lightning/pull/4771#issuecomment-930173831 and the following comment I believe that optimizing for CLTV is a poor choice and in min cost flow computations it might very well be non linear anyway and thus tricky to include in a meaningful way.Sure one could transform it to a unit cost by doing something like CLTV*max_cap/cap and add it to the cost function like the ppm. But I still do not really see why this is useful. On the other hand I very much believe we should start to investigate features that predict channel latency to setup / settle an HTLC as suggested in the last paragraph of this comment https://github.com/lightningdevkit/rust-lightning/issues/1170#issuecomment-972396747 However I fear that latency measures again are non linear though they could again be translated to a unit cost with the same trick as the CLTV.
Quoted text (8 lines)
> 6) Non-Zero Base Fee > > See Twitter [4]. > > According to Stefan [5] it should be possible to integrate ZmnSCPxj's ideas > to make this work with non-zero base fees. How? > Simpler approach: Twitter [6]. >
I don't have much to add to the base fee discussion at this point besides the emphasize that the above described linearization trick for CLTV or latency based features will not properly work for the base fee because one actually has to pay the full base fee at the end - independently of how much you saturate the channel. This might mess up the optimization.
Quoted text (18 lines)
> 7) Private Channels > > [very niche topic, not really that interesting nor urgent] > > I'm a fan of adding private channels to provide more outbound liquidity, > mainly to reduce gossip and hide my intentions. If my total liquidity to > some peer is below the amount announced in public channels, I don't see > any meaningful complication. However, I might have a public channel of > size N and several private channels bringing my local liquidity to some > value >N. It's rather obvious that not announcing this fact is a bad > idea, as any #pickhardtpayments implementation would think I have 0-N on > my side of the channel(s). Assuming I'm willing to accept this tradeoff, > do you see other complications or issues with hidden liquidity? > > My gut feeling is that this isn't an issue, at all, as channel balances > change all the time, which is something the algorithm already has to > deal with. >
As you noted from a probabilistic payment delivery point of view I might be interested in signaling all the liquidity that is being provided between two peers and I shoot myself if I hide it. That being said you might have reasons to do so and additionally I never rejected the idea to extend the current probabilistic model with a probabilistic node or channel provenance value that would be similar to the ideas in lnd's mission control or the routescore by https://lnrouter.app. Given the fact that with hidden liquidity the probabilities are constantly underestimated such a provenance score will probably be higher than the one of other channels fixing the "introduced issue" of hidden liquidity
Quoted text (10 lines)
8) Quality of Approximation > > There are some problems in computer science that are hard/impossible to > approximate, in the sense that any kind of deviation from the optimum > could cause the computed results to be extremely bad. Do you have some > idea (or proof) that your kind of approximation isn't causing a major > issue? I guess a piece-wise linearization with an infinite number of > pieces corresponds to the optimal result. Given a finite number of > pieces, how large is the difference to the optimum? >
We don't have to go to infinite to find a solution without error. We can stay with the finite number that corresponds to the channels capacity and make segments of 1 satoshi each encoding what this satoshi would actually cost in the original function (assuming all values in the original function were integers).
I have not spent the time to properly express the error in dependence of the number of segments N or even empirically study its tradeoffs in practice (as I haven't even included the optimal piecewise linearization yet) However the actual flow (see below) as well as the results from Dr. Martin Berger https://www.learnbitcoin.com/archive/lists/lightning-dev/t/2022/code-for-sub-second-runtime-of-piecewise-linarization-to-quickly-approximate-2#m-629b531f indicate that the error should be possible to be managed and stay small enough in practice. That being said and as above it certainly makes sense to invest a bit of time on how to conduct the piecewise linearization properly.
Output of the computed flow from the iPython notebok with a piece wise linearization of 5 equal sized segments per channel
Planning to deliver 0.50 BTC from 5051(03efccf...) to 13006 (021c97a...) via an approximated optimally reliable payment flow...
Runtime of flow computation: 0.85 sec Minimum approximated quadratic cost: 815932
Arc Flow / Capacity probability Fee (sats) 5051 -> 8463 6700000 / 16777215 0.600649 8957.900000 5051 -> 3437 1800000 / 9000000 0.800000 2406.600000 5051 -> 9162 1240000 / 6200000 0.800000 1657.880000 5051 -> 14746 6700000 / 16777215 0.600649 8957.900000 5051 -> 14832 2000000 / 10000000 0.800000 2674.000000 6257 -> 14832 3350000 / 2411344242 0.998611 335.100000 14832 -> 12446 5350000 / 6200000000 0.999137 6.350000 7870 -> 6257 3350000 / 20000000 0.832500 34.500000 14746 -> 12446 6700000 / 100000000 0.933000 3350.000000 7914 -> 13006 6700000 / 200000000 0.966500 33501.000000 5051 -> 550 3300000 / 15000000 0.780000 4412.100000 11396 -> 13192 6700000 / 1000000000 0.993300 2010.000000 5051 -> 11396 6700000 / 16777215 0.600649 8957.900000 7199 -> 9162 3350000 / 445000000 0.992472 848.550000 9162 -> 12446 16590000 / 3900000000 0.995746 17.590000 5051 -> 13287 2000000 / 10000000 0.800000 2674.000000 5051 -> 1843 6700000 / 16777215 0.600649 8957.900000 5051 -> 11257 3350000 / 16777215 0.800324 4478.950000 1953 -> 12446 2160000 / 750000000 0.997120 1080.000000 550 -> 1843 3300000 / 30000000 0.890000 1155.000000 12756 -> 12446 2000000 / 16775679 0.880780 301.000000 5051 -> 12756 2000000 / 10000000 0.800000 2674.000000 3437 -> 12446 1800000 / 400000000 0.995500 225.001000 6713 -> 7914 6700000 / 200000000 0.966500 837.501000 11257 -> 7199 3350000 / 16777215 0.800324 663.300000 10914 -> 9162 2000000 / 500000000 0.996000 1000.001000 5051 -> 7870 3350000 / 16777215 0.800324 3.781000 8463 -> 5288 6700000 / 500000000 0.986600 837.501000 2781 -> 10914 2000000 / 500000000 0.996000 401.000000 13192 -> 6713 6700000 / 500000000 0.986600 16750.000000 32 -> 2781 2000000 / 210000000 0.990476 200.000000 5051 -> 9530 2160000 / 10811137 0.800206 2.591000 9530 -> 1953 2160000 / 16777215 0.871254 438.336000 1843 -> 9162 10000000 / 300000000 0.966667 2500.000000 5051 -> 14642 2000000 / 10000000 0.800000 2.431000 14642 -> 13006 2000000 / 50000000 0.960000 6001.000000 13287 -> 32 2000000 / 16777215 0.880791 500.000000 12446 -> 13006 34600000 / 200000000 0.827000 103766.400000 5288 -> 13006 6700000 / 100000000 0.933000 15216.700000
Probability of entire flow: 0.0032 Total fee: 248793.763 sats Effective fee rate: 0.498 % Arcs included in payment flow: 39
Don't get confused by a low probability. The first attampt always has high uncertainty. We will learn fast in each consequitive round.
With kind regards Rene Pickhardt
Hi Rene,
On Mon, Mar 14, 2022 at 12:56:24PM +0100, René Pickhardt via Lightning-dev wrote:
Quoted text (4 lines)
> > 1) What's the reasoning behind combining parallel channels? > I think that should work and especially when including fees to the > cost function and considering how nodes handle routing requests on > parallel channels we might have to do so anyway.
I think lnd accepts the minimum fee of all parallel channels, even if a higher fee rate is configured for the channel that is actually used. I'm not too sure about this, though. Having parallel channels with different fee settings seems weird to me, anyway.
Quoted text (4 lines)
> 1.1) A payment of size 2 needs to be split into 1+1 to fit through > However I believe in practice one cannot just send a 2 satoshi onion and > expect the routing node to split the amount correctly / accordingly > between the two parallel channels. (I might be wrong here).
Exactly. This kind of split could be possible in theory, but at least lnd doesn't do it. I guess there are lots of interesting questions to answer before this becomes reality (channel jamming?).
Quoted text (4 lines)
> So in that case > modelling and computing probabilities for parallel channels might be > necessary anyway though the math indicates that splitting liquidity in > parallel channels will get you selected less frequently for routing.
Which is OK, as in reality it IS less likely to succeed.
Quoted text (3 lines)
> 1.2) The Mission Control information provided by lnd [...] > I think you talk a about a maximum available balance of a channel (and not > min available balance)?
Yes, although MC also has information about "known" amounts (due to failures that only happened further down the road).
Quoted text (4 lines)
> In the case of parallel channels I am not even sure if such information is > accurate as it is my understanding that the routing node may decide to use > the parallel channel to forward the amount even though the other channel > was specified in the onion.
The routing node is free to pick any of the parallel channels, yes. The MC data only reasons about pairs of nodes, though, not individual channels.
Quoted text (3 lines)
> Assuming that routing nodes indeed do so we would have learnt that neither > channel has an effective capacity of N. So the combined virtual channel > could be seen as 2N-1.
You mean 2(N-1) = 2N-2?
Quoted text (3 lines)
> However if routing nodes don't locally split a > forwarding request across both channels we would know that calaculating > with 2N-1 is bad as a request of N could not be fulfilled.
Exactly, also for 2N-2. Only N-1 would be a reasonable assumption.
Based on your responses I'll treat parallel channels individually, and see how it works out.
Quoted text (8 lines)
> > 3) Size of Piecewise Linearization > The main difference here is that a channel of 1 BTC is highly preferable > from a probabilistic payment delivery perspective over a channel of 0.01 > BTC. Even approximating the 1 BTC channel with 1000 intervalls of 0.001 BTC > should still have a lower unit cost in all pieces of the first 0.01 BTC of > the liquidity than the first piece of the 0.01 BTC channel. So I think > splitting all channels in the equal number of pieces is pretty well > motivated but let me elaborate on this:
OK great, got it.
Quoted text (4 lines)
> > 4) Leftovers after Piecewise Linearization > I am not sure if I understand your question / issue here. The splitting > works by selecting N points on the domain of the function and splitting the > domain into segments at those points. This should never leave sats over.
With quantization of 10,000 a channel of size 123,456 ends up as an arc with a capacity of 12 units. Cutting this into 5 pieces gives us 5*2 with 2 units not ending up in any of those pieces. Or am I missing something here, and we should split into 5 pieces of size 2.4 = 12/5?
Quoted text (3 lines)
> If the quantization however makes a channel so small that we cannot > even create 5 (or N) disjoint segments then I guess the likelihood for > being included into the final result is too small anyway.
It may not be very likely, but flat-out ignoring 20k sat (in my contrived example above) or up to 4*quantization sats (which is the case you described) doesn't feel right.
Quoted text (5 lines)
> Again this yield interesting pruning opportunities to reduce the seize of > the network before doing the expensive min cost flow computation. For > example I could prune channels with high unit costs on the first segment. > Especially if they are further away from the source and destination node. > This would overall reduce the size of the graph and improve runtime.
Let's talk about optimizations later :)
Quoted text (3 lines)
> 5) Fees (and other properties?) > arcs.append((src,dest,int(cap/(N*QUANTIZATION)),(i+1)*unit_cost + > mu*fee_rate_ppm))
Great, that helps! Thanks alot!
Quoted text (5 lines)
> Note two things: > 1. the only requirement for the solver to work is that \mu*fee_rate_ppm > needs to be an integer. So in case \mu was smaller than 1 we could also > scale the term from the linearized log probabilities by putting a larger mu > to the feature arising from the cost of the uncertainty.
Good to know!
Bye, Carsten
Dear Carsten and fellow lightning developers,
thanks for going into such detail and discovering some of the minor inaccuracies of my very rough piecewise linearization!
On Mon, Mar 14, 2022 at 1:53 PM Carsten Otto <bitcoin at c-otto.de> wrote:
Quoted text (8 lines)
> 1.2) The Mission Control information provided by lnd [...] > > I think you talk a about a maximum available balance of a channel (and > not > > min available balance)? > > Yes, although MC also has information about "known" amounts (due to > failures that only happened further down the road). >
I am unsure how mission control stores and handles that data. In my understanding they are mainly interested in a statistic of the ratio of successfull payments over the past X attempts on a channel given a certain time interval. But I assume they should have all the relevant data to produce a proper conditional proability to utilize our learnt knowledge.
In any case from the probabilistic model we can do it mathematically precise by just looking at the conditional probabilities. As said I have written hands on instructions in the rust repo https://github.com/lightningdevkit/rust-lightning/issues/1170#issuecomment-972396747 and they have been fully implemented in https://github.com/lightningdevkit/rust-lightning/pull/1227. Also in our mainnet test and simulations we have updated the priors according to those rules and this revealed the full power of the approach.
To summarize: Basically we need to know the effective uncertainty by only looking at the effective amount that goes above the minimum certain liquidity (that we might know from a prior attempt) and the effective capacity (somebody recently suggested that conditional capacity might be a better wording)
Quoted text (6 lines)
> Assuming that routing nodes indeed do so we would have learnt that neither > > channel has an effective capacity of N. So the combined virtual channel > > could be seen as 2N-1. > > You mean 2(N-1) = 2N-2? >
Probably though the difference would be neglectable and if I understood you correctly you will just keep parallel channels separate anyway.
Quoted text (11 lines)
> > 4) Leftovers after Piecewise Linearization > > I am not sure if I understand your question / issue here. The splitting > > works by selecting N points on the domain of the function and splitting > the > > domain into segments at those points. This should never leave sats over. > > With quantization of 10,000 a channel of size 123,456 ends up as an arc > with a capacity of 12 units. Cutting this into 5 pieces gives us > 5*2 with 2 units not ending up in any of those pieces. Or am I missing > something here, and we should split into 5 pieces of size 2.4 = 12/5? >
Your observation is correct! Indeed I think my code rounds down the capacity instead of going to the correct points and using all of the capacity in the segmentation by making some channels 1 unit larger than others which would happen if actually finding points on the domain to build the segments. This could easily be fixed. However as always: Fully saturated channels mean very low probabilities so even in my situation where I may cut off a significant part of the channel I'd say in the extreme case where we would need to saturate even those sats the flow will and should most likely fail as the min cust is probably just lower than the amount we would attempt to send. Probably opening a new channel or doing an on chain transaction will be more useful. Though of course we should build the piecewise linearization correctly by the end of the day without throughing away some capacity.
Quoted text (8 lines)
> If the quantization however makes a channel so small that we cannot > > even create 5 (or N) disjoint segments then I guess the likelihood for > > being included into the final result is too small anyway. > > It may not be very likely, but flat-out ignoring 20k sat (in my > contrived example above) or up to 4*quantization sats (which is the case > you described) doesn't feel right. >
See above. I agree it is not 100% accurate. but in practice I doubt it would ever become a problem as this will only be an issue when the payment amount is very close to the min cut which would make flows so unlikely to begin with that we would use other ways to conduct the payment anyway.
witch kind regards Rene
Good morning Rene, sorry for the lateness,
Quoted text (1 line)
> Last but not least, please allow me to make a short remark on the (still to me very surprisingly controversial) base fee discussion: For simplicity I did not include any fee considerations to the published code (besides a fee report on how expensive the computed flow is). However in practice we wish to optimize at least for high reliability (via neg log success probabilities) and cheap fees which in particular with the ppm is very easily possible to be included to the piece wise linearized cost function. While for small base fees it seems possible to encode the base fee into the first segment of the piecewise linearized approximation I think the base fee will still be tricky to be handled in practice (even with this approximation). For example if the base fee is too high the "base fee adjusted" unit cost of the first segment of the piecewise linearized problem might be higher than the unit cost of the second segment which effectively would break the convexity. Thus I reiterate my earlier point that from the perspective of the year long pursued goal of optimizing for fees (which all Dijkstra based single path implementations do) it seems to be best if the non linearity that is introduced by the base fee would be removed at all. According to discussions with people who crate Lightning Network explorer (and according to my last check of gossip) about 90% of channels have a base fee of 1 sat or lower and ~38% of all channels already set their base fee away from the default value to 0 [16].
I think the issue against 0-base-fee is that, to a forwarding node operator, every HTLC in-flight is a potential cost center (there is always some probability that the channel has to be forced onchain with the HTLC in-flight, and every HTLC has to be published on the commitment tx), and that cost is *not* proportional to the value of the HTLC (because onchain fees do not work that way). Thus, it seems reasonable for a forwarding node to decide to pass on that cost to their customers, the payers, in the form of base fees.
The response of customers would be to boycott non-0-base fees, by e.g. using a heuristic that overweighs non-0-base-fee and reducing usage of such channels (but if every forwarding node *has* a base fee, going through them anyway, which is why you just overweigh them, not eliminate them from the graph outright). Then forwarding nodes will economically move towards 0-base fee.
So I think you would find it impossible to remove the base fee field, but you can strongly encourage 0-base-fee usage by integrating the base fee but overweighted. (I think my previous formulation --- treat the base fee as a proportional fee --- would do some overweighing of the base fee.)
Which reminds me, I have not gotten around to make a 0-base-fee flag for `clboss`, haha. And I might need to figure out a learning algorithm that splits base and proportional fees as well, *sigh*.
Regards, ZmnSCPxj
Dear Carsten, Rene and fellow lightning developers,
Regarding the approximation quality of the minimum convex cost flow formulation for multi-part payments on the lightning network [1] and Carsten's discussion points on Twitter [2] and on the mailing list:
Quoted text (9 lines)
> 8) Quality of Approximation > > There are some problems in computer science that are hard/impossible to > approximate, in the sense that any kind of deviation from the optimum > could cause the computed results to be extremely bad. Do you have some > idea (or proof) that your kind of approximation isn't causing a major > issue? I guess a piece-wise linearization with an infinite number of > pieces corresponds to the optimal result. Given a finite number of > pieces, how large is the difference to the optimum?
I did some literature research and came across an insightful paper [3] by Dorit Hochbaum from 1993, that proves proximity results for integer and continuous optimal solutions of the minimum convex cost flow as well as proximity results of the optimal solutions for a piecewise linear approximation and the original problem.
Admittedly theoretical results, however, it further underpins that a piecewise linear approximation is a reasonable approach to find optimal flows and even shows that searching for optimal solutions on the continuous domain (e.g. with descent methods from convex optimization) also gives near-optimal solutions on the integer domain.
Cheers, Martin
[1] https://arxiv.org/abs/2107.05322 [2] https://twitter.com/renepickhardt/status/1502293438498234371 [3] https://www.worldscientific.com/doi/abs/10.1142/9789812798190_0005
Good morning everyone,
with regards to zerobasefee, I think that the argument that HTLCs are costly doesn't quite hold up because they are always free to an attacker as it stands. However, I fully agree with Zmn's opinion that it's not necessary to bang our head against any opposition to this because we can simply follow his excellent method for overweighing base fee. I believe this is a very natural approach to let the market decide on the relative importance of optimized routing vs base fees.
As to Martin's approximation research, I have asked myself similar questions. Unfortunately, the paper you cite is paywalled and not available at sci-hub, so I haven't read it. FWIW, I believe I have a simple proof that minimum cost flow preserves approximation FACTORS:
Let O be the original problem and A the approximated problem such that every flow in O can be mapped 1:1 to a flow in A and vice versa. Let every edge e in O be represented by a set of edges in A whose total cost is within a factor (1+epsilon) for every possible flow (could be over- or underestimating). Note that this means that every flow in O has cost within a factor (1+epsilon) for the corresponding flow in A and vice versa.
Now let f_a be the min cost flow in A and f_o the min cost flow in O. Assume that c(f_o)(1+epsilon)<c(f_a). Then f_o corresponds to a flow in A that is cheaper than f_a, but that's impossible because f_a is the min cost flow. QED.
Problems might arise anyway because we represent probabilities only logarithmically in the cost, so that a factor of (1+epsilon) corresponds to an exponent (1+epsilon) for the probabilities. But René seems optimistic that the resulting flows look good enough in practice.
I am still optimistic that exact solvers with something like the cost scaling approach might also be feasible (as long as they produce integer flows), but I am happy that this simple approximation approach seems good enough. This should save us a lot of work because there are many linear min cost solvers available that represent years of cumulative work in optimization research.
Cheers Stefan
Am Sa., 19. März 2022 um 22:09 Uhr schrieb Martin via Lightning-dev <lightning-dev at lists.linuxfoundation.org>:
Quoted text (29 lines)
> > Dear Carsten, Rene and fellow lightning developers, > > Regarding the approximation quality of the minimum convex cost flow formulation for multi-part payments on the lightning network [1] and Carsten's discussion points on Twitter [2] and on the mailing list: > > > 8) Quality of Approximation > > > > There are some problems in computer science that are hard/impossible to > > approximate, in the sense that any kind of deviation from the optimum > > could cause the computed results to be extremely bad. Do you have some > > idea (or proof) that your kind of approximation isn't causing a major > > issue? I guess a piece-wise linearization with an infinite number of > > pieces corresponds to the optimal result. Given a finite number of > > pieces, how large is the difference to the optimum? > > I did some literature research and came across an insightful paper [3] by Dorit Hochbaum from 1993, that proves proximity results for integer and continuous optimal solutions of the minimum convex cost flow as well as proximity results of the optimal solutions for a piecewise linear approximation and the original problem. > > Admittedly theoretical results, however, it further underpins that a piecewise linear approximation is a reasonable approach to find optimal flows and even shows that searching for optimal solutions on the continuous domain (e.g. with descent methods from convex optimization) also gives near-optimal solutions on the integer domain. > > Cheers, > Martin > > [1] https://arxiv.org/abs/2107.05322 > [2] https://twitter.com/renepickhardt/status/1502293438498234371 > [3] https://www.worldscientific.com/doi/abs/10.1142/9789812798190_0005 > _______________________________________________ > Lightning-dev mailing list > Lightning-dev at lists.linuxfoundation.org > https://www.learnbitcoin.com/archive/lists/lightning-dev
Hello Stefan, hello Lightning Devs,
Quoted text (5 lines)
> As to Martin's approximation research, I have asked myself similar > > questions. Unfortunately, the paper you cite is paywalled and not > > available at sci-hub, so I haven't read it.
Sorry for the paywalled link, without paywall you can read the article on Google Books preview:
https://books.google.de/books?id=hbXsCgAAQBAJ&pg=PA63&source=gbs_toc_r#v=onepage
I like your neat and simple proof idea for approximation preservation!
Cheers, Martin