diff --git a/gossipd/gossip_wire.csv b/gossipd/gossip_wire.csv index 45e11c494..23a5cf360 100644 --- a/gossipd/gossip_wire.csv +++ b/gossipd/gossip_wire.csv @@ -165,3 +165,13 @@ gossip_outpoint_spent,,short_channel_id,struct short_channel_id # master -> gossipd: stop gossip timers. gossip_dev_suppress,3032 + +#include + +# 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 diff --git a/gossipd/gossipd.c b/gossipd/gossipd.c index e93409253..505f65890 100644 --- a/gossipd/gossipd.c +++ b/gossipd/gossipd.c @@ -1492,6 +1492,43 @@ out: 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, @@ -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); @@ -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: diff --git a/lightningd/gossip_control.c b/lightningd/gossip_control.c index 06c31237b..72d5ca47f 100644 --- a/lightningd/gossip_control.c +++ b/lightningd/gossip_control.c @@ -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. */ @@ -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: