Skip to content

Commit

Permalink
plugin: Allow custom features only if the plugin is not dynamic
Browse files Browse the repository at this point in the history
This is in order to avoid having to update featurebits as plugins get
activated and deactivated.
  • Loading branch information
cdecker committed Feb 6, 2020
1 parent c8d5621 commit fd8d137
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
17 changes: 16 additions & 1 deletion lightningd/plugin.c
Original file line number Diff line number Diff line change
Expand Up @@ -835,7 +835,7 @@ bool plugin_parse_getmanifest_response(const char *buffer,
struct plugin *plugin)
{
const jsmntok_t *resulttok, *dynamictok, *featurestok, *tok;
bool dynamic_plugin;
bool dynamic_plugin, have_featurebits = false;
u8 *featurebits;

resulttok = json_get_member(buffer, toks, "result");
Expand All @@ -845,8 +845,11 @@ bool plugin_parse_getmanifest_response(const char *buffer,
dynamictok = json_get_member(buffer, resulttok, "dynamic");
if (dynamictok && json_to_bool(buffer, dynamictok, &dynamic_plugin))
plugin->dynamic = dynamic_plugin;
else
plugin->dynamic = false;

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,
Expand All @@ -858,6 +861,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 {
Expand All @@ -871,6 +876,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) ||
Expand Down
1 change: 1 addition & 0 deletions tests/plugins/feature-test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# 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,
Expand Down

0 comments on commit fd8d137

Please sign in to comment.