From f078a916e72b900c7d6f78654885155c1cc2dc65 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Mon, 21 Mar 2022 11:28:27 +1030 Subject: [PATCH] lightningd: enforce htlc_maximum_msat. When we let them set it, this matters! Signed-off-by: Rusty Russell --- lightningd/channel.h | 3 ++- lightningd/peer_control.c | 1 + lightningd/peer_htlcs.c | 12 ++++++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/lightningd/channel.h b/lightningd/channel.h index 867f8208d..5390ad74a 100644 --- a/lightningd/channel.h +++ b/lightningd/channel.h @@ -202,9 +202,10 @@ struct channel { /* Feerate per channel */ u32 feerate_base, feerate_ppm; - /* But allow these feerates up until this time. */ + /* But allow these feerates/htlcs up until this time. */ struct timeabs old_feerate_timeout; u32 old_feerate_base, old_feerate_ppm; + struct amount_msat old_htlc_maximum_msat; /* If they used option_upfront_shutdown_script. */ const u8 *remote_upfront_shutdown_script; diff --git a/lightningd/peer_control.c b/lightningd/peer_control.c index 0d776ba05..aae61a8c2 100644 --- a/lightningd/peer_control.c +++ b/lightningd/peer_control.c @@ -2015,6 +2015,7 @@ static void set_channel_fees(struct command *cmd, struct channel *channel, = timeabs_add(time_now(), time_from_sec(delaysecs)); channel->old_feerate_base = channel->feerate_base; channel->old_feerate_ppm = channel->feerate_ppm; + channel->old_htlc_maximum_msat = channel->htlc_maximum_msat; } /* set new values */ diff --git a/lightningd/peer_htlcs.c b/lightningd/peer_htlcs.c index b95746590..fc55f2b27 100644 --- a/lightningd/peer_htlcs.c +++ b/lightningd/peer_htlcs.c @@ -656,6 +656,18 @@ static void forward_htlc(struct htlc_in *hin, "Allowing payment using older feerate"); } + if (amount_msat_greater(amt_to_forward, next->htlc_maximum_msat)) { + /* Are we in old-max grace-period? */ + if (!time_before(time_now(), next->old_feerate_timeout) + || amount_msat_greater(amt_to_forward, next->old_htlc_maximum_msat)) { + failmsg = towire_temporary_channel_failure(tmpctx, + get_channel_update(next)); + goto fail; + } + log_info(hin->key.channel->log, + "Allowing large htlc using older htlc_maximum_msat"); + } + if (!check_cltv(hin, cltv_expiry, outgoing_cltv_value, ld->config.cltv_expiry_delta)) { failmsg = towire_incorrect_cltv_expiry(tmpctx, cltv_expiry,