Browse Source

lightningd: add `blinding` and `enctlv` field to `struct route_hop`.

This will be used when we want to specify these in a route.  But for now, they
only alter gossipd, which always sets them to NULL.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
travis-debug
Rusty Russell 5 years ago
parent
commit
490a819402
  1. 6
      gossipd/gossipd.c
  2. 35
      gossipd/routing.c
  3. 20
      gossipd/routing.h
  4. 6
      lightningd/gossip_control.c
  5. 23
      lightningd/gossip_msg.c
  6. 3
      lightningd/gossip_msg.h
  7. 1
      tools/generate-wire.py

6
gossipd/gossipd.c

@ -891,7 +891,7 @@ static struct io_plan *getroute_req(struct io_conn *conn, struct daemon *daemon,
u64 riskfactor_millionths; u64 riskfactor_millionths;
u32 max_hops; u32 max_hops;
u8 *out; u8 *out;
struct route_hop *hops; struct route_hop **hops;
/* fuzz 12.345% -> fuzz_millionths = 12345000 */ /* fuzz 12.345% -> fuzz_millionths = 12345000 */
u64 fuzz_millionths; u64 fuzz_millionths;
struct exclude_entry **excluded; struct exclude_entry **excluded;
@ -924,7 +924,9 @@ static struct io_plan *getroute_req(struct io_conn *conn, struct daemon *daemon,
fuzz_millionths / 1000000.0, pseudorand_u64(), fuzz_millionths / 1000000.0, pseudorand_u64(),
excluded, max_hops); excluded, max_hops);
out = towire_gossip_getroute_reply(NULL, hops); out = towire_gossip_getroute_reply(NULL,
cast_const2(const struct route_hop **,
hops));
daemon_conn_send(daemon->master, take(out)); daemon_conn_send(daemon->master, take(out));
return daemon_conn_read_next(conn, daemon->master); return daemon_conn_read_next(conn, daemon->master);
} }

35
gossipd/routing.c

