Skip to content
LearnBitcoin

ResearchBitcoin Dev Archive lightning-dev list

Research on proactive fee free channel rebalancing in the friend of a friend network / and roadmap for a protocol extension

6 messages, Dec 23, 2019, to Jan 8, 2020. Started by René Pickhardt.

ZmnSCPxj (4), René Pickhardt (2)

Permalink First message in the Wayback Machine

René Pickhardt permalink original

Dear fellow Lightning Developers,

today my research paper (together with Mariusz Nowostawski) "*Imbalance measure and proactive channel rebalancing algorithm for the Lightning Network*" was published on arxiv: https://arxiv.org/abs/1912.09555 The LaTeX project as well as the code for the experiments (simulation and evaluation) are open source (however not too well documented yet) at: https://github.com/renepickhardt/Imbalance-measure-and-proactive-channel-rebalancing-algorithm-for-the-Lightning-Network I am open for questions, feedback, discussions and in particular critical remarks. Let me just state that I was quite surprised about the positive impact of implementing such a rebalancing protocol in particular since in its current form it seems to protect the privacy of nodes (more research would be needed to be sure that the privacy is really protected).

# From the abstract:

*We further show that the success rate of a single unit payment increases from 11.2% on the imbalanced network to 98.3% in the balanced network. Similarly, the median possible payment size across all pairs of participants increases from 0 to 0.5 mBTC for initial routing attempts on the cheapest possible path. We provide an empirical evidence that routing fees should be dropped for proactive rebalancing operations. Executing 4 different strategies for selecting rebalancing cycles lead to similar results indicating that a collaborative approach within the friend of a friend network might be preferable from a practical point of view*

# Some thoughts and context:

Already in my proposal of JIT Routing https://www.learnbitcoin.com/archive/lists/lightning-dev/t/2019/just-in-time-routing-jit-routing-and-a-channel-rebalancing-heuristic-as-an-add#m-6b9ccd8c I suggested to allow for fee free rebalancing and do the rebalancing operations in the friend of a friend network. With this research I tested both assumptions and - unless someone points out methodological errors in my evaluation - we now have strong evidence that this in deed makes a lot of sense. I think it is in particular interesting that 0.5 mBTC can be routed successfully on first attempt in 50% of the cases. I guess using this together with Multi part / path payments as discussed in the future work section of the paper might be the way to go for the lightning network. I envision that while payments along several paths are routed and settled nodes could already rebalance their channels in particular if we introduce the redundancy to multi part / path payments as suggested in the Boomerang Paper https://arxiv.org/abs/1910.01834 by Vivek Bagaria, Joachim Neu and David Tse.

# Roadmap for BOLT 14 (Fee free Rebalancing Transport):

If no strong objections exist I would try to extend the BOLTs with the following to be able to implement the rebalancing algorithm across the network (as with JIT routing nodes can already opt to implement the algorithm for themselves but this is probably not to useful from an economic point of view).

