From dace9bfdcfd9bbd68a7661f0dfedf69cf42d7cba Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Sun, 4 Mar 2018 12:56:59 +1030 Subject: [PATCH] gossipd: the great renaming. We already have 'struct node', so rename 'struct routing_channel' to 'struct chan', and 'struct node_connection' to 'struct half_chan'. Other minor changes: 1. rstate->channels -> rstate->chanmap. 2. 'connections' -> 'half'. 3. connection_to -> half_chan_to 4. connection_from -> half_chan_from Signed-off-by: Rusty Russell --- gossipd/gossip.c | 65 ++++++----- gossipd/routing.c | 147 ++++++++++++------------- gossipd/routing.h | 76 +++++++------ gossipd/test/run-bench-find_route.c | 20 ++-- gossipd/test/run-find_route-specific.c | 14 +-- gossipd/test/run-find_route.c | 30 ++--- 6 files changed, 172 insertions(+), 180 deletions(-) diff --git a/gossipd/gossip.c b/gossipd/gossip.c index aaf68978d..c613c13e1 100644 --- a/gossipd/gossip.c +++ b/gossipd/gossip.c @@ -708,7 +708,7 @@ static struct io_plan *peer_start_gossip(struct io_conn *conn, struct peer *peer static void handle_get_update(struct peer *peer, const u8 *msg) { struct short_channel_id scid; - struct routing_channel *chan; + struct chan *chan; const u8 *update; if (!fromwire_gossip_get_update(msg, &scid)) { @@ -728,9 +728,9 @@ static void handle_get_update(struct peer *peer, const u8 *msg) } else { /* We want update that comes from our end. */ if (pubkey_eq(&chan->nodes[0]->id, &peer->daemon->id)) - update = chan->connections[0].channel_update; + update = chan->half[0].channel_update; else if (pubkey_eq(&chan->nodes[1]->id, &peer->daemon->id)) - update = chan->connections[1].channel_update; + update = chan->half[1].channel_update; else { status_unusual("peer %s scid %s: not our channel?", type_to_string(trc, struct pubkey, @@ -760,7 +760,7 @@ static void handle_local_add_channel(struct peer *peer, u8 *msg) u32 fee_base_msat, fee_proportional_millionths; u64 htlc_minimum_msat; int idx; - struct routing_channel *chan; + struct chan *chan; if (!fromwire_gossip_local_add_channel( msg, &scid, &chain_hash, &remote_node_id, @@ -782,12 +782,11 @@ static void handle_local_add_channel(struct peer *peer, u8 *msg) return; } - /* Create new routing channel */ - chan = new_routing_channel(rstate, &scid, - &rstate->local_id, &remote_node_id); + /* Create new channel */ + chan = new_chan(rstate, &scid, &rstate->local_id, &remote_node_id); idx = pubkey_idx(&rstate->local_id, &remote_node_id), - /* Activate the node_connection from us to them. */ + /* Activate the half_chan from us to them. */ set_connection_values(chan, idx, fee_base_msat, fee_proportional_millionths, @@ -1072,10 +1071,10 @@ static struct io_plan *getroute_req(struct io_conn *conn, struct daemon *daemon, } static void append_half_channel(struct gossip_getchannels_entry **entries, - const struct routing_channel *chan, + const struct chan *chan, int idx) { - const struct node_connection *c = &chan->connections[idx]; + const struct half_chan *c = &chan->half[idx]; struct gossip_getchannels_entry *e; size_t n; @@ -1105,7 +1104,7 @@ static void append_half_channel(struct gossip_getchannels_entry **entries, } static void append_channel(struct gossip_getchannels_entry **entries, - const struct routing_channel *chan) + const struct chan *chan) { append_half_channel(entries, chan, 0); append_half_channel(entries, chan, 1); @@ -1117,7 +1116,7 @@ static struct io_plan *getchannels_req(struct io_conn *conn, struct daemon *daem tal_t *tmpctx = tal_tmpctx(daemon); u8 *out; struct gossip_getchannels_entry *entries; - struct routing_channel *chan; + struct chan *chan; struct short_channel_id *scid; fromwire_gossip_getchannels_request(msg, msg, &scid); @@ -1130,9 +1129,9 @@ static struct io_plan *getchannels_req(struct io_conn *conn, struct daemon *daem } else { u64 idx; - for (chan = uintmap_first(&daemon->rstate->channels, &idx); + for (chan = uintmap_first(&daemon->rstate->chanmap, &idx); chan; - chan = uintmap_after(&daemon->rstate->channels, &idx)) { + chan = uintmap_after(&daemon->rstate->chanmap, &idx)) { append_channel(&entries, chan); } } @@ -1275,7 +1274,7 @@ fail: } static void gossip_send_keepalive_update(struct routing_state *rstate, - struct node_connection *nc) + struct half_chan *hc) { tal_t *tmpctx = tal_tmpctx(rstate); secp256k1_ecdsa_signature sig; @@ -1288,7 +1287,7 @@ static void gossip_send_keepalive_update(struct routing_state *rstate, /* Parse old update */ if (!fromwire_channel_update( - nc->channel_update, &sig, &chain_hash, &scid, ×tamp, + hc->channel_update, &sig, &chain_hash, &scid, ×tamp, &flags, &cltv_expiry_delta, &htlc_minimum_msat, &fee_base_msat, &fee_proportional_millionths)) { status_failed( @@ -1341,28 +1340,26 @@ static void gossip_refresh_network(struct daemon *daemon) if (n) { /* Iterate through all outgoing connection and check whether * it's time to re-announce */ - for (size_t i = 0; i < tal_count(n->channels); i++) { - struct node_connection *nc; + for (size_t i = 0; i < tal_count(n->chans); i++) { + struct half_chan *hc = half_chan_from(n, n->chans[i]); - nc = connection_from(n, n->channels[i]); - - if (!nc->channel_update) { + if (!hc->channel_update) { /* Connection is not public yet, so don't even * try to re-announce it */ continue; } - if (nc->last_timestamp > highwater) { + if (hc->last_timestamp > highwater) { /* No need to send a keepalive update message */ continue; } - if (!nc->active) { + if (!hc->active) { /* Only send keepalives for active connections */ continue; } - gossip_send_keepalive_update(daemon->rstate, nc); + gossip_send_keepalive_update(daemon->rstate, hc); } } @@ -1507,7 +1504,7 @@ static struct io_plan *resolve_channel_req(struct io_conn *conn, struct daemon *daemon, const u8 *msg) { struct short_channel_id scid; - struct routing_channel *chan; + struct chan *chan; struct pubkey *keys; if (!fromwire_gossip_resolve_channel_request(msg, &scid)) @@ -1807,8 +1804,8 @@ static struct io_plan *handle_disable_channel(struct io_conn *conn, tal_t *tmpctx = tal_tmpctx(msg); struct short_channel_id scid; u8 direction; - struct routing_channel *chan; - struct node_connection *nc; + struct chan *chan; + struct half_chan *hc; bool active; u16 flags, cltv_expiry_delta; u32 timestamp, fee_base_msat, fee_proportional_millionths; @@ -1829,15 +1826,15 @@ static struct io_plan *handle_disable_channel(struct io_conn *conn, type_to_string(msg, struct short_channel_id, &scid)); goto fail; } - nc = &chan->connections[direction]; + hc = &chan->half[direction]; status_trace("Disabling channel %s/%d, active %d -> %d", type_to_string(msg, struct short_channel_id, &scid), - direction, nc->active, active); + direction, hc->active, active); - nc->active = active; + hc->active = active; - if (!nc->channel_update) { + if (!hc->channel_update) { status_trace( "Channel %s/%d doesn't have a channel_update yet, can't " "disable", @@ -1847,7 +1844,7 @@ static struct io_plan *handle_disable_channel(struct io_conn *conn, } if (!fromwire_channel_update( - nc->channel_update, &sig, &chain_hash, &scid, ×tamp, + hc->channel_update, &sig, &chain_hash, &scid, ×tamp, &flags, &cltv_expiry_delta, &htlc_minimum_msat, &fee_base_msat, &fee_proportional_millionths)) { status_failed( @@ -1856,8 +1853,8 @@ static struct io_plan *handle_disable_channel(struct io_conn *conn, } timestamp = time_now().ts.tv_sec; - if (timestamp <= nc->last_timestamp) - timestamp = nc->last_timestamp + 1; + if (timestamp <= hc->last_timestamp) + timestamp = hc->last_timestamp + 1; /* Active is bit 1 << 1, mask and apply */ flags = (0xFFFD & flags) | (!active << 1); diff --git a/gossipd/routing.c b/gossipd/routing.c index 66ccfdf37..336ec9f51 100644 --- a/gossipd/routing.c +++ b/gossipd/routing.c @@ -94,7 +94,7 @@ struct routing_state *new_routing_state(const tal_t *ctx, rstate->local_id = *local_id; rstate->prune_timeout = prune_timeout; list_head_init(&rstate->pending_cannouncement); - uintmap_init(&rstate->channels); + uintmap_init(&rstate->chanmap); rstate->pending_node_map = tal(ctx, struct pending_node_map); pending_node_map_init(rstate->pending_node_map); @@ -123,8 +123,8 @@ static void destroy_node(struct node *node, struct routing_state *rstate) node_map_del(rstate->nodes, node); /* These remove themselves from the array. */ - while (tal_count(node->channels)) - tal_free(node->channels[0]); + while (tal_count(node->chans)) + tal_free(node->chans[0]); } struct node *get_node(struct routing_state *rstate, const struct pubkey *id) @@ -141,7 +141,7 @@ static struct node *new_node(struct routing_state *rstate, n = tal(rstate, struct node); n->id = *id; - n->channels = tal_arr(n, struct routing_channel *, 0); + n->chans = tal_arr(n, struct chan *, 0); n->alias = NULL; n->node_announcement = NULL; n->announcement_idx = 0; @@ -153,8 +153,7 @@ static struct node *new_node(struct routing_state *rstate, return n; } -static bool remove_channel_from_array(struct routing_channel ***chans, - struct routing_channel *c) +static bool remove_channel_from_array(struct chan ***chans, struct chan *c) { size_t i, n; @@ -170,27 +169,26 @@ static bool remove_channel_from_array(struct routing_channel ***chans, return false; } -static void destroy_routing_channel(struct routing_channel *chan, - struct routing_state *rstate) +static void destroy_chan(struct chan *chan, struct routing_state *rstate) { - if (!remove_channel_from_array(&chan->nodes[0]->channels, chan) - || !remove_channel_from_array(&chan->nodes[1]->channels, chan)) + if (!remove_channel_from_array(&chan->nodes[0]->chans, chan) + || !remove_channel_from_array(&chan->nodes[1]->chans, chan)) /* FIXME! */ abort(); - uintmap_del(&rstate->channels, chan->scid.u64); + uintmap_del(&rstate->chanmap, chan->scid.u64); - if (tal_count(chan->nodes[0]->channels) == 0) + if (tal_count(chan->nodes[0]->chans) == 0) tal_free(chan->nodes[0]); - if (tal_count(chan->nodes[1]->channels) == 0) + if (tal_count(chan->nodes[1]->chans) == 0) tal_free(chan->nodes[1]); } -static void init_node_connection(struct routing_state *rstate, - struct routing_channel *chan, +static void init_half_chan(struct routing_state *rstate, + struct chan *chan, int idx) { - struct node_connection *c = &chan->connections[idx]; + struct half_chan *c = &chan->half[idx]; c->channel_update = NULL; c->channel_update_msgidx = 0; @@ -202,12 +200,12 @@ static void init_node_connection(struct routing_state *rstate, c->last_timestamp = time_now().ts.tv_sec - rstate->prune_timeout/2; } -struct routing_channel *new_routing_channel(struct routing_state *rstate, - const struct short_channel_id *scid, - const struct pubkey *id1, - const struct pubkey *id2) +struct chan *new_chan(struct routing_state *rstate, + const struct short_channel_id *scid, + const struct pubkey *id1, + const struct pubkey *id2) { - struct routing_channel *chan = tal(rstate, struct routing_channel); + struct chan *chan = tal(rstate, struct chan); int n1idx = pubkey_idx(id1, id2); size_t n; struct node *n1, *n2; @@ -228,20 +226,20 @@ struct routing_channel *new_routing_channel(struct routing_state *rstate, chan->channel_announce_msgidx = 0; chan->public = false; - n = tal_count(n2->channels); - tal_resize(&n2->channels, n+1); - n2->channels[n] = chan; - n = tal_count(n1->channels); - tal_resize(&n1->channels, n+1); - n1->channels[n] = chan; + n = tal_count(n2->chans); + tal_resize(&n2->chans, n+1); + n2->chans[n] = chan; + n = tal_count(n1->chans); + tal_resize(&n1->chans, n+1); + n1->chans[n] = chan; /* Populate with (inactive) connections */ - init_node_connection(rstate, chan, n1idx); - init_node_connection(rstate, chan, !n1idx); + init_half_chan(rstate, chan, n1idx); + init_half_chan(rstate, chan, !n1idx); - uintmap_add(&rstate->channels, scid->u64, chan); + uintmap_add(&rstate->chanmap, scid->u64, chan); - tal_add_destructor2(chan, destroy_routing_channel, rstate); + tal_add_destructor2(chan, destroy_chan, rstate); return chan; } @@ -262,7 +260,7 @@ static void clear_bfg(struct node_map *nodes) } } -static u64 connection_fee(const struct node_connection *c, u64 msatoshi) +static u64 connection_fee(const struct half_chan *c, u64 msatoshi) { u64 fee; @@ -284,13 +282,13 @@ static u64 risk_fee(u64 amount, u32 delay, double riskfactor) /* We track totals, rather than costs. That's because the fee depends * on the current amount passing through. */ static void bfg_one_edge(struct node *node, - struct routing_channel *chan, int idx, + struct chan *chan, int idx, double riskfactor, double fuzz, const struct siphash_seed *base_seed) { size_t h; double fee_scale = 1.0; - const struct node_connection *c = &chan->connections[idx]; + const struct half_chan *c = &chan->half[idx]; if (fuzz != 0.0) { u64 h = siphash24(base_seed, &chan->scid, sizeof(chan->scid)); @@ -339,21 +337,21 @@ static void bfg_one_edge(struct node *node, } } -/* Determine if the given node_connection is routable */ -static bool nc_is_routable(const struct node_connection *nc, time_t now) +/* Determine if the given half_chan is routable */ +static bool hc_is_routable(const struct half_chan *hc, time_t now) { - return nc->active && nc->unroutable_until < now; + return hc->active && hc->unroutable_until < now; } /* riskfactor is already scaled to per-block amount */ -static struct routing_channel ** +static struct chan ** find_route(const tal_t *ctx, struct routing_state *rstate, const struct pubkey *from, const struct pubkey *to, u64 msatoshi, double riskfactor, double fuzz, const struct siphash_seed *base_seed, u64 *fee) { - struct routing_channel **route; + struct chan **route; struct node *n, *src, *dst; struct node_map_iter it; int runs, i, best; @@ -401,18 +399,17 @@ find_route(const tal_t *ctx, struct routing_state *rstate, for (n = node_map_first(rstate->nodes, &it); n; n = node_map_next(rstate->nodes, &it)) { - size_t num_edges = tal_count(n->channels); + size_t num_edges = tal_count(n->chans); for (i = 0; i < num_edges; i++) { - struct routing_channel *chan = n->channels[i]; - int idx = connection_to(n, chan); + struct chan *chan = n->chans[i]; + int idx = half_chan_to(n, chan); SUPERVERBOSE("Node %s edge %i/%zu", type_to_string(trc, struct pubkey, &n->id), i, num_edges); - if (!nc_is_routable(&chan->connections[idx], - now)) { + if (!hc_is_routable(&chan->half[idx], now)) { SUPERVERBOSE("...unroutable"); continue; } @@ -441,7 +438,7 @@ find_route(const tal_t *ctx, struct routing_state *rstate, *fee = n->bfg[best-1].total - msatoshi; /* Lay out route */ - route = tal_arr(ctx, struct routing_channel *, best); + route = tal_arr(ctx, struct chan *, best); for (i = 0, n = dst; i < best; n = other_node(n, n->bfg[best-i].prev), i++) { @@ -539,7 +536,7 @@ const struct short_channel_id *handle_channel_announcement( u8 *features; secp256k1_ecdsa_signature node_signature_1, node_signature_2; secp256k1_ecdsa_signature bitcoin_signature_1, bitcoin_signature_2; - struct routing_channel *chan; + struct chan *chan; pending = tal(rstate, struct pending_cannouncement); pending->updates[0] = NULL; @@ -655,7 +652,7 @@ bool handle_pending_cannouncement(struct routing_state *rstate, u8 *tag; const u8 *s; struct pending_cannouncement *pending; - struct routing_channel *chan; + struct chan *chan; pending = find_pending_cannouncement(rstate, scid); if (!pending) @@ -703,7 +700,7 @@ bool handle_pending_cannouncement(struct routing_state *rstate, * channel_announcements. See handle_channel_announcement. */ chan = get_channel(rstate, scid); if (!chan) - chan = new_routing_channel(rstate, scid, + chan = new_chan(rstate, scid, &pending->node_id_1, &pending->node_id_2); @@ -756,7 +753,7 @@ static void update_pending(struct pending_cannouncement *pending, } } -void set_connection_values(struct routing_channel *chan, +void set_connection_values(struct chan *chan, int idx, u32 base_fee, u32 proportional_fee, @@ -765,7 +762,7 @@ void set_connection_values(struct routing_channel *chan, u64 timestamp, u32 htlc_minimum_msat) { - struct node_connection *c = &chan->connections[idx]; + struct half_chan *c = &chan->half[idx]; c->delay = delay; c->htlc_minimum_msat = htlc_minimum_msat; @@ -796,7 +793,7 @@ void set_connection_values(struct routing_channel *chan, void handle_channel_update(struct routing_state *rstate, const u8 *update) { u8 *serialized; - struct node_connection *c; + struct half_chan *c; secp256k1_ecdsa_signature signature; struct short_channel_id short_channel_id; u32 timestamp; @@ -807,7 +804,7 @@ void handle_channel_update(struct routing_state *rstate, const u8 *update) u32 fee_proportional_millionths; const tal_t *tmpctx = tal_tmpctx(rstate); struct bitcoin_blkid chain_hash; - struct routing_channel *chan; + struct chan *chan; u8 direction; size_t len = tal_len(update); @@ -858,7 +855,7 @@ void handle_channel_update(struct routing_state *rstate, const u8 *update) } } - c = &chan->connections[direction]; + c = &chan->half[direction]; if (c->last_timestamp >= timestamp) { SUPERVERBOSE("Ignoring outdated update."); @@ -891,7 +888,7 @@ void handle_channel_update(struct routing_state *rstate, const u8 *update) towire_short_channel_id(&tag, &short_channel_id); towire_u16(&tag, direction); replace_broadcast(rstate->broadcasts, - &chan->connections[direction].channel_update_msgidx, + &chan->half[direction].channel_update_msgidx, WIRE_CHANNEL_UPDATE, tag, serialized); @@ -1050,7 +1047,7 @@ struct route_hop *get_route(tal_t *ctx, struct routing_state *rstate, u32 final_cltv, double fuzz, const struct siphash_seed *base_seed) { - struct routing_channel **route; + struct chan **route; u64 total_amount; unsigned int total_delay; u64 fee; @@ -1074,9 +1071,9 @@ struct route_hop *get_route(tal_t *ctx, struct routing_state *rstate, /* Start at destination node. */ n = get_node(rstate, destination); for (i = tal_count(route) - 1; i >= 0; i--) { - const struct node_connection *c; - int idx = connection_to(n, route[i]); - c = &route[i]->connections[idx]; + const struct half_chan *c; + int idx = half_chan_to(n, route[i]); + c = &route[i]->half[idx]; hops[i].channel_id = route[i]->scid; hops[i].nodeid = n->id; hops[i].amount = total_amount; @@ -1099,10 +1096,10 @@ struct route_hop *get_route(tal_t *ctx, struct routing_state *rstate, static void routing_failure_channel_out(const tal_t *disposal_context, struct node *node, enum onion_type failcode, - struct routing_channel *chan, + struct chan *chan, time_t now) { - struct node_connection *nc = connection_from(node, chan); + struct half_chan *hc = half_chan_from(node, chan); /* BOLT #4: * @@ -1111,7 +1108,7 @@ static void routing_failure_channel_out(const tal_t *disposal_context, */ if (!(failcode & PERM)) /* Prevent it for 20 seconds. */ - nc->unroutable_until = now + 20; + hc->unroutable_until = now + 20; else /* Set it up to be pruned. */ tal_steal(disposal_context, chan); @@ -1154,13 +1151,13 @@ void routing_failure(struct routing_state *rstate, * */ if (failcode & NODE) { - for (i = 0; i < tal_count(node->channels); ++i) { + for (i = 0; i < tal_count(node->chans); ++i) { routing_failure_channel_out(tmpctx, node, failcode, - node->channels[i], + node->chans[i], now); } } else { - struct routing_channel *chan = get_channel(rstate, scid); + struct chan *chan = get_channel(rstate, scid); if (!chan) status_unusual("routing_failure: " @@ -1222,7 +1219,7 @@ void mark_channel_unroutable(struct routing_state *rstate, const struct short_channel_id *channel) { const tal_t *tmpctx = tal_tmpctx(rstate); - struct routing_channel *chan; + struct chan *chan; time_t now = time_now().ts.tv_sec; const char *scid = type_to_string(tmpctx, struct short_channel_id, channel); @@ -1238,8 +1235,8 @@ void mark_channel_unroutable(struct routing_state *rstate, tal_free(tmpctx); return; } - chan->connections[0].unroutable_until = now + 20; - chan->connections[1].unroutable_until = now + 20; + chan->half[0].unroutable_until = now + 20; + chan->half[1].unroutable_until = now + 20; tal_free(tmpctx); } @@ -1249,31 +1246,31 @@ void route_prune(struct routing_state *rstate) /* Anything below this highwater mark ought to be pruned */ const s64 highwater = now - rstate->prune_timeout; const tal_t *pruned = tal_tmpctx(rstate); - struct routing_channel *chan; + struct chan *chan; u64 idx; /* Now iterate through all channels and see if it is still alive */ - for (chan = uintmap_first(&rstate->channels, &idx); + for (chan = uintmap_first(&rstate->chanmap, &idx); chan; - chan = uintmap_after(&rstate->channels, &idx)) { + chan = uintmap_after(&rstate->chanmap, &idx)) { /* Local-only? Don't prune. */ if (!chan->public) continue; - if (chan->connections[0].last_timestamp < highwater - && chan->connections[1].last_timestamp < highwater) { + if (chan->half[0].last_timestamp < highwater + && chan->half[1].last_timestamp < highwater) { status_trace( "Pruning channel %s from network view (ages %"PRIu64" and %"PRIu64"s)", type_to_string(trc, struct short_channel_id, &chan->scid), - now - chan->connections[0].last_timestamp, - now - chan->connections[1].last_timestamp); + now - chan->half[0].last_timestamp, + now - chan->half[1].last_timestamp); /* This may perturb iteration so do outside loop. */ tal_steal(pruned, chan); } } - /* This frees all the routing_channels and maybe even nodes. */ + /* This frees all the chans and maybe even nodes. */ tal_free(pruned); } diff --git a/gossipd/routing.h b/gossipd/routing.h index 4df126e50..ce476c8fc 100644 --- a/gossipd/routing.h +++ b/gossipd/routing.h @@ -12,7 +12,7 @@ #define ROUTING_MAX_HOPS 20 #define ROUTING_FLAGS_DISABLED 2 -struct node_connection { +struct half_chan { /* millisatoshi. */ u32 base_fee; /* millionths */ @@ -42,6 +42,27 @@ struct node_connection { time_t unroutable_until; }; +struct chan { + struct short_channel_id scid; + u8 *txout_script; + + /* + * half[0]->src == nodes[0] half[0]->dst == nodes[1] + * half[1]->src == nodes[1] half[1]->dst == nodes[0] + */ + struct half_chan half[2]; + /* node[0].id < node[1].id */ + struct node *nodes[2]; + + /* Cached `channel_announcement` we might forward to new peers*/ + const u8 *channel_announcement; + + u64 channel_announce_msgidx; + + /* Is this a public channel, or was it only added locally? */ + bool public; +}; + struct node { struct pubkey id; @@ -52,7 +73,7 @@ struct node { struct wireaddr *addresses; /* Channels connecting us to other nodes */ - struct routing_channel **channels; + struct chan **chans; /* Temporary data for routefinding. */ struct { @@ -61,7 +82,7 @@ struct node { /* Total risk premium of this route. */ u64 risk; /* Where that came from. */ - struct routing_channel *prev; + struct chan *prev; } bfg[ROUTING_MAX_HOPS+1]; /* UTF-8 encoded alias as tal_arr, not zero terminated */ @@ -85,27 +106,6 @@ HTABLE_DEFINE_TYPE(struct node, node_map_keyof_node, node_map_hash_key, node_map struct pending_node_map; struct pending_cannouncement; -struct routing_channel { - struct short_channel_id scid; - u8 *txout_script; - - /* - * connections[0]->src == nodes[0] connections[0]->dst == nodes[1] - * connections[1]->src == nodes[1] connections[1]->dst == nodes[0] - */ - struct node_connection connections[2]; - /* nodes[0].id < nodes[1].id */ - struct node *nodes[2]; - - /* Cached `channel_announcement` we might forward to new peers*/ - const u8 *channel_announcement; - - u64 channel_announce_msgidx; - - /* Is this a public channel, or was it only added locally? */ - bool public; -}; - /* If the two nodes[] are id1 and id2, which index would id1 be? */ static inline int pubkey_idx(const struct pubkey *id1, const struct pubkey *id2) { @@ -113,8 +113,7 @@ static inline int pubkey_idx(const struct pubkey *id1, const struct pubkey *id2) } /* Fast versions: if you know n is one end of the channel */ -static inline struct node *other_node(const struct node *n, - struct routing_channel *chan) +static inline struct node *other_node(const struct node *n, struct chan *chan) { int idx = (chan->nodes[1] == n); @@ -123,18 +122,17 @@ static inline struct node *other_node(const struct node *n, } /* If you know n is one end of the channel, get connection src == n */ -static inline struct node_connection *connection_from(const struct node *n, - struct routing_channel *chan) +static inline struct half_chan *half_chan_from(const struct node *n, + struct chan *chan) { int idx = (chan->nodes[1] == n); assert(chan->nodes[0] == n || chan->nodes[1] == n); - return &chan->connections[idx]; + return &chan->half[idx]; } /* If you know n is one end of the channel, get index dst == n */ -static inline int connection_to(const struct node *n, - struct routing_channel *chan) +static inline int half_chan_to(const struct node *n, struct chan *chan) { int idx = (chan->nodes[1] == n); @@ -164,14 +162,14 @@ struct routing_state { u32 prune_timeout; /* A map of channels indexed by short_channel_ids */ - UINTMAP(struct routing_channel*) channels; + UINTMAP(struct chan *) chanmap; }; -static inline struct routing_channel * +static inline struct chan * get_channel(const struct routing_state *rstate, const struct short_channel_id *scid) { - return uintmap_get(&rstate->channels, scid->u64); + return uintmap_get(&rstate->chanmap, scid->u64); } struct route_hop { @@ -186,10 +184,10 @@ struct routing_state *new_routing_state(const tal_t *ctx, const struct pubkey *local_id, u32 prune_timeout); -struct routing_channel *new_routing_channel(struct routing_state *rstate, - const struct short_channel_id *scid, - const struct pubkey *id1, - const struct pubkey *id2); +struct chan *new_chan(struct routing_state *rstate, + const struct short_channel_id *scid, + const struct pubkey *id1, + const struct pubkey *id2); /* Handlers for incoming messages */ @@ -217,7 +215,7 @@ void handle_channel_update(struct routing_state *rstate, const u8 *update); void handle_node_announcement(struct routing_state *rstate, const u8 *node); /* Set values on the struct node_connection */ -void set_connection_values(struct routing_channel *chan, +void set_connection_values(struct chan *chan, int idx, u32 base_fee, u32 proportional_fee, diff --git a/gossipd/test/run-bench-find_route.c b/gossipd/test/run-bench-find_route.c index 4fa93b3da..ac037e3cf 100644 --- a/gossipd/test/run-bench-find_route.c +++ b/gossipd/test/run-bench-find_route.c @@ -102,22 +102,22 @@ void towire_u16(u8 **pptr UNNEEDED, u16 v UNNEEDED) const void *trc; /* Updates existing route if required. */ -static struct node_connection *add_connection(struct routing_state *rstate, - const struct pubkey *from, - const struct pubkey *to, - u32 base_fee, s32 proportional_fee, - u32 delay) +static struct half_chan *add_connection(struct routing_state *rstate, + const struct pubkey *from, + const struct pubkey *to, + u32 base_fee, s32 proportional_fee, + u32 delay) { struct short_channel_id scid; - struct node_connection *c; - struct routing_channel *chan; + struct half_chan *c; + struct chan *chan; memset(&scid, 0, sizeof(scid)); chan = get_channel(rstate, &scid); if (!chan) - chan = new_routing_channel(rstate, &scid, from, to); + chan = new_chan(rstate, &scid, from, to); - c = &chan->connections[pubkey_idx(from, to)]; + c = &chan->half[pubkey_idx(from, to)]; c->base_fee = base_fee; c->proportional_fee = proportional_fee; c->delay = delay; @@ -217,7 +217,7 @@ int main(int argc, char *argv[]) struct pubkey from = nodeid(pseudorand(num_nodes)); struct pubkey to = nodeid(pseudorand(num_nodes)); u64 fee; - struct routing_channel **route; + struct chan **route; route = find_route(ctx, rstate, &from, &to, pseudorand(100000), diff --git a/gossipd/test/run-find_route-specific.c b/gossipd/test/run-find_route-specific.c index 8255d313b..509bb28c9 100644 --- a/gossipd/test/run-find_route-specific.c +++ b/gossipd/test/run-find_route-specific.c @@ -68,25 +68,25 @@ const void *trc; bool short_channel_id_from_str(const char *str, size_t strlen, struct short_channel_id *dst); -static struct node_connection * +static struct half_chan * get_or_make_connection(struct routing_state *rstate, const struct pubkey *from_id, const struct pubkey *to_id, const char *shortid) { struct short_channel_id scid; - struct routing_channel *chan; + struct chan *chan; if (!short_channel_id_from_str(shortid, strlen(shortid), &scid)) abort(); chan = get_channel(rstate, &scid); if (!chan) - chan = new_routing_channel(rstate, &scid, from_id, to_id); + chan = new_chan(rstate, &scid, from_id, to_id); - return &chan->connections[pubkey_idx(from_id, to_id)]; + return &chan->half[pubkey_idx(from_id, to_id)]; } -static bool channel_is_between(const struct routing_channel *chan, +static bool channel_is_between(const struct chan *chan, const struct pubkey *a, const struct pubkey *b) { if (pubkey_eq(&chan->nodes[0]->id, a) @@ -104,11 +104,11 @@ int main(void) { static const struct bitcoin_blkid zerohash; const tal_t *ctx = trc = tal_tmpctx(NULL); - struct node_connection *nc; + struct half_chan *nc; struct routing_state *rstate; struct pubkey a, b, c; u64 fee; - struct routing_channel **route; + struct chan **route; const double riskfactor = 1.0 / BLOCKS_PER_YEAR / 10000; secp256k1_ctx = secp256k1_context_create(SECP256K1_CONTEXT_VERIFY diff --git a/gossipd/test/run-find_route.c b/gossipd/test/run-find_route.c index 1202fbf2e..0550b86e6 100644 --- a/gossipd/test/run-find_route.c +++ b/gossipd/test/run-find_route.c @@ -64,15 +64,15 @@ void towire_u16(u8 **pptr UNNEEDED, u16 v UNNEEDED) const void *trc; /* Updates existing route if required. */ -static struct node_connection *add_connection(struct routing_state *rstate, +static struct half_chan *add_connection(struct routing_state *rstate, const struct pubkey *from, const struct pubkey *to, u32 base_fee, s32 proportional_fee, u32 delay) { struct short_channel_id scid; - struct node_connection *c; - struct routing_channel *chan; + struct half_chan *c; + struct chan *chan; /* Make a unique scid. */ memcpy(&scid, from, sizeof(scid) / 2); @@ -80,9 +80,9 @@ static struct node_connection *add_connection(struct routing_state *rstate, chan = get_channel(rstate, &scid); if (!chan) - chan = new_routing_channel(rstate, &scid, from, to); + chan = new_chan(rstate, &scid, from, to); - c = &chan->connections[pubkey_idx(from, to)]; + c = &chan->half[pubkey_idx(from, to)]; c->base_fee = base_fee; c->proportional_fee = proportional_fee; c->delay = delay; @@ -91,9 +91,9 @@ static struct node_connection *add_connection(struct routing_state *rstate, return c; } -/* Returns routing_channel connecting from and to: *idx set to refer +/* Returns chan connecting from and to: *idx set to refer * to connection with src=from, dst=to */ -static struct routing_channel *find_channel(struct routing_state *rstate, +static struct chan *find_channel(struct routing_state *rstate, const struct node *from, const struct node *to, int *idx) @@ -102,21 +102,21 @@ static struct routing_channel *find_channel(struct routing_state *rstate, *idx = pubkey_idx(&from->id, &to->id); - n = tal_count(to->channels); + n = tal_count(to->chans); for (i = 0; i < n; i++) { - if (to->channels[i]->nodes[*idx] == from) - return to->channels[i]; + if (to->chans[i]->nodes[*idx] == from) + return to->chans[i]; } return NULL; } -static struct node_connection *get_connection(struct routing_state *rstate, +static struct half_chan *get_connection(struct routing_state *rstate, const struct pubkey *from_id, const struct pubkey *to_id) { int idx; struct node *from, *to; - struct routing_channel *c; + struct chan *c; from = get_node(rstate, from_id); to = get_node(rstate, to_id); @@ -126,10 +126,10 @@ static struct node_connection *get_connection(struct routing_state *rstate, c = find_channel(rstate, from, to, &idx); if (!c) return NULL; - return &c->connections[idx]; + return &c->half[idx]; } -static bool channel_is_between(const struct routing_channel *chan, +static bool channel_is_between(const struct chan *chan, const struct pubkey *a, const struct pubkey *b) { if (pubkey_eq(&chan->nodes[0]->id, a) @@ -151,7 +151,7 @@ int main(void) struct pubkey a, b, c, d; struct privkey tmp; u64 fee; - struct routing_channel **route; + struct chan **route; const double riskfactor = 1.0 / BLOCKS_PER_YEAR / 10000; secp256k1_ctx = secp256k1_context_create(SECP256K1_CONTEXT_VERIFY