Skip to content

Commit 96e4c90

Browse files
committed
openingd: work harder to intuit OPT_SCID_ALIAS.
option_scid_alias inside a channel_type allows for more private channels: in particular, it tells the peer that it MUST NOT allow routing via the real short channel id, and MUST use the alias. It only makes sense (and is only permitted!) on unannounced channels. Unfortunately, we didn't set this bit in the channel_type in v12.0 when it was introduced, instead relying on the presence of the feature bit with the peer. This was fixed in 23.05, but: 1. Prior to 23.05 we didn't allow it to be set at all, and 2. LND has a limited set of features they allow, and this isn't allowed without option_anchors_zero_fee_htlc_tx. We could simply drop this channel_type until we merge anchors, *but* that has nasty privacy implications (you can probe the real channel id). So, if we don't negotiate anchors (we don't!), we don't set this channel_type bit even if we want it, and *intuit* it, based on: 1. Is this a non-anchor channel_type? 2. Did we both send channel_type? 3. Is this an unannounced channel? 4. Did both peers announce support for scid aliases? In addition, while looking at the previous backwards-compat code, I realized that v23.05 violated the spec and send accept_channel with OPT_SCID_ALIAS if it intuited it, even if it wasn't offered. Stop doing this, but allow our peers to. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au> Changelog-Fixed: Fix incompatibility with LND which prevented us opening private channels Fixes: #6208
1 parent 50a7681 commit 96e4c90

File tree

3 files changed

+76
-31
lines changed

3 files changed

+76
-31
lines changed

lightningd/opening_control.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -964,8 +964,7 @@ bool peer_start_openingd(struct peer *peer, struct peer_fd *peer_fd)
964964
feerate_min(peer->ld, NULL),
965965
feerate_max(peer->ld, NULL),
966966
IFDEV(peer->ld->dev_force_tmp_channel_id, NULL),
967-
peer->ld->config.allowdustreserve,
968-
!deprecated_apis);
967+
peer->ld->config.allowdustreserve);
969968
subd_send_msg(uc->open_daemon, take(msg));
970969
return true;
971970
}

openingd/openingd.c

Lines changed: 75 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,6 @@ struct state {
102102
struct amount_sat *reserve;
103103

104104
bool allowdustreserve;
105-
106-
/* Are we allowed to set option_scid_alias is channel_type? */
107-
bool can_set_scid_alias_channel_type;
108105
};
109106

110107
/*~ If we can't agree on parameters, we fail to open the channel.
@@ -300,6 +297,33 @@ static void set_remote_upfront_shutdown(struct state *state,
300297
peer_failed_err(state->pps, &state->channel_id, "%s", err);
301298
}
302299

300+
/* Since we can't send OPT_SCID_ALIAS due to compat issues, intuit whether
301+
* we really actually want it anyway, we just can't say that. */
302+
static bool intuit_scid_alias_type(struct state *state, u8 channel_flags,
303+
bool peer_sent_channel_type)
304+
{
305+
/* Don't need to intuit if actually set */
306+
if (channel_type_has(state->channel_type, OPT_SCID_ALIAS))
307+
return false;
308+
309+
/* Old clients didn't send channel_type at all */
310+
if (!peer_sent_channel_type)
311+
return false;
312+
313+
/* Modern peer: no intuit hacks necessary. */
314+
if (channel_type_has(state->channel_type, OPT_ANCHORS_ZERO_FEE_HTLC_TX))
315+
return false;
316+
317+
/* Public channel: don't want OPT_SCID_ALIAS which means "only use
318+
* alias". */
319+
if (channel_flags & CHANNEL_FLAGS_ANNOUNCE_CHANNEL)
320+
return false;
321+
322+
/* If we both support it, presumably we want it? */
323+
return feature_negotiated(state->our_features, state->their_features,
324+
OPT_SCID_ALIAS);
325+
}
326+
303327
/* We start the 'open a channel' negotation with the supplied peer, but
304328
* stop when we get to the part where we need the funding txid */
305329
static u8 *funder_channel_start(struct state *state, u8 channel_flags)
@@ -336,9 +360,16 @@ static u8 *funder_channel_start(struct state *state, u8 channel_flags)
336360
state->their_features);
337361

