Fee a commitment transaction would currently cost */
| 740 | |
| 741 | /* Fee a commitment transaction would currently cost */ |
| 742 | static struct amount_sat commit_txfee(const struct channel *channel, |
| 743 | struct amount_msat amount, |
| 744 | enum side side) |
| 745 | { |
| 746 | /* FIXME: make per-channel htlc maps! */ |
| 747 | const struct htlc_in *hin; |
| 748 | struct htlc_in_map_iter ini; |
| 749 | const struct htlc_out *hout; |
| 750 | struct htlc_out_map_iter outi; |
| 751 | struct lightningd *ld = channel->peer->ld; |
| 752 | size_t num_untrimmed_htlcs = 0; |
| 753 | u32 feerate = get_feerate(channel->fee_states, |
| 754 | channel->opener, side); |
| 755 | struct amount_sat dust_limit; |
| 756 | struct amount_sat fee; |
| 757 | bool option_anchor_outputs = channel_has(channel, OPT_ANCHOR_OUTPUTS_DEPRECATED); |
| 758 | bool option_anchors_zero_fee_htlc_tx = channel_has(channel, OPT_ANCHORS_ZERO_FEE_HTLC_TX); |
| 759 | |
| 760 | if (side == LOCAL) |
| 761 | dust_limit = channel->our_config.dust_limit; |
| 762 | if (side == REMOTE) |
| 763 | dust_limit = channel->channel_info.their_config.dust_limit; |
| 764 | |
| 765 | /* Assume we tried to add "amount" */ |
| 766 | if (!htlc_is_trimmed(side, amount, feerate, dust_limit, side, |
| 767 | option_anchor_outputs, option_anchors_zero_fee_htlc_tx)) |
| 768 | num_untrimmed_htlcs++; |
| 769 | |
| 770 | for (hin = htlc_in_map_first(ld->htlcs_in, &ini); |
| 771 | hin; |
| 772 | hin = htlc_in_map_next(ld->htlcs_in, &ini)) { |
| 773 | if (hin->key.channel != channel) |
| 774 | continue; |
| 775 | if (!htlc_is_trimmed(!side, hin->msat, feerate, dust_limit, |
| 776 | side, option_anchor_outputs, option_anchors_zero_fee_htlc_tx)) |
| 777 | num_untrimmed_htlcs++; |
| 778 | } |
| 779 | for (hout = htlc_out_map_first(ld->htlcs_out, &outi); |
| 780 | hout; |
| 781 | hout = htlc_out_map_next(ld->htlcs_out, &outi)) { |
| 782 | if (hout->key.channel != channel) |
| 783 | continue; |
| 784 | if (!htlc_is_trimmed(side, hout->msat, feerate, dust_limit, |
| 785 | side, option_anchor_outputs, option_anchors_zero_fee_htlc_tx)) |
| 786 | num_untrimmed_htlcs++; |
| 787 | } |
| 788 | |
| 789 | /* |
| 790 | * BOLT #2: |
| 791 | * A sending node: |
| 792 | *... |
| 793 | * - SHOULD NOT offer `amount_msat` if, after adding that HTLC to its |
| 794 | * commitment transaction, its remaining balance doesn't allow it to |
| 795 | * pay the commitment transaction fee when receiving or sending a |
| 796 | * future additional non-dust HTLC while maintaining its channel |
| 797 | * reserve. It is recommended that this "fee spike buffer" can |
| 798 | * handle twice the current `feerate_per_kw` to ensure |
| 799 | * predictability between implementations. |
no test coverage detected