mirror of
https://github.com/ElementsProject/lightning.git
synced 2024-11-19 01:43:36 +01:00
plugin: Make unannounced notification topics no longer fatal
Since plugins will start sending them soon, and they are likely to get it wrong sometimes, be a bit more lenient, warn them in the logs instead and then make sure it doesn't accidentally work anyway.
This commit is contained in:
parent
c8c0c4dc99
commit
98aa3c3da7
@ -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 */
|
||||
|
@ -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()
|
||||
|
@ -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']]
|
||||
|
Loading…
Reference in New Issue
Block a user