Fee a commitment transaction would currently cost */
| 796 | |
| 797 | /* Fee a commitment transaction would currently cost */ |
| 798 | static 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. |
no test coverage detected