From 4737977128cb269cb92eb0a1dd3191d661592e2b Mon Sep 17 00:00:00 2001 From: Christian Decker Date: Mon, 3 Feb 2020 13:04:16 +0100 Subject: [PATCH] plugin: Allow custom features only if the plugin is not dynamic This is in order to avoid having to update featurebits as plugins get activated and deactivated. --- lightningd/plugin.c | 14 ++++++++++++++ tests/plugins/feature-test.py | 1 + 2 files changed, 15 insertions(+) diff --git a/lightningd/plugin.c b/lightningd/plugin.c index 8675290d3..1dc9f2d8c 100644 --- a/lightningd/plugin.c +++ b/lightningd/plugin.c @@ -836,6 +836,7 @@ bool plugin_parse_getmanifest_response(const char *buffer, struct plugin *plugin) { const jsmntok_t *resulttok, *dynamictok, *featurestok, *tok; + bool have_featurebits = false; u8 *featurebits; resulttok = json_get_member(buffer, toks, "result"); @@ -849,6 +850,7 @@ bool plugin_parse_getmanifest_response(const char *buffer, json_tok_full(buffer, dynamictok)); featurestok = json_get_member(buffer, resulttok, "featurebits"); + if (featurestok) { for (int i = 0; i < NUM_PLUGIN_FEATURES_TYPE; i++) { tok = json_get_member(buffer, featurestok, @@ -860,6 +862,8 @@ bool plugin_parse_getmanifest_response(const char *buffer, featurebits = json_tok_bin_from_hex(plugin, buffer, tok); + have_featurebits |= tal_bytelen(featurebits) > 0; + if (featurebits) { plugin->featurebits[i] = featurebits; } else { @@ -873,6 +877,16 @@ bool plugin_parse_getmanifest_response(const char *buffer, } } + if (plugin->dynamic && have_featurebits) { + plugin_kill(plugin, + "Custom featurebits only allows for non-dynamic " + "plugins: dynamic=%d, featurebits=%.*s", + plugin->dynamic, + featurestok->end - featurestok->start, + buffer + featurestok->start); + return true; + } + if (!plugin_opts_add(plugin, buffer, resulttok) || !plugin_rpcmethods_add(plugin, buffer, resulttok) || !plugin_subscriptions_add(plugin, buffer, resulttok) || diff --git a/tests/plugins/feature-test.py b/tests/plugins/feature-test.py index e43954208..8c8c68f9e 100755 --- a/tests/plugins/feature-test.py +++ b/tests/plugins/feature-test.py @@ -5,6 +5,7 @@ from pyln.client import Plugin # Register a different set feature of feature bits for each location so we can # later check that they are being passed correctly. plugin = Plugin( + dynamic=False, init_features=1 << 101, node_features=1 << 103, invoice_features=1 << 105,