@ -2630,20 +2630,20 @@ u8 *handle_node_announcement(struct routing_state *rstate, const u8 *node_ann,
return NULL; return NULL;
} }
struct route_hop *get_route(const tal_t *ctx, struct routing_state *rstate, struct route_hop **get_route(const tal_t *ctx, struct routing_state *rstate,
const struct node_id *source, const struct node_id *source,
const struct node_id *destination, const struct node_id *destination,
struct amount_msat msat, double riskfactor, struct amount_msat msat, double riskfactor,
u32 final_cltv, u32 final_cltv,
double fuzz, u64 seed, double fuzz, u64 seed,
struct exclude_entry **excluded, struct exclude_entry **excluded,
u32 max_hops) u32 max_hops)
{ {
struct chan **route; struct chan **route;
struct amount_msat total_amount; struct amount_msat total_amount;
unsigned int total_delay; unsigned int total_delay;
struct amount_msat fee; struct amount_msat fee;
struct route_hop *hops; struct route_hop **hops;
struct node *n; struct node *n;
struct amount_msat *saved_capacity; struct amount_msat *saved_capacity;
struct short_channel_id_dir *excluded_chan; struct short_channel_id_dir *excluded_chan;
@ -2717,7 +2717,7 @@ struct route_hop *get_route(const tal_t *ctx, struct routing_state *rstate,
} }
/* Fees, delays need to be calculated backwards along route. */ /* Fees, delays need to be calculated backwards along route. */
hops = tal_arr(ctx, struct route_hop, tal_count(route)); hops = tal_arr(ctx, struct route_hop *, tal_count(route));
total_amount = msat; total_amount = msat;
total_delay = final_cltv; total_delay = final_cltv;
@ -2728,12 +2728,15 @@ struct route_hop *get_route(const tal_t *ctx, struct routing_state *rstate,
int idx = half_chan_to(n, route[i]); int idx = half_chan_to(n, route[i]);
c = &route[i]->half[idx]; c = &route[i]->half[idx];
hops[i].channel_id = route[i]->scid; hops[i] = tal(hops, struct route_hop);
hops[i].nodeid = n->id; hops[i]->channel_id = route[i]->scid;
hops[i].amount = total_amount; hops[i]->nodeid = n->id;
hops[i].delay = total_delay; hops[i]->amount = total_amount;
hops[i].direction = idx; hops[i]->delay = total_delay;
hops[i].style = n->hop_style; hops[i]->direction = idx;
hops[i]->style = n->hop_style;
hops[i]->blinding = NULL;
hops[i]->enctlv = NULL;
/* 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,

20
gossipd/routing.h

@ -325,6 +325,8 @@ struct route_hop {
struct node_id nodeid; struct node_id nodeid;
struct amount_msat amount; struct amount_msat amount;
u32 delay; u32 delay;
struct pubkey *blinding;
u8 *enctlv;
enum route_hop_style style; enum route_hop_style style;
}; };
@ -408,15 +410,15 @@ struct node *get_node(struct routing_state *rstate,
const struct node_id *id); const struct node_id *id);
/* Compute a route to a destination, for a given amount and riskfactor. */ /* Compute a route to a destination, for a given amount and riskfactor. */
struct route_hop *get_route(const tal_t *ctx, struct routing_state *rstate, struct route_hop **get_route(const tal_t *ctx, struct routing_state *rstate,
const struct node_id *source, const struct node_id *source,
const struct node_id *destination, const struct node_id *destination,
const struct amount_msat msat, double riskfactor, const struct amount_msat msat, double riskfactor,
u32 final_cltv, u32 final_cltv,
double fuzz, double fuzz,
u64 seed, u64 seed,
struct exclude_entry **excluded, struct exclude_entry **excluded,
u32 max_hops); u32 max_hops);
/* Disable channel(s) based on the given routing failure. */ /* Disable channel(s) based on the given routing failure. */
void routing_failure(struct routing_state *rstate, void routing_failure(struct routing_state *rstate,
const struct node_id *erring_node, const struct node_id *erring_node,

6
lightningd/gossip_control.c

@ -333,12 +333,12 @@ static void json_add_route_hop(struct json_stream *r, char const *n,
/* Output a route */ /* Output a route */
static void json_add_route(struct json_stream *r, char const *n, static void json_add_route(struct json_stream *r, char const *n,
const struct route_hop *hops, size_t hops_len) struct route_hop **hops, size_t hops_len)
{ {
size_t i; size_t i;
json_array_start(r, n); json_array_start(r, n);
for (i = 0; i < hops_len; ++i) { for (i = 0; i < hops_len; ++i) {
json_add_route_hop(r, NULL, &hops[i]); json_add_route_hop(r, NULL, hops[i]);
} }
json_array_end(r); json_array_end(r);
} }
@ -347,7 +347,7 @@ static void json_getroute_reply(struct subd *gossip UNUSED, const u8 *reply, con
struct command *cmd) struct command *cmd)
{ {
struct json_stream *response; struct json_stream *response;
struct route_hop *hops; struct route_hop **hops;
fromwire_gossip_getroute_reply(reply, reply, &hops); fromwire_gossip_getroute_reply(reply, reply, &hops);

23
lightningd/gossip_msg.c

@ -58,14 +58,28 @@ void towire_gossip_getnodes_entry(u8 **pptr,
towire(pptr, entry->color, ARRAY_SIZE(entry->color)); towire(pptr, entry->color, ARRAY_SIZE(entry->color));
} }
void fromwire_route_hop(const u8 **pptr, size_t *max, struct route_hop *entry) struct route_hop *fromwire_route_hop(const tal_t *ctx,
const u8 **pptr, size_t *max)
{ {
struct route_hop *entry = tal(ctx, struct route_hop);
size_t enclen;
fromwire_node_id(pptr, max, &entry->nodeid); fromwire_node_id(pptr, max, &entry->nodeid);
fromwire_short_channel_id(pptr, max, &entry->channel_id); fromwire_short_channel_id(pptr, max, &entry->channel_id);
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); entry->style = fromwire_u8(pptr, max);
if (fromwire_bool(pptr, max)) {
entry->blinding = tal(entry, struct pubkey);
fromwire_pubkey(pptr, max, entry->blinding);
}
enclen = fromwire_u16(pptr, max);
if (enclen)
entry->enctlv = fromwire_tal_arrn(entry, pptr, max, enclen);
else
entry->enctlv = NULL;
return entry;
} }
void towire_route_hop(u8 **pptr, const struct route_hop *entry) void towire_route_hop(u8 **pptr, const struct route_hop *entry)
@ -76,6 +90,13 @@ void towire_route_hop(u8 **pptr, const struct route_hop *entry)
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); towire_u8(pptr, entry->style);
if (entry->blinding) {
towire_bool(pptr, true);
towire_pubkey(pptr, entry->blinding);
} else
towire_bool(pptr, false);
towire_u16(pptr, tal_bytelen(entry->enctlv));
towire_u8_array(pptr, entry->enctlv, tal_bytelen(entry->enctlv));
} }
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)

3
lightningd/gossip_msg.h

@ -40,7 +40,8 @@ fromwire_gossip_getnodes_entry(const tal_t *ctx, const u8 **pptr, size_t *max);
void towire_gossip_getnodes_entry(u8 **pptr, void towire_gossip_getnodes_entry(u8 **pptr,
const struct gossip_getnodes_entry *entry); const struct gossip_getnodes_entry *entry);
void fromwire_route_hop(const u8 **pprt, size_t *max, struct route_hop *entry); struct route_hop *fromwire_route_hop(const tal_t *ctx,
const u8 **pptr, size_t *max);
void towire_route_hop(u8 **pprt, const struct route_hop *entry); void towire_route_hop(u8 **pprt, const struct route_hop *entry);
void fromwire_route_info(const u8 **pprt, size_t *max, struct route_info *entry); void fromwire_route_info(const u8 **pprt, size_t *max, struct route_info *entry);

1
tools/generate-wire.py

@ -228,6 +228,7 @@ class Type(FieldSet):
'witscript', 'witscript',
'feature_set', 'feature_set',
'onionmsg_path', 'onionmsg_path',
'route_hop',
] ]
# Some BOLT types are re-typed based on their field name # Some BOLT types are re-typed based on their field name

Loading…
Cancel
Save