| 495 | } |
| 496 | |
| 497 | static struct amount_sat get_htlc_success_fee(struct tracked_output *out) |
| 498 | { |
| 499 | static struct amount_sat fee = AMOUNT_SAT_INIT(UINT64_MAX); |
| 500 | size_t weight; |
| 501 | struct amount_msat htlc_amount; |
| 502 | struct bitcoin_tx *tx; |
| 503 | |
| 504 | /* We only grind once, since they're all equiv. */ |
| 505 | if (!amount_sat_eq(fee, AMOUNT_SAT(UINT64_MAX))) |
| 506 | return fee; |
| 507 | |
| 508 | if (option_anchors_zero_fee_htlc_tx) { |
| 509 | fee = AMOUNT_SAT(0); |
| 510 | return fee; |
| 511 | } |
| 512 | |
| 513 | if (!amount_sat_to_msat(&htlc_amount, out->sat)) |
| 514 | status_failed(STATUS_FAIL_INTERNAL_ERROR, |
| 515 | "Overflow in get_htlc_success_fee %s", |
| 516 | fmt_amount_sat(tmpctx, out->sat)); |
| 517 | tx = htlc_success_tx(tmpctx, chainparams, |
| 518 | &out->outpoint, |
| 519 | out->wscript, |
| 520 | htlc_amount, |
| 521 | to_self_delay[LOCAL], |
| 522 | 0, |
| 523 | keyset, |
| 524 | option_anchor_outputs, |
| 525 | option_anchors_zero_fee_htlc_tx); |
| 526 | |
| 527 | /* BOLT #3: |
| 528 | * |
| 529 | * The fee for an HTLC-success transaction: |
| 530 | * - If `option_anchors` applies: |
| 531 | * 1. MUST be 0. |
| 532 | * - Otherwise, MUST be calculated to match: |
| 533 | * 1. Multiply `feerate_per_kw` by 703 and divide by 1000 (rounding down). |
| 534 | */ |
| 535 | /* FIXME: Older bolt used to say (706 if `option_anchor_outputs` applies) */ |
| 536 | if (option_anchor_outputs) |
| 537 | weight = 706; |
| 538 | else |
| 539 | weight = 703; |
| 540 | |
| 541 | weight += elements_tx_overhead(chainparams, 1, 1); |
| 542 | if (!grind_htlc_tx_fee(&fee, tx, out->remote_htlc_sig, |
| 543 | out->wscript, weight)) { |
| 544 | status_failed(STATUS_FAIL_INTERNAL_ERROR, |
| 545 | "htlc_success_fee can't be found " |
| 546 | "for tx %s (weight %zu, feerate %u-%u), signature %s, wscript %s", |
| 547 | fmt_bitcoin_tx(tmpctx, tx), |
| 548 | weight, |
| 549 | min_possible_feerate, max_possible_feerate, |
| 550 | fmt_bitcoin_signature(tmpctx, |
| 551 | out->remote_htlc_sig), |
| 552 | tal_hex(tmpctx, out->wscript)); |
| 553 | } |
| 554 |
no test coverage detected