From fa069d7d9727ae6ac09cd31898823a620cf77a42 Mon Sep 17 00:00:00 2001 From: Christian Decker Date: Thu, 1 Feb 2018 14:37:17 +0100 Subject: [PATCH] gossip: Use the channels map to look up by scid Signed-off-by: Christian Decker --- gossipd/routing.c | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/gossipd/routing.c b/gossipd/routing.c index f45ce7066..c6b139254 100644 --- a/gossipd/routing.c +++ b/gossipd/routing.c @@ -183,23 +183,13 @@ struct node_connection *get_connection_by_scid(const struct routing_state *rstat const struct short_channel_id *schanid, const u8 direction) { - struct node *n; - int i, num_conn; - struct node_map *nodes = rstate->nodes; - struct node_connection *c; - struct node_map_iter it; + u64 scid = short_channel_id_to_uint(schanid); + struct routing_channel *chan = uintmap_get(&rstate->channels, scid); - //FIXME(cdecker) We probably want to speed this up by indexing by chanid. - for (n = node_map_first(nodes, &it); n; n = node_map_next(nodes, &it)) { - num_conn = tal_count(n->out); - for (i = 0; i < num_conn; i++){ - c = n->out[i]; - if (short_channel_id_eq(&c->short_channel_id, schanid) && - (c->flags&0x1) == direction) - return c; - } - } - return NULL; + if (chan == NULL) + return NULL; + else + return chan->connections[direction]; } static struct node_connection *