Skip to content

Commit ec99f89

Browse files
pm47rustyrussell
authored andcommitted
fixed htlc weight calculation
1 parent 8409213 commit ec99f89

File tree

1 file changed

+23
-21
lines changed

1 file changed

+23
-21
lines changed

03-transactions.md

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -239,20 +239,20 @@ Thus we use a simplified formula for *expected weight*, which assumes:
239239
This gives us the following *expected weights* (details of the computation in [Appendix A](#appendix-a-expected-weights)):
240240

241241
Commitment weight: 724 + 172 * num-untrimmed-htlc-outputs
242-
HTLC-timeout weight: 634
243-
HTLC-success weight: 671
242+
HTLC-timeout weight: 635
243+
HTLC-success weight: 673
244244

245245
Note that we refer to the "base fee" for a commitment transaction in the requirements below, which is what the funder pays. The actual fee may be higher than the amount calculated here, due to rounding and trimmed outputs.
246246

247247
#### Requirements
248248

249249
The fee for an HTLC-timeout transaction MUST BE calculated to match:
250250

251-
1. Multiply `feerate-per-kw` by 634 and divide by 1000 (rounding down).
251+
1. Multiply `feerate-per-kw` by 635 and divide by 1000 (rounding down).
252252

253253
The fee for an HTLC-success transaction MUST BE calculated to match:
254254

255-
1. Multiply `feerate-per-kw` by 671 and divide by 1000 (rounding down).
255+
1. Multiply `feerate-per-kw` by 673 and divide by 1000 (rounding down).
256256

257257
The base fee for a commitment transaction MUST BE calculated to match:
258258

@@ -269,26 +269,26 @@ For example, suppose that we have a `feerate-per-kw` of 5000, a `dust-limit-sato
269269
* 2 offered HTLCs of 5000000 and 1000000 millisatoshis (5000 and 1000 satoshis)
270270
* 2 received HTLCs of 7000000 and 800000 millisatoshis (7000 and 800 satoshis)
271271

272-
The HTLC timeout transaction weight is 634, thus fee would be 3170 satoshis.
273-
The HTLC success transaction weight is 671, thus fee would be 3355 satoshis
272+
The HTLC timeout transaction weight is 635, thus fee would be 3175 satoshis.
273+
The HTLC success transaction weight is 673, thus fee would be 3365 satoshis
274274

275275
The commitment transaction weight would be calculated as follows:
276276

277277
* weight starts at 724.
278278

279-
* The offered HTLC of 5000 satoshis is above 546 + 3170 and would result in:
279+
* The offered HTLC of 5000 satoshis is above 546 + 3175 and would result in:
280280
* an output of 5000 satoshi in the commitment transaction
281-
* a HTLC timeout transaction of 5000 - 3170 satoshis which spends this output
281+
* a HTLC timeout transaction of 5000 - 3175 satoshis which spends this output
282282
* weight increases to 896
283283

284-
* The offered HTLC of 1000 satoshis is below 546 + 3710, so would be trimmed.
284+
* The offered HTLC of 1000 satoshis is below 546 + 3175, so would be trimmed.
285285

286-
* The received HTLC of 7000 satoshis is above 546 + 3355 and would result in:
286+
* The received HTLC of 7000 satoshis is above 546 + 3365 and would result in:
287287
* an output of 7000 satoshi in the commitment transaction
288-
* a HTLC success transaction of 7000 - 3355 satoshis which spends this output
288+
* a HTLC success transaction of 7000 - 3365 satoshis which spends this output
289289
* weight increases to 1068
290290

291-
* The received HTLC of 800 satoshis is below 546 + 3355 so would be trimmed.
291+
* The received HTLC of 800 satoshis is below 546 + 3365 so would be trimmed.
292292

293293
The base commitment transaction fee would be 5340 satoshi; the actual
294294
fee (adding the 1000 and 800 satoshi HTLCs which would have made dust
@@ -588,11 +588,12 @@ Multiplying non-witness data by 4, this gives a weight of:
588588

589589
The *expected weight* of an HTLC transaction is calculated as follows:
590590

591-
accepted_htlc_script: 109 bytes
591+
accepted_htlc_script: 111 bytes
592592
- OP_DATA: 1 byte (remotekey length)
593593
- remotekey: 33 bytes
594594
- OP_SWAP: 1 byte
595595
- OP_SIZE: 1 byte
596+
- OP_DATA: 1 byte (32 length)
596597
- 32: 1 byte
597598
- OP_EQUAL: 1 byte
598599
- OP_IF: 1 byte
@@ -608,18 +609,19 @@ The *expected weight* of an HTLC transaction is calculated as follows:
608609
- OP_CHECKMULTISIG: 1 byte
609610
- OP_ELSE: 1 byte
610611
- OP_DROP: 1 byte
611-
- OP_PUSHDATA2: 1 byte (locktime length)
612-
- locktime: 2 bytes
612+
- OP_DATA: 1 byte (locktime length)
613+
- locktime: 3 bytes
613614
- OP_CHECKLOCKTIMEVERIFY: 1 byte
614615
- OP_DROP: 1 byte
615616
- OP_CHECKSIG: 1 byte
616617
- OP_ENDIF: 1 byte
617618

618-
offered_htlc_script: 104 bytes
619+
offered_htlc_script: 105 bytes
619620
- OP_DATA: 1 byte (remotekey length)
620621
- remotekey: 33 bytes
621622
- OP_SWAP: 1 byte
622623
- OP_SIZE: 1 byte
624+
- OP_DATA: 1 byte (32 length)
623625
- 32: 1 byte
624626
- OP_EQUAL: 1 byte
625627
- OP_NOTIF: 1 byte
@@ -638,7 +640,7 @@ The *expected weight* of an HTLC transaction is calculated as follows:
638640
- OP_CHECKSIG: 1 byte
639641
- OP_ENDIF: 1 byte
640642

641-
timeout_witness: 256 bytes
643+
timeout_witness: 257 bytes
642644
- number_of_witness_elements: 1 byte
643645
- nil_length: 1 byte
644646
- sig_alice_length: 1 byte
@@ -649,7 +651,7 @@ The *expected weight* of an HTLC transaction is calculated as follows:
649651
- witness_script_length: 1 byte
650652
- witness_script (offered_htlc_script)
651653

652-
success_witness: 293 bytes
654+
success_witness: 295 bytes
653655
- number_of_witness_elements: 1 byte
654656
- nil_length: 1 byte
655657
- sig_alice_length: 1 byte
@@ -687,11 +689,11 @@ The *expected weight* of an HTLC transaction is calculated as follows:
687689
- lock_time: 4 bytes
688690

689691
Multiplying non-witness data by 4, this gives a weight of 376. Adding
690-
the witness data for each case (256 + 2 for HTLC-timeout, 293 + 2 for
692+
the witness data for each case (257 + 2 for HTLC-timeout, 295 + 2 for
691693
HTLC-success) gives a weight of:
692694

693-
634 (HTLC-timeout)
694-
671 (HTLC-success)
695+
635 (HTLC-timeout)
696+
673 (HTLC-success)
695697

696698
# Appendix C: Funding Transaction Test Vectors
697699

0 commit comments

Comments
 (0)