Browse Source

paymod: Add reason why a payment was attempted

This is a slight change in interface in that the string no longer spells out
that a specific node was excluded.
keysend
Christian Decker 4 years ago
parent
commit
2f0e535b81
  1. 4
      plugins/libplugin-pay.c
  2. 3
      plugins/libplugin-pay.h
  3. 8
      plugins/pay.c
  4. 2
      tests/test_pay.py

4
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);

3
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 {

8
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);

2
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]

Loading…
Cancel
Save