Skip to content
LearnBitcoin

ResearchBitcoin Dev Archive lightning-dev list

`htlc_maximum_msat` as a valve for flow control on the Lightning Network

12 messages, Sep 22 to 29, 2022. Started by René Pickhardt.

ZmnSCPxj (5), Anthony Towns (4), René Pickhardt (2), Matt Corallo

Permalink First message in the Wayback Machine

René Pickhardt permalink original

Good morning fellow Lightning Developers,

I am pleased to share my most recent research results [1] with you. They may (if at all) only have a small impact on protocol development / specification but are actually mainly of concern to node operators and LSPs. I still thought they may be relevant for the list.

While trying to estimate the expected liquidity distribution in depleted channels due to drain via Markov Models I realized that we can exploit the `htlc_maxium_msat` setting to act as a control valve and regulate the "pressure" coming from the drain and mitigate the depletion of channels. Such ideas are btw not novel at all and heavily used in fluid networks [2]. Thus it seems very natural that we do the same on the Lightning Network.

In the article we show within a theoretic model how expected payment failure rates per channel may drop significantly by up to an order of magnitude if channels set up proper asymmetric `htlc_maximum_msat` pairs.

We furthermore provide in our iPython notebook [3] two experimental algorithmic ideas with which node operators can find decent `htlc_maximum_msat` values in a greedy fashion. One of the algorithms does not even require to know the drain or payment size distribution or build the Markov model but just looks at the liquidity distribution in the channel at the last x routing attempts and adjusts the `htlc_maximum_msat` value if the distribution is to far away from a uniform distribution.

Looking forwards for your thoughts and feedback.

with kind regards Rene

[1]: https://blog.bitmex.com/the-power-of-htlc_maximum_msat-as-a-control-valve-for-better-flow-control-improved-reliability-and-lower-expected-payment-failure-rates-on-the-lightning-network/ [2]: https://en.wikipedia.org/wiki/Control_valve [3]: https://github.com/lnresearch/Flow-Control-on-Lightning-Network-Channels-with-Drain-via-Control-Valves/blob/main/htlc_maximum_msat%20as%20a%20valve%20for%20flow%20control%20on%20the%20Lightnig%20network.ipynb

Matt Corallo in reply to René Pickhardt permalink original

Two questions - a) How much gossip overhead do you expect this type of protocol to generate/is there a useful outcome for this type of update even if you limit gossip updates to once/twice/thrice per day? b) What are the privacy implications of the naive "update on drained channel", and have you done any analysis of the value of this type of gossip update at different levels of privacy?

Thanks, Matt

On 9/22/22 2:40 AM, René Pickhardt via Lightning-dev wrote:

Quoted text (40 lines)
> Good morning fellow Lightning Developers,
>
> I am pleased to share my most recent research results [1] with you. They may (if at all) only have a
> small impact on protocol development / specification but are actually mainly of concern to node
> operators and LSPs. I still thought they may be relevant for the list.
>
> While trying to estimate the expected liquidity distribution in depleted channels due to drain via
> Markov Models I realized that we can exploit the `htlc_maxium_msat` setting to act as a control
> valve and regulate the "pressure" coming from the drain and mitigate the depletion of channels. Such
> ideas are btw not novel at all and heavily used in fluid networks [2]. Thus it seems very natural
> that we do the same on the Lightning Network.
>
> In the article we show within a theoretic model how expected payment failure rates per channel may
> drop significantly by up to an order of magnitude if channels set up proper asymmetric
> `htlc_maximum_msat` pairs.
>
> We furthermore provide in our iPython notebook [3] two experimental algorithmic ideas with which
> node operators can find decent `htlc_maximum_msat` values in a greedy fashion. One of the algorithms
> does not even require to know the drain or payment size distribution or build the Markov model but
> just looks at the liquidity distribution in the channel at the last x routing attempts and adjusts
> the `htlc_maximum_msat` value if the distribution is to far away from a uniform distribution.
>
> Looking forwards for your thoughts and feedback.
>
> with kind regards Rene
>
>
> [1]:
> https://blog.bitmex.com/the-power-of-htlc_maximum_msat-as-a-control-valve-for-better-flow-control-improved-reliability-and-lower-expected-payment-failure-rates-on-the-lightning-network/ <https://blog.bitmex.com/the-power-of-htlc_maximum_msat-as-a-control-valve-for-better-flow-control-improved-reliability-and-lower-expected-payment-failure-rates-on-the-lightning-network/>
> [2]: https://en.wikipedia.org/wiki/Control_valve <https://en.wikipedia.org/wiki/Control_valve>
> [3]:
> https://github.com/lnresearch/Flow-Control-on-Lightning-Network-Channels-with-Drain-via-Control-Valves/blob/main/htlc_maximum_msat%20as%20a%20valve%20for%20flow%20control%20on%20the%20Lightnig%20network.ipynb <https://github.com/lnresearch/Flow-Control-on-Lightning-Network-Channels-with-Drain-via-Control-Valves/blob/main/htlc_maximum_msat%20as%20a%20valve%20for%20flow%20control%20on%20the%20Lightnig%20network.ipynb>
>
> --
> https://ln.rene-pickhardt.de <https://ln.rene-pickhardt.de>
>
> _______________________________________________
> Lightning-dev mailing list
> Lightning-dev at lists.linuxfoundation.org
> https://www.learnbitcoin.com/archive/lists/lightning-dev
René Pickhardt in reply to Matt Corallo permalink original

Dear Matt and Lightning developers,

those are excellent and important questions that I should probably have addressed more explicitly in the article / ml-post! Let me add what I currently know and begin with your second question as I think I think the answer will be more objective / verifiable while my response to the gossip question is a bit more speculative at this point:

On Fri, Sep 23, 2022 at 10:43 AM Matt Corallo <lf-lists at mattcorallo.com> wrote:

Quoted text (5 lines, sent without quote marks)
b) What are the privacy implications of the naive "update on drained
> channel", and have you done any
> analysis of the value of this type of gossip update at different levels of
> privacy?
>

We know from information theory that the distribution with the highest entropy is the uniform distribution [1] which in the context of a channel with capacity of `c` means `log(c+1)` bits as shown in [2].

Now if a given drain leads to a pair of `htlc_maximum_msat` one could in deed also go the other way around and look at the pair of `htlc_maximum_msat` and estimate the *past* drain. And of course also the (the non uniform) liquidity distribution from the past. Note that now with the better `htlc_maximum_msat` pair the distribution should be closer to uniform again which is actually best from an information theoretic point of view as this maximizes the entropy in the channel.

I have just created and uploaded a small python script / notebook [3] from which we can see for example how much information about the shape of the past liquidity distribution we would learn if we could induce from the `htlc_maximum_msat` pair that the drain was 0.75. So from the notebook I quote:

Assume we learnt a drain of 0.75 ================================= Entropy of uniform: 20.00 bits. Entropy of the channel with drain: 19.17 bits Information gain: 0.83 bits

Yes we learnt less than 1 bit of information by knowing the shape of the distribution from the last payments. This much is learnt by a single probe. Given that we expect our payment failure rates to drop by an order of magnitude and the fact that I could probably learn the drain from the on chain signal or gossip anyway I personally would consider this information leakage to be acceptable. But of course people may not agree with me and just not set their `htlc_maximum_msat` flag in the proposed manner. Also it is obvious that higher drain values produce a more heavily depleted channel and we might learn more bits (in case of a 0.95 drain we learnt about 3 bits.)

Quoted text (5 lines)
a) How much gossip overhead do you expect this type of protocol to
> generate/is there a useful
> outcome for this type of update even if you limit gossip updates to
> once/twice/thrice per day?
>

As written in the article I expect the setting of the valves as throtteling devices to be rather stable as I would assume the drain on channels should not be impacted too heavily by installing valves. This assumption is certainly more reasonable if nodes already used min cost flow solvers to send out payments and less reasonable if nodes still use ad-hoc splitting heuristics and restrict their path finding on channels with sufficiently large `htlc_maximum_msat` values for the amount of the partial payment.

In any case I expect that once the valve is in a good setting for a particular channel / drain the setting can stay as long as the drain won't change significantly. In general I would not expect drain on channels to change heavily over time (though I certainly would not expect it to be static / stable either). Certainly fee changes in the network (and other factors) may eventually produce changes in drain on channels which would also have to eventually be reflected in new settings for the valve.

