From 1ded3fc52f7148bbb0b36cf9bdc056ca469dbce7 Mon Sep 17 00:00:00 2001 From: ZmnSCPxj jxPCSnmZ Date: Tue, 4 Aug 2020 15:24:42 +0800 Subject: [PATCH] lightningd/plugin.c: Add a `--dev-builtin-plugins-unimportant` for developers who want to mess around with the builtin plugins. --- lightningd/options.c | 4 ++++ lightningd/plugin.c | 24 ++++++++++++++++++++++++ lightningd/plugin.h | 5 +++++ tests/test_plugin.py | 6 ++++++ 4 files changed, 39 insertions(+) diff --git a/lightningd/options.c b/lightningd/options.c index ba0099dd7..a1dad4f22 100644 --- a/lightningd/options.c +++ b/lightningd/options.c @@ -566,6 +566,10 @@ static void dev_register_opts(struct lightningd *ld) opt_register_noarg("--dev-no-version-checks", opt_set_bool, &ld->dev_no_version_checks, "Skip calling subdaemons with --version on startup"); + opt_register_early_noarg("--dev-builtin-plugins-unimportant", + opt_set_bool, + &ld->plugins->dev_builtin_plugins_unimportant, + "Make builtin plugins unimportant so you can plugin stop them."); } #endif /* DEVELOPER */ diff --git a/lightningd/plugin.c b/lightningd/plugin.c index 028ce8eb6..d117b7cef 100644 --- a/lightningd/plugin.c +++ b/lightningd/plugin.c @@ -57,6 +57,9 @@ struct plugins *plugins_new(const tal_t *ctx, struct log_book *log_book, p->json_cmds = tal_arr(p, struct command *, 0); p->blacklist = tal_arr(p, const char *, 0); p->shutdown = false; +#if DEVELOPER + p->dev_builtin_plugins_unimportant = false; +#endif /* DEVELOPER */ uintmap_init(&p->pending_requests); memleak_add_helper(p, memleak_help_pending_requests); @@ -1328,6 +1331,27 @@ void plugins_init(struct plugins *plugins) plugins->default_dir = path_join(plugins, plugins->ld->config_basedir, "plugins"); plugins_add_default_dir(plugins); +#if DEVELOPER + if (plugins->dev_builtin_plugins_unimportant) { + size_t i; + + log_debug(plugins->log, "Builtin plugins now unimportant"); + + /* For each builtin plugin, check for a matching plugin + * and make it unimportant. */ + for (i = 0; list_of_builtin_plugins[i]; ++i) { + const char *name = list_of_builtin_plugins[i]; + struct plugin *p; + list_for_each(&plugins->plugins, p, list) { + if (plugin_paths_match(p->cmd, name)) { + p->important = false; + break; + } + } + } + } +#endif /* DEVELOPER */ + setenv("LIGHTNINGD_PLUGIN", "1", 1); setenv("LIGHTNINGD_VERSION", version(), 1); diff --git a/lightningd/plugin.h b/lightningd/plugin.h index 5b4947460..1e4338f84 100644 --- a/lightningd/plugin.h +++ b/lightningd/plugin.h @@ -110,6 +110,11 @@ struct plugins { /* Whether we are shutting down (`plugins_free` is called) */ bool shutdown; + +#if DEVELOPER + /* Whether builtin plugins should be overridden as unimportant. */ + bool dev_builtin_plugins_unimportant; +#endif /* DEVELOPER */ }; /* The value of a plugin option, which can have different types. diff --git a/tests/test_plugin.py b/tests/test_plugin.py index 49dcd202f..a1830c9a7 100644 --- a/tests/test_plugin.py +++ b/tests/test_plugin.py @@ -1596,3 +1596,9 @@ def test_important_plugin(node_factory): # node should die as well. n.daemon.wait_for_log('pay: Plugin marked as important, shutting down lightningd') wait_for(lambda: not n.daemon.running) + + +@unittest.skipIf(not DEVELOPER, "tests developer-only option.") +def test_dev_builtin_plugins_unimportant(node_factory): + n = node_factory.get_node(options={"dev-builtin-plugins-unimportant": None}) + n.rpc.plugin_stop(plugin="pay")