Skip to content

Commit

Permalink
pay: Recover from unparseable routing failures by random disabling of…
Browse files Browse the repository at this point in the history
… channels.

Fixes: ElementsProject#868

Not pretty, but workable.
  • Loading branch information
ZmnSCPxj committed Feb 7, 2018
1 parent e54dc2a commit 5e23b0a
Showing 1 changed file with 37 additions and 3 deletions.
40 changes: 37 additions & 3 deletions lightningd/pay.c
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,34 @@ remote_routing_failure(const tal_t *ctx,
return routing_failure;
}

static void random_mark_channel_unroutable(struct log *log,
struct subd *gossip,
struct short_channel_id *route_channels)
{
const tal_t *tmpctx = tal_tmpctx(gossip);
size_t num_channels = tal_len(route_channels);
size_t i;
const struct short_channel_id *channel;
u8 *msg;
assert(tal_len(route_channels) != 0);

/* Select one channel by random. */
randombytes_buf(&i, sizeof(i));
i = i % num_channels;
channel = &route_channels[i];

log_debug(log,
"Disable randomly %dth channel (%s) along route "
"(guessing due to bad reply)",
(int) i,
type_to_string(tmpctx, struct short_channel_id,
channel));
msg = towire_gossip_mark_channel_unroutable(tmpctx, channel);
subd_send_msg(gossip, msg);

tal_free(tmpctx);
}

static void report_routing_failure(struct log *log,
struct subd *gossip,
struct routing_failure *fail)
Expand Down Expand Up @@ -374,9 +402,15 @@ void payment_failed(struct lightningd *ld, const struct htlc_out *hout,
/* Cannot report failure. */
fail = NULL;
failcode = WIRE_PERMANENT_NODE_FAILURE;
/* Not safe to retry, not know what failed. */
/* FIXME: some mitigation for this branch. */
retry_plausible = false;
/* Select a channel to mark unroutable by random */
random_mark_channel_unroutable(hout->key.peer->log,
ld->gossip,
payment->route_channels);
/* Can now retry; we selected a channel to mark
* unroutable by random */
retry_plausible = true;
/* Already reported something to gossipd, do not
* report anything else */
report_to_gossipd = false;
} else {
failcode = fromwire_peektype(reply->msg);
Expand Down

0 comments on commit 5e23b0a

Please sign in to comment.