* BOLT 07: a new gossip query and reply `query_want_rebalance_channel_ids` / `reply_want_rebalance_channel_ids` to ask channel partners on which of their channels they want inbound / outbound liquidity. The query could already include an optional offer how much the node initiating the rebalancing operation is willing to offer while the reply could have an optional offer field stating how much they nodes are willing to rebalance (as the paper shows nodes might not have consensus about the amount and the algorithm currently works by agreeing on the lowest value). Of course this extension needs some protection against probing attacks to protect the privacy of nodes. * BOLT 14: (Fee Free Rebalancing Transport) While it seems tempting to Reuse BOLT04 with a different realm that omits fees for the rebalancing cycles (which nodes would have to accept then) this seems impossible as the onions are not public and nodes could not verify that this is really a rebalancing operation and not a payment which tries to "steel" fees. While we might be able to extend BOLT 02 with a new message that transports a "rebalancing" onion together with the keys for every envelop so that everyone can verify that in fact this fee free onion is a rebalancing cycle it seems plausible to have an open tansport for fee free rebalancing to start with. We could also make it a feature flag and allow nodes to signal if they support fee free rebalancing. I guess for backwards compatebility this should be done in any case. * One problem / attack vector with circular fee free payments that I see is that if Alice wants to pay David she could initiate a rebalancing onion: A --> B --> C --> D --> A with the paymenthash that David has created in an invoice. David would just not set up the final HTLC from him to Alice as he wanted to receive money from Alice. As far as I see this attack would only be possible if Alice and David have a channel which they could have used for the payment right away. Not using that channel is effectively a rebalancing operation which is exactly why we allow such a protocol. This means that the channel between Alice and David has to be public to allow for a fee free operation. Otherwhise I could always claim to have a private channel if I wanted to pay someone without fees. Still this allows two people who have a public channel to spam out HTLCs which settle at no cost. However - according to my research - nodes along the cycle only participate if that was beneficial for them. Also since these rebalancing cycles are open and transparent they could be blocked if nodes feel they are being abused.

While the extension of BOLT 07 seems rather simple and straight forward. BOLT 14 (I like the fact, that it is actually 4 + 10 ) might be more controversial. Especially for that I would love to have some feedback before I start to spec this out.

Have good Christmas time everyone!

ZmnSCPxj in reply to René Pickhardt permalink original

Good morning Rene,

What no JIT-routing?

Quoted text (10 lines)
> # Roadmap for BOLT 14 (Fee free Rebalancing Transport):
>
> If no strong objections exist I would try to extend the BOLTs with the following to be able to implement the rebalancing algorithm across the network (as with JIT routing nodes can already opt to implement the algorithm for themselves but this is probably not to useful from an economic point of view).
>
> * BOLT 07: a new gossip query and reply `query_want_rebalance_channel_ids` / `reply_want_rebalance_channel_ids` to ask channel partners on which of their channels they want inbound / outbound liquidity. The query could already include an optional offer how much the node initiating the rebalancing operation is willing to offer while the reply could have an optional offer field stating how much they nodes are willing to rebalance (as the paper shows nodes might not have consensus about the amount and the algorithm currently works by agreeing on the lowest value). Of course this extension needs some protection against probing attacks to protect the privacy of nodes.
> * BOLT 14: (Fee Free Rebalancing Transport) While it seems tempting to Reuse BOLT04 with a different realm that omits fees for the rebalancing cycles (which nodes would have to accept then) this seems impossible as the onions are not public and nodes could not verify that this is really a rebalancing operation and not a payment which tries to "steel" fees. While we might be able to extend BOLT 02 with a new message that transports a "rebalancing" onion together with the keys for every envelop so that everyone can verify that in fact this fee free onion is a rebalancing cycle it seems plausible to have an open tansport for fee free rebalancing to start with. We could also make it a feature flag and allow nodes to signal if they support fee free rebalancing. I guess for backwards compatebility this should be done in any case.
> * One problem / attack vector with circular fee free payments that I see is that if Alice wants to pay David she could initiate a rebalancing onion: A --> B --> C --> D --> A with the paymenthash that David has created in an invoice. David would just not set up the final HTLC from him to Alice as he wanted to receive money from Alice. As far as I see this attack would only be possible if Alice and David have a channel which they could have used for the payment right away. Not using that channel is effectively a rebalancing operation which is exactly why we allow such a protocol. This means that the channel between Alice and David has to be public to allow for a fee free operation. Otherwhise I could always claim to have a private channel if I wanted to pay someone without fees.
> Still this allows two people who have a public channel to spam out HTLCs which settle at no cost. However - according to my research - nodes along the cycle only participate if that was beneficial for them. Also since these rebalancing cycles are open and transparent they could be blocked if nodes feel they are being abused.
>
> While the extension of BOLT 07 seems rather simple and straight forward. BOLT 14 (I like the fact, that it is actually 4 + 10 ) might be more controversial. Especially for that I would love to have some feedback before I start to spec this out.

