From 73cda2f2ae027f3c2c06b2fe1b15f18f28487a45 Mon Sep 17 00:00:00 2001 From: ZmnSCPxj Date: Mon, 26 Feb 2018 00:47:17 +0000 Subject: [PATCH] payalgo: Report route, and result of trying route. --- lightningd/payalgo.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/lightningd/payalgo.c b/lightningd/payalgo.c index 7527679ae..381ecd1e7 100644 --- a/lightningd/payalgo.c +++ b/lightningd/payalgo.c @@ -4,11 +4,13 @@ #include #include #include +#include #include #include #include #include #include +#include #include #include @@ -131,6 +133,7 @@ static void json_pay_sendpay_resolve(const struct sendpay_result *r, /* If we succeed, hurray */ if (r->succeeded) { + log_info(pay->cmd->ld->log, "pay(%p): Success", pay); json_pay_success(pay->cmd, &r->preimage, pay->getroute_tries, pay->sendpay_tries); return; @@ -140,13 +143,39 @@ static void json_pay_sendpay_resolve(const struct sendpay_result *r, * below. If it is not, fail now. */ if (r->errorcode != PAY_UNPARSEABLE_ONION && r->errorcode != PAY_TRY_OTHER_ROUTE) { + log_info(pay->cmd->ld->log, "pay(%p): Failed, reporting to caller", pay); json_pay_failure(pay, r); return; } + log_info(pay->cmd->ld->log, "pay(%p): Try another route", pay); json_pay_try(pay); } +/* Generates a string describing the route. Route should be a + * tal_arr */ +static char const *stringify_route(const tal_t *ctx, struct route_hop *route) +{ + size_t i; + char *rv = tal_strdup(ctx, "us"); + for (i = 0; i < tal_count(route); ++i) + tal_append_fmt(&rv, " -> %s (%"PRIu32"msat, %"PRIu32"blk) -> %s", + type_to_string(ctx, struct short_channel_id, &route[i].channel_id), + route[i].amount, route[i].delay, + type_to_string(ctx, struct pubkey, &route[i].nodeid)); + return rv; +} + +static void log_route(struct pay *pay, struct route_hop *route) +{ + const tal_t *tmpctx = tal_tmpctx(pay->try_parent); + + log_info(pay->cmd->ld->log, "pay(%p): sendpay via route: %s", + pay, stringify_route(tmpctx, route)); + + tal_free(tmpctx); +} + static void json_pay_getroute_reply(struct subd *gossip UNUSED, const u8 *reply, const int *fds UNUSED, struct pay *pay) @@ -215,6 +244,7 @@ static void json_pay_getroute_reply(struct subd *gossip UNUSED, ++pay->sendpay_tries; + log_route(pay, route); send_payment(pay->try_parent, pay->cmd->ld, &pay->payment_hash, route, &json_pay_sendpay_resolve, pay);