| 890 | } |
| 891 | |
| 892 | struct amount_msat channel_amount_receivable(const struct channel *channel) |
| 893 | { |
| 894 | struct amount_msat their_msat, receivable; |
| 895 | bool wumbo; |
| 896 | |
| 897 | /* Compute how much we can receive via this channel in one payment */ |
| 898 | if (!amount_sat_sub_msat(&their_msat, |
| 899 | channel->funding_sats, channel->our_msat)) |
| 900 | their_msat = AMOUNT_MSAT(0); |
| 901 | |
| 902 | if (!amount_msat_sub_sat(&receivable, |
| 903 | their_msat, |
| 904 | channel->our_config.channel_reserve)) |
| 905 | return AMOUNT_MSAT(0); |
| 906 | |
| 907 | /* Take away any currently-offered HTLCs. */ |
| 908 | subtract_received_htlcs(channel, &receivable); |
| 909 | |
| 910 | /* If they're opener, subtract txfees they'll need to spend this */ |
| 911 | if (channel->opener == REMOTE) { |
| 912 | if (!amount_msat_deduct_sat(&receivable, |
| 913 | commit_txfee(channel, |
| 914 | receivable, REMOTE))) |
| 915 | return AMOUNT_MSAT(0); |
| 916 | } |
| 917 | |
| 918 | /* They can't offer an HTLC less than what we will accept. */ |
| 919 | if (amount_msat_less(receivable, channel->our_config.htlc_minimum)) |
| 920 | return AMOUNT_MSAT(0); |
| 921 | |
| 922 | wumbo = feature_negotiated(channel->peer->ld->our_features, |
| 923 | channel->peer->their_features, |
| 924 | OPT_LARGE_CHANNELS); |
| 925 | |
| 926 | /* They can't offer an HTLC over the max payment threshold either. */ |
| 927 | if (amount_msat_greater(receivable, chainparams->max_payment) |
| 928 | && !wumbo) { |
| 929 | receivable = chainparams->max_payment; |
| 930 | } |
| 931 | |
| 932 | return receivable; |
| 933 | } |
| 934 | |
| 935 | static void NON_NULL_ARGS(1, 2, 4, 5) json_add_channel(struct command *cmd, |
| 936 | struct json_stream *response, |
no test coverage detected