Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamic plugin cleanups #3679

Merged
merged 24 commits into from
May 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
020bdd1
lightningd: fix race where we do rescan before all plugins finish init.
rustyrussell May 4, 2020
02e1698
plugin_hook_call: return indication whether we called the callback or…
rustyrussell May 5, 2020
7387f22
lightningd: avoid plugin timer indirection.
rustyrussell May 5, 2020
6cbb44c
lightningd: remove obsolete FIXME comment.
rustyrussell May 5, 2020
c183b06
lightningd: complete plugin state machine.
rustyrussell May 5, 2020
b9b86ed
lightningd: plugins_any_in_state and plugins_all_in_state helpers.
rustyrussell May 5, 2020
4631ed5
lightningd: remove counter for pending_manifests in favor of checking…
rustyrussell May 5, 2020
140e0b8
lightningd: attach plugins natively to the command which started it.
rustyrussell May 5, 2020
981c152
pytest: add test for a plugin which falls over outside a command.
rustyrussell May 5, 2020
ded2eaa
lightningd: refactor to extract getmanifest paths.
rustyrussell May 5, 2020
d51514c
pytest: test loading all plugins at once, including failing ones.
rustyrussell May 5, 2020
605f76f
lightningd: unify dynamic and static plugin initialization.
rustyrussell May 5, 2020
7d6f09c
lightningd: make plugin response functions return the error.
rustyrussell May 5, 2020
00fffac
lightningd: plugin init routines return error string or NULL.
rustyrussell May 5, 2020
8f4a93e
lightningd: make plugin_kill() free the plugin.
rustyrussell May 5, 2020
eb94a9a
lightningd: make plugin opts free themselves.
rustyrussell May 5, 2020
a0f9ec6
lightningd: have plugin_send_getmanifest return an error string.
rustyrussell May 5, 2020
aee9276
lightningd: make plugin_kill take a simple string.
rustyrussell May 5, 2020
dd18a45
lightningd: remove `stop` member from plugin.
rustyrussell May 5, 2020
4cac01d
lightningd: final cleanup for plugins.
rustyrussell May 5, 2020
6050adc
lightningd: have plugin-disable be more persistent.
rustyrussell May 5, 2020
92c51e7
lightningd: list disabled plugins in listconfig.
rustyrussell May 5, 2020
f157ada
lightningd: simplify plugin stdin/stdout initialization.
rustyrussell May 5, 2020
b2ec70a
lightningd: fix obsolete comment.
rustyrussell May 5, 2020
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
8 changes: 5 additions & 3 deletions doc/lightningd-config.5
Original file line number Diff line number Diff line change
Expand Up @@ -528,9 +528,11 @@ normal effect\.


\fBdisable-plugin\fR=\fIPLUGIN\fR
If \fIPLUGIN\fR contains a /, plugins with the same path as \fIPLUGIN\fR are
disabled\. Otherwise, any plugin with that base name is disabled,
whatever directory it is in\.
If \fIPLUGIN\fR contains a /, plugins with the same path as \fIPLUGIN\fR will
not be loaded at startup\. Otherwise, no plugin with that base name will
be loaded at startup, whatever directory it is in\. This option is useful for
disabling a single plugin inside a directory\. You can still explicitly
load plugins which have been disabled, using \fBlightning-plugin\fR(7) \fBstart\fR\.

.SH BUGS

Expand Down
8 changes: 5 additions & 3 deletions doc/lightningd-config.5.md
Original file line number Diff line number Diff line change
Expand Up @@ -434,9 +434,11 @@ including the default built-in plugin directory. You can still add
normal effect.

**disable-plugin**=*PLUGIN*
If *PLUGIN* contains a /, plugins with the same path as *PLUGIN* are
disabled. Otherwise, any plugin with that base name is disabled,
whatever directory it is in.
If *PLUGIN* contains a /, plugins with the same path as *PLUGIN* will
not be loaded at startup. Otherwise, no plugin with that base name will
be loaded at startup, whatever directory it is in. This option is useful for
disabling a single plugin inside a directory. You can still explicitly
load plugins which have been disabled, using lightning-plugin(7) `start`.

BUGS
----
Expand Down
5 changes: 3 additions & 2 deletions lightningd/bitcoind.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ static void plugin_config_cb(const char *buffer,
const jsmntok_t *idtok,
struct plugin *plugin)
{
plugin->plugin_state = CONFIGURED;
plugin->plugin_state = INIT_COMPLETE;
io_break(plugin);
}

Expand Down Expand Up @@ -77,8 +77,9 @@ static void wait_plugin(struct bitcoind *bitcoind, const char *method,
* before responding to `init`).
* Note that lightningd/plugin will not send `init` to an already
* configured plugin. */
if (p->plugin_state != CONFIGURED)
if (p->plugin_state == NEEDS_INIT)
config_plugin(p);

strmap_add(&bitcoind->pluginsmap, method, p);
}

Expand Down
18 changes: 9 additions & 9 deletions lightningd/jsonrpc.c
Original file line number Diff line number Diff line change
Expand Up @@ -774,11 +774,6 @@ REGISTER_SINGLE_PLUGIN_HOOK(rpc_command,
rpc_command_hook_serialize,
struct rpc_command_hook_payload *);

