Skip to content
LearnBitcoin

ResearchBitcoin Dev Archive lightning-dev list

Do we really want users to solve an NP-hard problem when they wish to find a cheap way of paying each other on the Lightning Network?

11 messages, Aug 26 to Sep 2, 2021. Started by René Pickhardt.

ZmnSCPxj (5), Matt Corallo (2), René Pickhardt, Anthony Towns, Orfeas Stefanos Thyfronitis Litos, Stefan Richter

Permalink First message in the Wayback Machine

René Pickhardt permalink original

Dear fellow lightning developers,

with a mixture of shock and disbelief I have been following the (semi) public discussions for the last 6 weeks and the reaction of some companies / people that reached out to me. I have to say I am really surprised by the amount of hesitation that - despite obvious and overwhelming mathematical evidence - a small group of people demonstrated in response to our results. While I cannot make any sense of this I decided to post here despite the fact that I believe everything that needed to be said is already written and explained clearly in our paper [0] about optimally reliable and cheap payment flows on the Lightning Network. My hope is that this mail can help us to

* clarify a few misunderstandings
* stop having opinionated discussions about mathematical facts
* find a quick agreement on how to move on

As far as I can tell currently all implementations use some form of Dijkstra algorithm in payment delivery with a strong emphasize on finding paths with cheap fees. The reason seems to be that it is a well established assumption that users would prefer a cheap solution on the market of offered routing fees. (while routing nodes of course try to offer fees that maximize their earnings)

If we look at the mentioned paper there are several results (I will soon publish a separate mail here discussing some of the more interesting results and consequences but I decided to split it and put this one here first as it seemed to be more urgent). One of the results which I will discuss now is the realization that - given the current fee function - finding the cheapest payment flow is an NP-hard problem because the fee function is neither linear nor convex.

Our fee function is `f(x) = rx + b` where `r`= fee rate, `b`=base fee and `x` is the amount we want to send.

As we thought it was obvious that the function is not linear we only explained in the paper how the jump from f(0)=0 to f(1) = ppm+base_fee breaks convexity. But as the question came up several times (for example here [1]) I want to stress that the fee function - despite looking like a straight line - is **not linear**. While writing this post I realized that the issue might be that the concept of linearity [2] from the field of linear algebra seems to be intermixed in the english language and American school system with the concept of linear polynomials / linear functions [3]. So maybe that is part of the problem that emerged in previous discussions.

When I write linear here I am referring back to the concept of linearity from linear algebra (c.f.: [2]) which btw seems to be also the main reason why schnorr signatures [2b] are so powerful that everyone is happy they will find their way into bitcoin. We know that a necessary condition for a function to be called linear is that the following property holds:

f(x+y)=f(x)+f(y)

however if we look at our setting we see that:

f(x+y) = r(x+y) + b

and

f(x)+f(y) = rx+b + ry+b = r(x+y) + 2b

equality (and thus linearity) only holds if

r(x+y)+b = r(x+y) + 2b <==> b = 2b

the later is true if and only if `b=0`. In other words: **Our current fee function is only linear if we set the base fee to zero.**

On the other side we refer to research in our paper that shows that an optimal solution (in this case optimal means cheapest) cannot be found if the fee function is neither linear nor convex. I think one of the biggest misunderstandings that I saw in the discussions is that people seem to have thought this has something to do with our new / proposed method. But as far as I can tell it does absolutely not have any connection to it. Instead and as most of you probably know the property to be an NP-hard problem is completely independent of the used algorithm. This is why in the paper we suggested to drop the base_fee and mentioned in the German Podcast that the same effect could already be achieved by node operators today by setting their base fee to 0. it is also the reason why we asked before we published the paper why the base fee was introduced and what purpose it served [4].

I am so surprised by some of the resistance because some of the biggest talking points by Lightning Network critics in the past have been that routing is either not solved or if it was solved it would be NP-hard. In our paper we show that delivering a payment can always be modeled as a min cost flow and the resulting optimization problem will indeed be NP-hard depending on the cost function. Given the current fee function with a non zero base fee and the goal of minimizing fees that is followed by all implementations I have to agree with such critics and say yes, in that particular case delivering a payment optimally is an NP-hard problem.

Luckily there are things we can do about it:

