MCPcopy Create free account
hub / github.com/ElementsProject/lightning / calc_fee_bounds

Function calc_fee_bounds

closingd/closingd.c:610–678  ·  view source on GitHub ↗

Get the minimum and desired fees */

Source from the content-addressed store, hash-verified

608
609/* Get the minimum and desired fees */
610static void calc_fee_bounds(size_t expected_weight,
611 u32 min_feerate,
612 u32 desired_feerate,
613 u32 max_feerate,
614 struct amount_sat funding,
615 enum side opener,
616 struct amount_sat *minfee,
617 struct amount_sat *desiredfee,
618 struct amount_sat *maxfee)
619{
620 *minfee = amount_tx_fee(min_feerate, expected_weight);
621 *desiredfee = amount_tx_fee(desired_feerate, expected_weight);
622
623 /* BOLT #2:
624 * - if it is not the funder:
625 * - SHOULD set `max_fee_satoshis` to at least the `max_fee_satoshis` received
626 */
627 /* BOLT #2:
628 *
629 * Note that the non-funder is not paying the fee, so there is no reason for it
630 * to have a maximum feerate.
631 */
632 if (opener == REMOTE) {
633 *maxfee = funding;
634
635 } else {
636 /* BOLT #2:
637 * The sending node:
638 *
639 * - SHOULD set the initial `fee_satoshis` according to its
640 * estimate of cost of inclusion in a block.
641 *
642 * - SHOULD set `fee_range` according to the minimum and
643 * maximum fees it is prepared to pay for a close
644 * transaction.
645 */
646 *maxfee = amount_tx_fee(max_feerate, expected_weight);
647 status_debug("deriving max fee from rate %u -> %s",
648 max_feerate,
649 fmt_amount_sat(tmpctx, *maxfee));
650 }
651
652 /* Can't exceed maxfee. */
653 if (amount_sat_greater(*minfee, *maxfee))
654 *minfee = *maxfee;
655
656 if (amount_sat_less(*desiredfee, *minfee)) {
657 status_unusual("Our ideal fee is %s (%u sats/perkw),"
658 " but our minimum is %s: using that",
659 fmt_amount_sat(tmpctx, *desiredfee),
660 desired_feerate,
661 fmt_amount_sat(tmpctx, *minfee));
662 *desiredfee = *minfee;
663 }
664 if (amount_sat_greater(*desiredfee, *maxfee)) {
665 status_unusual("Our ideal fee is %s (%u sats/perkw),"
666 " but our maximum is %s: using that",
667 fmt_amount_sat(tmpctx, *desiredfee),

Callers 1

mainFunction · 0.85

Calls 4

amount_sat_greaterFunction · 0.85
amount_sat_lessFunction · 0.85
amount_tx_feeFunction · 0.50
fmt_amount_satFunction · 0.50

Tested by

no test coverage detected