3

The maximum acceptable max_accepted_htlcs (maximum number of HTLCs forwarded concurrently) is specified by the BOLTS as being 483.

How was this value chosen ?

2 Answers 2

4

The rationale is given in the BOLT #3: for the commitment_signed to be under the maximum message size allowed by BOLT #8 (~65kb), and for the penalty transaction to be able to sweep all HTLCs in one transaction.
Here is a more beginner-friendly explanation of the second part.

The 4000000 Weight Units limitation is the maximum Bitcoin block size limit (link to the BIP).

The 400000 Weight Units limitation is the limit for a transaction to be standard (hence relayed).

The penalty transaction is crucial to the security of Lightning Network channels, so you need a transaction which can be relayed, hence a transaction which size is standard.

But each new HTLC is a two additional outputs to the commitment transactions. Thus two new inputs to the penalty transaction (which spends it). It's an added size (calculated in Weight Units) to the penalty transaction.

So you must restrict the number of in-flight HTLCs to accept (i.e. to add to your commitment transaction concurrently) in order to be sure you can broadcast your penalty transaction if something goes wrong.

Now here is the explanation of the calculation :

max_num_htlcs = (400000 - 324 - 272 - (4 * 53) - 2) / 413 = 966
  • 400000 : the maximum transaction size, cf above
  • 324 : the size of the input corresponding to the commitment transaction output sending funds to you.
  • 272 : the size of the input corresponding to the commitment transaction output sending funds to your peer.
  • 53 : the size of the commitment transaction's non-witness data, this is wy it's timed by 4 to get weight units.
  • 2 : the size of the witness header.
  • 400000 - 324 - 272 - (4 * 53) - 2 : the free room left for adding HTLC inputs
  • 413 : the size to spend an accepted HTLC (used over the size to spend an offered HTLC because it's larger).
  • (400000 - 324 - 272 - (4 * 53) - 2) / 413 : the maximum number of HTLCs you can accepts so that they can be spent by a penalty transaction which can be relayed by the Bitcoin network.

Because each HTLC creates two outputs, you divide this result by two so :

Thus, 483 bidirectional HTLCs (containing both to_local and to_remote outputs) can be resolved in a single penalty transaction. Note: even if the to_remote output is not swept, the resulting max_num_htlcs is 967; which yields the same unidirectional limit of 483 HTLCs.

2
  • 1
    Great explanation, except that it's 400,000 WU, not 4,000,000, because it's limited by transaction standardness, not block size (see my answer above). Mar 20, 2020 at 10:48
  • Thanks Stephan, will amend ! Mar 21, 2020 at 10:09
0

The maximum standard weight is a restriction on bitcoin transaction size. It's the maximum weight that a transaction can have to be 'standard', which means it is still relayed by unmodified bitcoin core nodes. You could have a bigger tx in a block, but you would probably have to find a miner yourself that is willing to include it.

The concept of weight is important here, it's the new way of measuring transaction size since segwit and is thoroughly described here

Aside from that, what exactly don't you understand in the calculation?

2
  • Oh I don't understand how calculation of max_num_htlcs turns into 966. What does (400000 - 324 - 272 - (4 * 53) - 2) / 413 mean?
    – Guillaez
    Mar 12, 2020 at 0:18
  • I think you need to try a little harder. Please take the time to try to understand the text that you linked to. They tried to explain what they did there. Now it may be that you don't understand every part of what they are trying to explain. That's fine. Then you can ask a specific question. But just asking people to write an even more elaborate text in case you might take the time to read it this time seem a little lazy to me. Mar 13, 2020 at 9:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.