Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions plugins/spender/openchannel.c
Original file line number Diff line number Diff line change
Expand Up @@ -1078,15 +1078,20 @@ static struct command_result *signpsbt_done(struct command *aux_cmd,
return send_outreq(req);
}

/* Delay startup recovery so slow wallet signing does not block other
* important plugins from completing their init handshake. */
#define AWAITING_CHANNELS_RECOVERY_DELAY 180

/* If there are any channels with unsigned PSBTs in AWAITING_LOCKIN,
* sign them now (assume we crashed) */
static void list_awaiting_channels(struct command *init_cmd)
static struct command_result *list_awaiting_channels(struct command *timer_cmd,
void *unused UNUSED)
{
const char *buf;
size_t i;
const jsmntok_t *resp, *t, *channels;

resp = jsonrpc_request_sync(tmpctx, init_cmd,
resp = jsonrpc_request_sync(tmpctx, timer_cmd,
"listpeerchannels",
NULL, &buf);
channels = json_get_member(buf, resp, "channels");
Expand All @@ -1113,21 +1118,28 @@ static void list_awaiting_channels(struct command *init_cmd)
continue;

/* Don't do this sync, as it can reasonably fail! */
aux_cmd = aux_command(init_cmd);
aux_cmd = aux_command(timer_cmd);
req = jsonrpc_request_start(aux_cmd, "signpsbt",
signpsbt_done, psbt_error,
tal_dup(aux_cmd, struct channel_id, &cid));
json_add_psbt(req->js, "psbt", psbt);
send_outreq(req);
}

return timer_complete(timer_cmd);
}

void openchannel_init(struct command *init_cmd, const char *b, const jsmntok_t *t)
{
/* Initialize our list! */
list_head_init(&mfc_commands);

list_awaiting_channels(init_cmd);
/* Recover any waiting channel funding PSBTs after plugin startup.
* Signing can be slow on large wallets, and doing it during init can block
* other important builtins from completing their startup handshake. */
global_timer(init_cmd->plugin,
time_from_sec(AWAITING_CHANNELS_RECOVERY_DELAY),
list_awaiting_channels, NULL);
}

const struct plugin_notification openchannel_notifs[] = {
Expand Down