Definitely. In particular I am wary of making the rebalance different from payments. We should consider always that there will be nodes whose only purpose in life is to monitor the activities of other people.

The fact that current rebalances are indistinguishable (or at least hard to distinguish) from normal payments is helpful for privacy: it makes it harder for surveillors, since they have to filter out rebalance attempts from actual real payments. Splitting out rebalances from payments breaks this privacy advantage.

I suggest rather that:

* Add a local-scope broadcast "I provisionally allow routing via this channel-direction without fees; this offer is valid up to blockheight B".
  * Add a secret in this broadcast ("here is the claimcode: ZmnSCPxj").
* Hide rebalances in the current onion format; just do not decrement the outgoing value from the incoming value (i.e. 0 fee).
  * Add the secret in the broadcast in a new even TLV.

I think it is not necessary for a node to directly know if an HTLC to be forwarded is a "real" payment or a "rebalance". In particular:

* The node will only offer a fee-free rebalance if its own channel is imbalanced in that direction.
* It does not matter if the payment is "real" or "rebalance": it will change the channel to be balanced anyway, which is already a win.
* Regardless of whether the payment is "real" or "rebalance", if the payment will not cause the channel to be balanced (for example, somebody else managed to already balance that channel, *or* the payment is too big and causes the channel to be imbalanced in the reverse direction instead), then the node should reject the payment anyway if the fee is 0.

Thus, I suggest instead:

* Define a new message for local broadcast of channels that would be nice to balance.
* Add a new TLV for onions that includes a secret from the previous message.
* Add a new onion failure code that includes a proposed amount.
  * The sender MUST NOT send this failure code if the onion entry for that node does not contain the previous TLV.

Regards, ZmnSCPxj

ZmnSCPxj in reply to ZmnSCPxj permalink original

Good morning Rene, and list,

It seems to me that the rule used here might be useful to guide how to split a payment for multipath as well.

For example, consider the case where a payer Alice has channels to Bob and Charlie.

* Alice-Bob has A=0.5, B=0.5
* Alice-Charlie has A=0.5, C=0.5

In that case, in order to retain balance, if Alice has to pay 0.1, it should strive to split the payment into a 0.05 via Alice-Bob and 0.05 via Alice-Charlie.

Would it be possible to derive such a calculation from your published rule? For example, if one of the payer channels is imbalanced in favor of the payer, then the payment probably should not be split, but if the payment is big enough that it would be imbalanced against the payer afterwards, then some small amount must be split out to another channel.

Regards, ZmnSCPxj

René Pickhardt in reply to ZmnSCPxj permalink original

Good morning ZmnSCPxj, and list,

the answer to your question is absolutely yes and we can can achieve this actually in a very simple and elegant way.

Please find attached a clear and simple adaption of the algorithm described from the paper for a general multipath payment and a small python code example available at: https://github.com/renepickhardt/Imbalance-measure-and-proactive-channel-rebalancing-algorithm-for-the-Lightning-Network/blob/master/code/mppalgo.py that computes this in a model case (assuming 10 payment channels that all have a capacity of 1 BTC just to save some lines in coding). The output of the code is at the end of the Mail.

Algorithm to conduct payments which optimally (? I have not proved this yet but I see no way that would be more optimal with respect to the Ginicoefficients) reduces the imbalance of nodes when conducting a (multipath)payment.

Let us assume a node $u$ wants to pay someone for an amount $a$.

