Skip to content

Commit

Permalink
openingd: Reject zeroconf if the peer is not allowed
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
cdecker committed Aug 18, 2023
1 parent 5cf3149 commit 8821242
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
3 changes: 2 additions & 1 deletion lightningd/opening_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 10 additions & 1 deletion openingd/openingd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand All @@ -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,
Expand Down
1 change: 1 addition & 0 deletions openingd/openingd_wire.csv
Original file line number Diff line number Diff line change
Expand Up @@ -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 <common/penalty_base.h>
# Openingd->master: we've successfully offered channel.
Expand Down

0 comments on commit 8821242

Please sign in to comment.