From ae825fff26bc76d5273f47a797ac3f8eae10ab32 Mon Sep 17 00:00:00 2001 From: niftynei Date: Mon, 19 Oct 2020 19:04:13 -0500 Subject: [PATCH] opening: use correct dust_limit for reserve floor Fixes #4140 Reported-By: @PsySc0rpi0n Changelog-Fixed: openingd now uses the correct dust limit for determining the allowable floor for a channel open (affects fundee only) --- openingd/openingd.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/openingd/openingd.c b/openingd/openingd.c index 75e1c6956..3bb7a10b2 100644 --- a/openingd/openingd.c +++ b/openingd/openingd.c @@ -197,7 +197,7 @@ static void negotiation_failed(struct state *state, bool am_opener, } /* We always set channel_reserve_satoshis to 1%, rounded down. */ -static void set_reserve(struct state *state) +static void set_reserve(struct state *state, const struct amount_sat dust_limit) { state->localconf.channel_reserve = amount_sat_div(state->funding, 100); @@ -206,12 +206,12 @@ static void set_reserve(struct state *state) * The sending node: *... * - MUST set `channel_reserve_satoshis` greater than or equal to - * `dust_limit_satoshis`. + * `dust_limit_satoshis` from the `open_channel` message. */ - if (amount_sat_greater(state->localconf.dust_limit, + if (amount_sat_greater(dust_limit, state->localconf.channel_reserve)) state->localconf.channel_reserve - = state->localconf.dust_limit; + = dust_limit; } /* BOLT #2: @@ -338,7 +338,7 @@ static bool setup_channel_funder(struct state *state) { /*~ For symmetry, we calculate our own reserve even though lightningd * could do it for the we-are-funding case. */ - set_reserve(state); + set_reserve(state, state->localconf.dust_limit); /*~ Grab a random ID until the funding tx is created (we can't do that * until we know their funding_pubkey) */ @@ -891,7 +891,7 @@ static u8 *fundee_channel(struct state *state, const u8 *open_channel_msg) } /* This reserves 1% of the channel (rounded up) */ - set_reserve(state); + set_reserve(state, state->remoteconf.dust_limit); /* BOLT #2: *