diff --git a/plugins/spender/openchannel.c b/plugins/spender/openchannel.c index 432963d41ab6..2ff5a57098e5 100644 --- a/plugins/spender/openchannel.c +++ b/plugins/spender/openchannel.c @@ -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"); @@ -1113,13 +1118,15 @@ 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) @@ -1127,7 +1134,12 @@ void openchannel_init(struct command *init_cmd, const char *b, const jsmntok_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[] = {