From a4c41a06a4f4ff746b3b0415dbdfb07eb725c4b8 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Thu, 11 Nov 2021 14:41:44 +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 +++++++++---- 5 files changed, 18 insertions(+), 4 deletions(-) diff --git a/contrib/pyln-testing/pyln/testing/utils.py b/contrib/pyln-testing/pyln/testing/utils.py index f986e4ffcdae..dfc2fd666017 100644 --- a/contrib/pyln-testing/pyln/testing/utils.py +++ b/contrib/pyln-testing/pyln/testing/utils.py @@ -675,6 +675,7 @@ def __init__(self, node_id, lightning_dir, bitcoind, executor, valgrind, may_fai 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 1af81a79032b..b20520d4ae7a 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 553f10a785b4..772de83923b3 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 b666a26ee17b..54dde2aa640d 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 39e6e480c939..ee3c2c967a78 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;