From bed7986650a8e26935d1f25274a463b94fd5b8a1 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Wed, 21 Nov 2018 21:06:21 +1030 Subject: [PATCH] channeld: speak no wumbo. We cap our htlc_maximum_msat at 2^32-1. Signed-off-by: Rusty Russell --- channeld/channeld.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/channeld/channeld.c b/channeld/channeld.c index bd0e0b493..d7f188f35 100644 --- a/channeld/channeld.c +++ b/channeld/channeld.c @@ -10,6 +10,7 @@ * reading and writing synchronously we could deadlock if we hit buffer * limits, unlikely as that is. */ +#include #include #include #include @@ -60,7 +61,6 @@ #define PEER_FD 3 #define GOSSIP_FD 4 #define HSM_FD 5 -#define min(x, y) ((x) < (y) ? (x) : (y)) struct commit_sigs { struct peer *peer; @@ -236,12 +236,22 @@ static const u8 *hsm_req(const tal_t *ctx, const u8 *req TAKES) * capacity minus the cumulative reserve. * FIXME: does this need fuzz? */ -static const u64 advertised_htlc_max(const struct channel *channel) +static u64 advertised_htlc_max(const struct channel *channel) { - u64 cumulative_reserve_msat = (channel->config[LOCAL].channel_reserve_satoshis + - channel->config[REMOTE].channel_reserve_satoshis) * 1000; - return min(channel->config[REMOTE].max_htlc_value_in_flight_msat, - channel->funding_msat - cumulative_reserve_msat); + u64 lower_bound; + u64 cumulative_reserve_msat; + + cumulative_reserve_msat = + (channel->config[LOCAL].channel_reserve_satoshis + + channel->config[REMOTE].channel_reserve_satoshis) * 1000; + + lower_bound = channel->config[REMOTE].max_htlc_value_in_flight_msat; + if (channel->funding_msat - cumulative_reserve_msat < lower_bound) + lower_bound = channel->funding_msat - cumulative_reserve_msat; + /* FIXME BOLT QUOTE: https://github.com/lightningnetwork/lightning-rfc/pull/512 once merged */ + if (channel->chainparams->max_payment_msat < lower_bound) + lower_bound = channel->chainparams->max_payment_msat; + return lower_bound; } /* Create and send channel_update to gossipd (and maybe peer) */