1.) we can decide to have a different optimization goal. For example in the Paper we used a previously introduced probabilisitic model that optimizes for reliability instead of fees and we show that in that case the function is convex and a polynomial exact algorithm is known and exists. 2.) If we want to optimize for fees which - given current implementations for single payments and the overwhelming feedback of users - seems to be the case we can modify the fee function to be either convex or linear. As everyone who read until here knows the later can be achieved by just removing the base fee. 3.) Of course we can follow the ideas of Matt Corallo and Olaoluwa Osuntokun to do more research. I mean there is a nice 1 million dollar bounty [5] for the person who finds a polynomial solution to NP-hard problems or proofs that such solutions cannot be found in polynomial time (which if you ask me personally is way more probable to happen but I usually try not to make wild conjectures about the future). 4.) We can try to find linear approximations so that we can have more efficient algorithms to approximate such problems which I guess is what Matt and Olaoluwa might have meant when they suggested to do more research.

As I was struggeling with the problem for over two years I personally have a pretty strong opinion about the 4 potentials paths:

@1: We already describe in the paper that reliability should be included when deciding which channels to use while fees should not be neglected. Thus I tend to say: Yes let's modify the goal in a way that we still keep optimizing for cheap delivery which by the end means keep a fee function but NOT the current fee function. @2: Seems like a total no-brainer to modify the fee function to drop the base fee because I believe nobody wants to drop the cheap requirement for payments and because of what I will say in reply to 3 & 4. @3: If you want to find solutions to hard problems I suggest to find a solution to the discrete logarithm instead of studying P=NP. The bounty is the the security of bitcoin and thus much higher than just the million dollar that you might get for the the solution to the P=NP problem. Ok, jokes aside of course doing research is always a good idea and we laid out a clear roadmap for further R&D in the paper that still holds even if we all agree that zerobasefee is a good thing. I am still seeking funding from the bitcoin / lightning network community to be able to continue research and development in this field so I full appreciate the suggestion by Matt and Olaoluwa who asked for more research and I hope the community will entrust me to lead such research. I can understand that people hesitated to support my work back in 2019 when I decided to focus on the reliability question and it was a gamble if I could deliver but I sincerely hope with my achievements that I lay out in full on https://ln.rene-pickhardt.de that there will be more support in the future (not only for me). @4: People in operation research have tried this for many years. In practice problems are being linearized all the time. But in the best case the models are already chosen to be linear and one hopes that such models are close enough to reality. We have been given a gift that the uncertainty in our channels naturally came as a convex cost function which makes the reliability goal somewhat easy to compute. More importantly it is a huge gift that it is just for us (users and developers) to decide how we want to have the fee structure on the Lightning network. A linear solution could just be agreed upon / recommended but of course we can keep a non-linear version and struggle around with approximations to handle np-hardness. For me it is so obvious what one would want to do that I will conclude with the subject line of this mail as a rethorical question "Do we really want users to solve an NP-hard problem when they wish to find a cheap way of paying each other on the Lightning Network?"

In the recent Optech newsletter [6] Olaoluwa Osuntokun is said to have "emphasized a point made earlier that there’s no clear current need for node operators to change a parameter today for a new pathfinding algorithm that nobody is currently ready to use in production". First of all I want to emphasize that Stefan and I have used this in production and have verified that our method works - as predicted in the paper - much better than the pay implementation used in LND (I will write more about that in the other mail that I already mentioned) But way more importantly (and as explained in this mail and our paper) this parameter change is not about some novel algorithm that we propose but rather about the mathematical structure of the optimization problem that we want(?) users to face when delivering payments (and that all implementations already presented to the users in the single path payment case). So I very strongly disagree with the statement that there is no clear need to change something. Actually I think there is an exceptionally strong need to change something and very good reason to do so rather sooner than later.

