Skip to content

Commit 574cb1c

Browse files
committed
xpay: don't place global reservations on generated channels.
We generate fake scids for routehints and blinded paths. But then we were placing reservations on them as if they were global. If there are two xpays going at once these reservations will clash, even though the same scid refers to different channels. Reported-by: @Lagrang3 Changelog-Fixed: xpay: fixed theoretical clash with simultanous payments via routehints and blinded paths. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
1 parent de91f36 commit 574cb1c

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

plugins/xpay/xpay.c

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,8 @@ struct hop {
145145
u32 cltv_value_in;
146146
/* This is the delay, out from node. */
147147
u32 cltv_value_out;
148+
/* This is a fake channel. */
149+
bool fake_channel;
148150
};
149151

150152
/* Each actual payment attempt */
@@ -478,18 +480,6 @@ static void payment_give_up(struct command *aux_cmd,
478480
cleanup(aux_cmd, payment);
479481
}
480482

481-
/* We usually add things we learned to the global layer, but not
482-
* if it's a fake channel */
483-
static const char *layer_of(const struct payment *payment,
484-
const struct short_channel_id_dir *scidd)
485-
{
486-
struct gossmap *gossmap = get_gossmap(xpay_of(payment->plugin));
487-
488-
if (gossmap_find_chan(gossmap, &scidd->scid))
489-
return "xpay";
490-
return payment->private_layer;
491-
}
492-
493483
static void add_result_summary(struct attempt *attempt,
494484
enum log_level level,
495485
const char *fmt, ...)
@@ -697,8 +687,11 @@ static void update_knowledge_from_error(struct command *aux_cmd,
697687
/* We learned something about prior nodes */
698688
for (size_t i = 0; i < index; i++) {
699689
req = payment_ignored_req(aux_cmd, attempt, "askrene-inform-channel");
690+
/* Put what we learned in xpay, unless it's a fake channel */
700691
json_add_string(req->js, "layer",
701-
layer_of(attempt->payment, &attempt->hops[i].scidd));
692+
attempt->hops[i].fake_channel
693+
? attempt->payment->private_layer
694+
: "xpay");
702695
json_add_short_channel_id_dir(req->js,
703696
"short_channel_id_dir",
704697
attempt->hops[i].scidd);
@@ -855,8 +848,11 @@ static void update_knowledge_from_error(struct command *aux_cmd,
855848

856849
channel_capacity:
857850
req = payment_ignored_req(aux_cmd, attempt, "askrene-inform-channel");
851+
/* Put what we learned in xpay, unless it's a fake channel */
858852
json_add_string(req->js, "layer",
859-
layer_of(attempt->payment, &attempt->hops[index].scidd));
853+
attempt->hops[index].fake_channel
854+
? attempt->payment->private_layer
855+
: "xpay");
860856
json_add_short_channel_id_dir(req->js,
861857
"short_channel_id_dir",
862858
attempt->hops[index].scidd);
@@ -892,6 +888,8 @@ static struct command_result *unreserve_path(struct command *aux_cmd,
892888
json_object_start(req->js, NULL);
893889
json_add_short_channel_id_dir(req->js, "short_channel_id_dir", hop->scidd);
894890
json_add_amount_msat(req->js, "amount_msat", hop->amount_out);
891+
if (hop->fake_channel)
892+
json_add_string(req->js, "layer", attempt->payment->private_layer);
895893
json_object_end(req->js);
896894
}
897895
json_array_end(req->js);
@@ -1177,6 +1175,7 @@ static struct command_result *getroutes_done(struct command *aux_cmd,
11771175
const jsmntok_t *t, *routes;
11781176
size_t i;
11791177
struct amount_msat needs_routing, was_routing;
1178+
struct gossmap *gossmap = get_gossmap(xpay_of(payment->plugin));
11801179

11811180
payment_log(payment, LOG_DBG, "getroutes_done: %s",
11821181
payment->cmd ? "continuing" : "ignoring");
@@ -1244,6 +1243,7 @@ static struct command_result *getroutes_done(struct command *aux_cmd,
12441243
if (err)
12451244
plugin_err(aux_cmd->plugin, "Malformed routes: %s",
12461245
err);
1246+
hop->fake_channel = !gossmap_find_chan(gossmap, &hop->scidd.scid);
12471247
if (j > 0) {
12481248
hops[j-1].amount_out = hop->amount_in;
12491249
hops[j-1].cltv_value_out = hop->cltv_value_in;
@@ -1268,6 +1268,8 @@ static struct command_result *getroutes_done(struct command *aux_cmd,
12681268
json_add_short_channel_id_dir(req->js, "short_channel_id_dir",
12691269
hop->scidd);
12701270
json_add_amount_msat(req->js, "amount_msat", hop->amount_out);
1271+
if (hop->fake_channel)
1272+
json_add_string(req->js, "layer", payment->private_layer);
12711273
json_object_end(req->js);
12721274
}
12731275
json_array_end(req->js);

0 commit comments

Comments
 (0)