mfc: cleanup static declarations/invert call chain

Move only.
This commit is contained in:
niftynei 2021-03-09 15:55:18 -06:00 committed by Rusty Russell
parent db87a5010c
commit 068dc8f5d2

View file

@ -453,68 +453,49 @@ And with a *multi* funding, it is more likely to
fail due to having to coordinate many more nodes. fail due to having to coordinate many more nodes.
*/ */
static void
connect_dest(struct multifundchannel_destination *dest);
/* Initiate the multiconnect. */
static struct command_result * static struct command_result *
perform_multiconnect(struct multifundchannel_command *mfc) perform_fundpsbt(struct multifundchannel_command *mfc);
/* Check results of connect. */
static struct command_result *
after_multiconnect(struct multifundchannel_command *mfc)
{ {
unsigned int i; unsigned int i;
plugin_log(mfc->cmd->plugin, LOG_DBG, plugin_log(mfc->cmd->plugin, LOG_DBG,
"mfc %"PRIu64": multiconnect.", mfc->id); "mfc %"PRIu64": multiconnect done.", mfc->id);
mfc->pending = tal_count(mfc->destinations); /* Check if anyone failed. */
for (i = 0; i < tal_count(mfc->destinations); ++i) {
struct multifundchannel_destination *dest;
for (i = 0; i < tal_count(mfc->destinations); ++i) dest = &mfc->destinations[i];
connect_dest(&mfc->destinations[i]);
assert(mfc->pending != 0); assert(dest->state == MULTIFUNDCHANNEL_CONNECTED
return command_still_pending(mfc->cmd); || dest->state == MULTIFUNDCHANNEL_FAILED);
if (dest->state != MULTIFUNDCHANNEL_FAILED)
continue;
/* One of them failed, oh no. */
return redo_multifundchannel(mfc, "connect");
}
return perform_fundpsbt(mfc);
} }
static struct command_result * static struct command_result *
connect_ok(struct command *cmd, connect_done(struct multifundchannel_destination *dest)
const char *buf,
const jsmntok_t *result,
struct multifundchannel_destination *dest);
static struct command_result *
connect_err(struct command *cmd,
const char *buf,
const jsmntok_t *error,
struct multifundchannel_destination *dest);
static void
connect_dest(struct multifundchannel_destination *dest)
{ {
struct multifundchannel_command *mfc = dest->mfc; struct multifundchannel_command *mfc = dest->mfc;
struct command *cmd = mfc->cmd;
const char *id;
struct out_req *req;
id = node_id_to_hexstr(tmpctx, &dest->id); --mfc->pending;
plugin_log(mfc->cmd->plugin, LOG_DBG, if (mfc->pending == 0)
"mfc %"PRIu64", dest %u: connect %s.", return after_multiconnect(mfc);
mfc->id, dest->index, id);
req = jsonrpc_request_start(cmd->plugin, cmd,
"connect",
&connect_ok,
&connect_err,
dest);
if (dest->addrhint)
json_add_string(req->js, "id",
tal_fmt(tmpctx, "%s@%s",
id,
dest->addrhint));
else else
json_add_node_id(req->js, "id", &dest->id); return command_still_pending(mfc->cmd);
send_outreq(cmd->plugin, req);
} }
static struct command_result *
connect_done(struct multifundchannel_destination *dest);
static struct command_result * static struct command_result *
connect_ok(struct command *cmd, connect_ok(struct command *cmd,
@ -553,6 +534,7 @@ connect_ok(struct command *cmd,
dest->state = MULTIFUNDCHANNEL_CONNECTED; dest->state = MULTIFUNDCHANNEL_CONNECTED;
return connect_done(dest); return connect_done(dest);
} }
static struct command_result * static struct command_result *
connect_err(struct command *cmd, connect_err(struct command *cmd,
const char *buf, const char *buf,
@ -587,50 +569,50 @@ connect_err(struct command *cmd,
return connect_done(dest); return connect_done(dest);
} }
static struct command_result * static void
after_multiconnect(struct multifundchannel_command *mfc); connect_dest(struct multifundchannel_destination *dest)
static struct command_result *
connect_done(struct multifundchannel_destination *dest)
{ {
struct multifundchannel_command *mfc = dest->mfc; struct multifundchannel_command *mfc = dest->mfc;
struct command *cmd = mfc->cmd;
const char *id;
struct out_req *req;
--mfc->pending; id = node_id_to_hexstr(tmpctx, &dest->id);
if (mfc->pending == 0) plugin_log(mfc->cmd->plugin, LOG_DBG,
return after_multiconnect(mfc); "mfc %"PRIu64", dest %u: connect %s.",
mfc->id, dest->index, id);
req = jsonrpc_request_start(cmd->plugin, cmd,
"connect",
&connect_ok,
&connect_err,
dest);
if (dest->addrhint)
json_add_string(req->js, "id",
tal_fmt(tmpctx, "%s@%s",
id,
dest->addrhint));
else else
return command_still_pending(mfc->cmd); json_add_node_id(req->js, "id", &dest->id);
send_outreq(cmd->plugin, req);
} }
/* Initiate the multiconnect. */
static struct command_result * static struct command_result *
perform_fundpsbt(struct multifundchannel_command *mfc); perform_multiconnect(struct multifundchannel_command *mfc)
/* Check results of connect. */
static struct command_result *
after_multiconnect(struct multifundchannel_command *mfc)
{ {
unsigned int i; unsigned int i;
plugin_log(mfc->cmd->plugin, LOG_DBG, plugin_log(mfc->cmd->plugin, LOG_DBG,
"mfc %"PRIu64": multiconnect done.", mfc->id); "mfc %"PRIu64": multiconnect.", mfc->id);
/* Check if anyone failed. */ mfc->pending = tal_count(mfc->destinations);
for (i = 0; i < tal_count(mfc->destinations); ++i) {
struct multifundchannel_destination *dest;
dest = &mfc->destinations[i]; for (i = 0; i < tal_count(mfc->destinations); ++i)
connect_dest(&mfc->destinations[i]);
assert(dest->state == MULTIFUNDCHANNEL_CONNECTED assert(mfc->pending != 0);
|| dest->state == MULTIFUNDCHANNEL_FAILED); return command_still_pending(mfc->cmd);
if (dest->state != MULTIFUNDCHANNEL_FAILED)
continue;
/* One of them failed, oh no. */
return redo_multifundchannel(mfc, "connect");
}
return perform_fundpsbt(mfc);
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/