| 906 | } |
| 907 | |
| 908 | struct amount_msat channel_amount_spendable(const struct channel *channel) |
| 909 | { |
| 910 | struct amount_msat spendable; |
| 911 | bool wumbo; |
| 912 | |
| 913 | /* Compute how much we can send via this channel in one payment. */ |
| 914 | if (!amount_msat_sub_sat(&spendable, |
| 915 | channel->our_msat, |
| 916 | channel->channel_info.their_config.channel_reserve)) |
| 917 | return AMOUNT_MSAT(0); |
| 918 | |
| 919 | /* Take away any currently-offered HTLCs. */ |
| 920 | subtract_offered_htlcs(channel, &spendable); |
| 921 | |
| 922 | /* If we're opener, subtract txfees we'll need to spend this */ |
| 923 | if (channel->opener == LOCAL) { |
| 924 | if (!amount_msat_deduct_sat(&spendable, |
| 925 | commit_txfee(channel, spendable, |
| 926 | LOCAL))) |
| 927 | return AMOUNT_MSAT(0); |
| 928 | } |
| 929 | |
| 930 | /* We can't offer an HTLC less than the other side will accept. */ |
| 931 | if (amount_msat_less(spendable, |
| 932 | channel->channel_info.their_config.htlc_minimum)) |
| 933 | return AMOUNT_MSAT(0); |
| 934 | |
| 935 | wumbo = feature_negotiated(channel->peer->ld->our_features, |
| 936 | channel->peer->their_features, |
| 937 | OPT_LARGE_CHANNELS); |
| 938 | |
| 939 | /* We can't offer an HTLC over the max payment threshold either. */ |
| 940 | if (amount_msat_greater(spendable, chainparams->max_payment) |
| 941 | && !wumbo) { |
| 942 | spendable = chainparams->max_payment; |
| 943 | } |
| 944 | |
| 945 | return spendable; |
| 946 | } |
| 947 | |
| 948 | struct amount_msat channel_amount_receivable(const struct channel *channel) |
| 949 | { |
no test coverage detected