json-invoice: add routeboost, warnings.

We split json_invoice(), as it now needs to round-trip to the gossipd,
and uniqueness checks need to happen *after* gossipd replies to avoid
a race.

For every candidate channel gossipd gives us, we check that it's in
state NORMAL (not shutting down, not still waiting for lockin), that
it's connected, and that it has capacity.  We then choose one with
probability weighted by excess capacity, so larger channels are more
likely.

As a side effect of this, we can tell if an invoice is unpayble (no
channels have sufficient incoming capacity) or difficuly (no *online*
channels have sufficient capacity), so we add those warnings.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2018-09-27 14:59:17 +09:30
committed by Christian Decker
parent 2f667c5227
commit c8c3294a23
9 changed files with 886 additions and 77 deletions

View File

@@ -270,6 +270,17 @@ struct channel *peer_active_channel(struct peer *peer)
return NULL;
}
struct channel *peer_normal_channel(struct peer *peer)
{
struct channel *channel;
list_for_each(&peer->channels, channel, list) {
if (channel->state == CHANNELD_NORMAL)
return channel;
}
return NULL;
}
struct channel *active_channel_by_id(struct lightningd *ld,
const struct pubkey *id,
struct uncommitted_channel **uc)