The experimental algorithm idea that I presented in cell 12 of the original notebook (which I also used in the privacy consideration code from above) computes the histogram of liquidity of the last N routing requests (failed and successful ones) that a node saw on the channel and then makes a decision weather to open or close the valve a bit more. Using this greedy strategy we saw in the notebook that a node could find decent values in logarithmic many steps . So while the setup of the valve may trigger a few gossip messages (but each one only after a sufficient amount of routing requests have been processed) and while I expect dynamics in drain on the channel I don't expect such adoptions should have to happen in real time or even several times per day and put unnecessary load / spam to gossip. But I guess we can only see this by operating nodes and probably there are some nodes where updates occure more frequently than with other nodes.

That being said of course if the peers of a channel work together and both exchange information / collaborate in finding a good `htlc_maximum_msat` pair (similalry as our protocol for finding fees in a mutual close) they will probably need less gossip messages than in the case where both nodes independently try to find decent settings.

I am happy if people have more insights into this and challenge my expectation (because it actually really is only an expectation / intuition at this point). That being said: Yes even with only a few gossip messages per day I expect for the given reasons the setup of valves to be possible and useful!

with kind regards Rene

[1]: https://en.wikipedia.org/wiki/Maximum_entropy_probability_distribution#Uniform_and_piecewise_uniform_distributions [2]: https://arxiv.org/abs/2103.08576 [3]: https://github.com/lnresearch/Flow-Control-on-Lightning-Network-Channels-with-Drain-via-Control-Valves/blob/main/Privacy%20Considerations%20of%20signaling%20past%20drain%20via%20%60htlc_maximum_msat%60%20pairs.ipynb

Quoted text (68 lines)
>
> Thanks,
> Matt
>
> On 9/22/22 2:40 AM, René Pickhardt via Lightning-dev wrote:
> > Good morning fellow Lightning Developers,
> >
> > I am pleased to share my most recent research results [1] with you. They
> may (if at all) only have a
> > small impact on protocol development / specification but are actually
> mainly of concern to node
> > operators and LSPs. I still thought they may be relevant for the list.
> >
> > While trying to estimate the expected liquidity distribution in depleted
> channels due to drain via
> > Markov Models I realized that we can exploit the `htlc_maxium_msat`
> setting to act as a control
> > valve and regulate the "pressure" coming from the drain and mitigate the
> depletion of channels. Such
> > ideas are btw not novel at all and heavily used in fluid networks [2].
> Thus it seems very natural
> > that we do the same on the Lightning Network.
> >
> > In the article we show within a theoretic model how expected payment
> failure rates per channel may
> > drop significantly by up to an order of magnitude if channels set up
> proper asymmetric
> > `htlc_maximum_msat` pairs.
> >
> > We furthermore provide in our iPython notebook [3] two experimental
> algorithmic ideas with which
> > node operators can find decent `htlc_maximum_msat` values in a greedy
> fashion. One of the algorithms
> > does not even require to know the drain or payment size distribution or
> build the Markov model but
> > just looks at the liquidity distribution in the channel at the last x
> routing attempts and adjusts
> > the `htlc_maximum_msat` value if the distribution is to far away from a
> uniform distribution.
> >
> > Looking forwards for your thoughts and feedback.
> >
> > with kind regards Rene
> >
> >
> > [1]:
> >
> https://blog.bitmex.com/the-power-of-htlc_maximum_msat-as-a-control-valve-for-better-flow-control-improved-reliability-and-lower-expected-payment-failure-rates-on-the-lightning-network/
> <
> https://blog.bitmex.com/the-power-of-htlc_maximum_msat-as-a-control-valve-for-better-flow-control-improved-reliability-and-lower-expected-payment-failure-rates-on-the-lightning-network/
> >
> > [2]: https://en.wikipedia.org/wiki/Control_valve <
> https://en.wikipedia.org/wiki/Control_valve>
> > [3]:
> >
> https://github.com/lnresearch/Flow-Control-on-Lightning-Network-Channels-with-Drain-via-Control-Valves/blob/main/htlc_maximum_msat%20as%20a%20valve%20for%20flow%20control%20on%20the%20Lightnig%20network.ipynb
> <
> https://github.com/lnresearch/Flow-Control-on-Lightning-Network-Channels-with-Drain-via-Control-Valves/blob/main/htlc_maximum_msat%20as%20a%20valve%20for%20flow%20control%20on%20the%20Lightnig%20network.ipynb
> >
> >
> > --
> > https://ln.rene-pickhardt.de <https://ln.rene-pickhardt.de>
> >
> > _______________________________________________
> > Lightning-dev mailing list
> > Lightning-dev at lists.linuxfoundation.org
> > https://www.learnbitcoin.com/archive/lists/lightning-dev
>
Anthony Towns in reply to René Pickhardt permalink original

On Thu, Sep 22, 2022 at 08:40:30AM +0200, René Pickhardt via Lightning-dev wrote:

Quoted text (4 lines)
> While trying to estimate the expected liquidity distribution in depleted
> channels due to drain via Markov Models I realized that we can exploit the
> `htlc_maxium_msat` setting to act as a control valve and regulate the
> "pressure" coming from the drain and mitigate the depletion of channels.

This is really neat!

I think "channel drain" confounds two issues (or, at least, I do when I think about it):

 1) one is you're trying to collect as many forwarding fees as you can,
    and since a drained channel prevents you from forwarding txs, that
    feels like a hit on profits
 2) the other is that a drained channel *can't* forward a payment even
    for no profit, so even attempting to forward a payment over a drained
    channel wastes everyone's time, increases payment latency, and may
    increase payment failures if you go through too many failures without
    finding a successful path

This seems like a great idea for solving (2) -- if you make lightning nodes look at htlc_max_msat and throttle their use of a channel based on its value, then channels can set that value so that their payment flow is balanced on average, at which point depletion becomes rare, and payments usually succeed.

I think a simple way of thinking about it is: suppose people are forwarding X BTC per hour through a channel in one direction, and 2X BTC through it in the other direction, with all payments being 1000 sats exactly. Then if you set htlc_max_msat to 500sats on the overloaded direction, and everyone then triggers their AMP paths and sends half their payments through a slightly more expensive path, you'll be at X-vs-X BTC per hour, with balanced flows and stable channel balances.

OTOH, it is relying on senders doing things that are slightly less optimal in the short term (pay higher fees) for things that benefit them only in the long term (avoid payment latency/failures due to depleted channels), and only if most people cooperate. Perhaps there's some privacy-preserving way that channel operators could throttle payments based on htlc_max_msat (and channel depletion percentage?) as well, so that cheaters are less likely to prosper?

But as far as (1) goes -- this isn't actually an improvement: instead of rejecting X BTC per hour from the overloaded direction because your channel's depleted, you're now not even getting the opportunity to forward those payments and collect the corresponding fees. It's no worse for your profit margins, but it's not any better. (And it could be worse if you're throttling both sides, and only getting 0.95*X BTC per hour in both directions.

But there aren't many ways you can actually do better with (1).

One way is if you have a cheap way to rebalance your channels -- in that case, rebalance your channel, let it drain again, collecting fees all the while, and repeat. If rebalancing is cheaper than the fees you collect, this works great!

The other way is if fees rates are expected to change -- if they're likely to go down later, then you might as well deplete your channel now, since you'll collect more fees for it now than you would later; likewise if you expect fees to up up later, then you might want to retain some balance now, so you can deplete it later. But that's a very dynamic situation, and the profits are limited -- you can only drain your channel once while waiting for fee rates to be ready to change, and your profit is going to be capped by your channel capacity times the difference in the fee rates.

This approach seems *much* better than the fee rate cards idea:

 * you're not decreasing your channel profitability half the time in
   order to avoid your channel depleting
 * you're making routing decisions *less* dependent on internal/private
   state, rather than more
 * you're not adding much gossip/probing traffic -- you might need
   to refine your htlc_max_msat a few times each time you change fees,
   but it shouldn't be often, and this should be reducing the frequency
   you have to change fees anyway
 * you're providing a way of throttling payment traffic independent of
   fees -- since fees are competitive, they can have discontinuous effects
   where a small change to fee can cause a large change to traffic volume;
   but this seems like it should mostly have a proportional response,
   with a small decrease in htlc_max_msat resulting in a small decrease in
   payment volume, and conversely. Much better for stability/optimisation!

