The maximum acceptable
max_accepted_htlcs (maximum number of HTLCs forwarded concurrently) is specified by the BOLTS as being
How was this value chosen ?
Bitcoin Stack Exchange is a question and answer site for Bitcoin crypto-currency enthusiasts. It only takes a minute to sign up.Sign up to join this community
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 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
4to 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.
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?