mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-03-01 01:32:34 +01:00
mfc: cleanup static declarations/invert call chain
Move only.
This commit is contained in:
parent
db87a5010c
commit
068dc8f5d2
1 changed files with 57 additions and 75 deletions
|
@ -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
|
||||||
|
|| 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 *
|
||||||
|
connect_done(struct multifundchannel_destination *dest)
|
||||||
|
{
|
||||||
|
struct multifundchannel_command *mfc = dest->mfc;
|
||||||
|
|
||||||
|
--mfc->pending;
|
||||||
|
if (mfc->pending == 0)
|
||||||
|
return after_multiconnect(mfc);
|
||||||
|
else
|
||||||
return command_still_pending(mfc->cmd);
|
return command_still_pending(mfc->cmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct command_result *
|
|
||||||
connect_ok(struct command *cmd,
|
|
||||||
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 command *cmd = mfc->cmd;
|
|
||||||
const char *id;
|
|
||||||
struct out_req *req;
|
|
||||||
|
|
||||||
id = node_id_to_hexstr(tmpctx, &dest->id);
|
|
||||||
plugin_log(mfc->cmd->plugin, LOG_DBG,
|
|
||||||
"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
|
|
||||||
json_add_node_id(req->js, "id", &dest->id);
|
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
|
|
Loading…
Add table
Reference in a new issue