diff --git a/lightningd/channel_control.c b/lightningd/channel_control.c index c4bd758c3..924cb0fec 100644 --- a/lightningd/channel_control.c +++ b/lightningd/channel_control.c @@ -462,7 +462,8 @@ void peer_start_channeld(struct channel *channel, channel_set_owner(channel, new_channel_subd(ld, - "lightning_channeld", channel, + "lightning_channeld", + channel, CHANNEL, &channel->peer->id, channel->log, true, channeld_wire_name, diff --git a/lightningd/closing_control.c b/lightningd/closing_control.c index 31b44c9ed..cb935b9ff 100644 --- a/lightningd/closing_control.c +++ b/lightningd/closing_control.c @@ -194,7 +194,7 @@ void peer_start_closingd(struct channel *channel, channel_set_owner(channel, new_channel_subd(ld, "lightning_closingd", - channel, &channel->peer->id, + channel, CHANNEL, &channel->peer->id, channel->log, true, closingd_wire_name, closing_msg, channel_errmsg, diff --git a/lightningd/dual_open_control.c b/lightningd/dual_open_control.c index 524849acd..eca90f754 100644 --- a/lightningd/dual_open_control.c +++ b/lightningd/dual_open_control.c @@ -816,7 +816,7 @@ static void accepter_commit_received(struct subd *dualopend, payload->rcvd->channel->dbid, pbase); - subd_swap_channel(uc->open_daemon, payload->rcvd->channel, + subd_swap_channel(uc->open_daemon, payload->rcvd->channel, CHANNEL, channel_errmsg, channel_set_billboard); payload->rcvd->channel->owner = dualopend; /* We don't have a command, so set to NULL here */ @@ -936,7 +936,7 @@ static void opener_commit_received(struct subd *dualopend, was_pending(command_success(uc->fc->cmd, response)); - subd_swap_channel(uc->open_daemon, channel, + subd_swap_channel(uc->open_daemon, channel, CHANNEL, channel_errmsg, channel_set_billboard); channel->owner = dualopend; goto cleanup; @@ -1708,7 +1708,8 @@ void peer_start_dualopend(struct peer *peer, uc->open_daemon = new_channel_subd(peer->ld, "lightning_dualopend", - uc, &peer->id, uc->log, + uc, UNCOMMITTED, &peer->id, + uc->log, true, dualopend_wire_name, dual_opend_msg, opend_channel_errmsg, diff --git a/lightningd/onchain_control.c b/lightningd/onchain_control.c index 92c6f70bd..80d83cf2b 100644 --- a/lightningd/onchain_control.c +++ b/lightningd/onchain_control.c @@ -588,7 +588,8 @@ enum watch_result onchaind_funding_spent(struct channel *channel, channel_set_owner(channel, new_channel_subd(ld, "lightning_onchaind", - channel, &channel->peer->id, + channel, CHANNEL, + &channel->peer->id, channel->log, false, onchaind_wire_name, onchain_msg, diff --git a/lightningd/opening_control.c b/lightningd/opening_control.c index d9f4ff273..38ce9e705 100644 --- a/lightningd/opening_control.c +++ b/lightningd/opening_control.c @@ -893,7 +893,7 @@ void peer_start_openingd(struct peer *peer, uc->open_daemon = new_channel_subd(peer->ld, "lightning_openingd", - uc, &peer->id, uc->log, + uc, UNCOMMITTED, &peer->id, uc->log, true, openingd_wire_name, openingd_msg, opend_channel_errmsg, diff --git a/lightningd/subd.c b/lightningd/subd.c index a1fba13e3..02a8cd830 100644 --- a/lightningd/subd.c +++ b/lightningd/subd.c @@ -606,6 +606,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, + enum channel_type ctype, const struct node_id *node_id, struct log *base_log, bool talks_to_peer, @@ -678,6 +679,7 @@ static struct subd *new_subd(struct lightningd *ld, tal_add_destructor(sd, destroy_subd); list_head_init(&sd->reqs); sd->channel = channel; + sd->ctype = ctype; if (node_id) sd->node_id = tal_dup(sd, struct node_id, node_id); else @@ -706,7 +708,8 @@ struct subd *new_global_subd(struct lightningd *ld, struct subd *sd; va_start(ap, msgcb); - sd = new_subd(ld, name, NULL, NULL, NULL, false, msgname, msgcb, NULL, NULL, &ap); + sd = new_subd(ld, name, NULL, NONE, NULL, NULL, false, + msgname, msgcb, NULL, NULL, &ap); va_end(ap); sd->must_not_exit = true; @@ -716,6 +719,7 @@ struct subd *new_global_subd(struct lightningd *ld, struct subd *new_channel_subd_(struct lightningd *ld, const char *name, void *channel, + enum channel_type ctype, const struct node_id *node_id, struct log *base_log, bool talks_to_peer, @@ -736,8 +740,8 @@ struct subd *new_channel_subd_(struct lightningd *ld, struct subd *sd; va_start(ap, billboardcb); - sd = new_subd(ld, name, channel, node_id, base_log, talks_to_peer, - msgname, msgcb, errcb, billboardcb, &ap); + sd = new_subd(ld, name, channel, ctype, node_id, base_log, + talks_to_peer, msgname, msgcb, errcb, billboardcb, &ap); va_end(ap); return sd; } @@ -823,16 +827,18 @@ void subd_release_channel(struct subd *owner, void *channel) } void subd_swap_channel_(struct subd *daemon, void *channel, - void (*errcb)(void *channel, - struct per_peer_state *pps, - const struct channel_id *channel_id, - const char *desc, - bool soft_error, - const u8 *err_for_them), + enum channel_type ctype, + void (*errcb)(void *channel, + struct per_peer_state *pps, + const struct channel_id *channel_id, + const char *desc, + bool soft_error, + const u8 *err_for_them), void (*billboardcb)(void *channel, bool perm, const char *happenings)) { daemon->channel = channel; + daemon->ctype = ctype; daemon->errcb = errcb; daemon->billboardcb = billboardcb; } diff --git a/lightningd/subd.h b/lightningd/subd.h index 93aa4ab94..f0cd09c0c 100644 --- a/lightningd/subd.h +++ b/lightningd/subd.h @@ -18,6 +18,12 @@ struct per_peer_state; /* And reply failures are requests + 200 */ #define SUBD_REPLYFAIL_OFFSET 200 +enum channel_type { + UNCOMMITTED, + CHANNEL, + NONE, +}; + /* One of our subds. */ struct subd { /* Name, like John, or "lightning_hsmd" */ @@ -31,6 +37,7 @@ struct subd { /* If we are associated with a single channel, this points to it. */ void *channel; + enum channel_type ctype; /* For logging */ struct log *log; @@ -98,6 +105,7 @@ struct subd *new_global_subd(struct lightningd *ld, * @ld: global state * @name: basename of daemon * @channel: channel to associate. + * @ctype: type of @channel struct. * @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 @@ -114,6 +122,7 @@ struct subd *new_global_subd(struct lightningd *ld, struct subd *new_channel_subd_(struct lightningd *ld, const char *name, void *channel, + enum channel_type ctype, const struct node_id *node_id, struct log *base_log, bool talks_to_peer, @@ -130,10 +139,11 @@ struct subd *new_channel_subd_(struct lightningd *ld, const char *happenings), ...); -#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), \ +#define new_channel_subd(ld, name, channel, ctype, node_id, log, \ + talks_to_peer, msgname, msgcb, errcb, \ + billboardcb, ...) \ + new_channel_subd_((ld), (name), (channel), (ctype), (node_id), \ + (log), (talks_to_peer), \ (msgname), (msgcb), \ typesafe_cb_postargs(void, void *, (errcb), \ (channel), \ @@ -146,8 +156,8 @@ struct subd *new_channel_subd_(struct lightningd *ld, __VA_ARGS__) /* subd_swap_channel - Swap the daemon's channel out */ -#define subd_swap_channel(subd, channel, errcb, billboardcb) \ - subd_swap_channel_((subd), (channel), \ +#define subd_swap_channel(subd, channel, ctype, errcb, billboardcb) \ + subd_swap_channel_((subd), (channel), (ctype), \ typesafe_cb_postargs(void, void *, \ (errcb), \ (channel), \ @@ -160,6 +170,7 @@ struct subd *new_channel_subd_(struct lightningd *ld, const char *)) void subd_swap_channel_(struct subd *daemon, void *channel, + enum channel_type ctype, void (*errcb)(void *channel, struct per_peer_state *pps, const struct channel_id *channel_id,