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

Function commit_txfee

lightningd/peer_control.c:504–577  ·  view source on GitHub ↗

Fee a commitment transaction would currently cost */

Source from the content-addressed store, hash-verified

502
503/* Fee a commitment transaction would currently cost */
504static struct amount_sat commit_txfee(const struct channel *channel,
505 struct amount_msat amount,
506 enum side side)
507{
508 /* FIXME: make per-channel htlc maps! */
509 const struct htlc_in *hin;
510 struct htlc_in_map_iter ini;
511 const struct htlc_out *hout;
512 struct htlc_out_map_iter outi;
513 struct lightningd *ld = channel->peer->ld;
514 size_t num_untrimmed_htlcs = 0;
515 u32 feerate = get_feerate(channel->fee_states,
516 channel->opener, side);
517 struct amount_sat dust_limit;
518 struct amount_sat fee;
519 bool option_anchor_outputs = channel_has(channel, OPT_ANCHOR_OUTPUTS);
520
521 if (side == LOCAL)
522 dust_limit = channel->our_config.dust_limit;
523 if (side == REMOTE)
524 dust_limit = channel->channel_info.their_config.dust_limit;
525
526 /* Assume we tried to add "amount" */
527 if (!htlc_is_trimmed(side, amount, feerate, dust_limit, side,
528 option_anchor_outputs))
529 num_untrimmed_htlcs++;
530
531 for (hin = htlc_in_map_first(&ld->htlcs_in, &ini);
532 hin;
533 hin = htlc_in_map_next(&ld->htlcs_in, &ini)) {
534 if (hin->key.channel != channel)
535 continue;
536 if (!htlc_is_trimmed(!side, hin->msat, feerate, dust_limit,
537 side, option_anchor_outputs))
538 num_untrimmed_htlcs++;
539 }
540 for (hout = htlc_out_map_first(&ld->htlcs_out, &outi);
541 hout;
542 hout = htlc_out_map_next(&ld->htlcs_out, &outi)) {
543 if (hout->key.channel != channel)
544 continue;
545 if (!htlc_is_trimmed(side, hout->msat, feerate, dust_limit,
546 side, option_anchor_outputs))
547 num_untrimmed_htlcs++;
548 }
549
550 /*
551 * BOLT #2:
552 * A sending node:
553 *...
554 * - SHOULD NOT offer `amount_msat` if, after adding that HTLC to its
555 * commitment transaction, its remaining balance doesn't allow it to
556 * pay the commitment transaction fee when receiving or sending a
557 * future additional non-dust HTLC while maintaining its channel
558 * reserve. It is recommended that this "fee spike buffer" can
559 * handle twice the current `feerate_per_kw` to ensure
560 * predictability between implementations.
561 */

Callers 2

channel_amount_spendableFunction · 0.85

Calls 5

commit_tx_base_feeFunction · 0.85
channel_hasFunction · 0.70
get_feerateFunction · 0.50
htlc_is_trimmedFunction · 0.50
amount_sat_addFunction · 0.50

Tested by

no test coverage detected