| 850 | } |
| 851 | |
| 852 | struct amount_msat channel_amount_spendable(const struct channel *channel) |
| 853 | { |
| 854 | struct amount_msat spendable; |
| 855 | bool wumbo; |
| 856 | |
| 857 | /* Compute how much we can send via this channel in one payment. */ |
| 858 | if (!amount_msat_sub_sat(&spendable, |
| 859 | channel->our_msat, |
| 860 | channel->channel_info.their_config.channel_reserve)) |
| 861 | return AMOUNT_MSAT(0); |
| 862 | |
| 863 | /* Take away any currently-offered HTLCs. */ |
| 864 | subtract_offered_htlcs(channel, &spendable); |
| 865 | |
| 866 | /* If we're opener, subtract txfees we'll need to spend this */ |
| 867 | if (channel->opener == LOCAL) { |
| 868 | if (!amount_msat_deduct_sat(&spendable, |
| 869 | commit_txfee(channel, spendable, |
| 870 | LOCAL))) |
| 871 | return AMOUNT_MSAT(0); |
| 872 | } |
| 873 | |
| 874 | /* We can't offer an HTLC less than the other side will accept. */ |
| 875 | if (amount_msat_less(spendable, |
| 876 | channel->channel_info.their_config.htlc_minimum)) |
| 877 | return AMOUNT_MSAT(0); |
| 878 | |
| 879 | wumbo = feature_negotiated(channel->peer->ld->our_features, |
| 880 | channel->peer->their_features, |
| 881 | OPT_LARGE_CHANNELS); |
| 882 | |
| 883 | /* We can't offer an HTLC over the max payment threshold either. */ |
| 884 | if (amount_msat_greater(spendable, chainparams->max_payment) |
| 885 | && !wumbo) { |
| 886 | spendable = chainparams->max_payment; |
| 887 | } |
| 888 | |
| 889 | return spendable; |
| 890 | } |
| 891 | |
| 892 | struct amount_msat channel_amount_receivable(const struct channel *channel) |
| 893 | { |
no test coverage detected