1. We assume the payment was already achieved over some channel(s) and compute the new node balance coefficient $\nu'_u$ after this imaginary payment has been conducted as $\frac{\tau_u - a}{\kappa_u}$. remember \tau_u is just the total amount of funds that node $u$ currently has and $\kappa_u$ is the sum of the capacities of all its payment channels. 2. For all online channel partners $\{v_1,...,v_d\}$ we compute $\zeta_{(u,v_1),...,\zeta_{(u,v_d})}$ 3. Let us assume channels are ordered such that $\zeta_{(u,v_1)>...>\zeta_{(u,v_d'})}$ and omit channels with $\zeta(u,v_i) - \nu'_u < 0$ Those channels need more funds and should not be used to pay. That is why we might have $d' < d$ 5. Compute all $d'$ rebalancing amounts $r_i = c(u,v_i)*(\zeta_{(u,v_i)}-\nu'_u)$ as in the paper but with the new node's balance coefficient! 6. set $R = sum_i r_i$ 7. distribute payments across channels $a_i = a*r_i/R$ being the amount $a_i$ that should be paid on channel $i$. Recall $a_i < a$ and $sum_i a_i = a$ and $a_i < r_i$. This means that with this computation all channel have enough liquidity to do the subpayments and the subpayments will add up to the amount (ignoring channel reserves) 8. probe for paths for each amount and channel (potentially split the amount for a channel across several paths that all start with that channel). As we don't know what the rest of the network looks like we don't know if we will be able to find paths for each channel (as before)

Now the really nice side effect: We could compute routing hints for the invoices in the same way! by now taking the channels where $\zeta(u,v_i) - \nu'_u$ < 0. We could also split the amounts in that way and also give amounts together with the routing hints. This would allow a sender to send the payments in a way that is most benefitial too us. (The sender could also follow the above method for their outgoing channels) Only the rest of the network might suffer worse imbalance bus guess what they charge a routing fee for that service!

With these nice results let me just review some notation from the paper (so that we in future might all agree to this wording/termonology):

* *Rebalancing* is the operation of moving funds along circular paths between channels. As pointed out in the past this does not really change the topology of the graph as the properties like the max flow / min cut will not be affected by this. As such some people (including myself) have argued in the past that multipathpayments are sufficient for path finding as they will quicker find the max flow and that rebalancing is not necessary. However the results of my research indicate that such operations will increase the likelihood of arbitrary payments to succeed and thus (at least in my interpretation) increase the reliability of the network. * in particular a node is *balanced* if the zeta values are the same and the gini coefficient is zero. While this is the case for all channels being 50-50 there are far less strict ways of achieving a good balance than asking for channels to be opened in such a way that everyone ha 50-50. * *Making payments actually changes the topology* of the network (similarly to opening and closing channels). With the notation of the paper the \tau values change and are part of the topology. This way "rebalancing" with submarine swaps using loop or any of those services is not a rebalancing operation in the sense of the paper and/or the above point but in fact a change of topology. * combining topology changes with rebalancing operations (which is often the goal when making submarine swaps) seems however to be a good idea. In that sense your general thought of rebalancing while paying should be pursued.

Last but not least the promised output of the example code:

$ python3 mppalgo.py 0.3 initial imblance new funds 4.8 and new node balance coefficient 0.48

Conduct the following payments: channel 0 old balance: 1.00, payment amount 0.22 new balance 0.78 channel 1 old balance: 0.90, payment amount 0.18 new balance 0.72 channel 2 old balance: 0.80, payment amount 0.14 new balance 0.66 channel 3 old balance: 0.70, payment amount 0.10 new balance 0.60 channel 4 old balance: 0.60, payment amount 0.05 new balance 0.55 channel 5 old balance: 0.50, payment amount 0.01 new balance 0.49

---- unchanged channels as they need more funds on our side ----

channel 6 old balance: 0.40, payment amount 0.00 new balance 0.40 channel 7 old balance: 0.30, payment amount 0.00 new balance 0.30 channel 8 old balance: 0.20, payment amount 0.00 new balance 0.20 channel 9 old balance: 0.10, payment amount 0.00 new balance 0.10 total amount paid over several channels: 0.7 (was asked to send: 0.7)

new imbalance 0.25 and old imbalance 0.30

Have a nice day! Rene

On Tue, Jan 7, 2020 at 3:30 AM ZmnSCPxj <ZmnSCPxj at protonmail.com> wrote:

