为什么闪电网络上HTLC的并发数量被限制为483个?
作者:互联网
为什么闪电网络上HTLC的并发数量被限制为483个?
一、闪电网络白皮书上的描述
- 闪电网络白皮书
- 闪电网络上HTLC并发数量描述:
二、从交易罚款的角度解释HTLC的并发数量限制
Penalty Transactions Weight Calculation (网址)
- There are three different scripts for penalty transactions, with the following witness weights:
to_local_penalty_witness: 160 bytes offered_htlc_penalty_witness: 243 bytes accepted_htlc_penalty_witness: 249 bytes
- The penalty txinput itself takes up 41 bytes and has a weight of 164 bytes, which results in the following weights for each input:
to_local_penalty_input_weight: 324 bytes offered_htlc_penalty_input_weight: 407 bytes accepted_htlc_penalty_input_weight: 413 bytes
- The rest of the penalty transaction takes up 4+1+1+8+1+34+4=53 bytes of non-witness data: assuming it has a pay-to-witness-script-hash (the largest standard output script), in addition to a 2-byte witness header.
- n addition to spending these outputs, a penalty transaction may optionally spend the commitment transaction’s to_remote output (e.g. to reduce the total amount paid in fees). Doing so requires the inclusion of a P2WPKH witness and an additional txinput, resulting in an additional 108 + 164 = 272 bytes.
- In the worst case scenario, the node holds only incoming HTLCs, and the HTLC-timeout transactions are not published, which forces the node to spend from the commitment transaction.
- With a maximum standard weight of 400000 bytes, the maximum number of HTLCs that can be swept in a single transaction is as follows:
max_num_htlcs = (400000 - 324 - 272 - (4 * 53) - 2) / 413 = 966
- 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.
三、自我总结
- 为了确保在出现问题时可以广播罚款交易,必须限制并发的HTLC数量。
- HTLC最大并发数量计算公式:
max_num_htlcs = (400000 - 324 - 272 - (4 * 53) - 2) / 413 = 966
- 4000000: maximum Bitcoin block size limit (比特币区块大小限制)
- 400000:limit for a transaction to be standard (闪电网络上交易标准对数据大小的限制)
- 324:to_local_penalty_input_weight
- 272:to_remote output
- 53:non-witness data
- 2:witness header
- 413:HTLC大小
- 交易数据减去一些必须的数据量,然后除以HTLC大小得到HTLC 可运行的最大数量,由于HTLC是双向传递,所以结果除以二,得到最大并行HTLC数量。
标签:transaction,bytes,penalty,并发,input,483,witness,HTLC 来源: https://blog.csdn.net/m0_46501404/article/details/116132669