gossipd: hand all candidates up to lightningd to select routeboost.

This lets us do more flexible filtering in the next patch.  But it also
keeps some weird logic out of gossipd.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2019-12-17 16:41:08 +10:30
committed by ZmnSCPxj, ZmnSCPxj jxPCSmnZ
parent 3f3a48dae9
commit 11dc1b341c
5 changed files with 135 additions and 57 deletions

View File

@@ -128,12 +128,15 @@ msgdata,gossip_dev_compact_store_reply,success,bool,
# master -> gossipd: get route_info for our incoming channels
msgtype,gossip_get_incoming_channels,3025
msgdata,gossip_get_incoming_channels,private_too,?bool,
# gossipd -> master: here they are.
msgtype,gossip_get_incoming_channels_reply,3125
msgdata,gossip_get_incoming_channels_reply,num,u16,
msgdata,gossip_get_incoming_channels_reply,route_info,route_info,num
msgdata,gossip_get_incoming_channels_reply,num_public,u16,
msgdata,gossip_get_incoming_channels_reply,public_route_info,route_info,num_public
msgdata,gossip_get_incoming_channels_reply,public_deadends,bool,num_public
msgdata,gossip_get_incoming_channels_reply,num_private,u16,
msgdata,gossip_get_incoming_channels_reply,private_route_info,route_info,num_private
msgdata,gossip_get_incoming_channels_reply,private_deadends,bool,num_private
# master -> gossipd: blockheight increased.
msgtype,gossip_new_blockheight,3026
Can't render this file because it has a wrong number of fields in line 6.

View File

@@ -1188,18 +1188,6 @@ static bool node_has_public_channels(const struct node *peer,
return false;
}
/*~ The `exposeprivate` flag is a trinary: NULL == dynamic, otherwise
* value decides. Thus, we provide two wrappers for clarity: */
static bool never_expose(bool *exposeprivate)
{
return exposeprivate && !*exposeprivate;
}
static bool always_expose(bool *exposeprivate)
{
return exposeprivate && *exposeprivate;
}
/*~ For routeboost, we offer payers a hint of what incoming channels might
* have capacity for their payment. To do this, lightningd asks for the
* information about all channels to this node; but gossipd doesn't know about
@@ -1211,14 +1199,12 @@ static struct io_plan *get_incoming_channels(struct io_conn *conn,
struct node *node;
struct route_info *public = tal_arr(tmpctx, struct route_info, 0);
struct route_info *private = tal_arr(tmpctx, struct route_info, 0);
bool has_public;
bool *exposeprivate;
bool *priv_deadends = tal_arr(tmpctx, bool, 0);
bool *pub_deadends = tal_arr(tmpctx, bool, 0);
if (!fromwire_gossip_get_incoming_channels(tmpctx, msg, &exposeprivate))
if (!fromwire_gossip_get_incoming_channels(msg))
master_badmsg(WIRE_GOSSIP_GET_INCOMING_CHANNELS, msg);
has_public = always_expose(exposeprivate);
node = get_node(daemon->rstate, &daemon->rstate->local_id);
if (node) {
struct chan_map_iter i;
@@ -1227,6 +1213,7 @@ static struct io_plan *get_incoming_channels(struct io_conn *conn,
for (c = first_chan(node, &i); c; c = next_chan(node, &i)) {
const struct half_chan *hc;
struct route_info ri;
bool deadend;
hc = &c->half[half_chan_to(node, c)];
@@ -1239,25 +1226,21 @@ static struct io_plan *get_incoming_channels(struct io_conn *conn,
ri.fee_proportional_millionths = hc->proportional_fee;
ri.cltv_expiry_delta = hc->delay;
has_public |= is_chan_public(c);
/* If peer doesn't have other public channels,
* no point giving route */
if (!node_has_public_channels(other_node(node, c), c))
continue;
if (always_expose(exposeprivate) || is_chan_public(c))
deadend = !node_has_public_channels(other_node(node, c),
c);
if (is_chan_public(c)) {
tal_arr_expand(&public, ri);
else
tal_arr_expand(&pub_deadends, deadend);
} else {
tal_arr_expand(&private, ri);
tal_arr_expand(&priv_deadends, deadend);
}
}
}
/* If no public channels (even deadend ones!), share private ones. */
if (!has_public && !never_expose(exposeprivate))
msg = towire_gossip_get_incoming_channels_reply(NULL, private);
else
msg = towire_gossip_get_incoming_channels_reply(NULL, public);
msg = towire_gossip_get_incoming_channels_reply(NULL,
public, pub_deadends,
private, priv_deadends);
daemon_conn_send(daemon->master, take(msg));
return daemon_conn_read_next(conn, daemon->master);