mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-01-18 21:35:11 +01:00
gossipd: route correctly using final CLTV value.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
8fdf334168
commit
68dae5648d
@ -789,19 +789,19 @@ static struct io_plan *getroute_req(struct io_conn *conn, struct daemon *daemon,
|
||||
{
|
||||
tal_t *tmpctx = tal_tmpctx(msg);
|
||||
struct pubkey source, destination;
|
||||
u32 msatoshi;
|
||||
u32 msatoshi, final_cltv;
|
||||
u16 riskfactor;
|
||||
u8 *out;
|
||||
struct route_hop *hops;
|
||||
|
||||
fromwire_gossip_getroute_request(msg, NULL, &source, &destination,
|
||||
&msatoshi, &riskfactor);
|
||||
&msatoshi, &riskfactor, &final_cltv);
|
||||
status_trace("Trying to find a route from %s to %s for %d msatoshi",
|
||||
pubkey_to_hexstr(tmpctx, &source),
|
||||
pubkey_to_hexstr(tmpctx, &destination), msatoshi);
|
||||
|
||||
hops = get_route(tmpctx, daemon->rstate, &source, &destination,
|
||||
msatoshi, 1);
|
||||
msatoshi, 1, final_cltv);
|
||||
|
||||
out = towire_gossip_getroute_reply(msg, hops);
|
||||
tal_free(tmpctx);
|
||||
|
@ -86,6 +86,7 @@ gossip_getroute_request,,source,struct pubkey
|
||||
gossip_getroute_request,,destination,struct pubkey
|
||||
gossip_getroute_request,,msatoshi,u32
|
||||
gossip_getroute_request,,riskfactor,u16
|
||||
gossip_getroute_request,,final_cltv,u32
|
||||
|
||||
gossip_getroute_reply,3106
|
||||
gossip_getroute_reply,,num_hops,u16
|
||||
|
|
@ -736,7 +736,8 @@ void handle_node_announcement(
|
||||
struct route_hop *get_route(tal_t *ctx, struct routing_state *rstate,
|
||||
const struct pubkey *source,
|
||||
const struct pubkey *destination,
|
||||
const u32 msatoshi, double riskfactor)
|
||||
const u32 msatoshi, double riskfactor,
|
||||
u32 final_cltv)
|
||||
{
|
||||
struct node_connection **route;
|
||||
u64 total_amount;
|
||||
@ -756,7 +757,7 @@ struct route_hop *get_route(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) + 1);
|
||||
total_amount = msatoshi;
|
||||
total_delay = 0;
|
||||
total_delay = final_cltv;
|
||||
|
||||
for (i = tal_count(route) - 1; i >= 0; i--) {
|
||||
hops[i + 1].channel_id = route[i]->short_channel_id;
|
||||
@ -764,16 +765,16 @@ struct route_hop *get_route(tal_t *ctx, struct routing_state *rstate,
|
||||
hops[i + 1].amount = total_amount;
|
||||
total_amount += connection_fee(route[i], total_amount);
|
||||
|
||||
total_delay += route[i]->delay;
|
||||
hops[i + 1].delay = total_delay;
|
||||
total_delay += route[i]->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. */
|
||||
/* We don't charge ourselves any fees, nor require delay */
|
||||
hops[0].amount = total_amount;
|
||||
/* We do require delay though. */
|
||||
total_delay += first_conn->delay;
|
||||
hops[0].delay = total_delay;
|
||||
|
||||
/* FIXME: Shadow route! */
|
||||
return hops;
|
||||
}
|
||||
|
@ -124,7 +124,8 @@ void handle_node_announcement(struct routing_state *rstate, const u8 *node, size
|
||||
struct route_hop *get_route(tal_t *ctx, struct routing_state *rstate,
|
||||
const struct pubkey *source,
|
||||
const struct pubkey *destination,
|
||||
const u32 msatoshi, double riskfactor);
|
||||
const u32 msatoshi, double riskfactor,
|
||||
u32 final_cltv);
|
||||
|
||||
/* Utility function that, given a source and a destination, gives us
|
||||
* the direction bit the matching channel should get */
|
||||
|
@ -204,8 +204,9 @@ static void json_getroute_reply(struct subd *gossip, const u8 *reply, const int
|
||||
static void json_getroute(struct command *cmd, const char *buffer, const jsmntok_t *params)
|
||||
{
|
||||
struct pubkey id;
|
||||
jsmntok_t *idtok, *msatoshitok, *riskfactortok;
|
||||
jsmntok_t *idtok, *msatoshitok, *riskfactortok, *cltvtok;
|
||||
u64 msatoshi;
|
||||
unsigned cltv = 9;
|
||||
double riskfactor;
|
||||
struct lightningd *ld = cmd->ld;
|
||||
|
||||
@ -213,6 +214,7 @@ static void json_getroute(struct command *cmd, const char *buffer, const jsmntok
|
||||
"id", &idtok,
|
||||
"msatoshi", &msatoshitok,
|
||||
"riskfactor", &riskfactortok,
|
||||
"?cltv", &cltvtok,
|
||||
NULL)) {
|
||||
command_fail(cmd, "Need id, msatoshi and riskfactor");
|
||||
return;
|
||||
@ -223,6 +225,11 @@ static void json_getroute(struct command *cmd, const char *buffer, const jsmntok
|
||||
return;
|
||||
}
|
||||
|
||||
if (cltvtok && !json_tok_number(buffer, cltvtok, &cltv)) {
|
||||
command_fail(cmd, "Invalid cltv");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!json_tok_u64(buffer, msatoshitok, &msatoshi)) {
|
||||
command_fail(cmd, "'%.*s' is not a valid number",
|
||||
(int)(msatoshitok->end - msatoshitok->start),
|
||||
@ -236,13 +243,13 @@ static void json_getroute(struct command *cmd, const char *buffer, const jsmntok
|
||||
buffer + riskfactortok->start);
|
||||
return;
|
||||
}
|
||||
u8 *req = towire_gossip_getroute_request(cmd, &ld->id, &id, msatoshi, riskfactor*1000);
|
||||
u8 *req = towire_gossip_getroute_request(cmd, &ld->id, &id, msatoshi, riskfactor*1000, cltv);
|
||||
subd_req(ld->gossip, ld->gossip, req, -1, 0, json_getroute_reply, cmd);
|
||||
}
|
||||
|
||||
static const struct json_command getroute_command = {
|
||||
"getroute", json_getroute,
|
||||
"Return route to {id} for {msatoshi}, using {riskfactor}",
|
||||
"Return route to {id} for {msatoshi}, using {riskfactor} and optional {cltv} (default 9)",
|
||||
"Returns a {route} array of {id} {msatoshi} {delay}: msatoshi and delay (in blocks) is cumulative."
|
||||
};
|
||||
AUTODATA(json_command, &getroute_command);
|
||||
|
Loading…
Reference in New Issue
Block a user