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

Function commit_txfee

lightningd/peer_control.c:798–872  ·  view source on GitHub ↗

Fee a commitment transaction would currently cost */

Source from the content-addressed store, hash-verified

796
797/* Fee a commitment transaction would currently cost */
798static struct amount_sat commit_txfee(const struct channel *channel,
799 struct amount_msat amount,
800 enum side side)
801{
802 /* FIXME: make per-channel htlc maps! */
803 const struct htlc_in *hin;
804 struct htlc_in_map_iter ini;
805 const struct htlc_out *hout;
806 struct htlc_out_map_iter outi;
807 struct lightningd *ld = channel->peer->ld;
808 size_t num_untrimmed_htlcs = 0;
809 u32 feerate = get_feerate(channel->fee_states,
810 channel->opener, side);
811 struct amount_sat dust_limit;
812 struct amount_sat fee;
813 bool option_anchor_outputs = channel_has(channel, OPT_ANCHOR_OUTPUTS_DEPRECATED);
814 bool option_anchors_zero_fee_htlc_tx = channel_has(channel, OPT_ANCHORS_ZERO_FEE_HTLC_TX);
815
816 if (side == LOCAL)
817 dust_limit = channel->our_config.dust_limit;
818 if (side == REMOTE)
819 dust_limit = channel->channel_info.their_config.dust_limit;
820
821 /* Assume we tried to add "amount" */
822 if (!htlc_is_trimmed(side, amount, feerate, dust_limit, side,
823 option_anchor_outputs, option_anchors_zero_fee_htlc_tx))
824 num_untrimmed_htlcs++;
825
826 for (hin = htlc_in_map_first(ld->htlcs_in, &ini);
827 hin;
828 hin = htlc_in_map_next(ld->htlcs_in, &ini)) {
829 if (hin->key.channel != channel)
830 continue;
831 if (!htlc_is_trimmed(!side, hin->msat, feerate, dust_limit,
832 side, option_anchor_outputs, option_anchors_zero_fee_htlc_tx))
833 num_untrimmed_htlcs++;
834 }
835 for (hout = htlc_out_map_first(ld->htlcs_out, &outi);
836 hout;
837 hout = htlc_out_map_next(ld->htlcs_out, &outi)) {
838 if (hout->key.channel != channel)
839 continue;
840 if (!htlc_is_trimmed(side, hout->msat, feerate, dust_limit,
841 side, option_anchor_outputs, option_anchors_zero_fee_htlc_tx))
842 num_untrimmed_htlcs++;
843 }
844
845 /*
846 * BOLT #2:
847 * A sending node:
848 *...
849 * - SHOULD NOT offer `amount_msat` if, after adding that HTLC to its
850 * commitment transaction, its remaining balance doesn't allow it to
851 * pay the commitment transaction fee when receiving or sending a
852 * future additional non-dust HTLC while maintaining its channel
853 * reserve. It is recommended that this "fee spike buffer" can
854 * handle twice the current `feerate_per_kw` to ensure
855 * predictability between implementations.

Callers 2

channel_amount_spendableFunction · 0.85

Calls 6

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

Tested by

no test coverage detected