Skip to content

Commit 28df766

Browse files
committed
askrene: change getroutes amount and delay values
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 <lagrang3@protonmail.com>
1 parent 3f2b490 commit 28df766

File tree

5 files changed

+142
-56
lines changed

5 files changed

+142
-56
lines changed

contrib/msggen/msggen/schema.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16190,7 +16190,7 @@
1619016190
"delay": {
1619116191
"type": "u32",
1619216192
"description": [
16193-
"The total CLTV expected by the node at the start of this hop."
16193+
"The total CLTV on this hop's HTLC."
1619416194
]
1619516195
}
1619616196
}
@@ -16241,14 +16241,14 @@
1624116241
{
1624216242
"short_channel_id_dir": "109x1x1/1",
1624316243
"next_node_id": "nodeid020202020202020202020202020202020202020202020202020202020202",
16244-
"amount_msat": 1250026,
16245-
"delay": 12
16244+
"amount_msat": 1250013,
16245+
"delay": 6
1624616246
},
1624716247
{
1624816248
"short_channel_id_dir": "123x1x1/0",
1624916249
"next_node_id": "nodeid030303030303030303030303030303030303030303030303030303030303",
16250-
"amount_msat": 1250013,
16251-
"delay": 6
16250+
"amount_msat": 1250000,
16251+
"delay": 0
1625216252
}
1625316253
]
1625416254
}

doc/schemas/lightning-getroutes.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@
155155
"delay": {
156156
"type": "u32",
157157
"description": [
158-
"The total CLTV expected by the node at the start of this hop."
158+
"The total CLTV on this hop's HTLC."
159159
]
160160
}
161161
}
@@ -206,14 +206,14 @@
206206
{
207207
"short_channel_id_dir": "109x1x1/1",
208208
"next_node_id": "nodeid020202020202020202020202020202020202020202020202020202020202",
209-
"amount_msat": 1250026,
210-
"delay": 12
209+
"amount_msat": 1250013,
210+
"delay": 6
211211
},
212212
{
213213
"short_channel_id_dir": "123x1x1/0",
214214
"next_node_id": "nodeid030303030303030303030303030303030303030303030303030303030303",
215-
"amount_msat": 1250013,
216-
"delay": 6
215+
"amount_msat": 1250000,
216+
"delay": 0
217217
}
218218
]
219219
}

plugins/askrene/askrene.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,8 @@ static const char *get_routes(const tal_t *ctx,
526526
struct gossmap_node *far_end;
527527
const struct half_chan *h = flow_edge(flows[i], j);
528528

529+
rh->amount = msat;
530+
rh->delay = delay;
529531
if (!amount_msat_add_fee(&msat, h->base_fee, h->proportional_fee))
530532
plugin_err(rq->plugin, "Adding fee to amount");
531533
delay += h->delay;
@@ -534,8 +536,6 @@ static const char *get_routes(const tal_t *ctx,
534536
rh->direction = flows[i]->dirs[j];
535537
far_end = gossmap_nth_node(rq->gossmap, flows[i]->path[j], !flows[i]->dirs[j]);
536538
gossmap_node_get_id(rq->gossmap, far_end, &rh->node_id);
537-
rh->amount = msat;
538-
rh->delay = delay;
539539
}
540540
(*amounts)[i] = flows[i]->delivers;
541541
rq_log(tmpctx, rq, LOG_INFORM, "Flow %zu/%zu: %s",

plugins/xpay/xpay.c

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -127,12 +127,8 @@ struct hop {
127127
struct pubkey next_node;
128128
/* Via this channel */
129129
struct short_channel_id_dir scidd;
130-
/* This is amount the node needs (including fees) */
131-
struct amount_msat amount_in;
132130
/* ... to send this amount */
133131
struct amount_msat amount_out;
134-
/* This is the delay, including delay across node */
135-
u32 cltv_value_in;
136132
/* This is the delay, out from node. */
137133
u32 cltv_value_out;
138134
};
@@ -347,14 +343,14 @@ static struct amount_msat initial_sent(const struct attempt *attempt)
347343
{
348344
if (tal_count(attempt->hops) == 0)
349345
return attempt->delivers;
350-
return attempt->hops[0].amount_in;
346+
return attempt->hops[0].amount_out;
351347
}
352348

353349
static u32 initial_cltv_delta(const struct attempt *attempt)
354350
{
355351
if (tal_count(attempt->hops) == 0)
356352
return attempt->payment->final_cltv;
357-
return attempt->hops[0].cltv_value_in;
353+
return attempt->hops[0].cltv_value_out;
358354
}
359355

360356
/* The current attempt is the first to succeed: we assume all the ones
@@ -776,7 +772,7 @@ static struct amount_msat total_fees_being_sent(const struct payment *payment)
776772
if (tal_count(attempt->hops) == 0)
777773
continue;
778774
if (!amount_msat_sub(&fee,
779-
attempt->hops[0].amount_in,
775+
attempt->hops[0].amount_out,
780776
attempt->delivers))
781777
abort();
782778
if (!amount_msat_accumulate(&sum, fee))
@@ -1053,16 +1049,12 @@ static struct command_result *getroutes_done(struct command *aux_cmd,
10531049
",delay:%}",
10541050
JSON_SCAN(json_to_short_channel_id_dir,
10551051
&hop->scidd),
1056-
JSON_SCAN(json_to_msat, &hop->amount_in),
1052+
JSON_SCAN(json_to_msat, &hop->amount_out),
10571053
JSON_SCAN(json_to_pubkey, &hop->next_node),
1058-
JSON_SCAN(json_to_u32, &hop->cltv_value_in));
1054+
JSON_SCAN(json_to_u32, &hop->cltv_value_out));
10591055
if (err)
10601056
plugin_err(aux_cmd->plugin, "Malformed routes: %s",
10611057
err);
1062-
if (j > 0) {
1063-
hops[j-1].amount_out = hop->amount_in;
1064-
hops[j-1].cltv_value_out = hop->cltv_value_in;
1065-
}
10661058
}
10671059
hops[j-1].amount_out = delivers;
10681060
hops[j-1].cltv_value_out = payment->final_cltv;

0 commit comments

Comments
 (0)