connectd: tell lightningd the channel_id when we give it the active peer.

Now we always have it (either extracted from an unsolicited message,
or told to us by lightningd when it tells us it wants to talk), we can
always send it.

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 2bc58e2327
commit fe9f391a93
5 changed files with 28 additions and 15 deletions

View File

@ -86,7 +86,7 @@ msgdata,connectd_peer_make_active,channel_id,channel_id,
msgtype,connectd_peer_active,2005
msgdata,connectd_peer_active,id,node_id,
msgdata,connectd_peer_active,msgtype,?u16,
msgdata,connectd_peer_active,channel_id,?channel_id,
msgdata,connectd_peer_active,channel_id,channel_id,
# master -> connectd: peer no longer wanted, you can disconnect.
msgtype,connectd_discard_peer,2015

1 #include <bitcoin/block.h>
86 msgdata,connectd_peer_final_msg,msg,u8,len
87 # connectd->master: You said to connect, but we already were.
88 msgtype,connectd_peer_already_connected,2007
89 msgdata,connectd_peer_already_connected,id,node_id,
90 # master -> connectd: do you have a memleak?
91 msgtype,connectd_dev_memleak,2033
92 msgtype,connectd_dev_memleak_reply,2133

View File

@ -402,7 +402,9 @@ void send_custommsg(struct daemon *daemon, const u8 *msg)
}
/* FIXME: fwd decl */
static struct subd *multiplex_subd_setup(struct peer *peer, int *fd_for_subd);
static struct subd *multiplex_subd_setup(struct peer *peer,
const struct channel_id *channel_id,
int *fd_for_subd);
static struct subd *activate_peer(struct peer *peer,
const enum peer_wire *type,
@ -415,7 +417,7 @@ static struct subd *activate_peer(struct peer *peer,
/* If it wasn't active before, it is now! */
peer->active = true;
subd = multiplex_subd_setup(peer, &fd_for_subd);
subd = multiplex_subd_setup(peer, channel_id, &fd_for_subd);
if (!subd)
return NULL;
@ -816,11 +818,18 @@ static struct io_plan *read_body_from_peer_done(struct io_conn *peer_conn,
if (!subd) {
struct channel_id channel_id;
enum peer_wire t = fromwire_peektype(decrypted);
bool has_channel_id = extract_channel_id(decrypted, &channel_id);
if (!extract_channel_id(decrypted, &channel_id)) {
send_warning(peer, "Unrecognized message %s: %s",
peer_wire_name(t),
tal_hex(tmpctx, decrypted));
tal_free(decrypted);
io_wake(peer->peer_outq);
return read_hdr_from_peer(peer_conn, peer);
}
status_peer_debug(&peer->id, "Activating for message %s",
peer_wire_name(t));
subd = activate_peer(peer, &t,
has_channel_id ? &channel_id : NULL);
subd = activate_peer(peer, &t, &channel_id);
if (!subd)
return io_close(peer_conn);
}
@ -915,7 +924,9 @@ void close_peer_conn(struct peer *peer)
msg_wake(peer->peer_outq);
}
static struct subd *multiplex_subd_setup(struct peer *peer, int *fd_for_subd)
static struct subd *multiplex_subd_setup(struct peer *peer,
const struct channel_id *channel_id,
int *fd_for_subd)
{
int fds[2];
struct subd *subd;
@ -929,6 +940,8 @@ static struct subd *multiplex_subd_setup(struct peer *peer, int *fd_for_subd)
subd = tal(peer->subds, struct subd);
subd->peer = peer;
subd->outq = msg_queue_new(subd, false);
subd->channel_id = *channel_id;
subd->temporary_channel_id = NULL;
/* This sets subd->conn inside subd_conn_init */
io_new_conn(peer, fds[0], subd_conn_init, subd);
/* When conn dies, subd is freed. */

View File

@ -1237,7 +1237,7 @@ void peer_active(struct lightningd *ld, const u8 *msg, int fd)
struct node_id id;
u16 *msgtype;
struct channel *channel;
struct channel_id *channel_id;
struct channel_id channel_id;
struct peer *peer;
bool dual_fund;
u8 *error;
@ -1342,8 +1342,8 @@ void peer_active(struct lightningd *ld, const u8 *msg, int fd)
/* 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 (*msgtype == WIRE_CHANNEL_REESTABLISH) {
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",
@ -1351,12 +1351,12 @@ void peer_active(struct lightningd *ld, const u8 *msg, int fd)
peer_start_channeld(channel, peer_fd, NULL, true, true);
return;
} else {
const u8 *err = towire_errorfmt(tmpctx, channel_id,
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));
&channel_id));
/* Unless we're shutting down, tell connectd to send err */
if (ld->connectd)
subd_send_msg(ld->connectd,
@ -1374,7 +1374,7 @@ void peer_active(struct lightningd *ld, const u8 *msg, int fd)
channel = new_unsaved_channel(peer,
peer->ld->config.fee_base,
peer->ld->config.fee_per_satoshi);
channel->cid = *channel_id;
channel->cid = channel_id;
peer_start_dualopend(peer, peer_fd, channel);
} else {
peer->uncommitted_channel = new_uncommitted_channel(peer);

View File

@ -209,7 +209,7 @@ bool fromwire_channel_id(const u8 **cursor UNNEEDED, size_t *max UNNEEDED,
bool fromwire_channeld_dev_memleak_reply(const void *p UNNEEDED, bool *leak UNNEEDED)
{ fprintf(stderr, "fromwire_channeld_dev_memleak_reply called!\n"); abort(); }
/* Generated stub for fromwire_connectd_peer_active */
bool fromwire_connectd_peer_active(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, struct node_id *id UNNEEDED, u16 **msgtype UNNEEDED, struct channel_id **channel_id UNNEEDED)
bool fromwire_connectd_peer_active(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, struct node_id *id UNNEEDED, u16 **msgtype UNNEEDED, struct channel_id *channel_id UNNEEDED)
{ fprintf(stderr, "fromwire_connectd_peer_active called!\n"); abort(); }
/* Generated stub for fromwire_connectd_peer_connected */
bool fromwire_connectd_peer_connected(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, struct node_id *id UNNEEDED, struct wireaddr_internal *addr UNNEEDED, struct wireaddr **remote_addr UNNEEDED, bool *incoming UNNEEDED, u8 **features UNNEEDED)

View File

@ -153,7 +153,7 @@ bool fromwire_channeld_offer_htlc_reply(const tal_t *ctx UNNEEDED, const void *p
bool fromwire_channeld_sending_commitsig(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, u64 *commitnum UNNEEDED, struct penalty_base **pbase UNNEEDED, struct fee_states **fee_states UNNEEDED, struct height_states **blockheight_states UNNEEDED, struct changed_htlc **changed UNNEEDED, struct bitcoin_signature *commit_sig UNNEEDED, struct bitcoin_signature **htlc_sigs UNNEEDED)
{ fprintf(stderr, "fromwire_channeld_sending_commitsig called!\n"); abort(); }
/* Generated stub for fromwire_connectd_peer_active */
bool fromwire_connectd_peer_active(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, struct node_id *id UNNEEDED, u16 **msgtype UNNEEDED, struct channel_id **channel_id UNNEEDED)
bool fromwire_connectd_peer_active(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, struct node_id *id UNNEEDED, u16 **msgtype UNNEEDED, struct channel_id *channel_id UNNEEDED)
{ fprintf(stderr, "fromwire_connectd_peer_active called!\n"); abort(); }
/* Generated stub for fromwire_connectd_peer_connected */
bool fromwire_connectd_peer_connected(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, struct node_id *id UNNEEDED, struct wireaddr_internal *addr UNNEEDED, struct wireaddr **remote_addr UNNEEDED, bool *incoming UNNEEDED, u8 **features UNNEEDED)