That being said the high reliability and large amounts that we could deliver through the use of our method with a standard min convex cost flow solver as the algorithm comes from the fact that we used probablistic path finding [7] as the cost function. As demonstrated last march this already works much better for single paths when used as a weight in dijsktra than the stuff current implementations do. Also it did not create such a discussion when I shared the results about probabilisitic pathfinding last march and already mentioned that I only need to finish the work on optimal splitting. So for the higher reliability and larger amounts alone that our method can do, we do not even need a zerobasefee. This is because probabilistic path finding merely models the uncertainty of the liquidity in the channels to decide which channels to use with what amounts in payment delivery to maximize the success probability. The only reason why we mention (zerobase)fees is because of @1 and the assumption that node operators would arbitrarily increase their fees on channels if we would not take fees into consideration when deciding which channels to use. Since the basefee kicks in and breaks the nice mathematical properties we addressed it.

Btw I have a suggestion to node operators who seek channel partners and nodes with whom to open channels. If you don't want your customers / users be required to solve or approximate NP-hard problems you could open your channels with other nodes who already support zero base fee on their channels. As of now this seems to be a clear indicator that those nodes care about reliability and try to provide a good & honest service to the network. As more and more wallets should use optimal payment flows it is also reasonable to expect that a lot of routing is likely to happen in the #zerobasefee part of the network which is already pretty large [8]. At least when I make a payment this part of the network is where I look first to deliver the payment. Also connecting to nodes that indicate via zerobasefee that they care seems at least to me personally way more reasonable than following some random intransparent score that assigns numbers to nodes.

As said initially I thought I already had said everything which is why - unless substential new information comes up - I will most likely not engage into further bike shedding discussions on the zero base fee discussions. This is now for the community to decide and not for me to argue.

with kind regards Rene

[0]: https://arxiv.org/abs/2107.05322 [1]: https://bitcoin.stackexchange.com/questions/108018/would-a-min-fee-setting-for-lightning-channels-make-sense#comment124039_108325 [2]: https://en.wikipedia.org/wiki/Linearity [2b]: https://courses.csail.mit.edu/6.857/2020/projects/4-Elbahrawy-Lovejoy-Ouyang-Perez.pdf [3]: https://en.wikipedia.org/wiki/Linear_function [4]: https://bitcoin.stackexchange.com/questions/107311/why-was-the-base-fee-for-the-routing-fee-calculation-of-the-lightning-network-in [5]: https://en.wikipedia.org/wiki/P_versus_NP_problem#Results_about_difficulty_of_proof [6]: https://bitcoinops.org/en/newsletters/2021/08/25/ [7]: https://www.learnbitcoin.com/archive/lists/lightning-dev/t/2021/towards-more-reliable-payment-path-finding-via-probabilistic-modeling-the#m-8e41549f [8]: https://lnrouter.app/graph/zero-base-fee

Anthony Towns in reply to René Pickhardt permalink original

On Thu, Aug 26, 2021 at 04:33:23PM +0200, René Pickhardt via Lightning-dev wrote:

Quoted text (2 lines)
> As we thought it was obvious that the function is not linear we only explained
> in the paper how the jump from f(0)=0 to f(1) = ppm+base_fee breaks convexity.

(This would make more sense to me as "f(0)=0 but f(epsilon)->b as epsilon->0, so it's discontinuous")

Quoted text (2 lines)
> "Do we really want users to solve an NP-hard problem when
> they wish to find a cheap way of paying each other on the Lightning Network?"

FWIW, my answer to this is "sure, if that's the way it turns out".

Another program which solves an NP-hard problem every time it runs is "apt-get install" -- you can simulate 3SAT using Depends: and Conflicts: relationships between packages. I worked on a related project in Debian back in the day that did a slightly more complicated variant of that problem, namely working out if updating a package in the distro would render other packages uninstallable (eg due to providing a different library version) -- as it turned out, that even actually managed to hit some of the "hard" NP cases every now and then. But it was never really that big a deal in practice: you just set an iteration limit and consider it to "fail" if things get too complicated, and if it fails too often, you re-analyse what's going on manually and add a new heuristic to cope with it.

I don't see any reason to think you can't do roughly the same for lightning; at worst just consider yourself as routing on log(N) different networks: one that routes payments of up to 500msat at (b+0.5ppm), one that routes payments of up to 1sat at (b+ppm), one that routes payments of up to 2sat at (b+2ppm), one that routes payments of up to 4sat at (b+4ppm), etc. Try to choose a route for all the funds; if that fails, split it; repeat. In some case that will fail despite there being a possible successful multipath route, and in other cases it will choose a moderately higher fee path than necessary, but if you're talking a paying a 0.2% fee vs a 0.1% fee when the current state of the art is a 1% fee, that's fine.

