Skip to content

Commit

Permalink
lightningd: don't send other messages until we've received version.
Browse files Browse the repository at this point in the history
This avoids subdaemons complaining about malformed messages from us,
or doing the completely wrong thing, if they are really the wrong
version.

Signed-off-by: Rusty Russell <[email protected]>
  • Loading branch information
rustyrussell committed Apr 24, 2021
1 parent 7b56b2b commit f97a51c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
13 changes: 12 additions & 1 deletion lightningd/subd.c
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,11 @@ static bool handle_version(struct subd *sd, const u8 *msg)
io_break(sd->ld);
return false;
}

sd->rcvd_version = true;
/* In case there are outgoing msgs, we can send now. */
msg_wake(sd->outq);

return true;
}

Expand Down Expand Up @@ -605,10 +610,15 @@ static void destroy_subd(struct subd *sd)

static struct io_plan *msg_send_next(struct io_conn *conn, struct subd *sd)
{
const u8 *msg = msg_dequeue(sd->outq);
const u8 *msg;
int fd;

/* Don't send if we haven't read version! */
if (!sd->rcvd_version)
return msg_queue_wait(conn, sd->outq, msg_send_next, sd);

/* Nothing to do? Wait for msg_enqueue. */
msg = msg_dequeue(sd->outq);
if (!msg)
return msg_queue_wait(conn, sd->outq, msg_send_next, sd);

Expand Down Expand Up @@ -702,6 +712,7 @@ static struct subd *new_subd(struct lightningd *ld,
tal_add_destructor(sd, destroy_subd);
list_head_init(&sd->reqs);
sd->channel = channel;
sd->rcvd_version = false;
if (node_id)
sd->node_id = tal_dup(sd, struct node_id, node_id);
else
Expand Down
3 changes: 3 additions & 0 deletions lightningd/subd.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ struct subd {
/* If we are associated with a single channel, this points to it. */
void *channel;

/* Have we received the version msg yet? Don't send until we do. */
bool rcvd_version;

/* For logging */
struct log *log;
const struct node_id *node_id;
Expand Down

0 comments on commit f97a51c

Please sign in to comment.