From 6b7546b94dc12ff9da1df4359460f9bc2415e064 Mon Sep 17 00:00:00 2001 From: Christian Decker Date: Thu, 18 Oct 2018 14:06:29 +0200 Subject: [PATCH] json-rpc: Rename `getroutestats` and move stats to getinfo Signed-off-by: Christian Decker <@cdecker> --- contrib/pylightning/lightning/lightning.py | 10 ++--- lightningd/jsonrpc.c | 30 +++++++++++++ lightningd/peer_htlcs.c | 51 ++++------------------ tests/test_pay.py | 2 +- 4 files changed, 42 insertions(+), 51 deletions(-) diff --git a/contrib/pylightning/lightning/lightning.py b/contrib/pylightning/lightning/lightning.py index 8da0ba269..cd1196657 100644 --- a/contrib/pylightning/lightning/lightning.py +++ b/contrib/pylightning/lightning/lightning.py @@ -428,14 +428,10 @@ class LightningRpc(UnixDomainSocketRpc): """ return self.call("listfunds") - def getroutestats(self, details=True): - """Get statistics about routed payments. - - If @details is True, this'll include the individual forwarded - payments. - + def listforwards(self): + """List all forwarded payments and their information """ - return self.call("getroutestats", payload={'details': details}) + return self.call("listforwards") def dev_rescan_outputs(self): """ diff --git a/lightningd/jsonrpc.c b/lightningd/jsonrpc.c index b4a8cc471..145653d18 100644 --- a/lightningd/jsonrpc.c +++ b/lightningd/jsonrpc.c @@ -138,6 +138,35 @@ static const struct json_command dev_crash_command = { AUTODATA(json_command, &dev_crash_command); #endif /* DEVELOPER */ +static void getinfo_add_routestats(struct json_result *response, + struct wallet *wallet) +{ + const struct forwarding_stats *stats; + stats = wallet_forwarded_payments_stats(wallet, tmpctx); + + json_object_start(response, "routestats"); + json_object_start(response, "settled"); + json_add_num(response, "fee_msatoshis", stats->fee[FORWARD_SETTLED]); + json_add_num(response, "count", stats->count[FORWARD_SETTLED]); + json_add_num(response, "msatoshi", stats->msatoshi[FORWARD_SETTLED]); + json_object_end(response); + + json_object_start(response, "failed"); + json_add_num(response, "fee_msatoshis", stats->fee[FORWARD_FAILED]); + json_add_num(response, "count", stats->count[FORWARD_FAILED]); + json_add_num(response, "msatoshi", stats->msatoshi[FORWARD_FAILED]); + json_object_end(response); + + json_object_start(response, "pending"); + json_add_num(response, "fee_msatoshis", stats->fee[FORWARD_OFFERED]); + json_add_num(response, "count", stats->count[FORWARD_FAILED]); + json_add_num(response, "msatoshi", stats->msatoshi[FORWARD_FAILED]); + json_object_end(response); + json_object_end(response); + + tal_free(stats); +} + static void json_getinfo(struct command *cmd, const char *buffer UNUSED, const jsmntok_t *params UNUSED) { @@ -167,6 +196,7 @@ static void json_getinfo(struct command *cmd, json_add_string(response, "version", version()); json_add_num(response, "blockheight", get_block_height(cmd->ld->topology)); json_add_string(response, "network", get_chainparams(cmd->ld)->network_name); + getinfo_add_routestats(response, cmd->ld->wallet); json_object_end(response); command_success(cmd, response); } diff --git a/lightningd/peer_htlcs.c b/lightningd/peer_htlcs.c index c4d58175a..2aff5a5f3 100644 --- a/lightningd/peer_htlcs.c +++ b/lightningd/peer_htlcs.c @@ -1843,34 +1843,6 @@ static const struct json_command dev_ignore_htlcs = { AUTODATA(json_command, &dev_ignore_htlcs); #endif /* DEVELOPER */ -static void listforwardings_add_stats(struct json_result *response, struct wallet *wallet) -{ - const struct forwarding_stats *stats; - stats = wallet_forwarded_payments_stats(wallet, tmpctx); - - json_object_start(response, "stats"); - json_object_start(response, "settled"); - json_add_num(response, "fee_msatoshis", stats->fee[FORWARD_SETTLED]); - json_add_num(response, "count", stats->count[FORWARD_SETTLED]); - json_add_num(response, "msatoshi", stats->msatoshi[FORWARD_SETTLED]); - json_object_end(response); - - json_object_start(response, "failed"); - json_add_num(response, "fee_msatoshis", stats->fee[FORWARD_FAILED]); - json_add_num(response, "count", stats->count[FORWARD_FAILED]); - json_add_num(response, "msatoshi", stats->msatoshi[FORWARD_FAILED]); - json_object_end(response); - - json_object_start(response, "pending"); - json_add_num(response, "fee_msatoshis", stats->fee[FORWARD_OFFERED]); - json_add_num(response, "count", stats->count[FORWARD_FAILED]); - json_add_num(response, "msatoshi", stats->msatoshi[FORWARD_FAILED]); - json_object_end(response); - json_object_end(response); - - tal_free(stats); -} - static void listforwardings_add_forwardings(struct json_result *response, struct wallet *wallet) { const struct forwarding *forwardings; @@ -1894,31 +1866,24 @@ static void listforwardings_add_forwardings(struct json_result *response, struct tal_free(forwardings); } -static void json_getroutestats(struct command *cmd, const char *buffer, +static void json_listforwards(struct command *cmd, const char *buffer, const jsmntok_t *params) { struct json_result *response = new_json_result(cmd); - bool *details; - if (!param(cmd, buffer, params, - p_opt_def("details", json_tok_bool, &details, true), - NULL)) + if (!param(cmd, buffer, params, NULL)) return; json_object_start(response, NULL); - listforwardings_add_stats(response, cmd->ld->wallet); - - if (*details) - listforwardings_add_forwardings(response, cmd->ld->wallet); - + listforwardings_add_forwardings(response, cmd->ld->wallet); json_object_end(response); command_success(cmd, response); } -static const struct json_command getroutestats_command = { - "getroutestats", json_getroutestats, - "Get statistics about routed / forwarded payments", false, - "Get statistics about routed payments, i.e., the ones we aren't the initiator or recipient, including a detailed list if {details} is true." +static const struct json_command listforwards_command = { + "listforwards", json_listforwards, + "List all forwarded payments and their information", false, + "List all forwarded payments and their information" }; -AUTODATA(json_command, &getroutestats_command); +AUTODATA(json_command, &listforwards_command); diff --git a/tests/test_pay.py b/tests/test_pay.py index 9a2063e14..3d484444c 100644 --- a/tests/test_pay.py +++ b/tests/test_pay.py @@ -1047,6 +1047,6 @@ def test_forward_stats(node_factory, bitcoind): assert outchan['out_msatoshi_fulfilled'] < inchan['in_msatoshi_fulfilled'] - stats = l2.rpc.getroutestats() + stats = l2.rpc.listforwards() assert [f['status'] for f in stats['forwards']] == ['settled', 'failed', 'offered']