Research/Bitcoin Dev Archive / lightning-dev list
Thoughts on Improving MPP
4 messages, Aug 2 to 16, 2020. Started by ZmnSCPxj.
ZmnSCPxj (4)
Good morning Lightning world,
This was originally written for C-Lightning, hence the C-Lightning-isms, but I realized the general principles were valid for all LN implementations.
---
First, let us consider some C-Lightning node who, for some reason, only has unpublished channels to the network (note: in my opinion, ***unpublished channels delenda est!***). Let us suppose this node wishes to receive some amount of funds, from multiple different payers.
Now, the payee node knows MPP exists, and thus, it is not very concerned that it has insufficient incoming capacity in a ***single*** channel to accept one of the payments. Reasoning that MPP exists, it considers instead the *sum total* of all incoming capacities. It sees that it has sufficient *sum total* incoming capacity that it can accept all payments from all payers, with some to spare.
However, at the channel-level detail, *none* of the channels has sufficient capacity to accept a single one of the payments the C-Lightning node now expects to receive, in full. So, what should the C-Lightning node put as routehints in a generated invoice?
Another, is that we should note that I described "payers" with an "s" at the end. In the English language as commonly used by puny humans, adding an "s" at the end of a noun is a common (but not universal) convention implying that the subject under discussion is actually composed of more than one item. So not only must the C-Lightning node (all of whose channels are unpublished, thus cannot be paid unless it reveals at least some of the channels as routehints in the invoice) make an invoice with sufficient routehints to get an MPP delivered, it must make *multiple* invoices, such that the invoices it issues have as little overlap in their routehints as possible
Otherwise, if we provide the **same** set of routehints in invoices to two **different** payers, both of them will interfere with each other, possibly to the point that neither can pay to the payee (since e.g. some of the available capacity is taken up by parts of one payment while the rest is taken up by parts of the other payment, and neither payment can then complete in full due to this deadlock).
This is important in case the C-Lightning node receiver is completely unannounced (i.e. has only unpublished channels). The payers cannot fall back to just trying directly routing on a different incoming channel of the receiver, as they may not have any knowledge of such channels.
I suggest, then, that the C-Lightning node that wants to get paid, and uses only unpublished channels, should use a Round-Robin strategy for selecting routehints.
To implement this, the `invoice` command maintains a persistent list of all channels the node has. When a newly funded channel is locked-in by both sides (transitions to `CHANNELD_NORMAL`) it is simply appended to this list. When a channel leaves `CHANNELD_NORMAL`it is simply removed from this list. Let us call this the round-robin list.
Then, when the `invoice` command is invoked, it generates routehints by executing a loop:
* Maintain variables: a removed list (initially empty), a running sum amount (initially `AMOUNT_MSAT(0)`), and a set of proposed routehints (initially empty) * Round-robin: Remove a channel from the front of the round-robin list and put it in the end of the removed list. * If the channel has no incoming capacity, skip to the top of the loop again (`continue;`). * If the channel is a dead end (i.e. connects to a node which has no published channels elsewhere), skip as well (`continue;`). * Copy the scid and any other details to the set of proposed routehints. * Add the incoming capacity of the taken channel to the running sum. If the running sum now exceeds the amount to be paid, append the removed list to the current round-robin list and leave the loop. * If the round-robin list is now empty, exit the loop (append the removed list to the current empty round-robin list) and report a `warning_capacity` that it looks like there is insufficient incoming capacity for this invoice.
On exit of the above loop, we sort the set of proposed routehints, from highest incoming capacity to lowest, and use that set as the routehints for the invoice.
(It would probably be a good idea as well to persist the round-robin list)
The above ensures that as much as possible, different invoices will have different sets of channels routehinted (due to the round-robin behavior), but gracefully degrades (some overlap in routehints) if the number of channels available is low.
An issue is privacy. A probing fake payer could spam the receiver with multiple requests for invoices it never intends to pay. This can let the fake payer discover, at minimum, the entry points used by the payee to connect to the public network (which cannot be removed, even if you somehow obscure the actual short-channel-IDs of the payee, since the payer has to know *what* node to reach to get to the payee), which the payer can then probe or otherwise hack or buy out in order to extract information about the economic activity of the payee (due to the Axiom of Terminus, any forward that goes *to* an unpublished channel, *is* the final hop to the actual final destination, so the entry points have accurate data on incoming payments of the unpublished payee via the channel with them). If the payer simulates multiple payers (i.e. Sybils) the payee cannot attempt to reuse channels in routehints to the different simulated payers, as that would degrade the ability to pay since the capacity of the channels has to be shared by the different payers if those payers were not sockpuppets. Thus the lie of improved privacy by unpublished channels is revealed, and therefore, in my opinion, unpublished channels delenda est.
----
Now, let us turn our attention to the payer of such an invoice.
Currently, our `paymod` system uses a single sequence of routehints for all sub-payments of an MPP.
Thus, if a payment is split in two, both sub-payments will start executing on the same routehint.
Yet as considered above, the point of multiple routehints is that not a single one has sufficient capacity to receive, and the multiple routehints are provided which in total are needed to receive all the incoming funds.
Thus, I suggest as well, that sub-payments should have different sequences of routehints to try.
For example, currently, for sub-payments 0 and 1, they will try routehints A, B, C, D in this order:
0 1
A A
B B
C C
D D
Instead of using the same shared sequence of routehints, on splitting, the split payments should use:
0 1
A B
C D
B A
D C
That is, sub-payment 0 should try routehints in the order A, C, B, D, while the sub-payment 1 should try routehints in the order B, D, A, C.
The reasoning is the same as with the argument for round-robin routehint selection: by having different sub-payments initially try different routehints, we improve our success by reducing their overlap in the use of shared resources, and therefore reduce the risk of deadlock (especially if the sub-payments are adaptively split into even more sub-payments).
We can do this by a sort of round-robin, as well. For each sub-payment we initially create an empty list of routehints. Then we "spread" the routehints to each sub-payment.
* If there are more sub-payments than routehints, then we repeat the routehints until we have given one routehint to each sub-payment. * If there are more routehints than sub-payments, then we repeat the sub-payments until we have completed the routehints.
After the above initial distribution, we then go through all sub-payments, and for each sub-payment, append routehints in the original order, but skipping those that were already given to that sub-payment in the above initial distribution.
For example, suppose we are distributing 3 routehints A B C to two sub-payments 0 1. We do the initial distribution:
0 1
A B
C
And then we give each sub-payment the rest of the routehints:
0 1
A B
C A
B C
Another example, where we are distributing 2 routehints A B to four sub-payments 0 1 2 3. Our initial distribution is:
0 1 2 3
A B A B
Then we give each sub-payment the rest of the routehints:
0 1 2 3
A B A B
B A B A
Thus, each sub-payment gets the entire list of routehints, but in a different order.
----
Finally: the same argument --- that sub-payments should avoid using the same set of resources as much as possible -- applies to the *first* hop just as much as the *last* hop.
Thus, one possibility is to also maintain a list of outgoing channels for each sub-payment, which sub-payments try in round-robin order. And again, each sub-payment should get a different order from each other in a coordinated fashion which reduces their interference.
We do this by, at the *start* of the payment before we split it up, taking all local channels and shuffling them. Then we distribute the outgoing channels with the same algorithm as the above.
Then, when a sub-payment executes, we use a similar algorithm as the `invoice` case where it selects routehints.
* Maintain a removed list (initially empty). * Round-robin: Remove the channel at the front of the round-robin list, append to removed list. * If the round-robin list is empty, then we should append the removed list to the round-robin list and consider splitting the payment. * If it has insufficient outgoing capacity, skip. * If it is a dead end, skip. * Otherwise it has sufficient capacity, break out of the loop (append the removed list to the round-robin list) and try routing via that channel.
Good morning Lightning world,
A minor report from the MPP trenches.
One of the resources that the C-Lightning MPP implementation is hitting is the limit on the number of HTLCs a channel can have.
For the 0.9.0 release, the initial consideration was that we can count the number of channels with outgoing capacity, and from there derive a number of HTLCs that the payer can afford to put on the network. Very roughly speaking, for every channel with outgoing capacity, we allocate 10 HTLCs. This is the "limit" on our connectivity to the network: adding more HTLCs beyond this risks overloading our local connectivity and we would be unable to get good capacity.
However, we neglected to consider the *incoming number-of-HTLCs limit* of the the payee. I believe this is the cause of this reported issue: https://github.com/ElementsProject/lightning/issues/3926 In the report, the payer node has 16 channels, and thus it allows up to 160 HTLCs. Initial splitting of the payment led to 51 starting splits, and since we do not implement re-merging of sub-payments, that number of splits can only grow. Yet it seems that the payee had far fewer channels than the payer, and the much higher number of splits then could not fit in the incoming channels of the payee.
This is exacerbated by the use of the same failure code `temporary_channel_failure` for hitting both *msat capacity* and *number of HTLCs* limits. Our assumption was that any such `temporary_channel_failure` was due only to *msat capacity* being hit. We then annotated that channel with the smallest HTLC that failed to route through it, and do not route through that channel for sub-payments equal or larger than that size. This lead our code into splitting the 51 payments even further into more smaller payments, when it would have been objectively better to instead *merge* those payments (or not split up into such tiny pieces in the first place!). Unfortunately, the local annotations would then be poisoned --- it would think that very small payments were failing because of the *msat capacity* of the channel being ridiculously low. This ended up convincing the payment subsystem that it would be better to keep on splitting payments **even more**, leading to >100 payments outgoing, further preventing the receiver from being able to receive (because the problem was not *msat capacity* but rather *number of HTLCs*) and further crashing ourselves into the problem.
So, I think it would be reasonable:
* To count the number of channels the payee has (if the receiver is not published, count the number of routehints in the invoice), and use it as well as the basis of the number of HTLCs the receiver can get, and to get the lower of this and the outgoing channels of the payer.
Overall, the issue is probably fixable if we consider the number of channels of the payer (as C-Lightning 0.9.0 does) ***and*** also the number of channels of the payee. We can consider that, if we assume the rest of the public LN is well-connected, the only bottlenecks are at the payer and at the payee, and that for intermediate nodes there are a large number of alternate routes available. So it may be sufficient to just limit based on the smaller of the number of payer-side channels and the number of payee-side channels.
Regards, ZmnSCPxj
Good morning Lightning world,
A minor report from the MPP trenches.
One of the resources that the C-Lightning MPP implementation is hitting is the limit on the number of HTLCs a channel can have.
For the 0.9.0 release, the initial consideration was that we can count the number of channels with outgoing capacity, and from there derive a number of HTLCs that the payer can afford to put on the network. Very roughly speaking, for every channel with outgoing capacity, we allocate 10 HTLCs. This is the "limit" on our connectivity to the network: adding more HTLCs beyond this risks overloading our local connectivity and we would be unable to get good capacity.
However, we neglected to consider the *incoming number-of-HTLCs limit* of the the payee. I believe this is the cause of this reported issue: https://github.com/ElementsProject/lightning/issues/3926 In the report, the payer node has 16 channels, and thus it allows up to 160 HTLCs. Initial splitting of the payment led to 51 starting splits, and since we do not implement re-merging of sub-payments, that number of splits can only grow. Yet it seems that the payee had far fewer channels than the payer, and the much higher number of splits then could not fit in the incoming channels of the payee.
This is exacerbated by the use of the same failure code `temporary_channel_failure` for hitting both *msat capacity* and *number of HTLCs* limits. Our assumption was that any such `temporary_channel_failure` was due only to *msat capacity* being hit. We then annotated that channel with the smallest HTLC that failed to route through it, and do not route through that channel for sub-payments equal or larger than that size. This lead our code into splitting the 51 payments even further into more smaller payments, when it would have been objectively better to instead *merge* those payments (or not split up into such tiny pieces in the first place!). Unfortunately, the local annotations would then be poisoned --- it would think that very small payments were failing because of the *msat capacity* of the channel being ridiculously low. This ended up convincing the payment subsystem that it would be better to keep on splitting payments **even more**, leading to >100 payments outgoing, further preventing the receiver from being able to receive (because the problem was not *msat capacity* but rather *number of HTLCs*) and further crashing ourselves into the problem.
So, I think it would be reasonable:
* To count the number of channels the payee has (if the receiver is not published, count the number of routehints in the invoice), and use it as well as the basis of the number of HTLCs the receiver can get, and to get the lower of this and the outgoing channels of the payer.
Overall, the issue is probably fixable if we consider the number of channels of the payer (as C-Lightning 0.9.0 does) ***and*** also the number of channels of the payee. We can consider that, if we assume the rest of the public LN is well-connected, the only bottlenecks are at the payer and at the payee, and that for intermediate nodes there are a large number of alternate routes available. So it may be sufficient to just limit based on the smaller of the number of payer-side channels and the number of payee-side channels.
Regards, ZmnSCPxj
Good morning once again Lightningfolk,
An idea I have been entertaining is that rather than splitting payments by half in case of an adaptive split, we should split in terms of a Fibonacci sequence.
Intuitively, if we split payments in half all the time, then it implies that we have a set of "standard" bins that are some constant times the powers of two. For example, if we start with 1,000,000 msat, splitting by half results in splits of 500,000; 250,000; 125,000; 62,500; 31,250; 15,625; and it is as if we are using bins of 15,625 times powers of two.
Now, let us consider the *worst case* number of splits when we have some channel capacity.
For example, if we have a channel capacity of 4,294,967,295 msat. In that case, we would require 32 splits, from values ranging from 2^0 to 2^31, if we were to use the "split by half" rule.
However, what if we instead used amount bins that are derived from the Fibonacci sequence? For the same 4,294,967,295 capacity, we would split up into bins of:
29,712,150,73; 1,134,903,170; 165,580,141; 14,930,352; 5,702,887; 2,178,309; 317,811; 121,393; 17,711; 377; 55; 13; 3
That is 13 splits.
But that is unfair! 4,294,967,295 is specifically chosen as a worst-case behavior of the power-of-two splitting. So how do we choose a similar worst-case for the Fibonacci sequence?
An intuition we must have is that we derived the worst-case example for power-of-two splitting by adding the powers of two in sequence: 1 + 2 + 4 + 8 ... etc.
Now, what about if we add the Fibonacci sequence in sequence? Will that similarly provide a worst-case example similar to the 4,294,967,295 example? 1 + 1 + 2 + 3 + 5 ...
A thing to note is that if we add two adjacent Fibonacci sequence items, such as 2 + 3, we get the *next* Fibonacci sequence item. Thus, if our "worst-case" generation sums up two adjacent Fibonacci sequence items, that will actually cause the splits to move up, meaning fewer splits needed. Thus, to generate the worst-case example for the Fibonacci sequence, we should actually *skip* an entry each time. Thus for the Fibonacci sequence: 1; 1; 2; 3; 5; 8; 13; 21; 34; 55; .... we should sum up 1 + 2 + 5 + 13 + 34 + ....
And a thing we should notice is to compare that to the worst-case generation for the power-of-two sequence: 1 + 2 + 4 + 8 + 16 + ....
1 + 2 + 5 + 13 + 34 + ... 1 + 2 + 4 + 8 + 16 + ...
What you should notice is that the numbers being added to the worst-case Fibonacci case quickly becomes larger, faster, than the worst-case power-of-two.
What this means is that, given an arbitrary random channel capacity, in order to fully utilize that capacity for transport, we expect that it would require fewer splits, on average, if we use Fibonacci sequence than power-of-two sequence.
So I think Fibonacci sequence for our payment splitting schedule is better than the power-of-two sequence we currently use (I believe `lnd` as well also started with such a simple "split by half" solution). We expect this to lead to fewer splits in general (given that each HTLC is a risk of paying fees later, we want fewer splits) and better utilization of available channel capacity.
Now, of course, we are doing payment *splitting*, i.e. if a big payment does not go through we try again with multiple smaller payments. Getting into a power-of-two schedule is easy: just divide by 2.
In order to get into an approximately Fibonacci sequence, we can divide by the Golden Ratio, i.e. `phi`, i.e. 1.6180339887... i.e. (1 + sqrt(5))/2 This is because two consecutive entries in the Fibonacci sequence have a ratio that approximately converges towards this number. So for example, if we start with a 1,000,000 msat payment that fails, we should split it into 618,034 and 381,966 splits. And so on.
Regards, ZmnSCPxj