diff --git a/lightningd/plugin.c b/lightningd/plugin.c index 5d031e73af9a..42718c27bb7a 100644 --- a/lightningd/plugin.c +++ b/lightningd/plugin.c @@ -1821,7 +1821,7 @@ static const char *plugin_parse_getmanifest_response(const char *buffer, } /* Store fset to allow to remove feature bits when init returns disabled */ - plugin->fset = tal_dup_or_null(plugin, struct feature_set, fset); + plugin->fset = feature_set_dup(plugin, fset); } else { plugin->fset = NULL; } diff --git a/tests/plugins/feature-test.py b/tests/plugins/feature-test.py index 02be45004e5c..37f27fc2c450 100755 --- a/tests/plugins/feature-test.py +++ b/tests/plugins/feature-test.py @@ -12,4 +12,12 @@ ) +@plugin.init() +def init(configuration, options, plugin): + if options.get('disable-on-init'): + return {'disable': 'init saying disable'} + return {} + + +plugin.add_option('disable-on-init', False, 'disable plugin on init', opt_type='bool') plugin.run() diff --git a/tests/test_plugin.py b/tests/test_plugin.py index 82f832d42c2c..7e15fbf2d304 100644 --- a/tests/test_plugin.py +++ b/tests/test_plugin.py @@ -1748,6 +1748,27 @@ def test_plugin_feature_announce(node_factory): assert node['features'] == expected_node_features(extra=[203]) +def test_plugin_feature_remove(node_factory): + """Check that features registered by plugins get removed if a plugin + disables itself. + + We set the following feature bits we don't want to include if the plugin is + disabled during init. + - 1 << 201 for `init` messages + - 1 << 203 for `node_announcement` + - 1 << 205 for bolt11 invoices + """ + + plugin = os.path.join(os.path.dirname(__file__), 'plugins/feature-test.py') + l1 = node_factory.get_node(options={'plugin': plugin, 'disable-on-init': True}) + + # Check that we don't include the features set in getmanifest. + our_feats = l1.rpc.getinfo()["our_features"] + assert((int(our_feats["init"], 16) & (1 << 201)) == 0) + assert((int(our_feats["node"], 16) & (1 << 203)) == 0) + assert((int(our_feats["invoice"], 16) & (1 << 205)) == 0) + + def test_hook_chaining(node_factory): """Check that hooks are called in order and the chain exits correctly