338362
/* Spec says we should use the option_scid_alias variation if we
339-
* want them to *only* use the scid_alias. But we didn't accept this
340-
* in CLN prior to v23.05, so we don't send that in deprecated mode! */
341-
if (state->can_set_scid_alias_channel_type) {
363+
* want them to *only* use the scid_alias (which we do for unannounced
364+
* channels!).
365+
*
366+
* But:
367+
* 1. We didn't accept this in CLN prior to v23.05.
368+
* 2. LND won't accept that without OPT_ANCHORS_ZERO_FEE_HTLC_TX.
369+
*
370+
* So we keep it off for now, until anchors merge.
371+
*/
372+
if (channel_type_has(state->channel_type, OPT_ANCHORS_ZERO_FEE_HTLC_TX)) {
342373
if (!(channel_flags & CHANNEL_FLAGS_ANNOUNCE_CHANNEL))
343374
channel_type_set_scid_alias(state->channel_type);
344375
}
@@ -433,14 +464,26 @@ static u8 *funder_channel_start(struct state *state, u8 channel_flags)
433464
* `open_channel`, and they are not equal types:
434465
* - MUST reject the channel.
435466
*/
436-
if (accept_tlvs->channel_type
437-
&& !featurebits_eq(accept_tlvs->channel_type,
438-
state->channel_type->features)) {
439-
negotiation_failed(state,
440-
"Return unoffered channel_type: %s",
441-
fmt_featurebits(tmpctx,
442-
accept_tlvs->channel_type));
443-
return NULL;
467+
if (accept_tlvs->channel_type) {
468+
/* Except that v23.05 could set OPT_SCID_ALIAS in reply! */
469+
struct channel_type *atype;
470+
471+
atype = channel_type_from(tmpctx, accept_tlvs->channel_type);
472+
if (!channel_type_has(atype, OPT_ANCHORS_ZERO_FEE_HTLC_TX))
473+
featurebits_unset(&atype->features, OPT_SCID_ALIAS);
474+
475+
if (!channel_type_eq(atype, state->channel_type)) {
476+
negotiation_failed(state,
477+
"Return unoffered channel_type: %s",
478+
fmt_featurebits(tmpctx,
479+
accept_tlvs->channel_type));
480+
return NULL;
481+
}
482+
483+
/* If they "accepted" SCID_ALIAS, roll with it. */
484+
tal_free(state->channel_type);
485+
state->channel_type = channel_type_from(state,
486+
accept_tlvs->channel_type);
444487
}
445488

446489
/* BOLT #2:
@@ -547,6 +590,12 @@ static u8 *funder_channel_start(struct state *state, u8 channel_flags)
547590
"Funding channel start: awaiting funding_txid with output to %s",
548591
tal_hex(tmpctx, funding_output_script));
549592

593+
/* Backwards/cross compat hack */
594+
if (intuit_scid_alias_type(state, channel_flags,
595+
accept_tlvs->channel_type != NULL)) {
596+
channel_type_set_scid_alias(state->channel_type);
597+
}
598+
550599
return towire_openingd_funder_start_reply(state,
551600
funding_output_script,
552601
feature_negotiated(
@@ -860,6 +909,7 @@ static u8 *fundee_channel(struct state *state, const u8 *open_channel_msg)
860909
struct tlv_accept_channel_tlvs *accept_tlvs;
861910
struct tlv_open_channel_tlvs *open_tlvs;
862911
struct amount_sat *reserve;
912+
bool open_channel_had_channel_type;
863913

864914
/* BOLT #2:
865915
*
@@ -901,6 +951,7 @@ static u8 *fundee_channel(struct state *state, const u8 *open_channel_msg)
901951
* - if `type` includes `option_zeroconf` and it does not trust the sender to open an unconfirmed channel.
902952
*/
903953
if (open_tlvs->channel_type) {
954+
open_channel_had_channel_type = true;
904955
state->channel_type =
905956
channel_type_accept(state,
906957
open_tlvs->channel_type,
@@ -914,21 +965,13 @@ static u8 *fundee_channel(struct state *state, const u8 *open_channel_msg)
914965
open_tlvs->channel_type));
915966
return NULL;
916967
}
917-
918-
/* If we're not using scid_alias in channel type, intuit it here.
919-
* We have to do this, because we used not to accept that bit, so older
920-
* clients won't send it! */
921-
if (!state->can_set_scid_alias_channel_type
922-
&& !(channel_flags & CHANNEL_FLAGS_ANNOUNCE_CHANNEL)
923-
&& feature_negotiated(state->our_features, state->their_features,
924-
OPT_SCID_ALIAS)) {
925-
channel_type_set_scid_alias(state->channel_type);
926-
}
927-
} else
968+
} else {
969+
open_channel_had_channel_type = false;
928970
state->channel_type
929971
= default_channel_type(state,
930972
state->our_features,
931973
state->their_features);
974+
}
932975

933976
/* BOLT #2:
934977
*
@@ -1143,6 +1186,12 @@ static u8 *fundee_channel(struct state *state, const u8 *open_channel_msg)
11431186
&state->channel_id),
11441187
type_to_string(msg, struct channel_id, &id_in));
11451188

1189+
/* Backwards/cross compat hack */
1190+
if (intuit_scid_alias_type(state, channel_flags,
1191+
open_channel_had_channel_type)) {
1192+
channel_type_set_scid_alias(state->channel_type);
1193+
}
1194+
11461195
/*~ Channel is ready; Report the channel parameters to the signer. */
11471196
msg = towire_hsmd_ready_channel(NULL,
11481197
false, /* is_outbound */
@@ -1475,8 +1524,7 @@ int main(int argc, char *argv[])
14751524
&state->minimum_depth,
14761525
&state->min_feerate, &state->max_feerate,
14771526
&force_tmp_channel_id,
1478-
&state->allowdustreserve,
1479-
&state->can_set_scid_alias_channel_type))
1527+
&state->allowdustreserve))
14801528
master_badmsg(WIRE_OPENINGD_INIT, msg);
14811529

14821530
#if DEVELOPER

openingd/openingd_wire.csv

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ msgdata,openingd_init,dev_temporary_channel_id,?byte,32
2828
# reserves? This is explicitly required by the spec for safety
2929
# reasons, but some implementations and users keep asking for it.
3030
msgdata,openingd_init,allowdustreserve,bool,
31-
# Core LN prior to 23.05 didn't like this bit set!
32-
msgdata,openingd_init,can_set_scid_alias_channel_type,bool,
3331

3432
# Openingd->master: they offered channel, should we continue?
3533
msgtype,openingd_got_offer,6005

0 commit comments

Comments
 (0)