static void call_rpc_command_hook(struct rpc_command_hook_payload *p)
{
plugin_hook_call_rpc_command(p->cmd->ld, p);
}

/* We return struct command_result so command_fail return value has a natural
* sink; we don't actually use the result. */
static struct command_result *
Expand All @@ -787,6 +782,7 @@ parse_request(struct json_connection *jcon, const jsmntok_t tok[])
const jsmntok_t *method, *id, *params;
struct command *c;
struct rpc_command_hook_payload *rpc_hook;
bool completed;

if (tok[0].type != JSMN_OBJECT) {
json_command_malformed(jcon, "null",
Expand Down Expand Up @@ -850,11 +846,15 @@ parse_request(struct json_connection *jcon, const jsmntok_t tok[])
/* Duplicate since we might outlive the connection */
rpc_hook->buffer = tal_dup_talarr(rpc_hook, char, jcon->buffer);
rpc_hook->request = tal_dup_talarr(rpc_hook, jsmntok_t, tok);
/* Prevent a race between was_pending and still_pending */
new_reltimer(c->ld->timers, rpc_hook, time_from_msec(1),
call_rpc_command_hook, rpc_hook);
Comment on lines -853 to -855
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉


return command_still_pending(c);
db_begin_transaction(jcon->ld->wallet->db);
completed = plugin_hook_call_rpc_command(jcon->ld, rpc_hook);
db_commit_transaction(jcon->ld->wallet->db);

/* If it's deferred, mark it (otherwise, it's completed) */
if (!completed)
return command_still_pending(c);
return NULL;
rustyrussell marked this conversation as resolved.
Show resolved Hide resolved
}

/* Mutual recursion */
Expand Down
4 changes: 2 additions & 2 deletions lightningd/lightningd.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ static struct lightningd *new_lightningd(const tal_t *ctx)
* is a nod to keeping it minimal and explicit: we need this code for
* testing, but its existence means we're not actually testing the
* same exact code users will be running. */
ld->dev_debug_subprocess = NULL;
#if DEVELOPER
ld->dev_debug_subprocess = NULL;
ld->dev_disconnect_fd = -1;
ld->dev_subdaemon_fail = false;
ld->dev_allow_localhost = false;
Expand Down Expand Up @@ -808,7 +808,7 @@ int main(int argc, char *argv[])
/*~ Initialize all the plugins we just registered, so they can
* do their thing and tell us about themselves (including
* options registration). */
plugins_init(ld->plugins, ld->dev_debug_subprocess);
plugins_init(ld->plugins);

/*~ Handle options and config. */
handle_opts(ld, argc, argv);
Expand Down
6 changes: 3 additions & 3 deletions lightningd/lightningd.h
Original file line number Diff line number Diff line change
Expand Up @@ -200,15 +200,15 @@ struct lightningd {
* if we are the fundee. */
u32 max_funding_unconfirmed;

/* If we want to debug a subdaemon/plugin. */
const char *dev_debug_subprocess;

/* RPC which asked us to shutdown, if non-NULL */
struct io_conn *stop_conn;
/* RPC response to send once we've shut down. */
const char *stop_response;

#if DEVELOPER
/* If we want to debug a subdaemon/plugin. */
const char *dev_debug_subprocess;

/* If we have a --dev-disconnect file */
int dev_disconnect_fd;

Expand Down
14 changes: 9 additions & 5 deletions lightningd/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -343,15 +343,18 @@ static char *opt_add_proxy_addr(const char *arg, struct lightningd *ld)

static char *opt_add_plugin(const char *arg, struct lightningd *ld)
{
plugin_register(ld->plugins, arg);
if (plugin_blacklisted(ld->plugins, arg)) {
log_info(ld->log, "%s: disabled via disable-plugin", arg);
return NULL;
}
plugin_register(ld->plugins, arg, NULL);
return NULL;
}

static char *opt_disable_plugin(const char *arg, struct lightningd *ld)
{
if (plugin_remove(ld->plugins, arg))
return NULL;
return tal_fmt(NULL, "Could not find plugin %s", arg);
plugin_blacklist(ld->plugins, arg);
return NULL;
}

static char *opt_add_plugin_dir(const char *arg, struct lightningd *ld)
Expand Down Expand Up @@ -1275,8 +1278,9 @@ static void add_config(struct lightningd *ld,
json_add_opt_plugins(response, ld->plugins);
} else if (opt->cb_arg == (void *)opt_log_level) {
json_add_opt_log_levels(response, ld->log);
} else if (opt->cb_arg == (void *)opt_disable_plugin) {
json_add_opt_disable_plugins(response, ld->plugins);
} else if (opt->cb_arg == (void *)opt_add_plugin_dir
|| opt->cb_arg == (void *)opt_disable_plugin
|| opt->cb_arg == (void *)plugin_opt_set
|| opt->cb_arg == (void *)plugin_opt_flag_set) {
/* FIXME: We actually treat it as if they specified
Expand Down
Loading