Browse Source

routing: Returning channel_id to getroute requests

The new onion uses the `channel_id` instead of the `node_id` of the
next hop to identify where to forward the payment. So we return the
exact channel chosen by the routing algo, to avoid having to look it
up again later.
ppa-0.6.1
Christian Decker 8 years ago
parent
commit
d87ca4121d
  1. 8
      daemon/json.c
  2. 6
      daemon/json.h
  3. 2
      daemon/routing.c
  4. 1
      daemon/routing.h
  5. 4
      lightningd/gossip_control.c
  6. 2
      lightningd/gossip_msg.c

8
daemon/json.c

@ -445,6 +445,14 @@ void json_add_pubkey(struct json_result *response,
json_add_hex(response, fieldname, der, sizeof(der)); json_add_hex(response, fieldname, der, sizeof(der));
} }
void json_add_short_channel_id(struct json_result *response,
const char *fieldname,
const struct short_channel_id *id)
{
char *str = tal_fmt(response, "%d:%d:%d", id->blocknum, id->txnum, id->outnum);
json_add_string(response, fieldname, str);
}
void json_add_object(struct json_result *result, ...) void json_add_object(struct json_result *result, ...)
{ {
va_list ap; va_list ap;

6
daemon/json.h

@ -3,6 +3,7 @@
#include "config.h" #include "config.h"
#include <bitcoin/pubkey.h> #include <bitcoin/pubkey.h>
#include <ccan/tal/tal.h> #include <ccan/tal/tal.h>
#include <daemon/routing.h>
#include <stdbool.h> #include <stdbool.h>
#include <stdint.h> #include <stdint.h>
#include <stdlib.h> #include <stdlib.h>
@ -106,6 +107,11 @@ void json_add_pubkey(struct json_result *response,
const char *fieldname, const char *fieldname,
const struct pubkey *key); const struct pubkey *key);
/* '"fieldname" : "1234/5/6"' */
void json_add_short_channel_id(struct json_result *response,
const char *fieldname,
const struct short_channel_id *id);
void json_add_object(struct json_result *result, ...); void json_add_object(struct json_result *result, ...);
const char *json_result_string(const struct json_result *result); const char *json_result_string(const struct json_result *result);

2
daemon/routing.c

@ -911,6 +911,7 @@ struct route_hop *get_route(tal_t *ctx, struct routing_state *rstate,
total_delay = 0; total_delay = 0;
for (i = tal_count(route) - 1; i >= 0; i--) { for (i = tal_count(route) - 1; i >= 0; i--) {
hops[i + 1].channel_id = route[i]->short_channel_id;
hops[i + 1].nodeid = route[i]->dst->id; hops[i + 1].nodeid = route[i]->dst->id;
hops[i + 1].amount = total_amount; hops[i + 1].amount = total_amount;
total_amount += connection_fee(route[i], total_amount); total_amount += connection_fee(route[i], total_amount);
@ -921,6 +922,7 @@ struct route_hop *get_route(tal_t *ctx, struct routing_state *rstate,
hops[i + 1].delay = total_delay; hops[i + 1].delay = total_delay;
} }
/* Backfill the first hop manually */ /* Backfill the first hop manually */
hops[0].channel_id = first_conn->short_channel_id;
hops[0].nodeid = first_conn->dst->id; hops[0].nodeid = first_conn->dst->id;
/* We don't charge ourselves any fees. */ /* We don't charge ourselves any fees. */
hops[0].amount = total_amount; hops[0].amount = total_amount;

1
daemon/routing.h

@ -90,6 +90,7 @@ struct routing_state {
}; };
struct route_hop { struct route_hop {
struct short_channel_id channel_id;
struct pubkey nodeid; struct pubkey nodeid;
u32 amount; u32 amount;
u32 delay; u32 delay;

4
lightningd/gossip_control.c

@ -252,9 +252,11 @@ static bool json_getroute_reply(struct subd *gossip, const u8 *reply, const int
response = new_json_result(cmd); response = new_json_result(cmd);
json_object_start(response, NULL); json_object_start(response, NULL);
json_array_start(response, "route"); json_array_start(response, "route");
for (i=0; i<tal_count(hops); i++) { for (i = 0; i < tal_count(hops); i++) {
json_object_start(response, NULL); json_object_start(response, NULL);
json_add_pubkey(response, "id", &hops[i].nodeid); json_add_pubkey(response, "id", &hops[i].nodeid);
json_add_short_channel_id(response, "channel",
&hops[i].channel_id);
json_add_u64(response, "msatoshi", hops[i].amount); json_add_u64(response, "msatoshi", hops[i].amount);
json_add_num(response, "delay", hops[i].delay); json_add_num(response, "delay", hops[i].delay);
json_object_end(response); json_object_end(response);

2
lightningd/gossip_msg.c

@ -29,12 +29,14 @@ void towire_gossip_getnodes_entry(u8 **pptr, const struct gossip_getnodes_entry
void fromwire_route_hop(const u8 **pptr, size_t *max, struct route_hop *entry) void fromwire_route_hop(const u8 **pptr, size_t *max, struct route_hop *entry)
{ {
fromwire_pubkey(pptr, max, &entry->nodeid); fromwire_pubkey(pptr, max, &entry->nodeid);
fromwire_short_channel_id(pptr, max, &entry->channel_id);
entry->amount = fromwire_u32(pptr, max); entry->amount = fromwire_u32(pptr, max);
entry->delay = fromwire_u32(pptr, max); entry->delay = fromwire_u32(pptr, max);
} }
void towire_route_hop(u8 **pptr, const struct route_hop *entry) void towire_route_hop(u8 **pptr, const struct route_hop *entry)
{ {
towire_pubkey(pptr, &entry->nodeid); towire_pubkey(pptr, &entry->nodeid);
towire_short_channel_id(pptr, &entry->channel_id);
towire_u32(pptr, entry->amount); towire_u32(pptr, entry->amount);
towire_u32(pptr, entry->delay); towire_u32(pptr, entry->delay);
} }

Loading…
Cancel
Save