Quoted text (24 lines)
> Good morning Rene, and list,
>
> It seems to me that the rule used here might be useful to guide how to
> split a payment for multipath as well.
>
> For example, consider the case where a payer Alice has channels to Bob and
> Charlie.
>
> * Alice-Bob has A=0.5, B=0.5
> * Alice-Charlie has A=0.5, C=0.5
>
> In that case, in order to retain balance, if Alice has to pay 0.1, it
> should strive to split the payment into a 0.05 via Alice-Bob and 0.05 via
> Alice-Charlie.
>
> Would it be possible to derive such a calculation from your published rule?
> For example, if one of the payer channels is imbalanced in favor of the
> payer, then the payment probably should not be split, but if the payment is
> big enough that it would be imbalanced against the payer afterwards, then
> some small amount must be split out to another channel.
>
> Regards,
> ZmnSCPxj
>
ZmnSCPxj in reply to René Pickhardt permalink original

Good morning Rene,

I am glad my question has triggered such interest from you!

I will confess that I do not yet understand the math you demonstrated and have not seen your program at all yet. It is a good thing as well that it can be used to derive routehints for invoices.

I do have a follow-up thought.

-----

I would like to point out that:

* A JIT Routing is really just a rebalancing while you have a forwarding.
* A rebalance is just a self-payment.
* A self-payment is a payment, and as such can be split via multipath.
* The multipath algorithm you derived here can still be reused for this case.

Suppose a node wishes to forward via some channel that sadly has insufficient capacity. Then we can use your MPP algorithm, removing that target channel from our computations, and with the target amount being the difference between the available capacity on that channel and the value to be forwarded. Then we can determine how much amount we can pull from our *other* channels, and then generate an MPP self-payment / rebalance.

Further, the algorithm you described, appears to me to be most useful if the payer is not currently very well-balanced. That is, the algorithm you described strives to move the payer from unbalanced to balanced. If the payer is already perfectly balanced then the algorithm will strive to split the payment to all channels the payer has.

Thus, it seems to me that we may be better off with a "lazy" balancing scheme, aka JIT Routing.

* If we have to pay, use the MPP splitting algorithm to better move towards balance.
* If we have to forward but have insufficient funds in the forwarding, again use the MPP splitting algorithm to determine which other channels are best to source the money from to rebalance.

It may be useful to implement as a C-Lightning plugin with a `suggestsplit` that is given a target amount, plus an optional array of local channels to exclude, and outputs an array of channels plus how much it suggests to get from that channel. Then the multipath payment algorithm could refer to this, and a putative JIT routing plugin can refer to this as well.

Regards, ZmnSCPxj

ZmnSCPxj in reply to ZmnSCPxj permalink original

Good morning again Rene,

An observation I would like to make is that, as I understand it, the model inherently assumes that all nodes are equally likely to be payer and equally likely to be payee.

While in a complete economy this is to be expected (the "customer" of a "merchant" will be an "employee" of some other "merchant") in an equilibrium state, it seems to me that transient states might exist where some nodes will demand more incoming funds. For example, consider a manufacturer that has just released a new model of their product; generally the expectation is that customer interest in the new model will be high when just recently released, thus transiently such manufacturers will need more incoming liquidity than in equilibrium.

Thus I think JIT Routing is still more useful in practice than a proactive rebalancing policy, as it is more resilient to such transient shocks to the system. Every rebalance is effectively a speculation that capacity in one (set of) channel(s) is less useful than capacity in another (set of) channel(s). Targeting some kind of "perfect balance" assumes that the equilibrium state will be that payments will generally be equal in all directions (an equilibrium state that I expect to be true, actually, once entire economies switch to the Lightning Network), but I think we should provision our nodes to also be resilient against transient shocks.

Though I could also be overestimating the effects of such transient shocks, in which case equilibrium probably implies that targeting a perfect balance proactively would be better.

Regards, ZmnSCPxj