From 15dc0a5c1862a84d8b39335e0ca11132e2885726 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Tue, 21 May 2019 09:57:14 +0930 Subject: [PATCH] pay: fix transient status 'failed' in listpays. Signed-off-by: Rusty Russell --- plugins/pay.c | 35 ++++++++++++++++++++++++++++++----- tests/test_pay.py | 1 - 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/plugins/pay.c b/plugins/pay.c index 39e3d7def..4edb64b4a 100644 --- a/plugins/pay.c +++ b/plugins/pay.c @@ -1115,6 +1115,20 @@ static const jsmntok_t *copy_member(char **ret, return m; } +static bool attempt_ongoing(const char *buf, const jsmntok_t *b11) +{ + struct pay_status *ps; + struct pay_attempt *attempt; + + list_for_each(&pay_status, ps, list) { + if (!json_tok_streq(buf, b11, ps->bolt11)) + continue; + attempt = &ps->attempts[tal_count(ps->attempts)-1]; + return attempt->result == NULL && attempt->failure == NULL; + } + return false; +} + static struct command_result *listsendpays_done(struct command *cmd, const char *buf, const jsmntok_t *result, @@ -1132,7 +1146,7 @@ static struct command_result *listsendpays_done(struct command *cmd, ret = tal_fmt(cmd, "{ 'pays': ["); json_for_each_arr(i, t, arr) { - const jsmntok_t *status; + const jsmntok_t *status, *b11; if (some) tal_append_fmt(&ret, ",\n"); @@ -1140,7 +1154,8 @@ static struct command_result *listsendpays_done(struct command *cmd, tal_append_fmt(&ret, "{"); /* Old payments didn't have bolt11 field */ - if (!copy_member(&ret, buf, t, "bolt11", ",")) { + b11 = copy_member(&ret, buf, t, "bolt11", ","); + if (!b11) { if (b11str) { /* If it's a single query, we can fake it */ tal_append_fmt(&ret, "'bolt11': '%s',", b11str); @@ -1151,9 +1166,19 @@ static struct command_result *listsendpays_done(struct command *cmd, } } - status = copy_member(&ret, buf, t, "status", ","); - if (status && json_tok_streq(buf, status, "complete")) - copy_member(&ret, buf, t, "payment_preimage", ","); + /* listsendpays might say it failed, but we're still retrying */ + status = json_get_member(buf, t, "status"); + if (status) { + if (json_tok_streq(buf, status, "failed") + && attempt_ongoing(buf, b11)) { + tal_append_fmt(&ret, "'status': 'pending',"); + } else { + copy_member(&ret, buf, t, "status", ","); + if (json_tok_streq(buf, status, "complete")) + copy_member(&ret, buf, t, + "payment_preimage", ","); + } + } copy_member(&ret, buf, t, "label", ","); copy_member(&ret, buf, t, "amount_sent_msat", ""); tal_append_fmt(&ret, "}"); diff --git a/tests/test_pay.py b/tests/test_pay.py index 67709010e..e0918ad1c 100644 --- a/tests/test_pay.py +++ b/tests/test_pay.py @@ -1413,7 +1413,6 @@ def test_pay_variants(node_factory): l1.rpc.pay(b11) -@pytest.mark.xfail(strict=True) @unittest.skipIf(not DEVELOPER, "gossip without DEVELOPER=1 is slow") def test_pay_retry(node_factory, bitcoind): """Make sure pay command retries properly. """