subd: keep track of 'channel's type

Back in the days before dual-funding, the `channel` struct on subd was
only every one type per daemon (either struct channel or struct
uncommitted_channel)

The RBF requirement on dualopend means that dualopend's channel,
however, can now be two different things -- either channel or
uncommitted_channel.

To track the difference/disambiguate, we now track the channel type on a
flag on the subd. It gets updated when we swap out the channel.
This commit is contained in:
niftynei 2020-12-01 14:49:35 -06:00 committed by Christian Decker
parent 0c520850b0
commit bf49bcfa90
7 changed files with 42 additions and 22 deletions

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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;
}

View File

@ -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,