* The maximum msat that this node could possibly accept for an htlc. * It's the default htlc_maximum_msat in channel_updates, if none is * explicitly set (and the cap on what can be set!). * * We advertize the maximum value possible, defined as the smaller * of the remote's maximum in-flight HTLC or the total channel * capacity the reserve we have to keep. * FIXME: does this need fuzz? */
| 296 | * FIXME: does this need fuzz? |
| 297 | */ |
| 298 | struct amount_msat htlc_max_possible_send(const struct channel *channel) |
| 299 | { |
| 300 | struct amount_sat lower_bound; |
| 301 | struct amount_msat lower_bound_msat; |
| 302 | |
| 303 | /* These shouldn't fail */ |
| 304 | if (!amount_sat_sub(&lower_bound, channel->funding_sats, |
| 305 | channel->channel_info.their_config.channel_reserve)) { |
| 306 | log_broken(channel->log, "%s: their reserve %s > funding %s!", |
| 307 | __func__, |
| 308 | type_to_string(tmpctx, struct amount_sat, |
| 309 | &channel->funding_sats), |
| 310 | type_to_string(tmpctx, struct amount_sat, |
| 311 | &channel->channel_info.their_config.channel_reserve)); |
| 312 | return AMOUNT_MSAT(0); |
| 313 | } |
| 314 | |
| 315 | if (!amount_sat_to_msat(&lower_bound_msat, lower_bound)) { |
| 316 | log_broken(channel->log, "%s: impossible size channel %s!", |
| 317 | __func__, |
| 318 | type_to_string(tmpctx, struct amount_sat, |
| 319 | &lower_bound)); |
| 320 | return AMOUNT_MSAT(0); |
| 321 | } |
| 322 | |
| 323 | if (amount_msat_less(channel->channel_info.their_config.max_htlc_value_in_flight, |
| 324 | lower_bound_msat)) |
| 325 | lower_bound_msat = channel->channel_info.their_config.max_htlc_value_in_flight; |
| 326 | |
| 327 | return lower_bound_msat; |
| 328 | } |
| 329 | |
| 330 | struct channel *new_channel(struct peer *peer, u64 dbid, |
| 331 | /* NULL or stolen */ |
no test coverage detected