Get the minimum and desired fees */
| 596 | |
| 597 | /* Get the minimum and desired fees */ |
| 598 | static void calc_fee_bounds(size_t expected_weight, |
| 599 | u32 min_feerate, |
| 600 | u32 desired_feerate, |
| 601 | u32 *max_feerate, |
| 602 | struct amount_sat commitment_fee, |
| 603 | struct amount_sat funding, |
| 604 | enum side opener, |
| 605 | struct amount_sat *minfee, |
| 606 | struct amount_sat *desiredfee, |
| 607 | struct amount_sat *maxfee) |
| 608 | { |
| 609 | *minfee = amount_tx_fee(min_feerate, expected_weight); |
| 610 | *desiredfee = amount_tx_fee(desired_feerate, expected_weight); |
| 611 | |
| 612 | /* BOLT #2: |
| 613 | * - if it is not the funder: |
| 614 | * - SHOULD set `max_fee_satoshis` to at least the `max_fee_satoshis` |
| 615 | * received |
| 616 | *... |
| 617 | * Note that the non-funder is not paying the fee, so there is |
| 618 | * no reason for it to have a maximum feerate. |
| 619 | */ |
| 620 | if (opener == REMOTE) { |
| 621 | *maxfee = funding; |
| 622 | |
| 623 | /* This used to appear in BOLT #2: we still set it for non-anchor |
| 624 | * peers who may still enforce it: |
| 625 | * - If the channel does not use `option_anchor_outputs`: |
| 626 | * - MUST set `fee_satoshis` less than or equal to the base fee of |
| 627 | * the final commitment transaction, as calculated in |
| 628 | * [BOLT #3](03-transactions.md#fee-calculation). |
| 629 | */ |
| 630 | } else if (max_feerate) { |
| 631 | *maxfee = amount_tx_fee(*max_feerate, expected_weight); |
| 632 | |
| 633 | status_debug("deriving max fee from rate %u -> %s (not %s)", |
| 634 | *max_feerate, |
| 635 | type_to_string(tmpctx, struct amount_sat, maxfee), |
| 636 | type_to_string(tmpctx, struct amount_sat, &commitment_fee)); |
| 637 | |
| 638 | /* option_anchor_outputs sets commitment_fee to max, so this |
| 639 | * doesn't do anything */ |
| 640 | if (amount_sat_greater(*maxfee, commitment_fee)) { |
| 641 | /* FIXME: would be nice to notify close cmd here! */ |
| 642 | status_unusual("Maximum feerate %u would give fee %s:" |
| 643 | " we must limit it to the final commitment fee %s", |
| 644 | *max_feerate, |
| 645 | type_to_string(tmpctx, struct amount_sat, |
| 646 | maxfee), |
| 647 | type_to_string(tmpctx, struct amount_sat, |
| 648 | &commitment_fee)); |
| 649 | *maxfee = commitment_fee; |
| 650 | } |
| 651 | } else |
| 652 | *maxfee = commitment_fee; |
| 653 | |
| 654 | /* Can't exceed maxfee. */ |
| 655 | if (amount_sat_greater(*minfee, *maxfee)) |
no test coverage detected