diff --git a/lightningd/peer_control.c b/lightningd/peer_control.c index d674ba5f1..3de82c74a 100644 --- a/lightningd/peer_control.c +++ b/lightningd/peer_control.c @@ -2404,6 +2404,16 @@ static struct command_result *json_sendcustommsg(struct command *cmd, type, wire_type_name(type)); } + if (type % 2 == 0) { + return command_fail( + cmd, JSONRPC2_INVALID_REQUEST, + "Cannot send even-typed %d custom message. Currently " + "custom messages are limited to odd-numbered message " + "types, as even-numbered types might result in " + "disconnections.", + type); + } + peer = peer_by_id(cmd->ld, dest); if (!peer) { return command_fail(cmd, JSONRPC2_INVALID_REQUEST, diff --git a/tests/test_misc.py b/tests/test_misc.py index 648374fa7..fe2bd5a65 100644 --- a/tests/test_misc.py +++ b/tests/test_misc.py @@ -2096,6 +2096,12 @@ def test_sendcustommsg(node_factory): with pytest.raises(RpcError, match=r'Cannot send messages of type 18 .WIRE_PING.'): l2.rpc.dev_sendcustommsg(l2.info['id'], r'0012') + # The sendcustommsg RPC call is currently limited to odd-typed messages, + # since they will not result in disconnections or even worse channel + # failures. + with pytest.raises(RpcError, match=r'Cannot send even-typed [0-9]+ custom message'): + l2.rpc.dev_sendcustommsg(l2.info['id'], r'00FE') + # This should work since the peer is currently owned by `channeld` l2.rpc.dev_sendcustommsg(l1.info['id'], msg) l2.daemon.wait_for_log(