From 8821242187c07f062a079b8aa238f381631ee3ce Mon Sep 17 00:00:00 2001 From: Christian Decker Date: Fri, 18 Aug 2023 10:17:14 +0200 Subject: [PATCH] openingd: Reject zeroconf if the peer is not allowed We determine whether they are allowed or not based on the hook return value of `mindepth`. To do so we need to pass that value down to `openingd` and verify that the `channel_type` and our permissions match up. --- lightningd/opening_control.c | 3 ++- openingd/openingd.c | 11 ++++++++++- openingd/openingd_wire.csv | 1 + 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/lightningd/opening_control.c b/lightningd/opening_control.c index 85f9c9c6ecf0..2b23d117499b 100644 --- a/lightningd/opening_control.c +++ b/lightningd/opening_control.c @@ -725,7 +725,8 @@ openchannel_hook_final(struct openchannel_hook_payload *payload STEALS) take(towire_openingd_got_offer_reply(NULL, errmsg, our_upfront_shutdown_script, upfront_shutdown_script_wallet_index, - payload->uc->reserve))); + payload->uc->reserve, + payload->uc->minimum_depth))); } static bool diff --git a/openingd/openingd.c b/openingd/openingd.c index 801d272b06ed..9fe0b0bc9036 100644 --- a/openingd/openingd.c +++ b/openingd/openingd.c @@ -1126,7 +1126,8 @@ static u8 *fundee_channel(struct state *state, const u8 *open_channel_msg) if (!fromwire_openingd_got_offer_reply(state, msg, &err_reason, &state->upfront_shutdown_script[LOCAL], &state->local_upfront_shutdown_wallet_index, - &reserve)) + &reserve, + &state->minimum_depth)) master_badmsg(WIRE_OPENINGD_GOT_OFFER_REPLY, msg); /* If they give us a reason to reject, do so. */ @@ -1136,6 +1137,14 @@ static u8 *fundee_channel(struct state *state, const u8 *open_channel_msg) return NULL; } + if (channel_type_has(state->channel_type, OPT_ZEROCONF) && + state->minimum_depth > 0) { + negotiation_failed( + state, + "You required zeroconf, but you're not on our allowlist"); + return NULL; + } + if (!state->upfront_shutdown_script[LOCAL]) state->upfront_shutdown_script[LOCAL] = no_upfront_shutdown_script(state, diff --git a/openingd/openingd_wire.csv b/openingd/openingd_wire.csv index 40c97b36c45c..0aca7974b889 100644 --- a/openingd/openingd_wire.csv +++ b/openingd/openingd_wire.csv @@ -51,6 +51,7 @@ msgdata,openingd_got_offer_reply,shutdown_len,u16, msgdata,openingd_got_offer_reply,our_shutdown_scriptpubkey,?u8,shutdown_len msgdata,openingd_got_offer_reply,our_shutdown_wallet_index,?u32, msgdata,openingd_got_offer_reply,reserve,?amount_sat, +msgdata,openingd_got_offer_reply,mindepth,u32, #include # Openingd->master: we've successfully offered channel.