diff --git a/lightningd/plugin.c b/lightningd/plugin.c index 587e3c9dc..cee3da116 100644 --- a/lightningd/plugin.c +++ b/lightningd/plugin.c @@ -464,32 +464,21 @@ static const char *plugin_notification_handle(struct plugin *plugin, methname = json_strdup(tmpctx, plugin->buffer, methtok); - if (notifications_have_topic(plugin->plugins, methname)) { - - if (!plugin_notification_allowed(plugin, methname)) { - log_unusual( - plugin->log, + if (!plugin_notification_allowed(plugin, methname)) { + log_unusual(plugin->log, "Plugin attempted to send a notification to topic " "\"%s\" it hasn't declared in its manifest, not " "forwarding to subscribers.", methname); - return NULL; - } else { + } else if (notifications_have_topic(plugin->plugins, methname)) { + n = jsonrpc_notification_start(NULL, methname); + json_add_string(n->stream, "origin", plugin->shortname); + json_add_tok(n->stream, "payload", paramstok, plugin->buffer); + jsonrpc_notification_end(n); - n = jsonrpc_notification_start(NULL, methname); - json_add_string(n->stream, "origin", plugin->shortname); - json_add_tok(n->stream, "payload", paramstok, - plugin->buffer); - jsonrpc_notification_end(n); - - plugins_notify(plugin->plugins, take(n)); - return NULL; - } - } else { - return tal_fmt(plugin, "Unknown notification method %.*s", - json_tok_full_len(methtok), - json_tok_full(plugin->buffer, methtok)); + plugins_notify(plugin->plugins, take(n)); } + return NULL; } /* Returns the error string, or NULL */ diff --git a/tests/plugins/custom_notifications.py b/tests/plugins/custom_notifications.py index 570543950..092f2d2c2 100755 --- a/tests/plugins/custom_notifications.py +++ b/tests/plugins/custom_notifications.py @@ -17,5 +17,19 @@ def emit(plugin): plugin.notify("custom", "Hello world") +@plugin.method("faulty-emit") +def faulty_emit(plugin): + """Emit a simple string notification to topic "custom" + """ + plugin.notify("ididntannouncethis", "Hello world") + + +@plugin.subscribe("ididntannouncethis") +def on_faulty_emit(origin, payload, **kwargs): + """We should never receive this as it gets dropped. + """ + plugin.log("Got the ididntannouncethis event") + + plugin.add_notification_topic("custom") plugin.run() diff --git a/tests/test_plugin.py b/tests/test_plugin.py index d16cc75fd..4691873bb 100644 --- a/tests/test_plugin.py +++ b/tests/test_plugin.py @@ -2411,3 +2411,15 @@ def test_custom_notification_topics(node_factory): l1 = node_factory.get_node(options={'plugin': plugin}) l1.rpc.emit() l1.daemon.wait_for_log(r'Got a custom notification Hello world') + + # And now make sure that we drop unannounced notifications + l1.rpc.faulty_emit() + l1.daemon.wait_for_log( + r"Plugin attempted to send a notification to topic .* not forwarding" + ) + time.sleep(1) + assert not l1.daemon.is_in_log(r'Got the ididntannouncethis event') + + # The plugin just dist what previously was a fatal mistake (emit + # an unknown notification), make sure we didn't kill it. + assert 'custom_notifications.py' in [p['name'] for p in l1.rpc.listconfigs()['plugins']]