lightningd: enforce htlc_maximum_msat.

When we let them set it, this matters!

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2022-03-21 11:28:27 +10:30
parent 3217dbe17f
commit f078a916e7
3 changed files with 15 additions and 1 deletions

View File

@@ -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;

View File

@@ -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 */

View File

@@ -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,