Cheers, aj

ZmnSCPxj in reply to Anthony Towns permalink original

Good morning aj and Rene,

Quoted text (7 lines)
> On Thu, Aug 26, 2021 at 04:33:23PM +0200, René Pickhardt via Lightning-dev wrote:
>
> > As we thought it was obvious that the function is not linear we only explained
> > in the paper how the jump from f(0)=0 to f(1) = ppm+base_fee breaks convexity.
>
> (This would make more sense to me as "f(0)=0 but f(epsilon)->b as
> epsilon->0, so it's discontinuous")

I as well, "discontinuous" is how I would understand it, and it really needs to be pointed out to me that f(0)=0 and the sudden step to f(1)=1*prop + base is problematic.

Quoted text (9 lines)
>
> > "Do we really want users to solve an NP-hard problem when
> > they wish to find a cheap way of paying each other on the Lightning Network?"
>
> FWIW, my answer to this is "sure, if that's the way it turns out".
>
> Another program which solves an NP-hard problem every time it runs is
> "apt-get install" -- you can simulate 3SAT using Depends: and Conflicts:
> relationships between packages.

Thank you for this, I now understand why functional package managers like Nix and Guix etc. exist.

Quoted text (22 lines)
> I worked on a related project in Debian
> back in the day that did a slightly more complicated variant of that
> problem, namely working out if updating a package in the distro would
> render other packages uninstallable (eg due to providing a different
> library version) -- as it turned out, that even actually managed to hit
> some of the "hard" NP cases every now and then. But it was never really
> that big a deal in practice: you just set an iteration limit and consider
> it to "fail" if things get too complicated, and if it fails too often,
> you re-analyse what's going on manually and add a new heuristic to cope
> with it.
>
> I don't see any reason to think you can't do roughly the same for
> lightning; at worst just consider yourself as routing on log(N) different
> networks: one that routes payments of up to 500msat at (b+0.5ppm), one
> that routes payments of up to 1sat at (b+ppm), one that routes payments
> of up to 2sat at (b+2ppm), one that routes payments of up to 4sat at
> (b+4ppm), etc. Try to choose a route for all the funds; if that fails,
> split it; repeat. In some case that will fail despite there being a
> possible successful multipath route, and in other cases it will choose a
> moderately higher fee path than necessary, but if you're talking a paying
> a 0.2% fee vs a 0.1% fee when the current state of the art is a 1% fee,
> that's fine.

Well, something similar is already done by C-Lightning, and the `pay` algorithm even includes a time limit after which it just fails instead of retrying (roughly equivalent to setting an iteration limit, and actually more practical since it is not the number of CPU iterations that matters, it is real time during which user economic preferences may change).

And for large enough payments, it *still* does not succeed often enough in practice.

I pointed out elsewhere that failure-to-pay has an economic cost. This economic cost is the difference between the value of the product being bought, minus the value of the bitcoin being used to pay for it. (remember, economic value is subjective to every economic actor; the economy is simply how the differences in value plays out as actors exchange objects, where each actor has its own subjective valuation of that value.) We can ask the user explicitly for a numeric amount equivalent to this cost, by the simple question "how much are you willing to pay in order for this transaction to succeed?" i.e. "what is the maximum transaction fee you will accept?"

Thus, failing to deliver imposes an economic cost on users, a cost that Lightning Network, rightfully or not, has implicitly promised to reduce in comparison to onchain transactions.

For myself, I think a variant of Pickhardt-Richter payments can be created which *adapts to* the reality of the current network where `base_fee > 0` is common, but is biased against `base_fee > 0`, can be a bridge from the current network with `base_fee > 0` and a future with `#zerobasefee`. With C-Lightning and its plugin nature allowing alternate implementations of `pay`, this can be done without requiring an entire new LN implementation. If popular enough, because it demonstrates actual ability to transfer large funds at low fees, this can force forwarding nodes to learn that `#zerobasefee` earns them more funds (such as if they use a hill-climbing algorithm like I described to discover optimal feerates that gives them maximum earnings). Then `#zerobasefee` just wins economically.

So I think this really just needs a good implementation somewhere.

Regards, ZmnSCPxj

Orfeas Stefanos Thyfronitis Litos in reply to Anthony Towns permalink original

Hi list,

On 8/31/21 5:01 AM, Anthony Towns wrote:

Quoted text (9 lines)
>> "Do we really want users to solve an NP-hard problem when
>> they wish to find a cheap way of paying each other on the Lightning Network?"
> FWIW, my answer to this is "sure, if that's the way it turns out".
>
> Another program which solves an NP-hard problem every time it runs is
> "apt-get install".
> [I]f it fails too often,
> you re-analyse what's going on manually and add a new heuristic to cope
> with it.

I've been following the conversation with interest and I acknowledge this is a thorny issue.

I am a bit worried with a path which relies on constantly finding new heuristics to approximate a solution to an NP-hard problem:
* It allows too much room for nonconstructive disagreement between LN developers in the future.
  - In a worst case scenario, all implementations end up using different, incompatible heuristics because each group of developers thinks that they have the best one, leading to a suboptimal performance for everyone. Heuristics are less of an exact science after all.
* It makes the job of node operators less predictable, since it would depend more on the decisions of said developers with no guarantee of convergence to a single solution.
  - Node operators may perceive this as loss of decentralization to the developers.

Such an approach is much more suitable to debian, since they have full control and a complete view over their "network" of packages, as opposed to LN, which is decentralized, nodes come and go at will and they can be private (even from developers!).

Best, Orfeas The University of Edinburgh is a charitable body, registered in Scotland, with registration number SC005336. Is e buidheann carthannais a th’ ann an Oilthigh Dhùn Èideann, clàraichte an Alba, àireamh clàraidh SC005336.

ZmnSCPxj in reply to Orfeas Stefanos Thyfronitis Litos permalink original

Good morning Orfeas,

Quoted text (1 line)
>         Such an approach is much more suitable to debian, since they have full control and a complete view over their "network" of packages, as opposed to LN, which is decentralized, nodes come and go at will and they can be private (even from developers!).

Indeed, I came back to this topic to make this argument as well. Maintainers of apt repositories often make *some* amount of effort to avoid having too many `Conflict`-ing packages, such that typical simple users never experience the NP-hard bits. Worse, such apt repositories are definitely central points of coordination.

Now of course users can add PPAs and anyone can create PPAs that others can consume, and the PPA-creation is not curated. But in practice, even just a handful of PPAs can risk horrible cascades of `Conflict`-ing packages and massive headaches that can only be fixed by just reinstalling the OS from scratch and never using PPAs ever again.

(Indeed, the ability for Nix and Guix to run "on top of" an existing OS is a good alternative to using PPAs, which avoids the `Conflict` issue.)

Now, with Lightning Network, we run the risk that some de facto centralized curator will be consulted to provide good payment solutions. That centralized curator avoids the NP-hard problems by being able to define which nodes and which channels are allowed to be considered in any payment solution, in much the same way an `apt` repository curator can define which packages are in and out of the repository, all in the name of avoiding the NP-hard problem for most users. The risk is that such central coordinators may very well dangerously centralize the network in such a way that evicting them is not easy. In particular, we do not want so central an entity that the choice for users becomes between accepting a centralized LN or making do with the expensive but decentralized base layer.

Regards, ZmnSCPxj

Stefan Richter in reply to ZmnSCPxj permalink original

Am Di., 31. Aug. 2021 um 10:29 Uhr schrieb ZmnSCPxj via Lightning-dev <lightning-dev at lists.linuxfoundation.org>:

Quoted text (1 line)
> For myself, I think a variant of Pickhardt-Richter payments can be created which *adapts to* the reality of the current network where `base_fee > 0` is common, but is biased against `base_fee > 0`, can be a bridge from the current network with `base_fee > 0` and a future with `#zerobasefee`.

I have been thinking about your idea (at least what I understood of it) of using amount*prop_fee + amount*base_fee/min_flow_size, where min_flow_size is a suitable quantization constant (say, 10k or 100k sats, may also chosen dynamically), as a component of the cost function, and I am pretty sure it is great at achieving exactly what you are proposing here. This is a nicely convex (even linear in this component) function and so it's easy to find min-cost flows for it. It solves the problem (that I hadn't thought about before) that you have pointed out in splitting flows into HTLCs. If you use min_flow_size=max_htlc_size, it is even optimal (for this min_flow_size). If you use a smaller min_flow_size, it is still optimal for channels with base_fee=0 but overestimates the fee for channels with base_fee>0, and is less accurate the smaller the min_flow_size and the larger the base_fee. So it will be biased against channels with larger base_fee. But notice that with min-cost flows, we are rarely looking for the cheapest solution anyway, because these solutions (if they include more than one path) will usually fully saturate the cheapest channels and thus have very low success probability. So all in all, I believe you found a great practical solution for this debate. Everybody is free to use any base_fee they chose, we get a workable cost function, and I conjecture that economics will convince most people to choose a zero or low base_fee.

