From 4fa7b30836355887260196030351388da8b66b65 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Sun, 17 Nov 2019 22:10:33 +1030 Subject: [PATCH] lightningd: have optional node_id associated with subdaemons. We'll use this for logging it. Signed-off-by: Rusty Russell --- lightningd/channel_control.c | 1 + lightningd/closing_control.c | 3 ++- lightningd/onchain_control.c | 2 +- lightningd/opening_control.c | 2 +- lightningd/subd.c | 12 +++++++++--- lightningd/subd.h | 10 +++++++--- 6 files changed, 21 insertions(+), 9 deletions(-) diff --git a/lightningd/channel_control.c b/lightningd/channel_control.c index 05d715ec3..beae0c623 100644 --- a/lightningd/channel_control.c +++ b/lightningd/channel_control.c @@ -353,6 +353,7 @@ void peer_start_channeld(struct channel *channel, channel_set_owner(channel, new_channel_subd(ld, "lightning_channeld", channel, + &channel->peer->id, channel->log, true, channel_wire_type_name, channel_msg, diff --git a/lightningd/closing_control.c b/lightningd/closing_control.c index 1aaea5fe3..71c6f88bd 100644 --- a/lightningd/closing_control.c +++ b/lightningd/closing_control.c @@ -195,7 +195,8 @@ void peer_start_closingd(struct channel *channel, channel_set_owner(channel, new_channel_subd(ld, "lightning_closingd", - channel, channel->log, true, + channel, &channel->peer->id, + channel->log, true, closing_wire_type_name, closing_msg, channel_errmsg, channel_set_billboard, diff --git a/lightningd/onchain_control.c b/lightningd/onchain_control.c index 85f7eb256..499b7ec13 100644 --- a/lightningd/onchain_control.c +++ b/lightningd/onchain_control.c @@ -471,7 +471,7 @@ enum watch_result onchaind_funding_spent(struct channel *channel, channel_set_owner(channel, new_channel_subd(ld, "lightning_onchaind", - channel, + channel, &channel->peer->id, channel->log, false, onchain_wire_type_name, onchain_msg, diff --git a/lightningd/opening_control.c b/lightningd/opening_control.c index 1350567bf..ec3548ea3 100644 --- a/lightningd/opening_control.c +++ b/lightningd/opening_control.c @@ -923,7 +923,7 @@ void peer_start_openingd(struct peer *peer, uc->openingd = new_channel_subd(peer->ld, "lightning_openingd", - uc, uc->log, + uc, &peer->id, uc->log, true, opening_wire_type_name, openingd_msg, opening_channel_errmsg, diff --git a/lightningd/subd.c b/lightningd/subd.c index 0f6fbb9e1..e23510814 100644 --- a/lightningd/subd.c +++ b/lightningd/subd.c @@ -601,6 +601,7 @@ static struct io_plan *msg_setup(struct io_conn *conn, struct subd *sd) static struct subd *new_subd(struct lightningd *ld, const char *name, void *channel, + const struct node_id *node_id, struct log *base_log, bool talks_to_peer, const char *(*msgname)(int msgtype), @@ -658,6 +659,10 @@ static struct subd *new_subd(struct lightningd *ld, tal_add_destructor(sd, destroy_subd); list_head_init(&sd->reqs); sd->channel = channel; + if (node_id) + sd->node_id = tal_dup(sd, struct node_id, node_id); + else + sd->node_id = NULL; /* conn actually owns daemon: we die when it does. */ sd->conn = io_new_conn(ld, msg_fd, msg_setup, sd); @@ -682,7 +687,7 @@ struct subd *new_global_subd(struct lightningd *ld, struct subd *sd; va_start(ap, msgcb); - sd = new_subd(ld, name, NULL, NULL, false, msgname, msgcb, NULL, NULL, &ap); + sd = new_subd(ld, name, NULL, NULL, NULL, false, msgname, msgcb, NULL, NULL, &ap); va_end(ap); sd->must_not_exit = true; @@ -692,6 +697,7 @@ struct subd *new_global_subd(struct lightningd *ld, struct subd *new_channel_subd_(struct lightningd *ld, const char *name, void *channel, + const struct node_id *node_id, struct log *base_log, bool talks_to_peer, const char *(*msgname)(int msgtype), @@ -711,8 +717,8 @@ struct subd *new_channel_subd_(struct lightningd *ld, struct subd *sd; va_start(ap, billboardcb); - sd = new_subd(ld, name, channel, base_log, talks_to_peer, msgname, - msgcb, errcb, billboardcb, &ap); + sd = new_subd(ld, name, channel, node_id, base_log, talks_to_peer, + msgname, msgcb, errcb, billboardcb, &ap); va_end(ap); return sd; } diff --git a/lightningd/subd.h b/lightningd/subd.h index 62ec672aa..4d4a31c0e 100644 --- a/lightningd/subd.h +++ b/lightningd/subd.h @@ -34,6 +34,7 @@ struct subd { /* For logging */ struct log *log; + const struct node_id *node_id; /* Callback when non-reply message comes in (inside db transaction) */ unsigned (*msgcb)(struct subd *, const u8 *, const int *); @@ -97,6 +98,7 @@ struct subd *new_global_subd(struct lightningd *ld, * @ld: global state * @name: basename of daemon * @channel: channel to associate. + * @node_id: node_id of peer, for logging. * @base_log: log to use (actually makes a copy so it has name in prefix) * @msgname: function to get name from messages * @msgcb: function to call (inside db transaction) when non-fatal message received (or NULL) @@ -112,6 +114,7 @@ struct subd *new_global_subd(struct lightningd *ld, struct subd *new_channel_subd_(struct lightningd *ld, const char *name, void *channel, + const struct node_id *node_id, struct log *base_log, bool talks_to_peer, const char *(*msgname)(int msgtype), @@ -127,9 +130,10 @@ struct subd *new_channel_subd_(struct lightningd *ld, const char *happenings), ...); -#define new_channel_subd(ld, name, channel, log, talks_to_peer, msgname, \ - msgcb, errcb, billboardcb, ...) \ - new_channel_subd_((ld), (name), (channel), (log), (talks_to_peer), \ +#define new_channel_subd(ld, name, channel, node_id, log, talks_to_peer, \ + msgname, msgcb, errcb, billboardcb, ...) \ + new_channel_subd_((ld), (name), (channel), (node_id), (log), \ + (talks_to_peer), \ (msgname), (msgcb), \ typesafe_cb_postargs(void, void *, (errcb), \ (channel), \