Skip to content

Commit

Permalink
askrene: change getroutes amount and delay values
Browse files Browse the repository at this point in the history
In the previous implementation getroutes would provide for every i-th
hop the value of the amount and delay which correspond to the (i-1)-th
HTLC. This commit changes that, instead the i-th hop contains the value
of the amount and delay of the i-th HTLC.

Changelog-Changed: askrene: getroutes outputs contains for each hop the correct amount and delay values.

Signed-off-by: Lagrang3 <[email protected]>
  • Loading branch information
Lagrang3 committed Feb 8, 2025
1 parent 3f2b490 commit 28df766
Show file tree
Hide file tree
Showing 5 changed files with 142 additions and 56 deletions.
10 changes: 5 additions & 5 deletions contrib/msggen/msggen/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -16190,7 +16190,7 @@
"delay": {
"type": "u32",
"description": [
"The total CLTV expected by the node at the start of this hop."
"The total CLTV on this hop's HTLC."
]
}
}
Expand Down Expand Up @@ -16241,14 +16241,14 @@
{
"short_channel_id_dir": "109x1x1/1",
"next_node_id": "nodeid020202020202020202020202020202020202020202020202020202020202",
"amount_msat": 1250026,
"delay": 12
"amount_msat": 1250013,
"delay": 6
},
{
"short_channel_id_dir": "123x1x1/0",
"next_node_id": "nodeid030303030303030303030303030303030303030303030303030303030303",
"amount_msat": 1250013,
"delay": 6
"amount_msat": 1250000,
"delay": 0
}
]
}
Expand Down
10 changes: 5 additions & 5 deletions doc/schemas/lightning-getroutes.json
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@
"delay": {
"type": "u32",
"description": [
"The total CLTV expected by the node at the start of this hop."
"The total CLTV on this hop's HTLC."
]
}
}
Expand Down Expand Up @@ -206,14 +206,14 @@
{
"short_channel_id_dir": "109x1x1/1",
"next_node_id": "nodeid020202020202020202020202020202020202020202020202020202020202",
"amount_msat": 1250026,
"delay": 12
"amount_msat": 1250013,
"delay": 6
},
{
"short_channel_id_dir": "123x1x1/0",
"next_node_id": "nodeid030303030303030303030303030303030303030303030303030303030303",
"amount_msat": 1250013,
"delay": 6
"amount_msat": 1250000,
"delay": 0
}
]
}
Expand Down
4 changes: 2 additions & 2 deletions plugins/askrene/askrene.c
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,8 @@ static const char *get_routes(const tal_t *ctx,
struct gossmap_node *far_end;
const struct half_chan *h = flow_edge(flows[i], j);

rh->amount = msat;
rh->delay = delay;
if (!amount_msat_add_fee(&msat, h->base_fee, h->proportional_fee))
plugin_err(rq->plugin, "Adding fee to amount");
delay += h->delay;
Expand All @@ -534,8 +536,6 @@ static const char *get_routes(const tal_t *ctx,
rh->direction = flows[i]->dirs[j];
far_end = gossmap_nth_node(rq->gossmap, flows[i]->path[j], !flows[i]->dirs[j]);
gossmap_node_get_id(rq->gossmap, far_end, &rh->node_id);
rh->amount = msat;
rh->delay = delay;
}
(*amounts)[i] = flows[i]->delivers;
rq_log(tmpctx, rq, LOG_INFORM, "Flow %zu/%zu: %s",
Expand Down
18 changes: 5 additions & 13 deletions plugins/xpay/xpay.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,8 @@ struct hop {
struct pubkey next_node;
/* Via this channel */
struct short_channel_id_dir scidd;
/* This is amount the node needs (including fees) */
struct amount_msat amount_in;
/* ... to send this amount */
struct amount_msat amount_out;
/* This is the delay, including delay across node */
u32 cltv_value_in;
/* This is the delay, out from node. */
u32 cltv_value_out;
};
Expand Down Expand Up @@ -347,14 +343,14 @@ static struct amount_msat initial_sent(const struct attempt *attempt)
{
if (tal_count(attempt->hops) == 0)
return attempt->delivers;
return attempt->hops[0].amount_in;
return attempt->hops[0].amount_out;
}

static u32 initial_cltv_delta(const struct attempt *attempt)
{
if (tal_count(attempt->hops) == 0)
return attempt->payment->final_cltv;
return attempt->hops[0].cltv_value_in;
return attempt->hops[0].cltv_value_out;
}

/* The current attempt is the first to succeed: we assume all the ones
Expand Down Expand Up @@ -776,7 +772,7 @@ static struct amount_msat total_fees_being_sent(const struct payment *payment)
if (tal_count(attempt->hops) == 0)
continue;
if (!amount_msat_sub(&fee,
attempt->hops[0].amount_in,
attempt->hops[0].amount_out,
attempt->delivers))
abort();
if (!amount_msat_accumulate(&sum, fee))
Expand Down Expand Up @@ -1053,16 +1049,12 @@ static struct command_result *getroutes_done(struct command *aux_cmd,
",delay:%}",
JSON_SCAN(json_to_short_channel_id_dir,
&hop->scidd),
JSON_SCAN(json_to_msat, &hop->amount_in),
JSON_SCAN(json_to_msat, &hop->amount_out),
JSON_SCAN(json_to_pubkey, &hop->next_node),
JSON_SCAN(json_to_u32, &hop->cltv_value_in));
JSON_SCAN(json_to_u32, &hop->cltv_value_out));
if (err)
plugin_err(aux_cmd->plugin, "Malformed routes: %s",
err);
if (j > 0) {
hops[j-1].amount_out = hop->amount_in;
hops[j-1].cltv_value_out = hop->cltv_value_in;
}
}
hops[j-1].amount_out = delivers;
hops[j-1].cltv_value_out = payment->final_cltv;
Expand Down
Loading

0 comments on commit 28df766

Please sign in to comment.