diff --git a/lightningd/plugin.c b/lightningd/plugin.c index 036903e91dae..deb29c4ce02a 100644 --- a/lightningd/plugin.c +++ b/lightningd/plugin.c @@ -1393,11 +1393,18 @@ static const char *plugin_rpcmethod_add(struct plugin *plugin, if (!jsonrpc_command_add(plugin->plugins->ld->jsonrpc, cmd, usage)) { struct plugin *p = find_plugin_for_command(plugin->plugins->ld, cmd->name); - return tal_fmt( - plugin, - "Could not register method \"%s\", a method with " - "that name is already registered by plugin %s", - cmd->name, p->cmd); + if (p) + return tal_fmt( + plugin, + "Could not register method \"%s\", a method with " + "that name is already registered by plugin %s", + cmd->name, p->cmd); + else + return tal_fmt(plugin, + "Could not register method \"%s\", a " + "builtin method with " + "that name is already registered", + cmd->name); } tal_arr_expand(&plugin->methods, cmd->name); return NULL; diff --git a/tests/test_plugin.py b/tests/test_plugin.py index bb4604aaf33c..65d145b19afa 100644 --- a/tests/test_plugin.py +++ b/tests/test_plugin.py @@ -6134,3 +6134,21 @@ def test_bwatch_blockdepth_watch_no_fire_before_start_block(node_factory, bitcoi # Clean up l1.rpc.delblockdepthwatch(owner=owner, start_block=future_start) + + +def test_command_collision(node_factory): + def xpay_duplicate(plugin): + @plugin.method("xpay") + def on_xpay(plugin): + return {} + l1 = node_factory.get_node(inline_plugin=xpay_duplicate) + l1.daemon.logsearch_start = 0 + l1.daemon.wait_for_log("a method with that name is already registered by plugin") + + def builtin_duplicate(plugin): + @plugin.method("getinfo") + def on_getinfo(plugin): + return {} + l2 = node_factory.get_node(inline_plugin=builtin_duplicate) + l2.daemon.logsearch_start = 0 + l2.daemon.wait_for_log("a builtin method with that name is already registered")