channeld: use explicit --experimental-upgrade flag, not #ifdef EXPERIMENTAL_FEATURES

And no longer insist on opt_quiesce.

Changelog-EXPERIMENTAL: Config: `--experimental-upgrade-protocol` enables simple channel upgrades.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2023-05-22 10:21:44 +09:30
parent 6c23349c72
commit ccf084156d
13 changed files with 115 additions and 177 deletions

View File

@ -194,6 +194,9 @@ struct peer {
/* Most recent channel_update message. */
u8 *channel_update;
/* --experimental-upgrade-protocol */
bool experimental_upgrade;
};
static u8 *create_channel_announcement(const tal_t *ctx, struct peer *peer);
@ -315,7 +318,6 @@ static bool handle_master_request_later(struct peer *peer, const u8 *msg)
return false;
}
#if EXPERIMENTAL_FEATURES
/* Compare, with false if either is NULL */
static bool match_type(const u8 *t1, const u8 *t2)
{
@ -345,7 +347,6 @@ static void set_channel_type(struct channel *channel, const u8 *type)
wire_sync_write(MASTER_FD,
take(towire_channeld_upgraded(NULL, channel->type)));
}
#endif /* EXPERIMENTAL_FEATURES */
/* Tell gossipd to create channel_update (then it goes into
* gossip_store, then streams out to peers, or sends it directly if
@ -2121,29 +2122,17 @@ static void handle_unexpected_reestablish(struct peer *peer, const u8 *msg)
u64 next_revocation_number;
struct secret your_last_per_commitment_secret;
struct pubkey my_current_per_commitment_point;
#if EXPERIMENTAL_FEATURES
struct tlv_channel_reestablish_tlvs *tlvs;
#endif
if (!fromwire_channel_reestablish
#if EXPERIMENTAL_FEATURES
(tmpctx, msg, &channel_id,
&next_commitment_number,
&next_revocation_number,
&your_last_per_commitment_secret,
&my_current_per_commitment_point,
&tlvs)
#else
(msg, &channel_id,
&next_commitment_number,
&next_revocation_number,
&your_last_per_commitment_secret,
&my_current_per_commitment_point)
#endif
)
if (!fromwire_channel_reestablish(tmpctx, msg, &channel_id,
&next_commitment_number,
&next_revocation_number,
&your_last_per_commitment_secret,
&my_current_per_commitment_point,
&tlvs)) {
peer_failed_warn(peer->pps, &peer->channel_id,
"Bad channel_reestablish %s", tal_hex(peer, msg));
}
/* Is it the same as the peer channel ID? */
if (channel_id_eq(&channel_id, &peer->channel_id)) {
@ -2653,7 +2642,6 @@ static bool capture_premature_msg(const u8 ***shit_lnd_says, const u8 *msg)
return true;
}
#if EXPERIMENTAL_FEATURES
/* Unwrap a channel_type into a raw byte array for the wire: can be NULL */
static u8 *to_bytearr(const tal_t *ctx,
const struct channel_type *channel_type TAKES)
@ -2673,23 +2661,6 @@ static u8 *to_bytearr(const tal_t *ctx,
return ret;
}
/* This is the no-tlvs version, where we can't handle old tlvs */
static bool fromwire_channel_reestablish_notlvs(const void *p, struct channel_id *channel_id, u64 *next_commitment_number, u64 *next_revocation_number, struct secret *your_last_per_commitment_secret, struct pubkey *my_current_per_commitment_point)
{
const u8 *cursor = p;
size_t plen = tal_count(p);
if (fromwire_u16(&cursor, &plen) != WIRE_CHANNEL_REESTABLISH)
return false;
fromwire_channel_id(&cursor, &plen, channel_id);
*next_commitment_number = fromwire_u64(&cursor, &plen);
*next_revocation_number = fromwire_u64(&cursor, &plen);
fromwire_secret(&cursor, &plen, your_last_per_commitment_secret);
fromwire_pubkey(&cursor, &plen, my_current_per_commitment_point);
return cursor != NULL;
}
#endif
static void peer_reconnect(struct peer *peer,
const struct secret *last_remote_per_commit_secret,
bool reestablish_only)
@ -2706,9 +2677,7 @@ static void peer_reconnect(struct peer *peer,
struct secret last_local_per_commitment_secret;
bool dataloss_protect, check_extra_fields;
const u8 **premature_msgs = tal_arr(peer, const u8 *, 0);
#if EXPERIMENTAL_FEATURES
struct tlv_channel_reestablish_tlvs *send_tlvs, *recv_tlvs;
#endif
dataloss_protect = feature_negotiated(peer->our_features,
peer->their_features,
@ -2723,53 +2692,45 @@ static void peer_reconnect(struct peer *peer,
get_per_commitment_point(peer->next_index[LOCAL] - 1,
&my_current_per_commitment_point, NULL);
#if EXPERIMENTAL_FEATURES
/* Subtle: we free tmpctx below as we loop, so tal off peer */
send_tlvs = tlv_channel_reestablish_tlvs_new(peer);
if (peer->experimental_upgrade) {
/* Subtle: we free tmpctx below as we loop, so tal off peer */
send_tlvs = tlv_channel_reestablish_tlvs_new(peer);
/* FIXME: v0.10.1 would send a different tlv set, due to older spec.
* That did *not* offer OPT_QUIESCE, so in that case don't send tlvs. */
if (!feature_negotiated(peer->our_features,
peer->their_features,
OPT_QUIESCE))
goto skip_tlvs;
/* BOLT-upgrade_protocol #2:
* A node sending `channel_reestablish`, if it supports upgrading channels:
* - MUST set `next_to_send` the commitment number of the next
* `commitment_signed` it expects to send.
*/
send_tlvs->next_to_send = tal_dup(send_tlvs, u64, &peer->next_index[REMOTE]);
/* BOLT-upgrade_protocol #2:
* - if it initiated the channel:
* - MUST set `desired_type` to the channel_type it wants for the
* channel.
*/
if (peer->channel->opener == LOCAL)
send_tlvs->desired_channel_type =
to_bytearr(send_tlvs,
take(channel_desired_type(NULL,
peer->channel)));
else {
/* BOLT-upgrade_protocol #2:
* - otherwise:
* - MUST set `current_type` to the current channel_type of the
* channel.
* - MUST set `upgradable` to the channel types it could change
* to.
* - MAY not set `upgradable` if it would be empty.
* A node sending `channel_reestablish`, if it supports upgrading channels:
* - MUST set `next_to_send` the commitment number of the next
* `commitment_signed` it expects to send.
*/
send_tlvs->current_channel_type
= to_bytearr(send_tlvs, peer->channel->type);
send_tlvs->upgradable_channel_type
= to_bytearr(send_tlvs,
take(channel_upgradable_type(NULL,
peer->channel)));
}
send_tlvs->next_to_send = tal_dup(send_tlvs, u64, &peer->next_index[REMOTE]);
skip_tlvs:
#endif
/* BOLT-upgrade_protocol #2:
* - if it initiated the channel:
* - MUST set `desired_type` to the channel_type it wants for the
* channel.
*/
if (peer->channel->opener == LOCAL) {
send_tlvs->desired_channel_type =
to_bytearr(send_tlvs,
take(channel_desired_type(NULL,
peer->channel)));
} else {
/* BOLT-upgrade_protocol #2:
* - otherwise:
* - MUST set `current_type` to the current channel_type of the
* channel.
* - MUST set `upgradable` to the channel types it could change
* to.
* - MAY not set `upgradable` if it would be empty.
*/
send_tlvs->current_channel_type
= to_bytearr(send_tlvs, peer->channel->type);
send_tlvs->upgradable_channel_type
= to_bytearr(send_tlvs,
take(channel_upgradable_type(NULL,
peer->channel)));
}
} else
send_tlvs = NULL;
/* BOLT #2:
*
@ -2808,22 +2769,15 @@ skip_tlvs:
peer->revocations_received,
last_remote_per_commit_secret,
/* Can send any (valid) point here */
&peer->remote_per_commit
#if EXPERIMENTAL_FEATURES
, send_tlvs
#endif
);
&peer->remote_per_commit, send_tlvs);
} else {
msg = towire_channel_reestablish
(NULL, &peer->channel_id,
peer->next_index[LOCAL],
peer->revocations_received,
last_remote_per_commit_secret,
&my_current_per_commitment_point
#if EXPERIMENTAL_FEATURES
, send_tlvs
#endif
);
&my_current_per_commitment_point,
send_tlvs);
}
peer_write(peer->pps, take(msg));
@ -2847,53 +2801,22 @@ skip_tlvs:
} while (handle_peer_error(peer->pps, &peer->channel_id, msg) ||
capture_premature_msg(&premature_msgs, msg));
#if EXPERIMENTAL_FEATURES
/* Initialize here in case we don't read it below! */
recv_tlvs = tlv_channel_reestablish_tlvs_new(tmpctx);
/* FIXME: v0.10.1 would send a different tlv set, due to older spec.
* That did *not* offer OPT_QUIESCE, so in that case ignore tlvs. */
if (!feature_negotiated(peer->our_features,
peer->their_features,
OPT_QUIESCE)) {
if (!fromwire_channel_reestablish_notlvs(msg,
&channel_id,
&next_commitment_number,
&next_revocation_number,
&last_local_per_commitment_secret,
&remote_current_per_commitment_point))
peer_failed_warn(peer->pps,
&peer->channel_id,
"bad reestablish msg: %s %s",
peer_wire_name(fromwire_peektype(msg)),
tal_hex(msg, msg));
} else if (!fromwire_channel_reestablish(tmpctx, msg,
&channel_id,
&next_commitment_number,
&next_revocation_number,
&last_local_per_commitment_secret,
&remote_current_per_commitment_point,
&recv_tlvs)) {
peer_failed_warn(peer->pps,
&peer->channel_id,
"bad reestablish msg: %s %s",
peer_wire_name(fromwire_peektype(msg)),
tal_hex(msg, msg));
}
#else /* !EXPERIMENTAL_FEATURES */
if (!fromwire_channel_reestablish(msg,
&channel_id,
&next_commitment_number,
&next_revocation_number,
&last_local_per_commitment_secret,
&remote_current_per_commitment_point)) {
if (!fromwire_channel_reestablish(tmpctx, msg,
&channel_id,
&next_commitment_number,
&next_revocation_number,
&last_local_per_commitment_secret,
&remote_current_per_commitment_point,
&recv_tlvs)) {
peer_failed_warn(peer->pps,
&peer->channel_id,
"bad reestablish msg: %s %s",
peer_wire_name(fromwire_peektype(msg)),
tal_hex(msg, msg));
}
#endif
if (!channel_id_eq(&channel_id, &peer->channel_id)) {
peer_failed_err(peer->pps,
@ -3071,7 +2994,10 @@ skip_tlvs:
/* (If we had sent `closing_signed`, we'd be in closingd). */
maybe_send_shutdown(peer);
#if EXPERIMENTAL_FEATURES
/* If we didn't send (i.e. don't support!) ignore theirs */
if (!send_tlvs)
recv_tlvs = tlv_channel_reestablish_tlvs_new(tmpctx);
if (recv_tlvs->desired_channel_type)
status_debug("They sent desired_channel_type [%s]",
fmt_featurebits(tmpctx,
@ -3151,8 +3077,6 @@ skip_tlvs:
}
tal_free(send_tlvs);
#endif /* EXPERIMENTAL_FEATURES */
/* Now stop, we've been polite long enough. */
if (reestablish_only) {
/* If we were successfully closing, we still go to closingd. */
@ -3822,7 +3746,8 @@ static void init_channel(struct peer *peer)
&dev_disable_commit,
&pbases,
&reestablish_only,
&peer->channel_update)) {
&peer->channel_update,
&peer->experimental_upgrade)) {
master_badmsg(WIRE_CHANNELD_INIT, msg);
}

View File

@ -82,6 +82,7 @@ msgdata,channeld_init,pbases,penalty_base,num_penalty_bases
msgdata,channeld_init,reestablish_only,bool,
msgdata,channeld_init,channel_update_len,u16,
msgdata,channeld_init,channel_update,u8,channel_update_len
msgdata,channeld_init,experimental_upgrade,bool,
# master->channeld funding hit new depth(funding locked if >= lock depth)
# alias != NULL if zeroconf and short_channel_id == NULL

Can't render this file because it has a wrong number of fields in line 14.

View File

@ -64,6 +64,7 @@ On success, an object is returned, containing:
- **experimental-websocket-port** (u16, optional): `experimental-websocket-port` field from config or cmdline, or default
- **experimental-peer-storage** (boolean, optional): `experimental-peer-storage` field from config or cmdline, or default *(added v23.02)*
- **experimental-quiesce** (boolean, optional): `experimental-quiesce` field from config or cmdline, or default *(added v23.08)*
- **experimental-upgrade-protocol** (boolean, optional): `experimental-upgrade-protocol` field from config or cmdline, or default *(added v23.08)*
- **database-upgrade** (boolean, optional): `database-upgrade` field from config or cmdline
- **rgb** (hex, optional): `rgb` field from config or cmdline, or default (always 6 characters)
- **alias** (string, optional): `alias` field from config or cmdline, or default
@ -225,4 +226,4 @@ RESOURCES
Main web site: <https://github.com/ElementsProject/lightning>
[comment]: # ( SHA256STAMP:62e8c380f4fa7b063c145ad43428c4ce48cb142cab61da72a26c2961375fabab)
[comment]: # ( SHA256STAMP:4e361c39e45812c4dd1e168c3e4e0960f06511850db7b70475b4b547e92f3bc2)

View File

@ -725,6 +725,14 @@ store as well, based on a protocol similar to [bolt][bolt] #881.
Specifying this option advertizes `option_quiesce`. Not very useful
by itself, except for testing.
* **experimental-upgrade-protocol**
Specifying this option means we send (and allow receipt of) a simple
protocol to update channel types. At the moment, we only support setting
`option_static_remotekey` to ancient channels. The peer must also support
this option.
BUGS
----

View File

@ -147,6 +147,11 @@
"added": "v23.08",
"description": "`experimental-quiesce` field from config or cmdline, or default"
},
"experimental-upgrade-protocol": {
"type": "boolean",
"added": "v23.08",
"description": "`experimental-upgrade-protocol` field from config or cmdline, or default"
},
"database-upgrade": {
"type": "boolean",
"description": "`database-upgrade` field from config or cmdline"

View File

@ -480,7 +480,6 @@ static void forget_channel(struct channel *channel, const char *why)
forget(channel);
}
#if EXPERIMENTAL_FEATURES
static void handle_channel_upgrade(struct channel *channel,
const u8 *msg)
{
@ -519,7 +518,6 @@ static void handle_channel_upgrade(struct channel *channel,
wallet_channel_save(channel->peer->ld->wallet, channel);
}
#endif /* EXPERIMENTAL_FEATURES */
static unsigned channel_msg(struct subd *sd, const u8 *msg, const int *fds)
{
@ -569,13 +567,9 @@ static unsigned channel_msg(struct subd *sd, const u8 *msg, const int *fds)
case WIRE_CHANNELD_LOCAL_PRIVATE_CHANNEL:
handle_local_private_channel(sd->channel, msg);
break;
#if EXPERIMENTAL_FEATURES
case WIRE_CHANNELD_UPGRADED:
handle_channel_upgrade(sd->channel, msg);
break;
#else
case WIRE_CHANNELD_UPGRADED:
#endif
/* And we never get these from channeld. */
case WIRE_CHANNELD_INIT:
case WIRE_CHANNELD_FUNDING_DEPTH:
@ -790,7 +784,8 @@ bool peer_start_channeld(struct channel *channel,
NULL),
pbases,
reestablish_only,
channel->channel_update);
channel->channel_update,
ld->experimental_upgrade_protocol);
/* We don't expect a response: we are triggered by funding_depth_cb. */
subd_send_msg(channel->owner, take(initmsg));

View File

@ -235,6 +235,9 @@ static struct lightningd *new_lightningd(const tal_t *ctx)
ld->try_reexec = false;
ld->db_upgrade_ok = NULL;
/* --experimental-upgrade-protocol */
ld->experimental_upgrade_protocol = false;
/*~ This is from ccan/timer: it is efficient for the case where timers
* are deleted before expiry (as is common with timeouts) using an
* ingenious bucket system which more precisely sorts timers as they

View File

@ -360,6 +360,9 @@ struct lightningd {
/* EXPERIMENTAL: websocket port if non-zero */
u16 websocket_port;
/* --experimental-upgrade-protocol */
bool experimental_upgrade_protocol;
};
/* Turning this on allows a tal allocation to return NULL, rather than aborting.

View File

@ -981,9 +981,7 @@ static char *list_features_and_exit(struct lightningd *ld)
const char **features = list_supported_features(tmpctx, ld->our_features);
for (size_t i = 0; i < tal_count(features); i++)
printf("%s\n", features[i]);
#if EXPERIMENTAL_FEATURES
printf("supports_open_accept_channel_type\n");
#endif
exit(0);
}
@ -1332,6 +1330,9 @@ static void register_opts(struct lightningd *ld)
ld,
"experimental: alternate port for peers to connect"
" using WebSockets (RFC6455)");
opt_register_noarg("--experimental-upgrade-protocol",
opt_set_bool, &ld->experimental_upgrade_protocol,
"experimental: allow channel types to be upgraded on reconnect");
opt_register_arg("--database-upgrade",
opt_set_db_upgrade, NULL,
ld,

View File

@ -3947,9 +3947,7 @@ static void do_reconnect_dance(struct state *state)
last_remote_per_commit_secret;
struct pubkey remote_current_per_commit_point;
struct tx_state *tx_state = state->tx_state;
#if EXPERIMENTAL_FEATURES
struct tlv_channel_reestablish_tlvs *tlvs;
#endif
/* BOLT #2:
* - if `next_revocation_number` equals 0:
@ -3963,11 +3961,7 @@ static void do_reconnect_dance(struct state *state)
msg = towire_channel_reestablish
(NULL, &state->channel_id, 1, 0,
&last_remote_per_commit_secret,
&state->first_per_commitment_point[LOCAL]
#if EXPERIMENTAL_FEATURES
, NULL
#endif
);
&state->first_per_commitment_point[LOCAL], NULL);
peer_write(state->pps, take(msg));
peer_billboard(false, "Sent reestablish, waiting for theirs");
@ -3982,22 +3976,12 @@ static void do_reconnect_dance(struct state *state)
&state->channel_id,
msg));
if (!fromwire_channel_reestablish
#if EXPERIMENTAL_FEATURES
(tmpctx, msg, &cid,
&next_commitment_number,
&next_revocation_number,
&last_local_per_commit_secret,
&remote_current_per_commit_point,
&tlvs)
#else
(msg, &cid,
&next_commitment_number,
&next_revocation_number,
&last_local_per_commit_secret,
&remote_current_per_commit_point)
#endif
)
if (!fromwire_channel_reestablish(tmpctx, msg, &cid,
&next_commitment_number,
&next_revocation_number,
&last_local_per_commit_secret,
&remote_current_per_commit_point,
&tlvs))
open_err_fatal(state, "Bad reestablish msg: %s %s",
peer_wire_name(fromwire_peektype(msg)),
tal_hex(msg, msg));

View File

@ -3713,13 +3713,14 @@ def test_openchannel_init_alternate(node_factory, executor):
print("nothing to do")
@unittest.skipIf(not EXPERIMENTAL_FEATURES, "upgrade protocol not available")
@pytest.mark.developer("dev-force-features required")
def test_upgrade_statickey(node_factory, executor):
"""l1 doesn't have option_static_remotekey, l2 offers it."""
l1, l2 = node_factory.line_graph(2, opts=[{'may_reconnect': True,
'dev-force-features': ["-13", "-21"]},
{'may_reconnect': True}])
'dev-force-features': ["-13"],
'experimental-upgrade-protocol': None},
{'may_reconnect': True,
'experimental-upgrade-protocol': None}])
l1.rpc.disconnect(l2.info['id'], force=True)
l1.rpc.connect(l2.info['id'], 'localhost', l2.port)
@ -3743,17 +3744,18 @@ def test_upgrade_statickey(node_factory, executor):
l2.daemon.wait_for_log(r"They sent desired_channel_type \[12\]")
@unittest.skipIf(not EXPERIMENTAL_FEATURES, "upgrade protocol not available")
@pytest.mark.developer("dev-force-features required")
def test_upgrade_statickey_onchaind(node_factory, executor, bitcoind):
"""We test penalty before/after, and unilateral before/after"""
l1, l2 = node_factory.line_graph(2, opts=[{'may_reconnect': True,
'dev-no-reconnect': None,
'dev-force-features': ["-13", "-21"],
'dev-force-features': ["-13"],
'experimental-upgrade-protocol': None,
# We try to cheat!
'allow_broken_log': True},
{'may_reconnect': True,
'dev-no-reconnect': None}])
'dev-no-reconnect': None,
'experimental-upgrade-protocol': None}])
# TEST 1: Cheat from pre-upgrade.
tx = l1.rpc.dev_sign_last_tx(l2.info['id'])['tx']
@ -3877,7 +3879,6 @@ def test_upgrade_statickey_onchaind(node_factory, executor, bitcoind):
wait_for(lambda: len(l2.rpc.listpeerchannels()['channels']) == 0)
@unittest.skipIf(not EXPERIMENTAL_FEATURES, "upgrade protocol not available")
@pytest.mark.developer("dev-force-features, dev-disconnect required")
def test_upgrade_statickey_fail(node_factory, executor, bitcoind):
"""We reconnect at all points during retransmit, and we won't upgrade."""
@ -3889,11 +3890,13 @@ def test_upgrade_statickey_fail(node_factory, executor, bitcoind):
l1, l2 = node_factory.line_graph(2, opts=[{'may_reconnect': True,
'dev-no-reconnect': None,
'disconnect': l1_disconnects,
'dev-force-features': ["-13", "-21"],
'experimental-upgrade-protocol': None,
'dev-force-features': ["-13"],
# Don't have feerate changes!
'feerates': (7500, 7500, 7500, 7500)},
{'may_reconnect': True,
'dev-no-reconnect': None,
'experimental-upgrade-protocol': None,
'disconnect': l2_disconnects,
'plugin': os.path.join(os.getcwd(), 'tests/plugins/hold_htlcs.py'),
'hold-time': 10000,

View File

@ -266,6 +266,15 @@ msgdata,channel_reestablish,next_commitment_number,u64,
msgdata,channel_reestablish,next_revocation_number,u64,
msgdata,channel_reestablish,your_last_per_commitment_secret,byte,32
msgdata,channel_reestablish,my_current_per_commitment_point,point,
msgdata,channel_reestablish,tlvs,channel_reestablish_tlvs,
tlvtype,channel_reestablish_tlvs,next_to_send,1
tlvdata,channel_reestablish_tlvs,next_to_send,commitment_number,tu64,
tlvtype,channel_reestablish_tlvs,desired_channel_type,3
tlvdata,channel_reestablish_tlvs,desired_channel_type,type,byte,...
tlvtype,channel_reestablish_tlvs,current_channel_type,5
tlvdata,channel_reestablish_tlvs,current_channel_type,type,byte,...
tlvtype,channel_reestablish_tlvs,upgradable_channel_type,7
tlvdata,channel_reestablish_tlvs,upgradable_channel_type,type,byte,...
msgtype,peer_storage,7
msgdata,peer_storage,len,u16,
msgdata,peer_storage,blob,byte,len

1 msgtype,init,16
266 msgdata,channel_reestablish,next_revocation_number,u64,
267 msgdata,channel_reestablish,your_last_per_commitment_secret,byte,32
268 msgdata,channel_reestablish,my_current_per_commitment_point,point,
269 msgdata,channel_reestablish,tlvs,channel_reestablish_tlvs,
270 tlvtype,channel_reestablish_tlvs,next_to_send,1
271 tlvdata,channel_reestablish_tlvs,next_to_send,commitment_number,tu64,
272 tlvtype,channel_reestablish_tlvs,desired_channel_type,3
273 tlvdata,channel_reestablish_tlvs,desired_channel_type,type,byte,...
274 tlvtype,channel_reestablish_tlvs,current_channel_type,5
275 tlvdata,channel_reestablish_tlvs,current_channel_type,type,byte,...
276 tlvtype,channel_reestablish_tlvs,upgradable_channel_type,7
277 tlvdata,channel_reestablish_tlvs,upgradable_channel_type,type,byte,...
278 msgtype,peer_storage,7
279 msgdata,peer_storage,len,u16,
280 msgdata,peer_storage,blob,byte,len