Cheers
  Stefan
ZmnSCPxj in reply to Stefan Richter permalink original

Good morning Stefan,

Quoted text (24 lines)
> > For myself, I think a variant of Pickhardt-Richter payments can be created which adapts to the reality of the current network where `base_fee > 0` is common, but is biased against `base_fee > 0`, can be a bridge from the current network with `base_fee > 0` and a future with `#zerobasefee`.
>
> I have been thinking about your idea (at least what I understood of
> it) of using amountprop_fee + amountbase_fee/min_flow_size, where
> min_flow_size is a suitable quantization constant (say, 10k or 100k
> sats, may also chosen dynamically), as a component of the cost
> function, and I am pretty sure it is great at achieving exactly what
> you are proposing here. This is a nicely convex (even linear in this
> component) function and so it's easy to find min-cost flows for it. It
> solves the problem (that I hadn't thought about before) that you have
> pointed out in splitting flows into HTLCs. If you use
> min_flow_size=max_htlc_size, it is even optimal (for this
> min_flow_size). If you use a smaller min_flow_size, it is still
> optimal for channels with base_fee=0 but overestimates the fee for
> channels with base_fee>0, and is less accurate the smaller the
> min_flow_size and the larger the base_fee. So it will be biased
> against channels with larger base_fee. But notice that with min-cost
> flows, we are rarely looking for the cheapest solution anyway, because
> these solutions (if they include more than one path) will usually
> fully saturate the cheapest channels and thus have very low success
> probability. So all in all, I believe you found a great practical
> solution for this debate. Everybody is free to use any base_fee they
> chose, we get a workable cost function, and I conjecture that
> economics will convince most people to choose a zero or low base_fee.

I am glad that this is helpful. Still, I have not really understood well the variant problem "min cost flow with gains and losses" and this scheme might not work there very well. On the other hand, the current algorithms are already known to suck for large payments, so even a not-so-good algorithm based on Pickhardt-Richter may be significantly better than existing deployed code.

On the software engineering side, the fact that it took you 2 months probably means implementing this would take even longer, like 6 months or so. I mean to say that prior to deployment we would need the dreary tasks of unit tests and edge cases (which are needed to ensure that basic functionality is not lost if the code is later modified, or more perniciously, that bugfixes do not introduce more bugs), code review, and so on. And for C-Lightning it would have to be implemented in C, which brings its own set of problems (memory management, being a lot more stringent about dotting every i and crossing every t, explicitly passing objects around, most likely rewriting in a continuation passing style/"callback style"...). Now we could argue that C-Lightning in practice requires Python anyway, but it also depends on what libraries you pull in, even if C-Lightning in practice requires Python you still want to keep the dependencies few or else deployment can suffer.

Regards, ZmnSCPxj

Matt Corallo in reply to Orfeas Stefanos Thyfronitis Litos permalink original

Please be careful accepting the faulty premise that the proposed algorithm is “optimal”. It is optimal under a specific heuristic used to approximate what the user wants. In reality, there are a ton of different things to balance, from CLTV to feed to estimated failure probability calculated from node online percentages at-open liquidity, and even fees. There is no such thing as “optimal”, only heuristics for how to balance these things into a score that you can feed into a routing algorithm.

Quoted text (1 line)
> Do we really want users to solve an NP-hard problem when they wish to find a cheap way of paying each other on the Lightning Network?

I find this framing sufficiently insulting to the serious discussion people have had on this topic that I’m not really sure where to go from here aside from ignoring it.

Quoted text (31 lines)
> On Aug 31, 2021, at 03:35, Orfeas Stefanos Thyfronitis Litos <o.thyfronitis at ed.ac.uk> wrote:
>
> Hi list,
>
> On 8/31/21 5:01 AM, Anthony Towns wrote:
>>> "Do we really want users to solve an NP-hard problem when
>>> they wish to find a cheap way of paying each other on the Lightning Network?"
>> FWIW, my answer to this is "sure, if that's the way it turns out".
>>
>> Another program which solves an NP-hard problem every time it runs is
>> "apt-get install".
>> [I]f it fails too often,
>> you re-analyse what's going on manually and add a new heuristic to cope
>> with it.
> I've been following the conversation with interest and I acknowledge this is a thorny issue.
>
> I am a bit worried with a path which relies on constantly finding new heuristics to approximate a solution to an NP-hard problem:
> * It allows too much room for nonconstructive disagreement between LN developers in the future.
>  - In a worst case scenario, all implementations end up using different, incompatible heuristics because each group of developers thinks that they have the best one, leading to a suboptimal performance for everyone. Heuristics are less of an exact science after all.
> * It makes the job of node operators less predictable, since it would depend more on the decisions of said developers with no guarantee of convergence to a single solution.
>  - Node operators may perceive this as loss of decentralization to the developers.
>
> Such an approach is much more suitable to debian, since they have full control and a complete view over their "network" of packages, as opposed to LN, which is decentralized, nodes come and go at will and they can be private (even from developers!).
>
> Best,
> Orfeas
> The University of Edinburgh is a charitable body, registered in Scotland, with registration number SC005336. Is e buidheann carthannais a th’ ann an Oilthigh Dhùn Èideann, clàraichte an Alba, àireamh clàraidh SC005336.
> _______________________________________________
> Lightning-dev mailing list
> Lightning-dev at lists.linuxfoundation.org
> https://www.learnbitcoin.com/archive/lists/lightning-dev
ZmnSCPxj in reply to Matt Corallo permalink original

Good morning Matt and all,

Quoted text (1 line)
> Please be careful accepting the faulty premise that the proposed algorithm is “optimal”. It is optimal under a specific heuristic used to approximate what the user wants. In reality, there are a ton of different things to balance, from CLTV to feed to estimated failure probability calculated from node online percentages at-open liquidity, and even fees.

It may be possible to translate all these "things to balance" to a single unit, the millisatoshi.

* CLTV-delta
  - The total CLTV-delta time is the worst-case amount of time that your outgoing payment will be stalled.
  - We can compute the expected nominal rate of return if the funds were instead put in a random Bitcoin-denominated investment, getting back a conversion ratio from time units to percentage of your funds.
    This is what C-Lightning already does via the `riskfactor` parameter.
* Node failure probablity
  - Can be multiplied with channel failure probability (the one based on the channel capacity).
  - As I pointed out elsewhere, we can ask the user "up to how much are you willing to pay in fees?", and that amount is the cost of failure (because economics; see my other mail); the failure probability times the cost of failure is the effective cost of this path.
* Fees
  - Are already denominated in millisatoshi.

One unit to rule them all....

Regards, ZmnSCPxj

Matt Corallo in reply to ZmnSCPxj permalink original
Quoted text (7 lines)
> On Sep 1, 2021, at 00:07, ZmnSCPxj <ZmnSCPxj at protonmail.com> wrote:
>
> Good morning Matt and all,
>
>> Please be careful accepting the faulty premise that the proposed algorithm is “optimal”. It is optimal under a specific heuristic used to approximate what the user wants. In reality, there are a ton of different things to balance, from CLTV to feed to estimated failure probability calculated from node online percentages at-open liquidity, and even fees.
>
> It may be possible to translate all these "things to balance" to a single unit, the millisatoshi.

Indeed, in practice this is what we all do today. My point is less that you cannot create a single unit out of all the various things you consider and more that doing so involves some heuristics on the part of the application developer. There is no “correct” or “optimal” answer to how to do this, only various designs different folks have. How you balance competing costs may lead to different score units (eg instead of msat, probability of success) and that’s fine, neither is provably better than the other.

Matt

ZmnSCPxj in reply to ZmnSCPxj permalink original

Good morning Stefan,

Quoted text (28 lines)
> > > For myself, I think a variant of Pickhardt-Richter payments can be created which adapts to the reality of the current network where `base_fee > 0` is common, but is biased against `base_fee > 0`, can be a bridge from the current network with `base_fee > 0` and a future with `#zerobasefee`.
> >
> > I have been thinking about your idea (at least what I understood of
> > it) of using amountprop_fee + amountbase_fee/min_flow_size, where
> > min_flow_size is a suitable quantization constant (say, 10k or 100k
> > sats, may also chosen dynamically), as a component of the cost
> > function, and I am pretty sure it is great at achieving exactly what
> > you are proposing here. This is a nicely convex (even linear in this
> > component) function and so it's easy to find min-cost flows for it. It
> > solves the problem (that I hadn't thought about before) that you have
> > pointed out in splitting flows into HTLCs. If you use
> > min_flow_size=max_htlc_size, it is even optimal (for this
> > min_flow_size). If you use a smaller min_flow_size, it is still
> > optimal for channels with base_fee=0 but overestimates the fee for
> > channels with base_fee>0, and is less accurate the smaller the
> > min_flow_size and the larger the base_fee. So it will be biased
> > against channels with larger base_fee. But notice that with min-cost
> > flows, we are rarely looking for the cheapest solution anyway, because
> > these solutions (if they include more than one path) will usually
> > fully saturate the cheapest channels and thus have very low success
> > probability. So all in all, I believe you found a great practical
> > solution for this debate. Everybody is free to use any base_fee they
> > chose, we get a workable cost function, and I conjecture that
> > economics will convince most people to choose a zero or low base_fee.
>
> I am glad that this is helpful.
> Still, I have not really understood well the variant problem "min cost flow with gains and losses" and this scheme might not work there very well.
> On the other hand, the current algorithms are already known to suck for large payments, so even a not-so-good algorithm based on Pickhardt-Richter may be significantly better than existing deployed code.

In yet another thread I proposed the cost function:

    fee + fee_budget * (1 - success_probability)

If the base-to-prop hack (i.e. use a quantization constant like I proposed) can be done on the `fee` component above, does it now become convex?

With an amount of 0, `success_probability` is 1, and if we use the base-to-prop hack to convert base fees to proportional fees, then the output is also 0 at `amount = 0`.

It can even be made separable by clever redefinition of addition (as I pointed out in that thread) but perhaps it is too clever and breaks other properties that a mincostflow algo needs.

The above is attractive since the cost unit ends up being millisatoshi. In my experience with CLBOSS, hastily-thought heuristics kinda suck unless they are based on actual economic theory, meaning everything should really be in terms of millisatoshis or other financial units.

Would this be workable? Pardon my complete ignorance of maths.

Presumably, there is a reason why the Pickhardt-Richter paper suggests `-log(success_probability) + fudging_factor * fee`. My initial understanding is that this makes simple addition a correct behavior (success_probabilities are multiplied), making for a separable cost function that uses "standard" arithmetic addition rather than the excessively clever one I came up with. However, it might affect convexity as well?

(on the other hand, credibility should really be measured in decibels anyway, and one is estimating the credibility of the implied claim of a published channel that it can actually deliver the money to where it is needed...)

The neglogprob is in units of decibels, and I am not sure how to convert a millisatoshi-unit fee into decibels. In particular the logarithm implies a non-linear relationship between probability and fee.

I think it is reasonable for paying users to say "if it will take more than NN millisatoshis to pay for it, never mind, I won't continue the transaction anymore", which is precisely why I added the fee budget in the C-Lightning `pay` implementation long ago.

On the other hand, perhaps the nonlinear relationship between the success probability and the fee makes sense. If the success probability is already fairly high, then any small change in fee is significant to the user, but as the success probability drops, then the user would be willing to accept up to the fee budget. This implies that if success probability is high, the effect of an increase in fee should be larger in comparison to the effect of an increase in success probability, but if success probability is low, then the effect of an increase in fee should be smaller compared to an increase in success probability. I am uncertain if the neglogprob plus some fee times a conversion factor has that behavior.

Regards, ZmnSCPxj