| 921 | } |
| 922 | |
| 923 | struct amount_msat channel_amount_receivable(const struct channel *channel) |
| 924 | { |
| 925 | struct amount_msat their_msat, receivable; |
| 926 | bool wumbo; |
| 927 | |
| 928 | /* Compute how much we can receive via this channel in one payment */ |
| 929 | if (!amount_sat_sub_msat(&their_msat, |
| 930 | channel->funding_sats, channel->our_msat)) |
| 931 | their_msat = AMOUNT_MSAT(0); |
| 932 | |
| 933 | if (!amount_msat_sub_sat(&receivable, |
| 934 | their_msat, |
| 935 | channel->our_config.channel_reserve)) |
| 936 | return AMOUNT_MSAT(0); |
| 937 | |
| 938 | /* Take away any currently-offered HTLCs. */ |
| 939 | subtract_received_htlcs(channel, &receivable); |
| 940 | |
| 941 | /* If they're opener, subtract txfees they'll need to spend this */ |
| 942 | if (channel->opener == REMOTE) { |
| 943 | if (!amount_msat_deduct_sat(&receivable, |
| 944 | commit_txfee(channel, |
| 945 | receivable, REMOTE))) |
| 946 | return AMOUNT_MSAT(0); |
| 947 | } |
| 948 | |
| 949 | /* They can't offer an HTLC less than what we will accept. */ |
| 950 | if (amount_msat_less(receivable, channel->our_config.htlc_minimum)) |
| 951 | return AMOUNT_MSAT(0); |
| 952 | |
| 953 | wumbo = feature_negotiated(channel->peer->ld->our_features, |
| 954 | channel->peer->their_features, |
| 955 | OPT_LARGE_CHANNELS); |
| 956 | |
| 957 | /* They can't offer an HTLC over the max payment threshold either. */ |
| 958 | if (amount_msat_greater(receivable, chainparams->max_payment) |
| 959 | && !wumbo) { |
| 960 | receivable = chainparams->max_payment; |
| 961 | } |
| 962 | |
| 963 | return receivable; |
| 964 | } |
| 965 | |
| 966 | static void NON_NULL_ARGS(1, 2, 4, 5) json_add_channel(struct command *cmd, |
| 967 | struct json_stream *response, |
no test coverage detected