From 5a54f450bdc5f659f9e8dfae27d931cebe9d462c Mon Sep 17 00:00:00 2001 From: Christian Decker Date: Thu, 9 Jun 2022 13:34:33 +0200 Subject: [PATCH] openingd: Pass `reserve` down to openingd when funding --- lightningd/opening_control.c | 19 ++++++++++--------- openingd/openingd.c | 18 +++++++++++++----- openingd/openingd_wire.csv | 1 + 3 files changed, 24 insertions(+), 14 deletions(-) diff --git a/lightningd/opening_control.c b/lightningd/opening_control.c index 6ba7c4097..bd0887947 100644 --- a/lightningd/opening_control.c +++ b/lightningd/opening_control.c @@ -1256,15 +1256,16 @@ static struct command_result *json_fundchannel_start(struct command *cmd, } else upfront_shutdown_script_wallet_index = NULL; - fc->open_msg - = towire_openingd_funder_start(fc, - *amount, - fc->push, - fc->our_upfront_shutdown_script, - upfront_shutdown_script_wallet_index, - *feerate_per_kw, - &tmp_channel_id, - fc->channel_flags); + fc->open_msg = towire_openingd_funder_start( + fc, + *amount, + fc->push, + fc->our_upfront_shutdown_script, + upfront_shutdown_script_wallet_index, + *feerate_per_kw, + &tmp_channel_id, + fc->channel_flags, + fc->uc->reserve); if (socketpair(AF_LOCAL, SOCK_STREAM, 0, fds) != 0) { return command_fail(cmd, FUND_MAX_EXCEEDED, diff --git a/openingd/openingd.c b/openingd/openingd.c index d05152e4c..60237f09f 100644 --- a/openingd/openingd.c +++ b/openingd/openingd.c @@ -99,6 +99,8 @@ struct state { struct channel_type *channel_type; struct feature_set *our_features; + + struct amount_sat *reserve; }; /*~ If we can't agree on parameters, we fail to open the channel. @@ -245,10 +247,6 @@ static u8 *opening_negotiate_msg(const tal_t *ctx, struct state *state, 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, state->localconf.dust_limit); - #if DEVELOPER /* --dev-force-tmp-channel-id specified */ if (dev_force_tmp_channel_id) @@ -329,6 +327,15 @@ static u8 *funder_channel_start(struct state *state, u8 channel_flags) if (!setup_channel_funder(state)) return NULL; + /* If we have a reserve override we use that, otherwise we'll + * use our default of 1% of the funding value. */ + if (state->reserve != NULL) { + set_reserve_absolute(state, state->localconf.dust_limit, + *state->reserve); + } else { + set_reserve(state, state->localconf.dust_limit); + } + if (!state->upfront_shutdown_script[LOCAL]) state->upfront_shutdown_script[LOCAL] = no_upfront_shutdown_script(state, @@ -1352,7 +1359,8 @@ static u8 *handle_master_in(struct state *state) &state->local_upfront_shutdown_wallet_index, &state->feerate_per_kw, &state->channel_id, - &channel_flags)) + &channel_flags, + &state->reserve)) master_badmsg(WIRE_OPENINGD_FUNDER_START, msg); msg = funder_channel_start(state, channel_flags); diff --git a/openingd/openingd_wire.csv b/openingd/openingd_wire.csv index d81dfff44..4f77446f2 100644 --- a/openingd/openingd_wire.csv +++ b/openingd/openingd_wire.csv @@ -80,6 +80,7 @@ msgdata,openingd_funder_start,upfront_shutdown_wallet_index,?u32, msgdata,openingd_funder_start,feerate_per_kw,u32, msgdata,openingd_funder_start,temporary_channel_id,channel_id, msgdata,openingd_funder_start,channel_flags,u8, +msgdata,openingd_funder_start,reserve,?amount_sat, # openingd->master: send back output script for 2-of-2 funding output msgtype,openingd_funder_start_reply,6102