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. 21
      gossipd/routing.c
  3. 4
      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;
u32 max_hops;
u8 *out;
struct route_hop *hops;
struct route_hop **hops;
/* fuzz 12.345% -> fuzz_millionths = 12345000 */
u64 fuzz_millionths;
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(),
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));
return daemon_conn_read_next(conn, daemon->master);
}

21
gossipd/routing.c

@ -2630,7 +2630,7 @@ u8 *handle_node_announcement(struct routing_state *rstate, const u8 *node_ann,
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 *destination,
struct amount_msat msat, double riskfactor,
@ -2643,7 +2643,7 @@ struct route_hop *get_route(const tal_t *ctx, struct routing_state *rstate,
struct amount_msat total_amount;
unsigned int total_delay;
struct amount_msat fee;
struct route_hop *hops;
struct route_hop **hops;
struct node *n;
struct amount_msat *saved_capacity;
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. */
hops = tal_arr(ctx, struct route_hop, tal_count(route));
hops = tal_arr(ctx, struct route_hop *, tal_count(route));
total_amount = msat;
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]);
c = &route[i]->half[idx];
hops[i].channel_id = route[i]->scid;
hops[i].nodeid = n->id;
hops[i].amount = total_amount;
hops[i].delay = total_delay;
hops[i].direction = idx;
hops[i].style = n->hop_style;
hops[i] = tal(hops, struct route_hop);
hops[i]->channel_id = route[i]->scid;
hops[i]->nodeid = n->id;
hops[i]->amount = total_amount;
hops[i]->delay = total_delay;
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! */
if (!amount_msat_add_fee(&total_amount,

4
gossipd/routing.h

@ -325,6 +325,8 @@ struct route_hop {
struct node_id nodeid;
struct amount_msat amount;
u32 delay;
struct pubkey *blinding;
u8 *enctlv;
enum route_hop_style style;
};
@ -408,7 +410,7 @@ struct node *get_node(struct routing_state *rstate,
const struct node_id *id);
/* 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 *destination,
const struct amount_msat msat, double riskfactor,

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 */
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;
json_array_start(r, n);
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);
}
@ -347,7 +347,7 @@ static void json_getroute_reply(struct subd *gossip UNUSED, const u8 *reply, con
struct command *cmd)
{
struct json_stream *response;
struct route_hop *hops;
struct route_hop **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));
}
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_short_channel_id(pptr, max, &entry->channel_id);
entry->direction = fromwire_u8(pptr, max);
entry->amount = fromwire_amount_msat(pptr, max);
entry->delay = fromwire_u32(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)
@ -76,6 +90,13 @@ void towire_route_hop(u8 **pptr, const struct route_hop *entry)
towire_amount_msat(pptr, entry->amount);
towire_u32(pptr, entry->delay);
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)

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,
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 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',
'feature_set',
'onionmsg_path',
'route_hop',
]
# Some BOLT types are re-typed based on their field name

Loading…
Cancel
Save