From 7a95e90ee4d4143ffd81814587433a8490a59c2b Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Thu, 2 Apr 2020 14:35:47 +1030 Subject: [PATCH] plugins: add `feature_set` to init object. Shows what features we use in various contexts, including those added by plugins in getmanifest. Signed-off-by: Rusty Russell Changelog-Added: Plugin: `feature_set` object added to `init` --- lightningd/plugin.c | 9 +++++++++ tests/plugins/show_feature_set.py | 17 +++++++++++++++++ tests/test_plugin.py | 11 +++++++++++ 3 files changed, 37 insertions(+) create mode 100755 tests/plugins/show_feature_set.py diff --git a/lightningd/plugin.c b/lightningd/plugin.c index f00b66e9b..a40f878fd 100644 --- a/lightningd/plugin.c +++ b/lightningd/plugin.c @@ -1169,6 +1169,15 @@ plugin_populate_init_request(struct plugin *plugin, struct jsonrpc_request *req) json_add_string(req->stream, "rpc-file", ld->rpc_filename); json_add_bool(req->stream, "startup", plugin->plugins->startup); json_add_string(req->stream, "network", chainparams->network_name); + json_object_start(req->stream, "feature_set"); + for (enum feature_place fp = 0; fp < NUM_FEATURE_PLACE; fp++) { + if (plugin_feature_place_names[fp]) { + json_add_hex_talarr(req->stream, + plugin_feature_place_names[fp], + ld->feature_set->bits[fp]); + } + } + json_object_end(req->stream); json_object_end(req->stream); } diff --git a/tests/plugins/show_feature_set.py b/tests/plugins/show_feature_set.py new file mode 100755 index 000000000..060f59e28 --- /dev/null +++ b/tests/plugins/show_feature_set.py @@ -0,0 +1,17 @@ +#!/usr/bin/env python3 +from pyln.client import Plugin + +plugin = Plugin() + + +@plugin.init() +def init(options, configuration, plugin): + plugin.feature_set = configuration['feature_set'] + + +@plugin.method('getfeatureset') +def getfeatureset(plugin): + return plugin.feature_set + + +plugin.run() diff --git a/tests/test_plugin.py b/tests/test_plugin.py index c32bacdc6..2bb49d3bb 100644 --- a/tests/test_plugin.py +++ b/tests/test_plugin.py @@ -1153,3 +1153,14 @@ def test_hook_crash(node_factory, executor, bitcoind): # Collect the results: [f.result(TIMEOUT) for f in futures] + + +def test_feature_set(node_factory): + plugin = os.path.join(os.path.dirname(__file__), 'plugins/show_feature_set.py') + l1 = node_factory.get_node(options={"plugin": plugin}) + + fs = l1.rpc.call('getfeatureset') + assert fs['init'] == expected_features() + assert fs['node'] == expected_features() + assert fs['channel'] == '' + assert 'invoice' in fs