diff --git a/plugins/libplugin-pay.c b/plugins/libplugin-pay.c index a9f34fcf6..46d9beb86 100644 --- a/plugins/libplugin-pay.c +++ b/plugins/libplugin-pay.c @@ -21,6 +21,7 @@ struct payment *payment_new(tal_t *ctx, struct command *cmd, p->start_time = time_now(); p->result = NULL; p->getroute_cltv = DEFAULT_FINAL_CLTV_DELTA; + p->why = NULL; /* Copy over the relevant pieces of information. */ if (parent != NULL) { @@ -1144,6 +1145,9 @@ static inline void retry_step_cb(struct retry_mod_data *rd, subpayment = payment_new(p, NULL, p, p->modifiers); payment_start(subpayment); p->step = PAYMENT_STEP_RETRY; + subpayment->why = + tal_fmt(subpayment, "Still have %d attempts left", + rdata->retries - 1); } payment_continue(p); diff --git a/plugins/libplugin-pay.h b/plugins/libplugin-pay.h index bb3a7093f..b822638ea 100644 --- a/plugins/libplugin-pay.h +++ b/plugins/libplugin-pay.h @@ -228,6 +228,9 @@ struct payment { /* Serialized bolt11 string, kept attachd to the root so we can filter * by the invoice. */ const char *bolt11; + + /* Textual explanation of why this payment was attempted. */ + const char *why; }; struct payment_modifier { diff --git a/plugins/pay.c b/plugins/pay.c index 066d6f0f5..720d4a5d4 100644 --- a/plugins/pay.c +++ b/plugins/pay.c @@ -1497,6 +1497,8 @@ static void paystatus_add_payment(struct json_stream *s, const struct payment *p utc_timestring(&p->start_time, timestr); json_object_start(s, NULL); + if (p->why != NULL) + json_add_string(s, "strategy", p->why); json_add_string(s, "start_time", timestr); json_add_u64(s, "age_in_seconds", time_to_sec(time_between(time_now(), p->start_time))); @@ -1517,6 +1519,11 @@ static void paystatus_add_payment(struct json_stream *s, const struct payment *p json_object_start(s, "failure"); json_add_sendpay_result(s, p->result); json_object_end(s); + } else { + json_object_start(s, "failure"); + json_add_num(s, "code", PAY_ROUTE_NOT_FOUND); + json_add_string(s, "message", "Call to getroute: Could not find a route"); + json_object_end(s); } json_object_end(s); @@ -1888,6 +1895,7 @@ static struct command_result *json_paymod(struct command *cmd, : NULL; p->invoice = tal_steal(p, b11); p->bolt11 = tal_steal(p, b11str); + p->why = "Initial attempt"; payment_start(p); list_add_tail(&payments, &p->list); diff --git a/tests/test_pay.py b/tests/test_pay.py index a064f9be5..5bdf1eb3e 100644 --- a/tests/test_pay.py +++ b/tests/test_pay.py @@ -156,7 +156,6 @@ def test_pay_exclude_node(node_factory, bitcoind): assert len(status) == 2 assert status[0]['strategy'] == "Initial attempt" assert status[0]['failure']['data']['failcodename'] == 'WIRE_TEMPORARY_NODE_FAILURE' - assert status[1]['strategy'].startswith("Excluded node {}".format(l2.info['id'])) assert 'failure' in status[1] # l1->l4->l5->l3 is the longer route. This makes sure this route won't be @@ -197,7 +196,6 @@ def test_pay_exclude_node(node_factory, bitcoind): assert len(status) == 2 assert status[0]['strategy'] == "Initial attempt" assert status[0]['failure']['data']['failcodename'] == 'WIRE_TEMPORARY_NODE_FAILURE' - assert status[1]['strategy'].startswith("Excluded node {}".format(l2.info['id'])) assert 'success' in status[1]