Skip to content

Commit

Permalink
payalgo: Report route, and result of trying route.
Browse files Browse the repository at this point in the history
  • Loading branch information
ZmnSCPxj committed Feb 26, 2018
1 parent d9a4de7 commit 5a95a5a
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions lightningd/payalgo.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
#include <ccan/tal/str/str.h>
#include <ccan/time/time.h>
#include <common/bolt11.h>
#include <common/type_to_string.h>
#include <gossipd/gen_gossip_wire.h>
#include <gossipd/routing.h>
#include <lightningd/jsonrpc.h>
#include <lightningd/jsonrpc_errors.h>
#include <lightningd/lightningd.h>
#include <lightningd/log.h>
#include <lightningd/subd.h>

struct pay {
Expand Down Expand Up @@ -120,6 +122,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->tries);
return;
}
Expand All @@ -128,13 +131,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->sendpay_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)
Expand Down Expand Up @@ -188,6 +217,7 @@ static void json_pay_getroute_reply(struct subd *gossip UNUSED,
return;
}

log_route(pay, route);
send_payment(pay->sendpay_parent,
pay->cmd->ld, &pay->payment_hash, route,
&json_pay_sendpay_resolve, pay);
Expand Down

0 comments on commit 5a95a5a

Please sign in to comment.