@@ -21,6 +21,8 @@ This details the exact format of on-chain transactions, which both sides need to
2121 * [Fees](#fees)
2222 * [Fee Calculation](#fee-calculation)
2323 * [Fee Payment](#fee-payment)
24+ * [Dust Limits](#dust-limits)
25+ * [Commitment Transaction Construction](#commitment-transaction-construction)
2426 * [ Keys] ( #keys )
2527 * [ Key Derivation] ( #key-derivation )
2628 * [ ` localpubkey ` , ` remotepubkey ` , ` local_htlcpubkey ` , ` remote_htlcpubkey ` , ` local_delayedpubkey ` , and ` remote_delayedpubkey ` Derivation] ( #localpubkey-remotepubkey-local_htlcpubkey-remote_htlcpubkey-local_delayedpubkey-and-remote_delayedpubkey-derivation )
@@ -480,6 +482,70 @@ A node:
480482 - if the resulting fee rate is too low:
481483 - MAY fail the channel.
482484
485+ ## Dust Limits
486+
487+ The ` dust_limit_satoshis ` parameter is used to configure the threshold below
488+ which nodes will not produce on-chain transaction outputs.
489+
490+ There is no consensus rule in Bitcoin that makes outputs below dust thresholds
491+ invalid or unspendable, but policy rules in popular implementations will prevent
492+ relaying transactions that contain such outputs.
493+
494+ Bitcoin Core defines the following dust thresholds:
495+
496+ - pay to pubkey hash (p2pkh): 546 satoshis
497+ - pay to script hash (p2sh): 540 satoshis
498+ - pay to witness pubkey hash (p2wpkh): 294 satoshis
499+ - pay to witness script hash (p2wsh): 330 satoshis
500+
501+ Details of this calculation (implemented [ here] ( https://github.com/bitcoin/bitcoin/blob/0.21/src/policy/policy.cpp ) ):
502+
503+ - the feerate is set to 3000 sat/kB
504+ - a p2wpkh output is 31 bytes:
505+ - 8 bytes for the output amount
506+ - 1 byte for the script length
507+ - 22 bytes for the script (` OP_0 ` ` 20 ` 20-bytes)
508+ - a p2wpkh input is at least 67 bytes (depending on the signature length):
509+ - 36 bytes for the previous output (32 bytes hash + 4 bytes index)
510+ - 1 byte for the script sig length
511+ - 4 bytes for the sequence
512+ - 26 bytes for the witness (with the 75% segwit discount applied):
513+ - 1 byte for the items count
514+ - 1 byte for the signature length
515+ - 71 bytes for the signature
516+ - 1 byte for the public key length
517+ - 33 bytes for the public key
518+ - the p2wpkh dust threshold is then ` (31 + 67) * 3000 / 1000 = 294 satoshis `
519+ - a p2wsh output is 43 bytes:
520+ - 8 bytes for the output amount
521+ - 1 byte for the script length
522+ - 34 bytes for the script (` OP_0 ` ` 32 ` 32-bytes)
523+ - a p2wsh input doesn't have a fixed size, since it depends on the underlying
524+ script, so we use 67 bytes as a lower bound
525+ - the p2wsh dust threshold is then ` (43 + 67) * 3000 / 1000 = 330 satoshis `
526+ - a p2pkh output is 34 bytes:
527+ - 8 bytes for the output amount
528+ - 1 byte for the script length
529+ - 25 bytes for the script (` OP_DUP ` ` OP_HASH160 ` ` 20 ` 20-bytes ` OP_EQUALVERIFY ` ` OP_CHECKSIG ` )
530+ - a p2pkh input is at least 148 bytes:
531+ - 36 bytes for the previous output (32 bytes hash + 4 bytes index)
532+ - 1 byte for the script sig length
533+ - 4 bytes for the sequence
534+ - 107 bytes for the script sig:
535+ - 1 byte for the items count
536+ - 1 byte for the signature length
537+ - 71 bytes for the signature
538+ - 1 byte for the public key length
539+ - 33 bytes for the public key
540+ - the p2pkh dust threshold is then ` (34 + 148) * 3000 / 1000 = 546 satoshis `
541+ - a p2sh output is 32 bytes:
542+ - 8 bytes for the output amount
543+ - 1 byte for the script length
544+ - 23 bytes for the script (` OP_HASH160 ` ` 20 ` 20-bytes ` OP_EQUAL ` )
545+ - a p2sh input doesn't have a fixed size, since it depends on the underlying
546+ script, so we use 148 bytes as a lower bound
547+ - the p2sh dust threshold is then ` (32 + 148) * 3000 / 1000 = 540 satoshis `
548+
483549## Commitment Transaction Construction
484550
485551This section ties the previous sections together to detail the
0 commit comments