Skip to content

Commit

Permalink
gossipd: routine to get route_info for known incoming channels.
Browse files Browse the repository at this point in the history
For routeboost, we want to select from all our enabled channels with
sufficient incoming capacity.  Gossipd knows which are enabled (ie. we
have received a `channel_update` from the peer), but doesn't know the
current incoming capacity.

So we get gossipd to give us all the candidates, and lightningd
selects from those.

Signed-off-by: Rusty Russell <[email protected]>
  • Loading branch information
rustyrussell authored and cdecker committed Sep 28, 2018
1 parent f64eee7 commit 2f667c5
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 0 deletions.
10 changes: 10 additions & 0 deletions gossipd/gossip_wire.csv
Original file line number Diff line number Diff line change
Expand Up @@ -165,3 +165,13 @@ gossip_outpoint_spent,,short_channel_id,struct short_channel_id

# master -> gossipd: stop gossip timers.
gossip_dev_suppress,3032

#include <common/bolt11.h>

# master -> gossipd: get route_info for our incoming channels
gossip_get_incoming_channels,3025

# gossipd -> master: here they are.
gossip_get_incoming_channels_reply,3125
gossip_get_incoming_channels_reply,,num,u16
gossip_get_incoming_channels_reply,,route_info,num*struct route_info
42 changes: 42 additions & 0 deletions gossipd/gossipd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1492,6 +1492,43 @@ static struct io_plan *ping_req(struct io_conn *conn, struct daemon *daemon,
return daemon_conn_read_next(conn, &daemon->master);
}

static struct io_plan *get_incoming_channels(struct io_conn *conn,
struct daemon *daemon,
const u8 *msg)
{
struct node *node;
struct route_info *r = tal_arr(tmpctx, struct route_info, 0);

if (!fromwire_gossip_get_incoming_channels(msg))
master_badmsg(WIRE_GOSSIP_GET_INCOMING_CHANNELS, msg);

node = get_node(daemon->rstate, &daemon->rstate->local_id);
if (node) {
for (size_t i = 0; i < tal_count(node->chans); i++) {
const struct chan *c = node->chans[i];
const struct half_chan *hc;
struct route_info *ri;

hc = &c->half[half_chan_to(node, c)];

if (!is_halfchan_enabled(hc))
continue;

ri = tal_arr_expand(&r);
ri->pubkey = other_node(node, c)->id;
ri->short_channel_id = c->scid;
ri->fee_base_msat = hc->base_fee;
ri->fee_proportional_millionths = hc->proportional_fee;
ri->cltv_expiry_delta = hc->delay;
}
}

msg = towire_gossip_get_incoming_channels_reply(NULL, r);
daemon_conn_send(&daemon->master, take(msg));

return daemon_conn_read_next(conn, &daemon->master);
}

#if DEVELOPER
static struct io_plan *query_scids_req(struct io_conn *conn,
struct daemon *daemon,
Expand Down Expand Up @@ -1948,6 +1985,10 @@ static struct io_plan *recv_req(struct io_conn *conn, struct daemon_conn *master
case WIRE_GOSSIP_PING:
return ping_req(conn, daemon, daemon->master.msg_in);

case WIRE_GOSSIP_GET_INCOMING_CHANNELS:
return get_incoming_channels(conn, daemon,
daemon->master.msg_in);

#if DEVELOPER
case WIRE_GOSSIP_QUERY_SCIDS:
return query_scids_req(conn, daemon, daemon->master.msg_in);
Expand Down Expand Up @@ -1981,6 +2022,7 @@ static struct io_plan *recv_req(struct io_conn *conn, struct daemon_conn *master
case WIRE_GOSSIP_SCIDS_REPLY:
case WIRE_GOSSIP_QUERY_CHANNEL_RANGE_REPLY:
case WIRE_GOSSIP_RESOLVE_CHANNEL_REPLY:
case WIRE_GOSSIP_GET_INCOMING_CHANNELS_REPLY:
case WIRE_GOSSIP_GET_UPDATE:
case WIRE_GOSSIP_GET_UPDATE_REPLY:
case WIRE_GOSSIP_SEND_GOSSIP:
Expand Down
2 changes: 2 additions & 0 deletions lightningd/gossip_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ static unsigned gossip_msg(struct subd *gossip, const u8 *msg, const int *fds)
case WIRE_GOSSIP_QUERY_SCIDS:
case WIRE_GOSSIP_QUERY_CHANNEL_RANGE:
case WIRE_GOSSIP_SEND_TIMESTAMP_FILTER:
case WIRE_GOSSIP_GET_INCOMING_CHANNELS:
case WIRE_GOSSIP_DEV_SET_MAX_SCIDS_ENCODE_SIZE:
case WIRE_GOSSIP_DEV_SUPPRESS:
/* This is a reply, so never gets through to here. */
Expand All @@ -126,6 +127,7 @@ static unsigned gossip_msg(struct subd *gossip, const u8 *msg, const int *fds)
case WIRE_GOSSIP_SCIDS_REPLY:
case WIRE_GOSSIP_QUERY_CHANNEL_RANGE_REPLY:
case WIRE_GOSSIP_RESOLVE_CHANNEL_REPLY:
case WIRE_GOSSIP_GET_INCOMING_CHANNELS_REPLY:
/* These are inter-daemon messages, not received by us */
case WIRE_GOSSIP_LOCAL_ADD_CHANNEL:
case WIRE_GOSSIP_LOCAL_CHANNEL_UPDATE:
Expand Down

0 comments on commit 2f667c5

Please sign in to comment.