From 4c74ff48cbbc4bee22de03ffcfec5710bf5266fb Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Wed, 14 Feb 2024 16:38:09 +1030 Subject: [PATCH] lightningd: add --dev-allow-shutdown-destination-change to unstick existing nodes. This will solve the problem for users who already hit the bug fixed by the previous patch! Signed-off-by: Rusty Russell --- lightningd/closing_control.c | 3 ++- lightningd/lightningd.c | 1 + lightningd/lightningd.h | 3 +++ lightningd/options.c | 4 ++++ openingd/common.c | 8 -------- openingd/common.h | 1 - openingd/dualopend.c | 4 ++-- 7 files changed, 12 insertions(+), 12 deletions(-) diff --git a/lightningd/closing_control.c b/lightningd/closing_control.c index 50181eda4a45..f6f7ff467c4f 100644 --- a/lightningd/closing_control.c +++ b/lightningd/closing_control.c @@ -692,7 +692,8 @@ static struct command_result *json_close(struct command *cmd, if (close_to_script) { bool is_p2sh; - if (!tal_arr_eq(close_to_script, channel->shutdown_scriptpubkey[LOCAL])) { + if (!tal_arr_eq(close_to_script, channel->shutdown_scriptpubkey[LOCAL]) + && !cmd->ld->dev_allow_shutdown_destination_change) { const u8 *defp2tr, *defp2wpkh; /* We cannot change the closing script once we've * started shutdown: onchaind relies on it for output diff --git a/lightningd/lightningd.c b/lightningd/lightningd.c index e13750de02f0..4789dc5a2bfe 100644 --- a/lightningd/lightningd.c +++ b/lightningd/lightningd.c @@ -146,6 +146,7 @@ static struct lightningd *new_lightningd(const tal_t *ctx) ld->dev_disable_commit = -1; ld->dev_no_ping_timer = false; ld->dev_any_channel_type = false; + ld->dev_allow_shutdown_destination_change = false; /*~ This is a CCAN list: an embedded double-linked list. It's not * really typesafe, but relies on convention to access the contents. diff --git a/lightningd/lightningd.h b/lightningd/lightningd.h index c344a4a0304c..1d778e2961aa 100644 --- a/lightningd/lightningd.h +++ b/lightningd/lightningd.h @@ -343,6 +343,9 @@ struct lightningd { /* Tell openingd/dualopend to accept all, allow sending any. */ bool dev_any_channel_type; + /* Allow changing of shutdown output point even if dangerous */ + bool dev_allow_shutdown_destination_change; + /* tor support */ struct wireaddr *proxyaddr; bool always_use_proxy; diff --git a/lightningd/options.c b/lightningd/options.c index 38250b325358..7b46a05b9f38 100644 --- a/lightningd/options.c +++ b/lightningd/options.c @@ -907,6 +907,10 @@ static void dev_register_opts(struct lightningd *ld) opt_set_bool, &ld->dev_any_channel_type, "Allow sending any channel type, and accept any"); + clnopt_noarg("--dev-allow-shutdown-destination-change", OPT_DEV, + opt_set_bool, + &ld->dev_allow_shutdown_destination_change, + "Allow destination override on close, even if risky"); } static const struct config testnet_config = { diff --git a/openingd/common.c b/openingd/common.c index d8d34313c3f2..e0d59c3b8265 100644 --- a/openingd/common.c +++ b/openingd/common.c @@ -188,17 +188,9 @@ bool check_config_bounds(const tal_t *ctx, } u8 *no_upfront_shutdown_script(const tal_t *ctx, - bool developer, struct feature_set *our_features, const u8 *their_features) { - if (developer) { - /* This is a hack, for feature testing */ - const char *e = getenv("DEV_OPENINGD_UPFRONT_SHUTDOWN_SCRIPT"); - if (e) - return tal_hexdata(ctx, e, strlen(e)); - } - /* BOLT #2: * * - if both nodes advertised the `option_upfront_shutdown_script` diff --git a/openingd/common.h b/openingd/common.h index 71fded0f1fa6..c48930dd0c90 100644 --- a/openingd/common.h +++ b/openingd/common.h @@ -24,7 +24,6 @@ bool anchors_negotiated(struct feature_set *our_features, const u8 *their_features); u8 *no_upfront_shutdown_script(const tal_t *ctx, - bool developer, struct feature_set *our_features, const u8 *their_features); diff --git a/openingd/dualopend.c b/openingd/dualopend.c index 969d34ae0214..4ecfe28112d2 100644 --- a/openingd/dualopend.c +++ b/openingd/dualopend.c @@ -2665,7 +2665,7 @@ static void accepter_start(struct state *state, const u8 *oc2_msg) struct tlv_accept_tlvs *a_tlv = tlv_accept_tlvs_new(tmpctx); if (!state->upfront_shutdown_script[LOCAL]) state->upfront_shutdown_script[LOCAL] - = no_upfront_shutdown_script(state, state->developer, + = no_upfront_shutdown_script(state, state->our_features, state->their_features); @@ -3021,7 +3021,7 @@ static void opener_start(struct state *state, u8 *msg) if (!state->upfront_shutdown_script[LOCAL]) state->upfront_shutdown_script[LOCAL] - = no_upfront_shutdown_script(state, state->developer, + = no_upfront_shutdown_script(state, state->our_features, state->their_features);