subd: remove ctype (channel_type)

We only needed the type check for dual_open, since it was the only
subdaemon path that used two 'types' in the subd->channel field.
This commit is contained in:
niftynei 2021-01-19 19:51:15 -06:00 committed by neil saitug
parent 1e9a900918
commit de3599e98a
7 changed files with 19 additions and 47 deletions

View File

@ -470,7 +470,7 @@ void peer_start_channeld(struct channel *channel,
channel_set_owner(channel, channel_set_owner(channel,
new_channel_subd(ld, new_channel_subd(ld,
"lightning_channeld", "lightning_channeld",
channel, CHANNEL, channel,
&channel->peer->id, &channel->peer->id,
channel->log, true, channel->log, true,
channeld_wire_name, channeld_wire_name,

View File

@ -194,7 +194,7 @@ void peer_start_closingd(struct channel *channel,
channel_set_owner(channel, channel_set_owner(channel,
new_channel_subd(ld, new_channel_subd(ld,
"lightning_closingd", "lightning_closingd",
channel, CHANNEL, &channel->peer->id, channel, &channel->peer->id,
channel->log, true, channel->log, true,
closingd_wire_name, closing_msg, closingd_wire_name, closing_msg,
channel_errmsg, channel_errmsg,

View File

@ -459,7 +459,6 @@ static void rbf_channel_hook_cb(struct rbf_channel_payload *payload STEALS)
if (!dualopend) if (!dualopend)
return; return;
assert(dualopend->ctype == CHANNEL);
channel = dualopend->channel; channel = dualopend->channel;
tal_del_destructor2(dualopend, rbf_channel_remove_dualopend, payload); tal_del_destructor2(dualopend, rbf_channel_remove_dualopend, payload);
@ -504,7 +503,6 @@ rbf_channel_hook_deserialize(struct rbf_channel_payload *payload,
return false; return false;
} }
assert(dualopend->ctype == CHANNEL);
channel = dualopend->channel; channel = dualopend->channel;
/* FIXME: move to new json extraction */ /* FIXME: move to new json extraction */
@ -1006,11 +1004,11 @@ static void handle_peer_wants_to_close(struct subd *dualopend,
{ {
u8 *scriptpubkey; u8 *scriptpubkey;
struct lightningd *ld = dualopend->ld; struct lightningd *ld = dualopend->ld;
struct channel *channel; struct channel *channel = dualopend->channel;
char *errmsg; char *errmsg;
/* We shouldn't get this message while we're waiting to finish */ /* We shouldn't get this message while we're waiting to finish */
if (dualopend->ctype == UNCOMMITTED) { if (channel_unsaved(channel)) {
log_broken(dualopend->ld->log, "Channel in wrong state for" log_broken(dualopend->ld->log, "Channel in wrong state for"
" shutdown, still has uncommitted" " shutdown, still has uncommitted"
" channel pending."); " channel pending.");
@ -1021,8 +1019,6 @@ static void handle_peer_wants_to_close(struct subd *dualopend,
return; return;
} }
channel = dualopend->channel;
if (!fromwire_dualopend_got_shutdown(channel, msg, &scriptpubkey)) { if (!fromwire_dualopend_got_shutdown(channel, msg, &scriptpubkey)) {
channel_internal_error(channel, "bad channel_got_shutdown %s", channel_internal_error(channel, "bad channel_got_shutdown %s",
tal_hex(msg, msg)); tal_hex(msg, msg));
@ -1077,7 +1073,7 @@ static void handle_channel_closed(struct subd *dualopend,
const u8 *msg) const u8 *msg)
{ {
struct per_peer_state *pps; struct per_peer_state *pps;
struct channel *channel; struct channel *channel = dualopend->channel;
if (!fromwire_dualopend_shutdown_complete(tmpctx, msg, &pps)) { if (!fromwire_dualopend_shutdown_complete(tmpctx, msg, &pps)) {
channel_internal_error(dualopend->channel, channel_internal_error(dualopend->channel,
@ -1091,8 +1087,6 @@ static void handle_channel_closed(struct subd *dualopend,
per_peer_state_set_fds_arr(pps, fds); per_peer_state_set_fds_arr(pps, fds);
assert(dualopend->ctype == CHANNEL);
channel = dualopend->channel;
peer_start_closingd(channel, pps, false, NULL); peer_start_closingd(channel, pps, false, NULL);
channel_set_state(channel, channel_set_state(channel,
CHANNELD_SHUTTING_DOWN, CHANNELD_SHUTTING_DOWN,
@ -1294,10 +1288,7 @@ static void handle_peer_tx_sigs_sent(struct subd *dualopend,
static void handle_peer_locked(struct subd *dualopend, const u8 *msg) static void handle_peer_locked(struct subd *dualopend, const u8 *msg)
{ {
struct pubkey remote_per_commit; struct pubkey remote_per_commit;
struct channel *channel; struct channel *channel = dualopend->channel;
assert(dualopend->ctype == CHANNEL);
channel = dualopend->channel;
if (!fromwire_dualopend_peer_locked(msg, &remote_per_commit)) if (!fromwire_dualopend_peer_locked(msg, &remote_per_commit))
channel_internal_error(channel, channel_internal_error(channel,
@ -1362,9 +1353,9 @@ void dualopen_tell_depth(struct subd *dualopend,
const u8 *msg; const u8 *msg;
u32 to_go; u32 to_go;
if (depth < channel->minimum_depth) if (depth < channel->minimum_depth) {
to_go = channel->minimum_depth - depth; to_go = channel->minimum_depth - depth;
else } else
to_go = 0; to_go = 0;
/* Are we there yet? */ /* Are we there yet? */
@ -1414,7 +1405,6 @@ static void rbf_got_offer(struct subd *dualopend, const u8 *msg)
struct channel *channel; struct channel *channel;
struct rbf_channel_payload *payload; struct rbf_channel_payload *payload;
assert(dualopend->ctype == CHANNEL);
channel = dualopend->channel; channel = dualopend->channel;
payload = tal(dualopend, struct rbf_channel_payload); payload = tal(dualopend, struct rbf_channel_payload);
@ -2036,10 +2026,7 @@ static struct command_result *json_openchannel_init(struct command *cmd,
static void static void
channel_fail_fallen_behind(struct subd* dualopend, const u8 *msg) channel_fail_fallen_behind(struct subd* dualopend, const u8 *msg)
{ {
struct channel *channel; struct channel *channel = dualopend->channel;
assert(dualopend->ctype == CHANNEL);
channel = dualopend->channel;
if (!fromwire_dualopend_fail_fallen_behind(msg)) { if (!fromwire_dualopend_fail_fallen_behind(msg)) {
channel_internal_error(channel, channel_internal_error(channel,
@ -2407,7 +2394,7 @@ void peer_restart_dualopend(struct peer *peer,
channel_set_owner(channel, channel_set_owner(channel,
new_channel_subd(peer->ld, "lightning_dualopend", new_channel_subd(peer->ld, "lightning_dualopend",
channel, CHANNEL, channel,
&peer->id, &peer->id,
channel->log, true, channel->log, true,
dualopend_wire_name, dualopend_wire_name,
@ -2495,7 +2482,7 @@ void peer_start_dualopend(struct peer *peer,
channel->owner = new_channel_subd(peer->ld, channel->owner = new_channel_subd(peer->ld,
"lightning_dualopend", "lightning_dualopend",
channel, CHANNEL, channel,
&peer->id, &peer->id,
channel->log, true, channel->log, true,
dualopend_wire_name, dualopend_wire_name,

View File

@ -589,7 +589,7 @@ enum watch_result onchaind_funding_spent(struct channel *channel,
channel_set_owner(channel, new_channel_subd(ld, channel_set_owner(channel, new_channel_subd(ld,
"lightning_onchaind", "lightning_onchaind",
channel, CHANNEL, channel,
&channel->peer->id, &channel->peer->id,
channel->log, false, channel->log, false,
onchaind_wire_name, onchaind_wire_name,

View File

@ -892,7 +892,7 @@ void peer_start_openingd(struct peer *peer,
uc->open_daemon = new_channel_subd(peer->ld, uc->open_daemon = new_channel_subd(peer->ld,
"lightning_openingd", "lightning_openingd",
uc, UNCOMMITTED, &peer->id, uc->log, uc, &peer->id, uc->log,
true, openingd_wire_name, true, openingd_wire_name,
openingd_msg, openingd_msg,
opend_channel_errmsg, opend_channel_errmsg,

View File

@ -606,7 +606,6 @@ static struct io_plan *msg_setup(struct io_conn *conn, struct subd *sd)
static struct subd *new_subd(struct lightningd *ld, static struct subd *new_subd(struct lightningd *ld,
const char *name, const char *name,
void *channel, void *channel,
enum channel_type ctype,
const struct node_id *node_id, const struct node_id *node_id,
struct log *base_log, struct log *base_log,
bool talks_to_peer, bool talks_to_peer,
@ -679,7 +678,6 @@ static struct subd *new_subd(struct lightningd *ld,
tal_add_destructor(sd, destroy_subd); tal_add_destructor(sd, destroy_subd);
list_head_init(&sd->reqs); list_head_init(&sd->reqs);
sd->channel = channel; sd->channel = channel;
sd->ctype = ctype;
if (node_id) if (node_id)
sd->node_id = tal_dup(sd, struct node_id, node_id); sd->node_id = tal_dup(sd, struct node_id, node_id);
else else
@ -708,7 +706,7 @@ struct subd *new_global_subd(struct lightningd *ld,
struct subd *sd; struct subd *sd;
va_start(ap, msgcb); va_start(ap, msgcb);
sd = new_subd(ld, name, NULL, NONE, NULL, NULL, false, sd = new_subd(ld, name, NULL, NULL, NULL, false,
msgname, msgcb, NULL, NULL, &ap); msgname, msgcb, NULL, NULL, &ap);
va_end(ap); va_end(ap);
@ -719,7 +717,6 @@ struct subd *new_global_subd(struct lightningd *ld,
struct subd *new_channel_subd_(struct lightningd *ld, struct subd *new_channel_subd_(struct lightningd *ld,
const char *name, const char *name,
void *channel, void *channel,
enum channel_type ctype,
const struct node_id *node_id, const struct node_id *node_id,
struct log *base_log, struct log *base_log,
bool talks_to_peer, bool talks_to_peer,
@ -740,7 +737,7 @@ struct subd *new_channel_subd_(struct lightningd *ld,
struct subd *sd; struct subd *sd;
va_start(ap, billboardcb); va_start(ap, billboardcb);
sd = new_subd(ld, name, channel, ctype, node_id, base_log, sd = new_subd(ld, name, channel, node_id, base_log,
talks_to_peer, msgname, msgcb, errcb, billboardcb, &ap); talks_to_peer, msgname, msgcb, errcb, billboardcb, &ap);
va_end(ap); va_end(ap);
return sd; return sd;
@ -827,7 +824,6 @@ void subd_release_channel(struct subd *owner, void *channel)
} }
void subd_swap_channel_(struct subd *daemon, void *channel, void subd_swap_channel_(struct subd *daemon, void *channel,
enum channel_type ctype,
void (*errcb)(void *channel, void (*errcb)(void *channel,
struct per_peer_state *pps, struct per_peer_state *pps,
const struct channel_id *channel_id, const struct channel_id *channel_id,
@ -838,7 +834,6 @@ void subd_swap_channel_(struct subd *daemon, void *channel,
const char *happenings)) const char *happenings))
{ {
daemon->channel = channel; daemon->channel = channel;
daemon->ctype = ctype;
daemon->errcb = errcb; daemon->errcb = errcb;
daemon->billboardcb = billboardcb; daemon->billboardcb = billboardcb;
} }

View File

@ -18,12 +18,6 @@ struct per_peer_state;
/* And reply failures are requests + 200 */ /* And reply failures are requests + 200 */
#define SUBD_REPLYFAIL_OFFSET 200 #define SUBD_REPLYFAIL_OFFSET 200
enum channel_type {
UNCOMMITTED,
CHANNEL,
NONE,
};
/* One of our subds. */ /* One of our subds. */
struct subd { struct subd {
/* Name, like John, or "lightning_hsmd" */ /* Name, like John, or "lightning_hsmd" */
@ -37,7 +31,6 @@ struct subd {
/* If we are associated with a single channel, this points to it. */ /* If we are associated with a single channel, this points to it. */
void *channel; void *channel;
enum channel_type ctype;
/* For logging */ /* For logging */
struct log *log; struct log *log;
@ -105,7 +98,6 @@ struct subd *new_global_subd(struct lightningd *ld,
* @ld: global state * @ld: global state
* @name: basename of daemon * @name: basename of daemon
* @channel: channel to associate. * @channel: channel to associate.
* @ctype: type of @channel struct.
* @node_id: node_id of peer, for logging. * @node_id: node_id of peer, for logging.
* @base_log: log to use (actually makes a copy so it has name in prefix) * @base_log: log to use (actually makes a copy so it has name in prefix)
* @msgname: function to get name from messages * @msgname: function to get name from messages
@ -122,7 +114,6 @@ struct subd *new_global_subd(struct lightningd *ld,
struct subd *new_channel_subd_(struct lightningd *ld, struct subd *new_channel_subd_(struct lightningd *ld,
const char *name, const char *name,
void *channel, void *channel,
enum channel_type ctype,
const struct node_id *node_id, const struct node_id *node_id,
struct log *base_log, struct log *base_log,
bool talks_to_peer, bool talks_to_peer,
@ -139,10 +130,10 @@ struct subd *new_channel_subd_(struct lightningd *ld,
const char *happenings), const char *happenings),
...); ...);
#define new_channel_subd(ld, name, channel, ctype, node_id, log, \ #define new_channel_subd(ld, name, channel, node_id, log, \
talks_to_peer, msgname, msgcb, errcb, \ talks_to_peer, msgname, msgcb, errcb, \
billboardcb, ...) \ billboardcb, ...) \
new_channel_subd_((ld), (name), (channel), (ctype), (node_id), \ new_channel_subd_((ld), (name), (channel), (node_id), \
(log), (talks_to_peer), \ (log), (talks_to_peer), \
(msgname), (msgcb), \ (msgname), (msgcb), \
typesafe_cb_postargs(void, void *, (errcb), \ typesafe_cb_postargs(void, void *, (errcb), \
@ -156,8 +147,8 @@ struct subd *new_channel_subd_(struct lightningd *ld,
__VA_ARGS__) __VA_ARGS__)
/* subd_swap_channel - Swap the daemon's channel out */ /* subd_swap_channel - Swap the daemon's channel out */
#define subd_swap_channel(subd, channel, ctype, errcb, billboardcb) \ #define subd_swap_channel(subd, channel, errcb, billboardcb) \
subd_swap_channel_((subd), (channel), (ctype), \ subd_swap_channel_((subd), (channel), \
typesafe_cb_postargs(void, void *, \ typesafe_cb_postargs(void, void *, \
(errcb), \ (errcb), \
(channel), \ (channel), \
@ -170,7 +161,6 @@ struct subd *new_channel_subd_(struct lightningd *ld,
const char *)) const char *))
void subd_swap_channel_(struct subd *daemon, void *channel, void subd_swap_channel_(struct subd *daemon, void *channel,
enum channel_type ctype,
void (*errcb)(void *channel, void (*errcb)(void *channel,
struct per_peer_state *pps, struct per_peer_state *pps,
const struct channel_id *channel_id, const struct channel_id *channel_id,