Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions lightningd/plugin.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
18 changes: 18 additions & 0 deletions tests/test_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Loading