From 87112415356ac08ac59de05af3b9a17e418feab3 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Tue, 13 Sep 2022 06:45:55 +0930 Subject: [PATCH] lightning-cli: use cli:- for all requests. This is the format we should standardize on. Signed-off-by: Rusty Russell --- cli/lightning-cli.c | 15 +++++++++++++-- cli/test/run-human-mode.c | 2 +- cli/test/run-large-input.c | 2 +- cli/test/run-remove-hint.c | 2 +- tests/test_misc.py | 3 +++ 5 files changed, 19 insertions(+), 5 deletions(-) diff --git a/cli/lightning-cli.c b/cli/lightning-cli.c index 2f6066e75..9ef4b8124 100644 --- a/cli/lightning-cli.c +++ b/cli/lightning-cli.c @@ -562,9 +562,15 @@ static bool handle_notify(const char *buf, jsmntok_t *toks, static void enable_notifications(int fd) { - const char *enable = "{ \"jsonrpc\": \"2.0\", \"method\": \"notifications\", \"id\": 0, \"params\": { \"enable\": true } }"; + const char *enable; char rbuf[100]; + enable = tal_fmt(tmpctx, + "{\"jsonrpc\":\"2.0\"," + "\"method\":\"notifications\"," + "\"id\":\"cli:notifications#%i\"," + "\"params\":{\"enable\":true}}", + getpid()); if (!write_all(fd, enable, strlen(enable))) err(ERROR_TALKING_TO_LIGHTNINGD, "Writing enable command"); @@ -696,7 +702,12 @@ int main(int argc, char *argv[]) err(ERROR_TALKING_TO_LIGHTNINGD, "Connecting to '%s'", rpc_filename); - idstr = tal_fmt(ctx, "lightning-cli-%i", getpid()); + /* We use weird methodnames in test_misc.py::test_cli(), and then + * complain the cln mangles it. So omit method in that case */ + if (json_escape_needed(method, strlen(method))) + idstr = tal_fmt(ctx, "cli:weirdmethod!#%i", getpid()); + else + idstr = tal_fmt(ctx, "cli:%s#%i", method, getpid()); if (notification_level <= LOG_LEVEL_MAX) enable_notifications(fd); diff --git a/cli/test/run-human-mode.c b/cli/test/run-human-mode.c index 078af8465..96b1e31c0 100644 --- a/cli/test/run-human-mode.c +++ b/cli/test/run-human-mode.c @@ -134,7 +134,7 @@ int test_chdir(const char *path) static const char *response = "{ \"jsonrpc\":\"2.0\"," - "\"id\":\"lightning-cli-9999\"," + "\"id\":\"cli:listconfigs#9999\"," "\"result\":" "{\"# version\":\"v0.9.0-240-gd7ff74e-modded\",\"lightning-dir\":\"/home/rusty/.lightning\",\"network\":\"testnet\",\"allow-deprecated-apis\":false,\"rpc-file\":\"lightning-rpc\",\"plugins\":[{\"path\":\"/home/rusty/.lightning/plugins/summary/summary.py\",\"name\":\"summary.py\",\"options\":{\"summary-currency\":\"USD\",\"summary-currency-prefix\":\"USD $\",\"summary-availability-interval\":\"300\",\"summary-availability-window\":\"72\"}}],\"important-plugins\":[{\"path\":\"/home/rusty/lightning/lightningd/../plugins/autoclean\",\"name\":\"autoclean\",\"options\":{\"autocleaninvoice-cycle\":null,\"autocleaninvoice-expired-by\":null}},{\"path\":\"/home/rusty/lightning/lightningd/../plugins/bcli\",\"name\":\"bcli\",\"options\":{\"bitcoin-datadir\":null,\"bitcoin-cli\":null,\"bitcoin-rpcuser\":null,\"bitcoin-rpcpassword\":null,\"bitcoin-rpcconnect\":null,\"bitcoin-rpcport\":null,\"bitcoin-retry-timeout\":null,\"commit-fee\":null,\"dev-max-fee-multiplier\":null}},{\"path\":\"/home/rusty/lightning/lightningd/../plugins/fundchannel\",\"name\":\"fundchannel\"},{\"path\":\"/home/rusty/lightning/lightningd/../plugins/keysend\",\"name\":\"keysend\"},{\"path\":\"/home/rusty/lightning/lightningd/../plugins/pay\",\"name\":\"pay\",\"options\":{\"disable-mpp\":false}}],\"disable-plugin\":[],\"always-use-proxy\":false,\"daemon\":\"false\",\"wallet\":\"sqlite3:///home/rusty/.lightning/testnet/lightningd.sqlite3\",\"wumbo\":false,\"wumbo\":false,\"rgb\":\"031a34\",\"alias\":\"SLICKERMASTER-40-gd7ff74e-modded\",\"pid-file\":\"/home/rusty/.lightning/lightningd-testnet.pid\",\"ignore-fee-limits\":true,\"watchtime-blocks\":6,\"max-locktime-blocks\":2016,\"funding-confirms\":1,\"commit-fee-min\":0,\"commit-fee-max\":0,\"cltv-delta\":6,\"cltv-final\":10,\"commit-time\":10,\"fee-base\":1,\"rescan\":30,\"fee-per-satoshi\":10,\"max-concurrent-htlcs\":483,\"min-capacity-sat\":10000,\"bind-addr\":\":9736\",\"announce-addr\":\"128.199.202.168:9736\",\"announce-addr\":\"[2400:6180:0:d0::5cd2:a001]:9736\",\"offline\":\"false\",\"autolisten\":true,\"disable-dns\":\"false\",\"enable-autotor-v2-mode\":\"false\",\"encrypted-hsm\":false,\"rpc-file-mode\":\"0600\",\"log-level\":\"DEBUG\",\"log-prefix\":\"lightningd\",\"log-file\":\"/home/rusty/logs/lightningd-testnet.log\",\"dev-no-reconnect\":\"false\",\"dev-allow-localhost\":\"false\",\"dev-bitcoind-poll\":30,\"dev-fast-gossip\":\"false\",\"dev-fast-gossip-prune\":\"false\",\"dev-gossip-time\":0,\"dev-max-funding-unconfirmed-blocks\":2016,\"dev-no-htlc-timeout\":\"false\",\"dev-fail-process-onionpacket\":\"false\",\"dev-no-version-checks\":\"false\",\"dev-builtin-plugins-unimportant\":\"false\"}" "}\n\n"; diff --git a/cli/test/run-large-input.c b/cli/test/run-large-input.c index bbba588bd..be4f6eb21 100644 --- a/cli/test/run-large-input.c +++ b/cli/test/run-large-input.c @@ -151,7 +151,7 @@ ssize_t test_read(int fd UNUSED, void *buf, size_t len) #define NUM_ENTRIES (137772/2) #define HEADER "{ \"jsonrpc\": \"2.0\",\n" \ - " \"id\": \"lightning-cli-9999\",\n" \ + " \"id\": \"cli:test#9999\",\n" \ " \"result\" : {\n" \ " \"creation_time\" : \"1515999039.806099043\",\n" \ " \"bytes_used\" : 10787759,\n" \ diff --git a/cli/test/run-remove-hint.c b/cli/test/run-remove-hint.c index e416a2973..7d6dcfc32 100644 --- a/cli/test/run-remove-hint.c +++ b/cli/test/run-remove-hint.c @@ -125,7 +125,7 @@ int test_getpid(void) return 9999; } -static char *response = "{\"id\": \"lightning-cli-9999\", \"jsonrpc\": \"2.0\", \"result\": {\"channels\": [\"\n\", \"├477308sat OUT/OURS ┼ IN/THEIRS 477308sat┤ SCID FLAG ALIAS\", \"├──────────────────────┼──────────────────────┤ 580612x1826x0 [__] BLUEIRON-v0.7.2rc1\"], \"my_address\": \"02b78caed0f45120acc48efe867aa506e8ea60f0712a23303178471da0ca2213f5@hdco6sxkbisc7s5t.onion\", \"format-hint\": \"simple\", \"avail_in\": \"0.00477308500btc (USD $54.37)\", \"num_utxos\": 0, \"num_gossipers\": 1, \"channels_flags\": \"P:private O:offline\", \"avail_out\": \"0.00477308500btc (USD $54.37)\", \"utxo_amount\": \"0.00000000btc (USD $0.00)\", \"num_channels\": 1, \"num_connected\": 1}}\n\n"; +static char *response = "{\"id\": \"cli:test#9999\", \"jsonrpc\": \"2.0\", \"result\": {\"channels\": [\"\n\", \"├477308sat OUT/OURS ┼ IN/THEIRS 477308sat┤ SCID FLAG ALIAS\", \"├──────────────────────┼──────────────────────┤ 580612x1826x0 [__] BLUEIRON-v0.7.2rc1\"], \"my_address\": \"02b78caed0f45120acc48efe867aa506e8ea60f0712a23303178471da0ca2213f5@hdco6sxkbisc7s5t.onion\", \"format-hint\": \"simple\", \"avail_in\": \"0.00477308500btc (USD $54.37)\", \"num_utxos\": 0, \"num_gossipers\": 1, \"channels_flags\": \"P:private O:offline\", \"avail_out\": \"0.00477308500btc (USD $54.37)\", \"utxo_amount\": \"0.00000000btc (USD $0.00)\", \"num_channels\": 1, \"num_connected\": 1}}\n\n"; static size_t response_off; ssize_t test_read(int fd UNUSED, void *buf, size_t len) diff --git a/tests/test_misc.py b/tests/test_misc.py index b1d7d26b0..744469e66 100644 --- a/tests/test_misc.py +++ b/tests/test_misc.py @@ -873,6 +873,9 @@ def test_cli(node_factory): # Test some known output. assert 'help [command]\n List available commands, or give verbose help on one {command}' in out + # Check JSON id is as expected + l1.daemon.wait_for_log("jsonrpc#[0-9]*: IN:id=\"cli:help#[0-9]*") + # Test JSON output. out = subprocess.check_output(['cli/lightning-cli', '--network={}'.format(TEST_NETWORK),