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,
new_channel_subd(ld,
"lightning_channeld",
channel, 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, &channel->peer->id,
channel, &channel->peer->id,
channel->log, true,
closingd_wire_name, closing_msg,
channel_errmsg,

View File

@ -459,7 +459,6 @@ static void rbf_channel_hook_cb(struct rbf_channel_payload *payload STEALS)
if (!dualopend)
return;
assert(dualopend->ctype == CHANNEL);
channel = dualopend->channel;
tal_del_destructor2(dualopend, rbf_channel_remove_dualopend, payload);
@ -504,7 +503,6 @@ rbf_channel_hook_deserialize(struct rbf_channel_payload *payload,
return false;
}
assert(dualopend->ctype == CHANNEL);
channel = dualopend->channel;
/* FIXME: move to new json extraction */
@ -1006,11 +1004,11 @@ static void handle_peer_wants_to_close(struct subd *dualopend,
{
u8 *scriptpubkey;
struct lightningd *ld = dualopend->ld;
struct channel *channel;
struct channel *channel = dualopend->channel;
char *errmsg;
/* 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"
" shutdown, still has uncommitted"
" channel pending.");
@ -1021,8 +1019,6 @@ static void handle_peer_wants_to_close(struct subd *dualopend,
return;
}
channel = dualopend->channel;
if (!fromwire_dualopend_got_shutdown(channel, msg, &scriptpubkey)) {
channel_internal_error(channel, "bad channel_got_shutdown %s",
tal_hex(msg, msg));
@ -1077,7 +1073,7 @@ static void handle_channel_closed(struct subd *dualopend,
const u8 *msg)
{
struct per_peer_state *pps;
struct channel *channel;
struct channel *channel = dualopend->channel;
if (!fromwire_dualopend_shutdown_complete(tmpctx, msg, &pps)) {
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);
assert(dualopend->ctype == CHANNEL);
channel = dualopend->channel;
peer_start_closingd(channel, pps, false, NULL);
channel_set_state(channel,
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)
{
struct pubkey remote_per_commit;
struct channel *channel;
assert(dualopend->ctype == CHANNEL);
channel = dualopend->channel;
struct channel *channel = dualopend->channel;
if (!fromwire_dualopend_peer_locked(msg, &remote_per_commit))
channel_internal_error(channel,
@ -1362,9 +1353,9 @@ void dualopen_tell_depth(struct subd *dualopend,
const u8 *msg;
u32 to_go;
if (depth < channel->minimum_depth)
if (depth < channel->minimum_depth) {
to_go = channel->minimum_depth - depth;
else
} else
to_go = 0;
/* Are we there yet? */
@ -1414,7 +1405,6 @@ static void rbf_got_offer(struct subd *dualopend, const u8 *msg)
struct channel *channel;
struct rbf_channel_payload *payload;
assert(dualopend->ctype == CHANNEL);
channel = dualopend->channel;
payload = tal(dualopend, struct rbf_channel_payload);
@ -2036,10 +2026,7 @@ static struct command_result *json_openchannel_init(struct command *cmd,
static void
channel_fail_fallen_behind(struct subd* dualopend, const u8 *msg)
{
struct channel *channel;
assert(dualopend->ctype == CHANNEL);
channel = dualopend->channel;
struct channel *channel = dualopend->channel;
if (!fromwire_dualopend_fail_fallen_behind(msg)) {
channel_internal_error(channel,
@ -2407,7 +2394,7 @@ void peer_restart_dualopend(struct peer *peer,
channel_set_owner(channel,
new_channel_subd(peer->ld, "lightning_dualopend",
channel, CHANNEL,
channel,
&peer->id,
channel->log, true,
dualopend_wire_name,
@ -2495,7 +2482,7 @@ void peer_start_dualopend(struct peer *peer,
channel->owner = new_channel_subd(peer->ld,
"lightning_dualopend",
channel, CHANNEL,
channel,
&peer->id,
channel->log, true,
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,
"lightning_onchaind",
channel, CHANNEL,
channel,
&channel->peer->id,
channel->log, false,
onchaind_wire_name,

View File

@ -892,7 +892,7 @@ void peer_start_openingd(struct peer *peer,
uc->open_daemon = new_channel_subd(peer->ld,
"lightning_openingd",
uc, UNCOMMITTED, &peer->id, uc->log,
uc, &peer->id, uc->log,
true, openingd_wire_name,
openingd_msg,
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,
const char *name,
void *channel,
enum channel_type ctype,
const struct node_id *node_id,
struct log *base_log,
bool talks_to_peer,
@ -679,7 +678,6 @@ 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
@ -708,7 +706,7 @@ struct subd *new_global_subd(struct lightningd *ld,
struct subd *sd;
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);
va_end(ap);
@ -719,7 +717,6 @@ 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,
@ -740,7 +737,7 @@ struct subd *new_channel_subd_(struct lightningd *ld,
struct subd *sd;
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);
va_end(ap);
return sd;
@ -827,7 +824,6 @@ void subd_release_channel(struct subd *owner, void *channel)
}
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,
@ -838,7 +834,6 @@ void subd_swap_channel_(struct subd *daemon, void *channel,
const char *happenings))
{
daemon->channel = channel;
daemon->ctype = ctype;
daemon->errcb = errcb;
daemon->billboardcb = billboardcb;
}

View File

@ -18,12 +18,6 @@ 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" */
@ -37,7 +31,6 @@ 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;
@ -105,7 +98,6 @@ 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
@ -122,7 +114,6 @@ 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,
@ -139,10 +130,10 @@ struct subd *new_channel_subd_(struct lightningd *ld,
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, \
billboardcb, ...) \
new_channel_subd_((ld), (name), (channel), (ctype), (node_id), \
new_channel_subd_((ld), (name), (channel), (node_id), \
(log), (talks_to_peer), \
(msgname), (msgcb), \
typesafe_cb_postargs(void, void *, (errcb), \
@ -156,8 +147,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, ctype, errcb, billboardcb) \
subd_swap_channel_((subd), (channel), (ctype), \
#define subd_swap_channel(subd, channel, errcb, billboardcb) \
subd_swap_channel_((subd), (channel), \
typesafe_cb_postargs(void, void *, \
(errcb), \
(channel), \
@ -170,7 +161,6 @@ 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,