mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-24 01:24:26 +01:00
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.
This commit is contained in:
@@ -445,6 +445,14 @@ void json_add_pubkey(struct json_result *response,
|
||||
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, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include "config.h"
|
||||
#include <bitcoin/pubkey.h>
|
||||
#include <ccan/tal/tal.h>
|
||||
#include <daemon/routing.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
@@ -106,6 +107,11 @@ void json_add_pubkey(struct json_result *response,
|
||||
const char *fieldname,
|
||||
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, ...);
|
||||
|
||||
const char *json_result_string(const struct json_result *result);
|
||||
|
||||
@@ -911,6 +911,7 @@ struct route_hop *get_route(tal_t *ctx, struct routing_state *rstate,
|
||||
total_delay = 0;
|
||||
|
||||
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].amount = 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;
|
||||
}
|
||||
/* Backfill the first hop manually */
|
||||
hops[0].channel_id = first_conn->short_channel_id;
|
||||
hops[0].nodeid = first_conn->dst->id;
|
||||
/* We don't charge ourselves any fees. */
|
||||
hops[0].amount = total_amount;
|
||||
|
||||
@@ -90,6 +90,7 @@ struct routing_state {
|
||||
};
|
||||
|
||||
struct route_hop {
|
||||
struct short_channel_id channel_id;
|
||||
struct pubkey nodeid;
|
||||
u32 amount;
|
||||
u32 delay;
|
||||
|
||||
@@ -252,9 +252,11 @@ static bool json_getroute_reply(struct subd *gossip, const u8 *reply, const int
|
||||
response = new_json_result(cmd);
|
||||
json_object_start(response, NULL);
|
||||
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_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_num(response, "delay", hops[i].delay);
|
||||
json_object_end(response);
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
fromwire_pubkey(pptr, max, &entry->nodeid);
|
||||
fromwire_short_channel_id(pptr, max, &entry->channel_id);
|
||||
entry->amount = fromwire_u32(pptr, max);
|
||||
entry->delay = fromwire_u32(pptr, max);
|
||||
}
|
||||
void towire_route_hop(u8 **pptr, const struct route_hop *entry)
|
||||
{
|
||||
towire_pubkey(pptr, &entry->nodeid);
|
||||
towire_short_channel_id(pptr, &entry->channel_id);
|
||||
towire_u32(pptr, entry->amount);
|
||||
towire_u32(pptr, entry->delay);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user