From 65bb989cf179e8c8593cb315cb26a6c508d20ac3 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Fri, 12 Nov 2021 17:14:46 +1030 Subject: [PATCH] pytest: don't checksum plugins on startup in VALGRIND developer mode. This loads up 20MB of plugins temporarily; we seem to be getting OOM killed under CI and I wonder if this is contributing. Doesn't significantly reduce runtime here, but I have lots of memory. Signed-off-by: Rusty Russell --- contrib/pyln-testing/pyln/testing/utils.py | 1 + lightningd/lightningd.c | 1 + lightningd/lightningd.h | 3 +++ lightningd/options.c | 4 ++++ lightningd/plugin.c | 13 +++++++++---- tests/test_plugin.py | 3 +++ 6 files changed, 21 insertions(+), 4 deletions(-) diff --git a/contrib/pyln-testing/pyln/testing/utils.py b/contrib/pyln-testing/pyln/testing/utils.py index f986e4ffc..dfc2fd666 100644 --- a/contrib/pyln-testing/pyln/testing/utils.py +++ b/contrib/pyln-testing/pyln/testing/utils.py @@ -675,6 +675,7 @@ class LightningNode(object): self.daemon.opts["dev-debugger"] = os.getenv("DEBUG_SUBD") if valgrind: self.daemon.env["LIGHTNINGD_DEV_NO_BACKTRACE"] = "1" + self.daemon.opts["dev-no-plugin-checksum"] = None else: # Under valgrind, scanning can access uninitialized mem. self.daemon.env["LIGHTNINGD_DEV_MEMLEAK"] = "1" diff --git a/lightningd/lightningd.c b/lightningd/lightningd.c index 1af81a790..b20520d4a 100644 --- a/lightningd/lightningd.c +++ b/lightningd/lightningd.c @@ -114,6 +114,7 @@ static struct lightningd *new_lightningd(const tal_t *ctx) * same exact code users will be running. */ #if DEVELOPER ld->dev_debug_subprocess = NULL; + ld->dev_no_plugin_checksum = false; ld->dev_disconnect_fd = -1; ld->dev_subdaemon_fail = false; ld->dev_allow_localhost = false; diff --git a/lightningd/lightningd.h b/lightningd/lightningd.h index 553f10a78..772de8392 100644 --- a/lightningd/lightningd.h +++ b/lightningd/lightningd.h @@ -207,6 +207,9 @@ struct lightningd { /* If we want to debug a subdaemon/plugin. */ const char *dev_debug_subprocess; + /* If we have --dev-no-plugin-checksum */ + bool dev_no_plugin_checksum; + /* If we have a --dev-disconnect file */ int dev_disconnect_fd; diff --git a/lightningd/options.c b/lightningd/options.c index b666a26ee..54dde2aa6 100644 --- a/lightningd/options.c +++ b/lightningd/options.c @@ -584,6 +584,10 @@ static void dev_register_opts(struct lightningd *ld) opt_register_early_arg("--dev-debugger=", opt_subprocess_debug, NULL, ld, "Invoke gdb at start of "); + opt_register_early_noarg("--dev-no-plugin-checksum", opt_set_bool, + &ld->dev_no_plugin_checksum, + "Don't checksum plugins to detect changes"); + opt_register_noarg("--dev-no-reconnect", opt_set_invbool, &ld->reconnect, "Disable automatic reconnect-attempts by this node, but accept incoming"); diff --git a/lightningd/plugin.c b/lightningd/plugin.c index 39e6e480c..ee3c2c967 100644 --- a/lightningd/plugin.c +++ b/lightningd/plugin.c @@ -209,9 +209,14 @@ static void destroy_plugin(struct plugin *p) } } -static u32 file_checksum(const char* path) +static u32 file_checksum(struct lightningd *ld, const char *path) { - char *content = grab_file(tmpctx, path); + char *content; + + if (IFDEV(ld->dev_no_plugin_checksum, false)) + return 0; + + content = grab_file(tmpctx, path); if (content == NULL) return 0; return crc32c(0, content, tal_count(content)); } @@ -231,7 +236,7 @@ struct plugin *plugin_register(struct plugins *plugins, const char* path TAKES, if (important) p_temp->important = true; /* stop and restart plugin on different checksum */ - chksum = file_checksum(path); + chksum = file_checksum(plugins->ld, path); if (p_temp->checksum != chksum && !p_temp->important) { plugin_kill(p_temp, LOG_INFORM, "Plugin changed, needs restart."); @@ -246,7 +251,7 @@ struct plugin *plugin_register(struct plugins *plugins, const char* path TAKES, p = tal(plugins, struct plugin); p->plugins = plugins; p->cmd = tal_strdup(p, path); - p->checksum = file_checksum(p->cmd); + p->checksum = file_checksum(plugins->ld, p->cmd); p->shortname = path_basename(p, p->cmd); p->start_cmd = start_cmd; diff --git a/tests/test_plugin.py b/tests/test_plugin.py index b590ba680..c8eeff434 100644 --- a/tests/test_plugin.py +++ b/tests/test_plugin.py @@ -2520,6 +2520,9 @@ plugin.run() # get a node that is not started so we can put a plugin in its lightning_dir n = node_factory.get_node(start=False) + if "dev-no-plugin-checksum" in n.daemon.opts: + del n.daemon.opts["dev-no-plugin-checksum"] + lndir = n.daemon.lightning_dir # write hello world plugin to lndir/plugins