Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add exclude option to pay #4906

Merged
merged 4 commits into from
Dec 4, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add route exclusion payment modifier and pay rpc exclude arg
Changelog-Added: Add `exclude` option for `pay` command to manually exclude channels or nodes when finding a route.
  • Loading branch information
andrewtoth committed Nov 18, 2021
commit 79a9bf3ec462d305b26837fecbc8c104100ecf49
42 changes: 42 additions & 0 deletions plugins/libplugin-pay.c
Original file line number Diff line number Diff line change
Expand Up @@ -3885,3 +3885,45 @@ static void payee_incoming_limit_step_cb(void *d UNUSED, struct payment *p)

REGISTER_PAYMENT_MODIFIER(payee_incoming_limit, void *, NULL,
payee_incoming_limit_step_cb);

static struct route_exclusions_data *
route_exclusions_data_init(struct payment *p)
{
struct route_exclusions_data *d;
if (p->parent != NULL) {
return payment_mod_route_exclusions_get_data(p->parent);
} else {
d = tal(p, struct route_exclusions_data);
d->exclusions = NULL;
}
return d;
}

static void route_exclusions_step_cb(struct route_exclusions_data *d,
struct payment *p)
{
if (p->parent)
return payment_continue(p);
struct route_exclusion **exclusions = d->exclusions;
for (size_t i = 0; i < tal_count(exclusions); i++) {
struct route_exclusion *e = exclusions[i];
if (e->type == EXCLUDE_CHANNEL) {
channel_hints_update(p, e->u.chan_id.scid, e->u.chan_id.dir,
false, false, NULL, NULL);
} else {
if (node_id_eq(&e->u.node_id, p->destination)) {
payment_abort(p, "Payee is manually excluded");
return;
} else if (node_id_eq(&e->u.node_id, p->local_id)) {
payment_abort(p, "Payer is manually excluded");
return;
}

tal_arr_expand(&p->excluded_nodes, e->u.node_id);
}
}
payment_continue(p);
}

REGISTER_PAYMENT_MODIFIER(route_exclusions, struct route_exclusions_data *,
route_exclusions_data_init, route_exclusions_step_cb);
6 changes: 6 additions & 0 deletions plugins/libplugin-pay.h
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,10 @@ struct adaptive_split_mod_data {
u32 htlc_budget;
};

struct route_exclusions_data {
struct route_exclusion **exclusions;
};

/* List of globally available payment modifiers. */
REGISTER_PAYMENT_MODIFIER_HEADER(retry, struct retry_mod_data);
REGISTER_PAYMENT_MODIFIER_HEADER(routehints, struct routehints_data);
Expand All @@ -426,6 +430,8 @@ REGISTER_PAYMENT_MODIFIER_HEADER(local_channel_hints, void);
* we detect the payee to have, in order to not exhaust the number of HTLCs
* each of those channels can bear. */
REGISTER_PAYMENT_MODIFIER_HEADER(payee_incoming_limit, void);
REGISTER_PAYMENT_MODIFIER_HEADER(route_exclusions, struct route_exclusions_data);


struct payment *payment_new(tal_t *ctx, struct command *cmd,
struct payment *parent,
Expand Down
10 changes: 10 additions & 0 deletions plugins/pay.c
Original file line number Diff line number Diff line change
Expand Up @@ -2255,7 +2255,14 @@ payment_listsendpays_previous(struct command *cmd, const char *buf,
}

struct payment_modifier *paymod_mods[] = {
/* NOTE: The order in which these four paymods are executed is
* significant!
* local_channel_hints *must* execute first before route_exclusions
* which *must* execute before directpay.
* exemptfee *must* also execute before directpay.
*/
&local_channel_hints_pay_mod,
&route_exclusions_pay_mod,
&exemptfee_pay_mod,
&directpay_pay_mod,
&shadowroute_pay_mod,
Expand Down Expand Up @@ -2305,6 +2312,7 @@ static struct command_result *json_paymod(struct command *cmd,
struct sha256 *local_offer_id;
const struct tlv_invoice *b12;
struct out_req *req;
struct route_exclusion **exclusions;
#if DEVELOPER
bool *use_shadow;
#endif
Expand All @@ -2326,6 +2334,7 @@ static struct command_result *json_paymod(struct command *cmd,
maxdelay_default),
p_opt_def("exemptfee", param_msat, &exemptfee, AMOUNT_MSAT(5000)),
p_opt("localofferid", param_sha256, &local_offer_id),
p_opt("exclude", param_route_exclusion_array, &exclusions),
#if DEVELOPER
p_opt_def("use_shadow", param_bool, &use_shadow, true),
#endif
Expand Down Expand Up @@ -2479,6 +2488,7 @@ static struct command_result *json_paymod(struct command *cmd,
shadow_route = payment_mod_shadowroute_get_data(p);
payment_mod_presplit_get_data(p)->disable = disablempp;
payment_mod_adaptive_splitter_get_data(p)->disable = disablempp;
payment_mod_route_exclusions_get_data(p)->exclusions = exclusions;

/* This is an MPP enabled pay command, disable amount fuzzing. */
shadow_route->fuzz_amount = false;
Expand Down