Cheers, aj

ZmnSCPxj in reply to Anthony Towns permalink original

Good morning aj, and Rene,

Quoted text (6 lines)
> * you're providing a way of throttling payment traffic independent of
> fees -- since fees are competitive, they can have discontinuous effects
> where a small change to fee can cause a large change to traffic volume;
> but this seems like it should mostly have a proportional response,
> with a small decrease in htlc_max_msat resulting in a small decrease in
> payment volume, and conversely. Much better for stability/optimisation!

This may depend on what gets popular for sender algorithms.

Senders may quantize their payments, i.e. select a "standard" value and divide all payments into multipath sub-payments of this value.

* Simplifies the computation of base fee when using a min-cost solver.
* Simplifies the design of splitting/merging decisions if not using a min-cost solver.
* Improves privacy once we have PTLCs (if most senders use the same standard value, it is much harder to figure out if two sub-payments, with approximately the same standard quantum, belong to the same payment or not).

If so, then we expect a large discontinuity for the `htlc_max_msat` vs `htlcs_sent` curve around whatever selected quantum there is. If you set `htlc_max_msat` below this quantum your expected number of payments forwarded will drop to near 0, but a little above that and you might very well saturate since all payments are quantized anyway.

At least fees gets you basic economics of supply and demand, and is a natural throttle in all markets, including liquidity markets.

Regards, ZmnSCPxj

ZmnSCPxj in reply to ZmnSCPxj permalink original

Good morning again aj, and Rene,

Quoted text (22 lines)
> Good morning aj, and Rene,
>
> > * you're providing a way of throttling payment traffic independent of
> > fees -- since fees are competitive, they can have discontinuous effects
> > where a small change to fee can cause a large change to traffic volume;
> > but this seems like it should mostly have a proportional response,
> > with a small decrease in htlc_max_msat resulting in a small decrease in
> > payment volume, and conversely. Much better for stability/optimisation!
>
>
> This may depend on what gets popular for sender algorithms.
>
> Senders may quantize their payments, i.e. select a "standard" value and divide all payments into multipath sub-payments of this value.
>
> * Simplifies the computation of base fee when using a min-cost solver.
> * Simplifies the design of splitting/merging decisions if not using a min-cost solver.
> * Improves privacy once we have PTLCs (if most senders use the same standard value, it is much harder to figure out if two sub-payments, with approximately the same standard quantum, belong to the same payment or not).
>
> If so, then we expect a large discontinuity for the `htlc_max_msat` vs `htlcs_sent` curve around whatever selected quantum there is.
> If you set `htlc_max_msat` below this quantum your expected number of payments forwarded will drop to near 0, but a little above that and you might very well saturate since all payments are quantized anyway.
>
> At least fees gets you basic economics of supply and demand, and is a natural throttle in all markets, including liquidity markets.

Basically, the intuition "small decrease in `htlc_max_msat` == small decrease in payment volume" inherently assumes that HTLC sizes have a flat distribution across all possible sizes. The `htlc_max_msat` vs `payment_volume` curve is basically the integral of the distribution of HTLC sizes. But:

* As above, senders might quantize, and if some standard quantum becomes popular, the distribution is really a spike around the standard quantum, and there is a massive discontinuity there.
* Coffee or other popular everyday product may settle on a standard price, which again implies a spike around that standard price.

So the reliability of `htlc_max_msat` as a valve is dependent on market forces, and may be as non-linear as feerates, which *are* the sum total of the market force.

Feerates on the other hand are always going to be something that senders optimize for, because obviously senders will have a maximum amount they will be willing to pay in fees (as before, the intuition here is that the maximum fee senders are willing to pay is equivalent to the difference in subjective value between the millisatoshis they are sending and the service/product they are purchasing). Whatever future sender algorithms are devised, feerates will still work consistently as a valve, whreas `htlc_max_msat` may fail in a future where sender algorihms quantize the payments around some standard quantum for privacy and ease-of-implementation purposes.

Regards, ZmnSCPxj

Anthony Towns in reply to ZmnSCPxj permalink original

On Mon, Sep 26, 2022 at 01:26:57AM +0000, ZmnSCPxj via Lightning-dev wrote:

Quoted text (8 lines)
> > > * you're providing a way of throttling payment traffic independent of
> > > fees -- since fees are competitive, they can have discontinuous effects
> > > where a small change to fee can cause a large change to traffic volume;
> > > but this seems like it should mostly have a proportional response,
> > > with a small decrease in htlc_max_msat resulting in a small decrease in
> > > payment volume, and conversely. Much better for stability/optimisation!

> > This may depend on what gets popular for sender algorithms.
> > Senders may quantize their payments, i.e. select a "standard" value and divide all payments into multipath sub-payments of this value.

I don't think that's really the case.

One option is that you quantize based on the individual payment -- you want to send $100, great, your software splits it into 50x $2 payments, and routes them. But that doesn't have an all or nothing effect: if you reject anything over $1.99, then instead of routing 1/50th of payments up to $100, you're routing 1/50th of payments up to $99.50.

The other approach is to quantize by some fixed value no matter what the payment is (maybe for better privacy?). I don't think that's a good idea in the first place -- it trades off maybe a small win for your privacy for using up everyone else's HTLC slots -- but if it is, it'll need to be quite a small value so as not to force you to round up the overall payment too much, and to allow small payments in the first place. But in that case most channels will have their html_max_msat well above that value anyway.

Quoted text (1 line)
> Basically, the intuition "small decrease in `htlc_max_msat` == small decrease in payment volume" inherently assumes that HTLC sizes have a flat distribution across all possible sizes.

