* 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? */
| 460 | * FIXME: does this need fuzz? |
| 461 | */ |
| 462 | struct amount_msat htlc_max_possible_send(const struct channel *channel) |
| 463 | { |
| 464 | struct amount_sat lower_bound; |
| 465 | struct amount_msat lower_bound_msat; |
| 466 | |
| 467 | /* These shouldn't fail */ |
| 468 | if (!amount_sat_sub(&lower_bound, channel->funding_sats, |
| 469 | channel->channel_info.their_config.channel_reserve)) { |
| 470 | log_broken(channel->log, "%s: their reserve %s > funding %s!", |
| 471 | __func__, |
| 472 | fmt_amount_sat(tmpctx, channel->funding_sats), |
| 473 | fmt_amount_sat(tmpctx, |
| 474 | channel->channel_info.their_config.channel_reserve)); |
| 475 | return AMOUNT_MSAT(0); |
| 476 | } |
| 477 | |
| 478 | if (!amount_sat_to_msat(&lower_bound_msat, lower_bound)) { |
| 479 | log_broken(channel->log, "%s: impossible size channel %s!", |
| 480 | __func__, |
| 481 | fmt_amount_sat(tmpctx, lower_bound)); |
| 482 | return AMOUNT_MSAT(0); |
| 483 | } |
| 484 | |
| 485 | if (amount_msat_less(channel->channel_info.their_config.max_htlc_value_in_flight, |
| 486 | lower_bound_msat)) |
| 487 | lower_bound_msat = channel->channel_info.their_config.max_htlc_value_in_flight; |
| 488 | |
| 489 | return lower_bound_msat; |
| 490 | } |
| 491 | |
| 492 | struct channel *new_channel(struct peer *peer, u64 dbid, |
| 493 | /* NULL or stolen */ |
no test coverage detected