| 881 | } |
| 882 | |
| 883 | struct amount_msat channel_amount_spendable(const struct channel *channel) |
| 884 | { |
| 885 | struct amount_msat spendable; |
| 886 | bool wumbo; |
| 887 | |
| 888 | /* Compute how much we can send via this channel in one payment. */ |
| 889 | if (!amount_msat_sub_sat(&spendable, |
| 890 | channel->our_msat, |
| 891 | channel->channel_info.their_config.channel_reserve)) |
| 892 | return AMOUNT_MSAT(0); |
| 893 | |
| 894 | /* Take away any currently-offered HTLCs. */ |
| 895 | subtract_offered_htlcs(channel, &spendable); |
| 896 | |
| 897 | /* If we're opener, subtract txfees we'll need to spend this */ |
| 898 | if (channel->opener == LOCAL) { |
| 899 | if (!amount_msat_deduct_sat(&spendable, |
| 900 | commit_txfee(channel, spendable, |
| 901 | LOCAL))) |
| 902 | return AMOUNT_MSAT(0); |
| 903 | } |
| 904 | |
| 905 | /* We can't offer an HTLC less than the other side will accept. */ |
| 906 | if (amount_msat_less(spendable, |
| 907 | channel->channel_info.their_config.htlc_minimum)) |
| 908 | return AMOUNT_MSAT(0); |
| 909 | |
| 910 | wumbo = feature_negotiated(channel->peer->ld->our_features, |
| 911 | channel->peer->their_features, |
| 912 | OPT_LARGE_CHANNELS); |
| 913 | |
| 914 | /* We can't offer an HTLC over the max payment threshold either. */ |
| 915 | if (amount_msat_greater(spendable, chainparams->max_payment) |
| 916 | && !wumbo) { |
| 917 | spendable = chainparams->max_payment; |
| 918 | } |
| 919 | |
| 920 | return spendable; |
| 921 | } |
| 922 | |
| 923 | struct amount_msat channel_amount_receivable(const struct channel *channel) |
| 924 | { |
no test coverage detected