The intuition is really the other way around: if you want a stable, decentralised network, then you need the driving decision on routing to be something other than just "who's cheaper by 0.0001%" -- otherwise everyone just chooses the same route at all times (which becomes centralised towards the single provider who can best monetise forwarding via something other than fees), and probably that route quickly becomes unusable due to being drained (which isn't stable).

(But of course, I hadn't had any ideas on what such a thing could be, otherwise I'd have suggested something like this earlier!)

So, to extend the intuition further: that means that if using htlc_max_msat as a valve/throttle can fill that role, then that's a reason to not do weird things like force every HTLC to be 2**n msats or similar.

If there is a conflict, far better to have a lightning network that's decentralised, stable, and doesn't require node operators to spy on transactions to pay for their servers.

It's not quite as bad as you suggest though -- the payment sizes don't need to have a flat distribution, they only need to have a smooth/continuous distribution.

Quoted text (1 line)
> * Coffee or other popular everyday product may settle on a standard price, which again implies a spike around that standard price.

Imagine the price of coffee is $5, and you find three potential paths to pay for that coffee:

  Z -> A -> X
  Z -> B -> C -> X
  Z -> B -> D -> X

(I think you choose both the fee and max_msat for Z->A and Z->B hops, so we'll assume they're 0%/infinite, respectively)

Suppose the fee on AX is 0.01%, and the total fee for BCX is 0.02% and the total fee for BDX is 0.1%.

If AX's max_msat is $5, they'll get the entire transaction. If it's $4.99, you might instead optimise fees by doing AMP: send $4.99 through AX and $0.01 through BCX, for a total fee rate of 0.01002%.

If everyone quantizes at 10c (500sat?) instead of 1c (50sat?) or lower then that just means instead of getting maybe a 0.2% reduction in payment flow, AX gets a 2% reduction in payment flow.

Likewise, if AX's max_msat is $1, BCX's max_msat is $3, and BDX's max_msat is $20, then you split your payment up as $1/$3/$1 and pay a fee of 0.034%. Meanwhile AX's payment flow has been reduced by perhaps 80% (if everyone's buying $5 coffees), and BCX's by perhaps 25% (from $4 to $3), allowing them to maintain balanced channels.

Quoted text (1 line)
> So the reliability of `htlc_max_msat` as a valve is dependent on market forces, and may be as non-linear as feerates, which *are* the sum total of the market force.

No: without some sort of external throttle, fees have a tendency to be all or nothing. If there's no metric other than fees, why would I ever choose to pay 0.02% (let alone 0.1%!) in fees? And if a new path comes along offering a fee rate of 0.00999% fees, why would I continue paying 0.01%?

Even if everyone does start quantizing their payments -- and does so with an almost 6 order of magnitude jump from 1msat to 500sats -- you're only implying traffic bumps of perhaps 2% when tweaking parameters that are near important thresholds, rather than 100%.

Quoted text (1 line)
> Feerates on the other hand are always going to be something that senders optimize for, [...]

Sure, but that can't be the end of the story, since it has a clear winner that everyone immediately agrees upon, and there's no point anyone else participating in trying to route lightning transactions.

There's plenty of other possible throttling mechanisms: at the very least, senders can *not* optimise for fees, and instead randomly select routes within a budget; or you can maintain external "reliability" scores for nodes and factor those in along with fee rates.

What's novel and interesting about this approach (IMO) is it's one that the channel operator can use directly (so the person who's meant to know the private channel state is making the decision that depends on the private channel state), and that they don't have a particular incentive to lie about (with random choice, maybe you want to pretend you have many nodes/channels so you get selected more often; if reliability is factored in, maybe you're tempted to pretend to be more reliable than you are).

Cheers, aj

ZmnSCPxj in reply to Anthony Towns permalink original

Good morning aj,

Quoted text (10 lines)
> > Basically, the intuition "small decrease in `htlc_max_msat` == small decrease in payment volume" inherently assumes that HTLC sizes have a flat distribution across all possible sizes.
>
>
> The intuition is really the other way around: if you want a stable,
> decentralised network, then you need the driving decision on routing to
> be something other than just "who's cheaper by 0.0001%" -- otherwise
> everyone just chooses the same route at all times (which becomes
> centralised towards the single provider who can best monetise forwarding
> via something other than fees), and probably that route quickly becomes
> unusable due to being drained (which isn't stable).

All monetisation is fee-based; the question is who pays the fees. Certainly gossiped feerates will work less effectively if fees are paid via another mechanism.

In particular, discussing with actual forwarding node operators reveals that most of them think that CLBOSS undercuts fees too much searching a short-term profit, quickly depleting its usable liquidity in the long term. In short, they want CLBOSS modified to raise fees and preserve the liquidity supply. This suggests to me that channel saturation due to being cheaper by 0.0001% is not something that will occur often, as most operators will settle to a feerate that maximizes their earnings per unit liquidity they can provide, not trying to undercut everyone.

In particular, the fact that rebalancing already exists as part of the network protocol means that anyone trying to undercut will find their liquidity being bought out by more patient operators, who are willing to sacrifice short-term profits for long-term consistent earnings.

In short, the market will fix itself once we have more rational automated actors in place (i.e. not CLBOSS). Indeed, price signals are always places where you should pay attention to whether you need more of a good or not.

But maybe I am just modelling everything incorrectly. Certainly the fact that fees can be paid by somebody else other than senders can make gossiped feerates (which are the sender-paid feerates) less effective.

Regards, ZmnSCPxj

ZmnSCPxj in reply to ZmnSCPxj permalink original

Good morning aj, Rene, and all,

So let me discuss a little more about how I model the forwarding nodes.

Forwarding nodes want to maximize profit.

Forwarding nodes sell liquidity.

If a forwarding node runs out of stock of liquidity (i.e. their channel is unbalanced against the direction a payment request fails) they earn 0 profit.

If a forwarding node finds a liquidity being sold at a lower price than they would be able to sell it, they will buy out the cheaper stock and then resell it at a higher price. This is called rebalancing. In particular:

* Other economic activity is likely to be "has to happen at a particular time".
  * The intuition here is that people are not going to pay until they become interested in purchasing a product, and only then will they actually send out an HTLC.
* Rebalances (i.e. hostile takeover bids of cheap liquidity) are "can happen at any time".
* Thus, rebalances are likely to occur "first", because they can happen at any time, and can be done right now, whereas payments will need to wait until somebody somewhere is interested in paying.
* Thus, channels advertising low fees are likely to have their liquidity bought out by patient forwarding nodes.

The above implies that any "payment size distribution" can, and *will*, be manipulated by forwarding nodes out to buy out cheap liquidity. If you introduce an artificial impediment and say "I will only accept payment sizes below N millisats", and then go "I will #zerofeerouting guy", then a forwarding node will just split their rebalance into quanta of N millisats and make a spike in the payment size distribution and drain your channel anyway, so that they can turn around and resell the liquidity at a higher price later.

This also suggests to me that fees being paid by out-of-band means (i.e. "monetizing outside of the Lightning forwarding fees") is likely to fail, because forwarding nodes will exploit that and do a hostile takeover of the cheap liquidity. i.e. #zerofeerouting will never be a reliable forwarding node, because all the other forwarding nodes will be taking their liquidity for cheap long before you think to make a payment through them.

Rebalances cannot be differentiated from payments unless you force publication of source and destination (and even if you forced that, people can lie about who the *real* source and *real* destination are, so why bother). And rebalances are going to target cheap liquidity and will avoid any non-fee valves you impose.

Invisible hand wins, yo.

Regards, ZmnSCPxj

Anthony Towns in reply to ZmnSCPxj permalink original

On Tue, Sep 27, 2022 at 12:23:38AM +0000, ZmnSCPxj via Lightning-dev wrote:

Quoted text (1 line)
> All monetisation is fee-based; the question is who pays the fees.

This isn't true. For example, if you can successfully track the payments you route, you can monetize by selling data about who's buying what from whom. (Unless you meant it in some trivial sense, I guess, like "all monetisation is money-based; the question is who pays the money")

Quoted text (8 lines)
> In particular, discussing with actual forwarding node operators reveals
> that most of them think that CLBOSS undercuts fees too much searching
> a short-term profit, quickly depleting its usable liquidity in the
> long term.
> In short, they want CLBOSS modified to raise fees and preserve the
> liquidity supply.
> This suggests to me that channel saturation due to being cheaper by
> 0.0001% is not something that will occur often,

That seems a bit of a backwards conclusion: "undercutting fees depletes liquidity" therefore "channel saturation due to offering cheaper fees seems unlikely" -- channel saturation *is* depleted liquidity...

On Wed, Sep 28, 2022 at 02:07:51AM +0000, ZmnSCPxj via Lightning-dev wrote:

Quoted text (2 lines)
> Forwarding nodes sell liquidity.
> If a forwarding node runs out of stock of liquidity (i.e. their channel is unbalanced against the direction a payment request fails) they earn 0 profit.

I get what you're saying, but I don't think a "stock of liquidity" is a helpful metaphor/mental model here.

"Liquidity" usually means "how easy it is to exchange X for Y" -- assets for cash, etc; but for lightning, liquidity is guaranteed by being able to drop to chain. Likewise, "running out of stock" isn't usually something that gets automatically fixed by someone else coming in and buying something different.

(Also, you don't earn 0 profit on an imbalanced channel; you're just forced to stop accepting some txs. Every time you forward $1 in the available direction, you become able to forward another $1 back in the saturated direction; and you earn fees on both those $1s)

I think it's better to think in terms of "payment flow" -- are you forwarding $5/hour in one direction, but $10/hour in the other? Is that an ongoing imbalance, or something that evens itself out over time ($120/day in both directions)?

Once you start in that direction, there's also a few other questions you can ask:

 * can I get make more revenue by getting more payment flow at a
   lower fee, or by charging a higher fee over less payment flow?
 * if I had a higher capacity channel, would that let me tolerate
   a temporarily imbalanced flow over a longer period, allowing me
   to forward more payments and make more fee revenue?

If you want to have a long running lightning channel, your payment flows will *always* be balanced. That might be through luck, it might be through clever management of channel parameters, but if it's not through those, it'll be because your channel's saturated, and you're forced to fail payments.

Ultimately, over the *entire* lifetime of a lightning channel, the only imbalance you can have is to either lose the funds that you've put in, or gain the funds your channel partner put in.

That *is* something you could sensibly model as a stock that gets depleted over time, if your payment flows are reliably unbalanced in a particular direction. For example, consider a channel that starts off with $100k in funds and has a $5k imbalance every day: after 20 days, you'll have to choose between failing that $5k imbalance (though you could still route the remaining balanced flows), or between rebalancing your channels, possibly via on-chain transactions. Does the fee income from an additional $100k of imbalanced transactions justify the cost of rebalancing?

You can calculate that simply enough: if the on-chain/rebalance cost is $300, then if you were getting a fee rate of more than 0.3% ($300/$100k), then it's worth paying for the rebalance.

But if "lifetime drain" is the dominant factor, you're reducing lightning to the same performance as one-way payment channels: you move the aggregate payments up to the channel capacity, and then close the channel. If you get balanced payment flows, that allows you to cancel out 30,000 $1 transactions against 1,000 $30 transactions, and maintain the channel indefinitely, with all the off-chain scaling that implies.

Quoted text (2 lines)
> If a forwarding node finds a liquidity being sold at a lower price than they would be able to sell it, they will buy out the cheaper stock and then resell it at a higher price.
> This is called rebalancing.

All that does is move the flow imbalance to someone else's channel; it doesn't improve the state of the network.

There definitely are times when that makes sense:

 * maybe the channel's run by "dumb money" that will eat the fee for
   closing on-chain, so you don't have to
 * maybe you have secret information about the other channel, allowing
   you to route through it for cheaper than the general public
 * maybe you and they have different demand at different times of the
   day, so time-shifting imbalances is mutually beneficial? I don't
   see how this works out without secret information though -- the
   people who want to route payments should be choosing the cheapest
   link at all times of the day already

But those don't generally seem aligned with the long-term health of the lightning network?

Quoted text (1 line)
> * Thus, channels advertising low fees are likely to have their liquidity bought out by patient forwarding nodes.

I think the "liquidity" metaphor isn't doing you any favours here. Here's what (I think) that scenario looks like under "flow":

 - overall, there's unbalanced flow: for example, people want to pay a
   higher amount from A to B than from B to A.
 - X charges low fees to forward from A to B, so their channel is always
   depleted in that direction.
 - Y charges high fees to forward from A to B
 - Y takes advantage of being constantly online to always be the first
   to route their rebalance through X (Y->A->X->B->Y) when X's channel
   clears up

Y's rebalancing then is limited by the legitimate payment volume going back through X (ie B->X->A). Because there's an unbalanced flow overall, that means Y cannot rebalance to compensate for the total amount of payments it routes, and eventually both X and Y will become depleted in the same direction, and one or both channels will have to decide whether to rebalance on-chain. If X rebalances on-chain, allowing Y to repeatedly take advantage of their low fees, that's the "dumb money" situation.

Quoted text (6 lines)
> If you introduce an artificial impediment and say "I will only accept
> payment sizes below N millisats", and then go "I will #zerofeerouting
> guy", then a forwarding node will just split their rebalance into quanta
> of N millisats and make a spike in the payment size distribution and
> drain your channel anyway, so that they can turn around and resell the
> liquidity at a higher price later.

Of course, it's possible that overall flows *are* balanced, and you're just able to take advantage of your better understanding of lightning routing to charge higher fees than this "X" character.

But the same scenario applies in the max_msat world too, with only slight modifications.

 * instead of constantly probing the A->X->B channel so that you keep it
   drained, you create fake traffic over A->X->B causing X to detect an
   imbalance and lower their max_msat in order to get the flows
   balanced.
 * this causes users to send more traffic through A->Y->B, giving you
   more fee income
 * you can then repeatedly generate more fake traffic over A->X->B,
   causing X to lower max_msat further, perhaps giving you most of the
   A->B traffic
 * meanwhile you do regular rebalances (Y->A->X->B->Y) at values less
   X's than max_msat
 * your node sees perhaps 90% of A->B payment flows, and does the same
   volume in rebalancing
 * X's node sees 10% of legit A->B payment flows, and your 90% of legit
   payment flows via your rebalancing; and also 100% of legit B->A
   payment flows
 * so both nodes remain balanced, reducing payment failures; and Y can
   rebalance constantly, allowing them to operate with a smaller
   capacity channel making it more capital efficient

I think there's a few limitations on that "attack":

 * it only works if you're willing to forego legitimate fee income
   from B->Y->A -- but if you're competing with someone who charges
   zero fees anyway, maybe that's fine
 * it only works if A->X->B is charging much lower fees so your
   rebalancing really is cheap
 * you probably need to reserve capital in order to create the fake
   payment flows -- afterall, if you try to rebalance the capital you
   used to create the fake payment flow, that creates a payment flow
   in the other direction, which risks undoing your work
 * that A->X->B is overloaded (max_msat is lowish) that's a public
   indication that there's high demand at X's fee rate along that path,
   which may encourage people to create additional channels. creating
   fake payment flow for all of those channels may become prohibitively
   capital intensive.
Quoted text (1 line)
> i.e. #zerofeerouting will never be a reliable forwarding node, because all the other forwarding nodes will be taking their liquidity for cheap long before you think to make a payment through them.

I don't think it's ideal if a world that includes both:

 * altruists, who'll forward your payments for cheap/free
 * profiteers, who are trying to make a living offering lightning
   services

results in "oops, optimising for low lightning fees becomes horribly unreliable".

[repeating this one, to followup in a different way]

Quoted text (4 lines)
> If you introduce an artificial impediment and say "I will only accept
> payment sizes below N millisats", and then go "I will #zerofeerouting
> guy", then a forwarding node will just split their rebalance into quanta
> of N millisats

I mean, that's already a fundamental problem with max_msat: why wouldn't payment initiators do exactly that in the first place?

Making this incentive compatible with AMP payments does seem like a challenge. Why pay higher fees routing through some other channel, instead of just AMPing as many max_msat payments as you need through the cheapest channel? (Hmm, I guess I didn't express that concern as clearly as I thought I did; at least outside of any deleted drafts...)

I wonder whether a (per source/dest channel?) token bucket rate limit might suffice, though. Hmm, it maybe would so long as you're optimising for small/frequent payments to be reliable, and aren't worried so much about large/infrequent ones, which *might* be reasonable... That way you start rejecting payment flow *before* your channel's depleted if it becomes unusually bursty in one direction, despite you having indicated you want senders to throttle. And then the early rejections mean there's not so much value AMPing lots of max_msat payments through a single cheap channel.

I suppose in a *completely* ideal world, I might imagine something like this:

 * $100,000 a day travels from A to B; $90,000 a day travels from B to A
 * all the A->B payments are $5 each
 * onchain fees for rebalancing a channel is $200
 * X and Y run routing nodes and want to make stuff cheap, so charge
   0.001% (10-parts-per-million)
 * Z is happy to rebalance on chain, has $50,000 committed in his
   channel, so charges fees of $200/$50,000 = 0.4% (or, probably, more)

In order to get balanced flows, X and Y set their max_msat in the A to B direction to $2.25, meaning:

 * 20k $5 payments from A to B gets split into $2.25 through X, $2.25
   through Y, and $0.50 through Z
 * 90 $1000 payment from B to A get split into $500 through X and $500
   through Y.

Every day:

 * X and Y see $45000 going each way, collecting $0.90 in routing fees
   per day, and having their channel not go out of balance
 * Z sees $10,000 going from A to B, collecting $40 a day
 * Z's channel runs out after 5 days, at which point he's collected $200
   total, and has to spend $200 rebalancing on-chain
 * each person paying $5 to B pays $0.002045 in fees; each person
   paying $1000 to A pays $0.01 in fees

Z could reduce his fee rate below 0.4% and still break even if he increased his channel capacity above $50k. He can't make his channel last longer by getting more B->A channel flow though, because that would just lead X and Y's flows to be unbalanced, causing payers to have to route more flow through Z.

Cheers, aj

ZmnSCPxj in reply to Anthony Towns permalink original

Good morning aj,

Quoted text (12 lines)
> > Forwarding nodes sell liquidity.
> > If a forwarding node runs out of stock of liquidity (i.e. their channel is unbalanced against the direction a payment request fails) they earn 0 profit.
>
>
> I get what you're saying, but I don't think a "stock of liquidity"
> is a helpful metaphor/mental model here.
>
> "Liquidity" usually means "how easy it is to exchange X for Y" -- assets
> for cash, etc; but for lightning, liquidity is guaranteed by being
> able to drop to chain. Likewise, "running out of stock" isn't usually
> something that gets automatically fixed by someone else coming in and
> buying something different.

Semantics. You got what I am saying anyway.

So let me invent a completely new term derived from my local `/dev/random`, "IPpvHg".

When your channel is imbalanced against a particular direction, you cannot forward against the balance. In that case, we say "you have insufficient stock of IPpvHg".

A forwarding node is in the business of selling IPpvHg.

If a forwarding node sets the price of its IPpvHg too low, another forwarding node, one which is more patient, can buy out its stock of IPpvHg to add to its own stock of IPpvHg.

A patient and rich forwarding node can buy out the IPpvHg stock of many cheaper nodes, and that I think is what we are mostly seeing in the network.

Quoted text (4 lines)
> (Also, you don't earn 0 profit on an imbalanced channel; you're just
> forced to stop accepting some txs. Every time you forward $1 in the
> available direction, you become able to forward another $1 back in the
> saturated direction; and you earn fees on both those $1s)

But that is based on the existence of a stock of IPpvHg in another channel.

Actual forwarding node operators classify their peers as "mostly a source" and "mostly a drain" and "mostly balanced", they want CLBOSS to classify peers similarly. Their stock of IPpvHg is getting depleted from "mostly a drain" peers, and the stock of IPpvHg they get from "mostly a source" peers, which they get in compensation, is less valuable.

Which is the whole point: there is a price to IPpvHg, and that should be reflected in the feerates your forwarding node should publish.

Quoted text (4 lines)
> I think it's better to think in terms of "payment flow" -- are you
> forwarding $5/hour in one direction, but $10/hour in the other? Is
> that an ongoing imbalance, or something that evens itself out over time
> ($120/day in both directions)?

It is helpful to notice that the channel balance is the integral of the sum of payment flows in both directions. This is why actual forwarding node operators are obsessed with channel balance. They already *are* thinking in terms of payment flow, and using an analytical technique to keep track of it: the channel balance itself.

Quoted text (6 lines)
>
> Once you start in that direction, there's also a few other questions
> you can ask:
>
> * can I get make more revenue by getting more payment flow at a
> lower fee, or by charging a higher fee over less payment flow?

As I pointed out, if you sell your stock of IPpvHg at too low a price point, other forwarding nodes will snatch up the cheap IPpvHg, buying out that stock. They can then form an effective cartel, selling the stock of IPpvHg at a higher price later.

Quoted text (40 lines)
> * if I had a higher capacity channel, would that let me tolerate
> a temporarily imbalanced flow over a longer period, allowing me
> to forward more payments and make more fee revenue?
>
> If you want to have a long running lightning channel, your payment flows
> will always be balanced. That might be through luck, it might be through
> clever management of channel parameters, but if it's not through those,
> it'll be because your channel's saturated, and you're forced to fail
> payments.
>
> Ultimately, over the entire lifetime of a lightning channel, the only
> imbalance you can have is to either lose the funds that you've put in,
> or gain the funds your channel partner put in.
>
> That is something you could sensibly model as a stock that gets depleted
> over time, if your payment flows are reliably unbalanced in a particular
> direction. For example, consider a channel that starts off with $100k in
> funds and has a $5k imbalance every day: after 20 days, you'll have to
> choose between failing that $5k imbalance (though you could still route
> the remaining balanced flows), or between rebalancing your channels,
> possibly via on-chain transactions. Does the fee income from an additional
> $100k of imbalanced transactions justify the cost of rebalancing?
>
> You can calculate that simply enough: if the on-chain/rebalance cost is
> $300, then if you were getting a fee rate of more than 0.3% ($300/$100k),
> then it's worth paying for the rebalance.
>
> But if "lifetime drain" is the dominant factor, you're reducing
> lightning to the same performance as one-way payment channels: you move
> the aggregate payments up to the channel capacity, and then close the
> channel. If you get balanced payment flows, that allows you to cancel
> out 30,000 $1 transactions against 1,000 $30 transactions, and maintain
> the channel indefinitely, with all the off-chain scaling that implies.
>
> > If a forwarding node finds a liquidity being sold at a lower price than they would be able to sell it, they will buy out the cheaper stock and then resell it at a higher price.
> > This is called rebalancing.
>
>
> All that does is move the flow imbalance to someone else's channel;
> it doesn't improve the state of the network.

I agree.

"something you can sensibly model as a stock that gets depleted over time" is, in fact, the channel balance that forwarding node operators are so obsessed with.

This all implies to me that the main problem might not be *local* imbalances, but *global* ones.

* There are net receivers who just keep their funds in Lightning.

Long ago I proposed that we add to the base protocol a mandatory global functionality to support onchain-to-offchain swaps.

* A node whose channels have depleted contacts one of the payees it often pays to.
* The first node constructs an onchain HTLC offer to the second node.
* The second node routes back a payment over the Lightning Network to the first node.
* The first node releases the payment preimage over Lightning.
* The second node claims the onchain HTLC via the payment preimage.

I proposed that as an alternative to splicing.

Splicing involves (with current technology) one transaction (spending a 2-of-2 and creating another P2WSH) but only changes the state of a single local channel.

Onchain-to-offchain swaps require two transactions, but can change the state of many channels. The onchain-to-offchain swap direction also follows "initiator pays", since it is the initiator who takes on the risk of performing an onchain action and will pay fees in case the swap protocol does not run to completion.

The existence of such a protocol would force any net receivers to move their funds from Lightning to onchain, and thus make available any global IPpvHg stocks towards them.

Quoted text (8 lines)
>
> There definitely are times when that makes sense:
>
> * maybe the channel's run by "dumb money" that will eat the fee for
> closing on-chain, so you don't have to
>
> * maybe you have secret information about the other channel, allowing
> you to route through it for cheaper than the general public

Channel balance is private information.

If you know you have a low balance on your side of a channel, that implies that you have the (private) information that forwards to it are in high demand.

Thus you can rationally buy any cheaply-offered IPpvHg towards the same node and resell it later at a higher price.

Quoted text (5 lines)
> * maybe you and they have different demand at different times of the
> day, so time-shifting imbalances is mutually beneficial? I don't
> see how this works out without secret information though -- the
> people who want to route payments should be choosing the cheapest
> link at all times of the day already

Channel balance *is* the private information you are looking for here: it is the integral of the sum of payment flows. Knowing this integral at any time implies knowledge of the recent time-based payment flow.

Sure, a remote node through which you rebalance might not share this information to you, but half-knowing is one-fourth of the battle or else either math does not work or I should never have listened to G.I. Joe.

Quoted text (2 lines)
> But those don't generally seem aligned with the long-term health of the
> lightning network?

If there is no incentive to run a forwarding node, then the Lightning Network cannot exist, and its long-term health would be moot. This is similar to mining nodes on the base blockchain.

Quoted text (24 lines)
> > * Thus, channels advertising low fees are likely to have their liquidity bought out by patient forwarding nodes.
>
>
> I think the "liquidity" metaphor isn't doing you any favours here.
> Here's what (I think) that scenario looks like under "flow":
>
> - overall, there's unbalanced flow: for example, people want to pay a
> higher amount from A to B than from B to A.
> - X charges low fees to forward from A to B, so their channel is always
> depleted in that direction.
> - Y charges high fees to forward from A to B
> - Y takes advantage of being constantly online to always be the first
> to route their rebalance through X (Y->A->X->B->Y) when X's channel
>
> clears up
>
> Y's rebalancing then is limited by the legitimate payment volume going
> back through X (ie B->X->A). Because there's an unbalanced flow overall,
>
> that means Y cannot rebalance to compensate for the total amount of
> payments it routes, and eventually both X and Y will become depleted in
> the same direction, and one or both channels will have to decide whether
> to rebalance on-chain. If X rebalances on-chain, allowing Y to repeatedly
> take advantage of their low fees, that's the "dumb money" situation.

Yes, but again: the integral of payment flows is the channel balance, and you can replace every reference to "flow" here with "channel balance".

Quoted text (72 lines)
> > If you introduce an artificial impediment and say "I will only accept
> > payment sizes below N millisats", and then go "I will #zerofeerouting
> > guy", then a forwarding node will just split their rebalance into quanta
> > of N millisats and make a spike in the payment size distribution and
> > drain your channel anyway, so that they can turn around and resell the
> > liquidity at a higher price later.
>
>
> Of course, it's possible that overall flows are balanced, and you're
> just able to take advantage of your better understanding of lightning
> routing to charge higher fees than this "X" character.
>
> But the same scenario applies in the max_msat world too, with only
> slight modifications.
>
> * instead of constantly probing the A->X->B channel so that you keep it
>
> drained, you create fake traffic over A->X->B causing X to detect an
>
> imbalance and lower their max_msat in order to get the flows
> balanced.
>
> * this causes users to send more traffic through A->Y->B, giving you
>
> more fee income
>
> * you can then repeatedly generate more fake traffic over A->X->B,
>
> causing X to lower max_msat further, perhaps giving you most of the
> A->B traffic
>
>
> * meanwhile you do regular rebalances (Y->A->X->B->Y) at values less
>
> X's than max_msat
>
> * your node sees perhaps 90% of A->B payment flows, and does the same
>
> volume in rebalancing
>
> * X's node sees 10% of legit A->B payment flows, and your 90% of legit
>
> payment flows via your rebalancing; and also 100% of legit B->A
>
> payment flows
>
> * so both nodes remain balanced, reducing payment failures; and Y can
> rebalance constantly, allowing them to operate with a smaller
> capacity channel making it more capital efficient
>
> I think there's a few limitations on that "attack":
>
> * it only works if you're willing to forego legitimate fee income
> from B->Y->A -- but if you're competing with someone who charges
>
> zero fees anyway, maybe that's fine
>
> * it only works if A->X->B is charging much lower fees so your
>
> rebalancing really is cheap
>
> * you probably need to reserve capital in order to create the fake
> payment flows -- afterall, if you try to rebalance the capital you
> used to create the fake payment flow, that creates a payment flow
> in the other direction, which risks undoing your work
>
> * that A->X->B is overloaded (max_msat is lowish) that's a public
>
> indication that there's high demand at X's fee rate along that path,
> which may encourage people to create additional channels. creating
> fake payment flow for all of those channels may become prohibitively
> capital intensive.

But the same thing can be done in a world where fees are the valve, and you work directly with supply and demand instead of at one-layer-removed like `htlc_max_msat` does, which may hide more attacks: complexity is where exploits lurk.

Quoted text (11 lines)
> > i.e. #zerofeerouting will never be a reliable forwarding node, because all the other forwarding nodes will be taking their liquidity for cheap long before you think to make a payment through them.
>
>
> I don't think it's ideal if a world that includes both:
>
> * altruists, who'll forward your payments for cheap/free
> * profiteers, who are trying to make a living offering lightning
> services
>
> results in "oops, optimising for low lightning fees becomes horribly
> unreliable".

In the world outside of Lightning, we usually make the stink eye at any profiteers who exploit altruists and make noises about how such profiteers are evil, and occasionally even punish them a little bit.

Until you can import such a mechanism into Lightning --- which would, I think, require that forwarding nodes provide their identity, and for payments to have proof-of-identity from both sender and receiver --- then that is the result that will indeed occur.

Quoted text (10 lines)
> [repeating this one, to followup in a different way]
>
> > If you introduce an artificial impediment and say "I will only accept
> > payment sizes below N millisats", and then go "I will #zerofeerouting
> > guy", then a forwarding node will just split their rebalance into quanta
> > of N millisats
>
>
> I mean, that's already a fundamental problem with max_msat: why wouldn't
> payment initiators do exactly that in the first place?

Indeed, which suggests that the use of `htlc_max_msat` for a flow valve is flawed: it requires continuous payment flow / payment size curve, and the payment size can be manipulated trivially by any third parties.

What would limit this would be a decently high and definitely non-zero `base_fee`, but that is a fee-based valve already, which is what I have been pointing out is the simply best option we have.

Quoted text (16 lines)
>
> Making this incentive compatible with AMP payments does seem like a
> challenge. Why pay higher fees routing through some other channel,
> instead of just AMPing as many max_msat payments as you need through
> the cheapest channel? (Hmm, I guess I didn't express that concern as
> clearly as I thought I did; at least outside of any deleted drafts...)
>
> I wonder whether a (per source/dest channel?) token bucket rate limit
> might suffice, though. Hmm, it maybe would so long as you're optimising
> for small/frequent payments to be reliable, and aren't worried so much
> about large/infrequent ones, which might be reasonable... That way
> you start rejecting payment flow before your channel's depleted if it
> becomes unusually bursty in one direction, despite you having indicated
> you want senders to throttle. And then the early rejections mean there's
> not so much value AMPing lots of max_msat payments through a single
> cheap channel.

Given that a published channel is a global resource, any rate limit is going to be shared amongst many users, and if you underquote the value of the IPpvHg you are providing, rebalancers are going to grab as much of the rate limit as they can.

Quoted text (36 lines)
> I suppose in a completely ideal world, I might imagine something like
> this:
>
> * $100,000 a day travels from A to B; $90,000 a day travels from B to A
> * all the A->B payments are $5 each
>
> * onchain fees for rebalancing a channel is $200
> * X and Y run routing nodes and want to make stuff cheap, so charge
> 0.001% (10-parts-per-million)
> * Z is happy to rebalance on chain, has $50,000 committed in his
> channel, so charges fees of $200/$50,000 = 0.4% (or, probably, more)
>
> In order to get balanced flows, X and Y set their max_msat in the A to B
> direction to $2.25, meaning:
>
> * 20k $5 payments from A to B gets split into $2.25 through X, $2.25
> through Y, and $0.50 through Z
> * 90 $1000 payment from B to A get split into $500 through X and $500
> through Y.
>
> Every day:
>
> * X and Y see $45000 going each way, collecting $0.90 in routing fees
> per day, and having their channel not go out of balance
> * Z sees $10,000 going from A to B, collecting $40 a day
> * Z's channel runs out after 5 days, at which point he's collected $200
> total, and has to spend $200 rebalancing on-chain
> * each person paying $5 to B pays $0.002045 in fees; each person
> paying $1000 to A pays $0.01 in fees
>
> Z could reduce his fee rate below 0.4% and still break even if he
> increased his channel capacity above $50k. He can't make his channel last
> longer by getting more B->A channel flow though, because that would just
>
> lead X and Y's flows to be unbalanced, causing payers to have to route
> more flow through Z.

I think this implies we need to have a mechanism to move funds outside of the Lightning network, i.e. every published node should have onchain/offchain swap capability.

Regards, ZmnSCPxj

Anthony Towns in reply to ZmnSCPxj permalink original

On Thu, Sep 29, 2022 at 12:41:44AM +0000, ZmnSCPxj wrote:

Quoted text (9 lines)
> > I get what you're saying, but I don't think a "stock of liquidity"
> > is a helpful metaphor/mental model here.
> > "Liquidity" usually means "how easy it is to exchange X for Y" -- assets
> > for cash, etc; but for lightning, liquidity is guaranteed by being
> > able to drop to chain. Likewise, "running out of stock" isn't usually
> > something that gets automatically fixed by someone else coming in and
> > buying something different.
> Semantics.
> You got what I am saying anyway.

Semantics are important. If you choose the wrong analogies, you'll jump to the wrong conclusions, which I think you're doing here.

Quoted text (1 line)
> So let me invent a completely new term derived from my local `/dev/random`, "IPpvHg".

If you're going to make up words, at least make them pronouncable... apt-get install pwgen; pwgen -0A maybe. But there's no need to make up words; these aren't completely novel concepts, and existing terms describe the concepts pretty well.

Quoted text (1 line)
> A patient and rich forwarding node can buy out the IPpvHg stock of many cheaper nodes,

I just spent a lot of words explaining why I disagree with that claim. Restating it doesn't really seem constructive.

Quoted text (1 line)
> and that I think is what we are mostly seeing in the network.

I don't really agree. I think we're seeing a combination of unbalanced overall flows due to an insufficiently circular economy (which would perhaps be eased by more custodial wallets/exchanges supporting lightning) and the combination of a lack of any way to limit channel flow other than raising fees and an inability to dynamically change fees on a minute-by-minute timescale.

Quoted text (5 lines)
> > (Also, you don't earn 0 profit on an imbalanced channel; you're just
> > forced to stop accepting some txs. Every time you forward $1 in the
> > available direction, you become able to forward another $1 back in the
> > saturated direction; and you earn fees on both those $1s)
> But that is based on the existence of a stock of IPpvHg in another channel.

No, it's not. It applies even if there is only one channel in the entire network (though I guess that channel would have to be between two custodial entities, or there wouldn't be any point charging fees in the first place).

Quoted text (1 line)
> Actual forwarding node operators classify their peers as "mostly a source" and "mostly a drain" and "mostly balanced", they want CLBOSS to classify peers similarly.

"mostly a source" should trigger rate limiting in one direction, "mostly a drain" should trigger rate limiting in the other. Both should only be true briefly, until the rate limiting kicks in and the channel becomes "mostly balanced".

That's still the case even if the rate limiting is "oops, one side of the channel has ~0 balance".

Quoted text (5 lines)
> > I think it's better to think in terms of "payment flow" -- are you
> > forwarding $5/hour in one direction, but $10/hour in the other? Is
> > that an ongoing imbalance, or something that evens itself out over time
> > ($120/day in both directions)?
> It is helpful to notice that the channel balance is the integral of the sum of payment flows in both directions.

The channel balance is the sum of the initial balance and all payments, sure. No need to add an integral in there as well. For a successful, long lasting channel, sum(incoming payments) and sum(outgoing payments) will be much greater than the balance, to the point where the balance is just a rounding error by comparison.

Quoted text (2 lines)
> This is why actual forwarding node operators are obsessed with channel balance.
> They already *are* thinking in terms of payment flow, and using an analytical technique to keep track of it: the channel balance itself.

This is exactly backwards: you don't monitor your profits by looking at the rounding errors, you monitor your profits by looking at your sales.

If you've forwarded $100,000 in one direction, and $100,200 in the other direction, you care about the $200,200 total that you were charging fees on, not the $200 net delta that it's made to your channel balance.

Quoted text (8 lines)
> > Once you start in that direction, there's also a few other questions
> > you can ask:
> >
> > * can I get make more revenue by getting more payment flow at a
> > lower fee, or by charging a higher fee over less payment flow?
>
> As I pointed out, if you sell your stock of IPpvHg at too low a price point, other forwarding nodes will snatch up the cheap IPpvHg, buying out that stock.
> They can then form an effective cartel, selling the stock of IPpvHg at a higher price later.

No; changing your fee rate isn't about messing with other people's channels, it's about encouraging more use of lightning overall. For example, if you're charging a base_fee of 1sat per HTLC, then dropping that to 0sat might reduce fees from existing traffic, but maybe it will allow you to forward so many micropayments or AMP payments that it's wortwhile anyway.

The lightning network is tiny; if you're constantly thinking about how to steal what little profits there are from other participants, instead of how to grow the ecosystem, you're going to have a really bad time.

(Is AMP Atomic MultiPath, or Atomic Multipath Payment? I prefer the former, and that's why I don't think I'm saying ATM machine)

Quoted text (1 line)
> This all implies to me that the main problem might not be *local* imbalances, but *global* ones.

I mean, sure, that seems totally plausible. This thread is about solving routing problems that will occur even when there *isn't* a global imbalance of payment flow, though...

Quoted text (6 lines)
> * A node whose channels have depleted contacts one of the payees it often pays to.
> * The first node constructs an onchain HTLC offer to the second node.
> * The second node routes back a payment over the Lightning Network to the first node.
> * The first node releases the payment preimage over Lightning.
> * The second node claims the onchain HTLC via the payment preimage.
> I proposed that as an alternative to splicing.

Isn't this the same as Lightning Labs' Loop idea? It's a fine idea, but it's not really an alternative to splicing.

Quoted text (1 line)
> Channel balance is private information.

I mean, it would be nice if it was, but it's not, and the fee rate card proposal creates a strong incentive for everyone to try to discover that information?

Quoted text (6 lines)
> > * maybe you and they have different demand at different times of the
> > day, so time-shifting imbalances is mutually beneficial? I don't
> > see how this works out without secret information though -- the
> > people who want to route payments should be choosing the cheapest
> > link at all times of the day already
> Channel balance *is* the private information you are looking for here: it is the integral of the sum of payment flows.

You have precise knowledge of the payment flow for your own channels already: you run the channel and saw all the payments going each way, including the ones that failed. You don't need a proxy.

When I say "secret information" I mean that you, as someone who's going to rebalance, needs to have information about the policies of the other channel (the one you're going to rebalance over) that the rest of the network isn't privy too.

Quoted text (1 line)
> Sure, a remote node through which you rebalance might not share this information to you,

If the rebalance is mutually beneficial (as assumed), then they'll be happy to share the information with you. But in that case, they'll probably make the information fully public, at which point people will just route payments through them instead of you anyway.

Quoted text (1 line)
> Yes, but again: the integral of payment flows is the channel balance, and you can replace every reference to "flow" here with "channel balance".

Sure. Work out your profits based on the $200 delta, rather than the $200k of flows...

Quoted text (3 lines)
> > But the same scenario applies in the max_msat world too, with only
> > slight modifications. [...]
> But the same thing can be done in a world where fees are the valve,

I mean, I was duplicating a scenario that you were deriving from a world where people only use fees, so, obviously?

If you use the other scenario -- with $5 payments, two cheap channels that insist on balanced flows, one expensive one that doesn't, and an overall unbalanced flow -- then that doesn't work well if you only have fees. In that scenario:

 * people see two channels with 0.001% fees, pick one at random and
   route their entire $5 transaction through it
 * if they're lucky, and a $1000 payment has recently gone the other
   way, they succed and pay $0.00005 in tx fees
 * if they're not (10% of the time), then both the cheap channels will
   be drained, and they'll route their $5 payment through the expensive
   channel, suffering both latency while they find a workable path, and
   paying much higher fees ($0.02)

ie, some people are paying much higher fees (400x higher than the 90% of lucky people, or ~10x higher than everyone in the max_msat scenario).

Quoted text (5 lines)
> > I don't think it's ideal if a world that includes both:
> > * altruists, who'll forward your payments for cheap/free
> > * profiteers, who are trying to make a living offering lightning
> > services
> In the world outside of Lightning, we usually make the stink eye at any profiteers who exploit altruists and make noises about how such profiteers are evil, and occasionally even punish them a little bit.

Mmm. You (and CLBOSS) are the profiteer exploiting altruists with all your aggressive rebalancing ideas in this scenario. Be careful what you wish for maybe?

In a normally functioning economy, you just find the altruists come up with some way other than prices to limit who they "sell" too -- whether that be first come first served, or charities only giving alms to the obviously needy, or clubs that only provide benefits to members, etc.

You could think of max_msat throttling in exactly that role. But, if it can be made to work, it's more broadly useful than that, since what it's fundamentally about is avoiding the "whoops, this channel's depleted, better retry routing via some other path" cases which applies even in a world without CLBOSS rebalancing (ie, rationing via the "first come first served" principle).

Quoted text (3 lines)
> > I mean, that's already a fundamental problem with max_msat: why wouldn't
> > payment initiators do exactly that in the first place?
> Indeed, which suggests that the use of `htlc_max_msat` for a flow valve is flawed:

It was first proposed barely a week ago, of course it's flawed. The question is what the flaws are, and whether they're fundamental or things that can be worked around.

Quoted text (1 line)
> it requires continuous payment flow / payment size curve, and the payment size can be manipulated trivially by any third parties.

The blog post was based on a markov model, which has discrete payment steps by its nature, so I don't know what you're talking about with a "continuous" payment flow curve. Both "all payments are at the max size (simplified as 1 unit)" and "payments are uniform between (0, max)" were modelled, the former seeming a reasonable match to the "manipulation" you're proposing, at least for a first brush on the topic.

Quoted text (3 lines)
> > I wonder whether a (per source/dest channel?) token bucket rate limit
> > might suffice, though. [...]
> Given that a published channel is a global resource, any rate limit is going to be shared amongst many users, and if you underquote the value of the IPpvHg you are providing, rebalancers are going to grab as much of the rate limit as they can.

The goal here isn't to stop rebalancing, it's to achieve balanced payment flow by reducing payment attempts, so that fewer payment attempts fail. (Rather than achieving balanced payment flows by having many payment attempts fail)

Quoted text (1 line)
> I think this implies we need to have a mechanism to move funds outside of the Lightning network, i.e. every published node should have onchain/offchain swap capability.

I guess it would be appealing to a profiteer to have a way of forcing nodes operating competing channels to taint their wallets by sending to OFAC banned addresses... Sure seems like the sort of feature that should be opt-in only to me though.

Cheers, aj