Browse Source

gossipd: add hop-style to nodes to mark whether they speak TLV onion.

We keep the feature bitmap on disk, so we cache this in the struct
explicitly.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
travis-debug
Rusty Russell 5 years ago
committed by Christian Decker
parent
commit
3a25e9b8d6
  1. 9
      gossipd/routing.c
  2. 9
      gossipd/routing.h
  3. 2
      lightningd/gossip_msg.c

9
gossipd/routing.c

@ -380,6 +380,8 @@ static struct node *new_node(struct routing_state *rstate,
n->id = *id; n->id = *id;
memset(n->chans.arr, 0, sizeof(n->chans.arr)); memset(n->chans.arr, 0, sizeof(n->chans.arr));
broadcastable_init(&n->bcast); broadcastable_init(&n->bcast);
/* We don't know, so assume legacy. */
n->hop_style = ROUTE_HOP_LEGACY;
n->tokens = TOKEN_MAX; n->tokens = TOKEN_MAX;
node_map_add(rstate->nodes, n); node_map_add(rstate->nodes, n);
tal_add_destructor2(n, destroy_node, rstate); tal_add_destructor2(n, destroy_node, rstate);
@ -2510,6 +2512,12 @@ bool routing_add_node_announcement(struct routing_state *rstate,
&& node->bcast.timestamp < time_now().ts.tv_sec) && node->bcast.timestamp < time_now().ts.tv_sec)
rstate->last_timestamp = node->bcast.timestamp; rstate->last_timestamp = node->bcast.timestamp;
if (feature_offered(features, OPT_VAR_ONION))
node->hop_style = ROUTE_HOP_TLV;
else
/* Reset it in case they no longer offer the feature */
node->hop_style = ROUTE_HOP_LEGACY;
if (index) if (index)
node->bcast.index = index; node->bcast.index = index;
else { else {
@ -2707,6 +2715,7 @@ struct route_hop *get_route(const tal_t *ctx, struct routing_state *rstate,
hops[i].amount = total_amount; hops[i].amount = total_amount;
hops[i].delay = total_delay; hops[i].delay = total_delay;
hops[i].direction = idx; hops[i].direction = idx;
hops[i].style = n->hop_style;
/* Since we calculated this route, it should not overflow! */ /* Since we calculated this route, it should not overflow! */
if (!amount_msat_add_fee(&total_amount, if (!amount_msat_add_fee(&total_amount,

9
gossipd/routing.h

@ -133,6 +133,11 @@ HTABLE_DEFINE_TYPE(struct local_chan,
local_chan_map_scid, hash_scid, local_chan_eq_scid, local_chan_map_scid, hash_scid, local_chan_eq_scid,
local_chan_map); local_chan_map);
enum route_hop_style {
ROUTE_HOP_LEGACY = 1,
ROUTE_HOP_TLV = 2,
};
/* For a small number of channels (by far the most common) we use a simple /* For a small number of channels (by far the most common) we use a simple
* array, with empty buckets NULL. For larger, we use a proper hash table, * array, with empty buckets NULL. For larger, we use a proper hash table,
* with the extra allocation that implies. */ * with the extra allocation that implies. */
@ -147,6 +152,9 @@ struct node {
/* Token bucket */ /* Token bucket */
u8 tokens; u8 tokens;
/* route_hop_style */
enum route_hop_style hop_style;
/* Channels connecting us to other nodes */ /* Channels connecting us to other nodes */
union { union {
struct chan_map map; struct chan_map map;
@ -320,6 +328,7 @@ struct route_hop {
struct node_id nodeid; struct node_id nodeid;
struct amount_msat amount; struct amount_msat amount;
u32 delay; u32 delay;
enum route_hop_style style;
}; };
enum exclude_entry_type { enum exclude_entry_type {

2
lightningd/gossip_msg.c

@ -66,6 +66,7 @@ void fromwire_route_hop(const u8 **pptr, size_t *max, struct route_hop *entry)
entry->direction = fromwire_u8(pptr, max); entry->direction = fromwire_u8(pptr, max);
entry->amount = fromwire_amount_msat(pptr, max); entry->amount = fromwire_amount_msat(pptr, max);
entry->delay = fromwire_u32(pptr, max); entry->delay = fromwire_u32(pptr, max);
entry->style = fromwire_u8(pptr, max);
} }
void towire_route_hop(u8 **pptr, const struct route_hop *entry) void towire_route_hop(u8 **pptr, const struct route_hop *entry)
@ -75,6 +76,7 @@ void towire_route_hop(u8 **pptr, const struct route_hop *entry)
towire_u8(pptr, entry->direction); towire_u8(pptr, entry->direction);
towire_amount_msat(pptr, entry->amount); towire_amount_msat(pptr, entry->amount);
towire_u32(pptr, entry->delay); towire_u32(pptr, entry->delay);
towire_u8(pptr, entry->style);
} }
void fromwire_route_info(const u8 **pptr, size_t *max, struct route_info *entry) void fromwire_route_info(const u8 **pptr, size_t *max, struct route_info *entry)

Loading…
Cancel
Save