lightningd: handle reestablish directly from connectd.

We don't need to hand it to channeld: it will read it!  We simply
need to tell it to expect it.

Similarly, openingd/dualopend will never see it, so remove that logic.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2022-03-23 06:57:30 +10:30
parent 2424b7dea8
commit 57263a3eb2
12 changed files with 62 additions and 110 deletions

View File

@@ -2682,7 +2682,7 @@ static bool fromwire_channel_reestablish_notlvs(const void *p, struct channel_id
static void peer_reconnect(struct peer *peer,
const struct secret *last_remote_per_commit_secret,
u8 *reestablish_only)
bool reestablish_only)
{
struct channel_id channel_id;
/* Note: BOLT #2 uses these names! */
@@ -2820,23 +2820,23 @@ skip_tlvs:
peer_billboard(false, "Sent reestablish, waiting for theirs");
/* If they sent reestablish, we analyze it for courtesy, but also
* in case *they* are ahead of us! */
if (reestablish_only) {
msg = reestablish_only;
goto got_reestablish;
}
/* Read until they say something interesting (don't forward
* gossip *to* them yet: we might try sending channel_update
* before we've reestablished channel). */
do {
clean_tmpctx();
msg = peer_read(tmpctx, peer->pps);
/* connectd promised us the msg was reestablish? */
if (reestablish_only) {
if (fromwire_peektype(msg) != WIRE_CHANNEL_REESTABLISH)
status_failed(STATUS_FAIL_INTERNAL_ERROR,
"Expected reestablish, got: %s",
tal_hex(tmpctx, msg));
}
} while (handle_peer_error(peer->pps, &peer->channel_id, msg) ||
capture_premature_msg(&premature_msgs, msg));
got_reestablish:
#if EXPERIMENTAL_FEATURES
recv_tlvs = tlv_channel_reestablish_tlvs_new(tmpctx);
@@ -3730,7 +3730,7 @@ static void init_channel(struct peer *peer)
secp256k1_ecdsa_signature *remote_ann_node_sig;
secp256k1_ecdsa_signature *remote_ann_bitcoin_sig;
struct penalty_base *pbases;
u8 *reestablish_only;
bool reestablish_only;
struct channel_type *channel_type;
u32 *dev_disable_commit; /* Always NULL */
bool dev_fast_gossip;

View File

@@ -80,8 +80,7 @@ msgdata,channeld_init,dev_fail_process_onionpacket,bool,
msgdata,channeld_init,dev_disable_commit,?u32,
msgdata,channeld_init,num_penalty_bases,u32,
msgdata,channeld_init,pbases,penalty_base,num_penalty_bases
msgdata,channeld_init,reestablish_only_len,u16,
msgdata,channeld_init,reestablish_only,u8,reestablish_only_len
msgdata,channeld_init,reestablish_only,bool,
msgdata,channeld_init,channel_update_len,u16,
msgdata,channeld_init,channel_update,u8,channel_update_len
Can't render this file because it has a wrong number of fields in line 14.

View File

@@ -568,7 +568,7 @@ void peer_start_channeld(struct channel *channel,
struct peer_fd *peer_fd,
const u8 *fwd_msg,
bool reconnected,
const u8 *reestablish_only)
bool reestablish_only)
{
u8 *initmsg;
int hsmfd;

View File

@@ -14,7 +14,7 @@ void peer_start_channeld(struct channel *channel,
struct peer_fd *peer_fd,
const u8 *fwd_msg,
bool reconnected,
const u8 *reestablish_only);
bool reestablish_only);
/* Returns true if subd told, otherwise false. */
bool channel_tell_depth(struct lightningd *ld,

View File

@@ -166,38 +166,3 @@ void channel_config(struct lightningd *ld,
/* This is filled in by lightning_openingd, for consistency. */
ours->channel_reserve = AMOUNT_SAT(UINT64_MAX);
}
void handle_reestablish(struct lightningd *ld,
const struct node_id *peer_id,
const struct channel_id *channel_id,
const u8 *reestablish,
struct peer_fd *peer_fd)
{
struct peer *peer;
struct channel *c;
/* We very carefully re-xmit the last reestablish, so they can get
* their secrets back. We don't otherwise touch them. */
peer = peer_by_id(ld, peer_id);
if (peer)
c = find_channel_by_id(peer, channel_id);
else
c = NULL;
if (c && channel_closed(c)) {
log_debug(c->log, "Reestablish on %s channel: using channeld to reply",
channel_state_name(c));
peer_start_channeld(c, peer_fd, NULL, true, reestablish);
} else {
const u8 *err = towire_errorfmt(tmpctx, channel_id,
"Unknown channel for reestablish");
log_debug(ld->log, "Reestablish on UNKNOWN channel %s",
type_to_string(tmpctx, struct channel_id, channel_id));
/* Unless we're shutting down */
if (ld->connectd)
subd_send_msg(ld->connectd,
take(towire_connectd_peer_final_msg(NULL, peer_id,
err)));
tal_free(peer_fd);
}
}

View File

@@ -123,10 +123,4 @@ void channel_config(struct lightningd *ld,
u32 *max_to_self_delay,
struct amount_msat *min_effective_htlc_capacity);
void handle_reestablish(struct lightningd *ld,
const struct node_id *peer_id,
const struct channel_id *channel_id,
const u8 *reestablish,
struct peer_fd *peer_fd);
#endif /* LIGHTNING_LIGHTNINGD_OPENING_COMMON_H */

View File

@@ -804,32 +804,6 @@ static void opening_got_offer(struct subd *openingd,
plugin_hook_call_openchannel(openingd->ld, payload);
}
static void opening_got_reestablish(struct subd *openingd, const u8 *msg,
const int fds[2],
struct uncommitted_channel *uc)
{
struct lightningd *ld = openingd->ld;
struct node_id peer_id = uc->peer->id;
struct channel_id channel_id;
u8 *reestablish;
struct peer_fd *peer_fd;
peer_fd = new_peer_fd_arr(tmpctx, fds);
if (!fromwire_openingd_got_reestablish(tmpctx, msg, &channel_id,
&reestablish)) {
log_broken(openingd->log, "Malformed opening_got_reestablish %s",
tal_hex(tmpctx, msg));
tal_free(openingd);
return;
}
/* This could free peer */
tal_free(uc);
handle_reestablish(ld, &peer_id, &channel_id, reestablish, peer_fd);
}
static unsigned int openingd_msg(struct subd *openingd,
const u8 *msg, const int *fds)
{
@@ -871,12 +845,6 @@ static unsigned int openingd_msg(struct subd *openingd,
opening_got_offer(openingd, msg, uc);
return 0;
case WIRE_OPENINGD_GOT_REESTABLISH:
if (tal_count(fds) != 1)
return 1;
opening_got_reestablish(openingd, msg, fds, uc);
return 0;
/* We send these! */
case WIRE_OPENINGD_INIT:
case WIRE_OPENINGD_FUNDER_START:

View File

@@ -1337,18 +1337,48 @@ void peer_active(struct lightningd *ld, const u8 *msg, int fd)
&peer->id));
}
}
} else {
/* OK, it's unsolicited. What kind of open do they want? */
if (dual_fund) {
channel = new_unsaved_channel(peer,
peer->ld->config.fee_base,
peer->ld->config.fee_per_satoshi);
peer_start_dualopend(peer, peer_fd, channel);
return;
}
/* It's possible that they want to reestablish a channel, but
* it's closed? */
if (*msgtype == WIRE_CHANNEL_REESTABLISH && channel_id) {
channel = find_channel_by_id(peer, channel_id);
if (channel && channel_closed(channel)) {
log_debug(channel->log,
"Reestablish on %s channel: using channeld to reply",
channel_state_name(channel));
peer_start_channeld(channel, peer_fd, NULL, true, true);
return;
} else {
peer->uncommitted_channel = new_uncommitted_channel(peer);
peer_start_openingd(peer, peer_fd);
const u8 *err = towire_errorfmt(tmpctx, channel_id,
"Unknown channel for reestablish");
log_peer_debug(ld->log, &peer->id,
"Reestablish on UNKNOWN channel %s",
type_to_string(tmpctx, struct channel_id,
channel_id));
/* Unless we're shutting down, tell connectd to send err */
if (ld->connectd)
subd_send_msg(ld->connectd,
take(towire_connectd_peer_final_msg(NULL,
&peer->id,
err)));
else
peer->is_connected = false;
return;
}
}
/* OK, it's unsolicited. What kind of open do they want? */
if (dual_fund) {
channel = new_unsaved_channel(peer,
peer->ld->config.fee_base,
peer->ld->config.fee_per_satoshi);
peer_start_dualopend(peer, peer_fd, channel);
} else {
peer->uncommitted_channel = new_uncommitted_channel(peer);
peer_start_openingd(peer, peer_fd);
}
return;
send_error:

View File

@@ -187,6 +187,10 @@ bool feature_negotiated(const struct feature_set *our_features UNNEEDED,
/* Generated stub for featurebits_or */
u8 *featurebits_or(const tal_t *ctx UNNEEDED, const u8 *f1 TAKES UNNEEDED, const u8 *f2 TAKES UNNEEDED)
{ fprintf(stderr, "featurebits_or called!\n"); abort(); }
/* Generated stub for find_channel_by_id */
struct channel *find_channel_by_id(const struct peer *peer UNNEEDED,
const struct channel_id *cid UNNEEDED)
{ fprintf(stderr, "find_channel_by_id called!\n"); abort(); }
/* Generated stub for find_plugin_for_command */
struct plugin *find_plugin_for_command(struct lightningd *ld UNNEEDED,
const char *cmd_name UNNEEDED)
@@ -594,7 +598,7 @@ void peer_start_channeld(struct channel *channel UNNEEDED,
struct peer_fd *peer_fd UNNEEDED,
const u8 *fwd_msg UNNEEDED,
bool reconnected UNNEEDED,
const u8 *reestablish_only UNNEEDED)
bool reestablish_only UNNEEDED)
{ fprintf(stderr, "peer_start_channeld called!\n"); abort(); }
/* Generated stub for peer_start_dualopend */
bool peer_start_dualopend(struct peer *peer UNNEEDED, struct peer_fd *peer_fd UNNEEDED,

View File

@@ -1251,11 +1251,6 @@ static u8 *handle_peer_in(struct state *state)
extracted = extract_channel_id(msg, &channel_id);
/* Reestablish on some now-closed channel? Be nice. */
if (extracted && fromwire_peektype(msg) == WIRE_CHANNEL_REESTABLISH) {
return towire_openingd_got_reestablish(NULL,
&channel_id, msg);
}
peer_write(state->pps,
take(towire_warningfmt(NULL,
extracted ? &channel_id : NULL,
@@ -1352,7 +1347,6 @@ static u8 *handle_master_in(struct state *state)
case WIRE_OPENINGD_FAILED:
case WIRE_OPENINGD_GOT_OFFER:
case WIRE_OPENINGD_GOT_OFFER_REPLY:
case WIRE_OPENINGD_GOT_REESTABLISH:
break;
}

View File

@@ -25,12 +25,6 @@ msgdata,openingd_init,min_feerate,u32,
msgdata,openingd_init,max_feerate,u32,
msgdata,openingd_init,dev_temporary_channel_id,?byte,32
# Openingd->master: they tried to reestablish a channel.
msgtype,openingd_got_reestablish,6001
msgdata,openingd_got_reestablish,channel_id,channel_id,
msgdata,openingd_got_reestablish,len,u16,
msgdata,openingd_got_reestablish,msg,u8,len
# Openingd->master: they offered channel, should we continue?
msgtype,openingd_got_offer,6005
msgdata,openingd_got_offer,funding_satoshis,amount_sat,
1 #include <bitcoin/chainparams.h>
25 msgdata,openingd_init,dev_temporary_channel_id,?byte,32
26 # Openingd->master: they tried to reestablish a channel. # Openingd->master: they offered channel, should we continue?
27 msgtype,openingd_got_reestablish,6001 msgtype,openingd_got_offer,6005
msgdata,openingd_got_reestablish,channel_id,channel_id,
msgdata,openingd_got_reestablish,len,u16,
msgdata,openingd_got_reestablish,msg,u8,len
# Openingd->master: they offered channel, should we continue?
msgtype,openingd_got_offer,6005
msgdata,openingd_got_offer,funding_satoshis,amount_sat,
28 msgdata,openingd_got_offer,push_msat,amount_msat, msgdata,openingd_got_offer,funding_satoshis,amount_sat,
29 msgdata,openingd_got_offer,dust_limit_satoshis,amount_sat, msgdata,openingd_got_offer,push_msat,amount_msat,
30 msgdata,openingd_got_offer,max_htlc_value_in_flight_msat,amount_msat, msgdata,openingd_got_offer,dust_limit_satoshis,amount_sat,

View File

@@ -133,6 +133,10 @@ char *encode_scriptpubkey_to_addr(const tal_t *ctx UNNEEDED,
/* Generated stub for fatal */
void fatal(const char *fmt UNNEEDED, ...)
{ fprintf(stderr, "fatal called!\n"); abort(); }
/* Generated stub for find_channel_by_id */
struct channel *find_channel_by_id(const struct peer *peer UNNEEDED,
const struct channel_id *cid UNNEEDED)
{ fprintf(stderr, "find_channel_by_id called!\n"); abort(); }
/* Generated stub for fromwire_channeld_dev_memleak_reply */
bool fromwire_channeld_dev_memleak_reply(const void *p UNNEEDED, bool *leak UNNEEDED)
{ fprintf(stderr, "fromwire_channeld_dev_memleak_reply called!\n"); abort(); }
@@ -634,7 +638,7 @@ void peer_start_channeld(struct channel *channel UNNEEDED,
struct peer_fd *peer_fd UNNEEDED,
const u8 *fwd_msg UNNEEDED,
bool reconnected UNNEEDED,
const u8 *reestablish_only UNNEEDED)
bool reestablish_only UNNEEDED)
{ fprintf(stderr, "peer_start_channeld called!\n"); abort(); }
/* Generated stub for peer_start_dualopend */
bool peer_start_dualopend(struct peer *peer UNNEEDED, struct peer_fd *peer_fd UNNEEDED,