Skip to content

Commit 6ab9d54

Browse files
committed
renepay: filter channels using askrene API
Changelog-None. Signed-off-by: Lagrang3 <[email protected]>
1 parent 85abaa6 commit 6ab9d54

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

plugins/renepay/mods.c

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1198,24 +1198,31 @@ REGISTER_PAYMENT_MODIFIER(initpaymentlayer, initpaymentlayer_cb);
11981198
* FIXME: shall we set these threshold parameters as plugin options?
11991199
*/
12001200

1201+
static struct command_result *channelfilter_done(struct command *cmd,
1202+
struct payment *payment)
1203+
{
1204+
return payment_continue(payment);
1205+
}
1206+
12011207
static struct command_result *channelfilter_cb(struct payment *payment)
12021208
{
12031209
assert(payment);
12041210
assert(pay_plugin->gossmap);
12051211
const double HTLC_MAX_FRACTION = 0.01; // 1%
12061212
const u64 HTLC_MAX_STOP_MSAT = 1000000000; // 1M sats
1207-
12081213
u64 disabled_count = 0;
1209-
1210-
12111214
u64 htlc_max_threshold = HTLC_MAX_FRACTION * payment->payment_info
12121215
.amount.millisatoshis; /* Raw: a fraction of this amount. */
12131216
/* Don't exclude channels with htlc_max above HTLC_MAX_STOP_MSAT even if
12141217
* that represents a fraction of the payment smaller than
12151218
* HTLC_MAX_FRACTION. */
12161219
htlc_max_threshold = MIN(htlc_max_threshold, HTLC_MAX_STOP_MSAT);
12171220

1218-
gossmap_apply_localmods(pay_plugin->gossmap, payment->local_gossmods);
1221+
struct command *cmd = payment_command(payment);
1222+
struct request_batch *batch = request_batch_new(
1223+
cmd, NULL, log_payment_err, channelfilter_done, payment);
1224+
struct out_req *req;
1225+
12191226
for (const struct gossmap_node *node =
12201227
gossmap_first_node(pay_plugin->gossmap);
12211228
node; node = gossmap_next_node(pay_plugin->gossmap, node)) {
@@ -1230,19 +1237,24 @@ static struct command_result *channelfilter_cb(struct payment *payment)
12301237
.scid = gossmap_chan_scid(
12311238
pay_plugin->gossmap, chan),
12321239
.dir = dir};
1233-
disabledmap_add_channel(payment->disabledmap,
1234-
scidd);
1240+
req = add_to_batch(cmd, batch,
1241+
"askrene-update-channel");
1242+
json_add_string(req->js, "layer",
1243+
payment->payment_layer);
1244+
json_add_short_channel_id_dir(
1245+
req->js, "short_channel_id_dir", scidd);
1246+
json_add_bool(req->js, "enabled", false);
1247+
send_outreq(req);
12351248
disabled_count++;
12361249
}
12371250
}
12381251
}
1239-
gossmap_remove_localmods(pay_plugin->gossmap, payment->local_gossmods);
12401252
// FIXME: prune the network over other parameters, eg. capacity,
12411253
// fees, ...
12421254
plugin_log(pay_plugin->plugin, LOG_DBG,
12431255
"channelfilter: disabling %" PRIu64 " channels.",
12441256
disabled_count);
1245-
return payment_continue(payment);
1257+
return batch_done(cmd, batch);
12461258
}
12471259

12481260
REGISTER_PAYMENT_MODIFIER(channelfilter, channelfilter_cb);

0 commit comments

Comments
 (0)