Skip to content

Askrene single path solver #8299

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion contrib/msggen/msggen/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -15045,7 +15045,7 @@
"",
"Layers are generally maintained by plugins, either to contain persistent information about capacities which have been discovered, or to contain transient information for this particular payment (such as blinded paths or routehints).",
"",
"There are three automatic layers: *auto.localchans* contains information on local channels from this node (including non-public ones), and their exact current spendable capacities. *auto.sourcefree* overrides all channels (including those from previous layers) leading out of the *source* to be zero fee and zero delay. These are both useful in the case where the source is the current node. And *auto.no_mpp_support* forces getroutes to return a single flow, though only basic checks are done that the result is useful."
"There are three automatic layers: *auto.localchans* contains information on local channels from this node (including non-public ones), and their exact current spendable capacities. *auto.sourcefree* overrides all channels (including those from previous layers) leading out of the *source* to be zero fee and zero delay. These are both useful in the case where the source is the current node. And *auto.no_mpp_support* forces getroutes to return a single path solution which is useful for payments for which MPP is not supported."
],
"categories": [
"readonly"
Expand Down
2 changes: 1 addition & 1 deletion doc/schemas/getroutes.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"",
"Layers are generally maintained by plugins, either to contain persistent information about capacities which have been discovered, or to contain transient information for this particular payment (such as blinded paths or routehints).",
"",
"There are three automatic layers: *auto.localchans* contains information on local channels from this node (including non-public ones), and their exact current spendable capacities. *auto.sourcefree* overrides all channels (including those from previous layers) leading out of the *source* to be zero fee and zero delay. These are both useful in the case where the source is the current node. And *auto.no_mpp_support* forces getroutes to return a single flow, though only basic checks are done that the result is useful."
"There are three automatic layers: *auto.localchans* contains information on local channels from this node (including non-public ones), and their exact current spendable capacities. *auto.sourcefree* overrides all channels (including those from previous layers) leading out of the *source* to be zero fee and zero delay. These are both useful in the case where the source is the current node. And *auto.no_mpp_support* forces getroutes to return a single path solution which is useful for payments for which MPP is not supported."
],
"categories": [
"readonly"
Expand Down
33 changes: 26 additions & 7 deletions plugins/askrene/askrene.c
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,11 @@ const char *fmt_flow_full(const tal_t *ctx,
}

enum algorithm {
/* Min. Cost Flow by successive shortests paths. */
ALGO_DEFAULT,
/* Algorithm that finds the optimal routing solution constrained to a
* single path. */
ALGO_SINGLE_PATH,
};

static struct command_result *
Expand All @@ -343,6 +347,8 @@ param_algorithm(struct command *cmd, const char *name, const char *buffer,
*algo = tal(cmd, enum algorithm);
if (streq(algo_str, "default"))
**algo = ALGO_DEFAULT;
else if (streq(algo_str, "single-path"))
**algo = ALGO_SINGLE_PATH;
else
return command_fail_badparam(cmd, name, buffer, tok,
"unknown algorithm");
Expand Down Expand Up @@ -517,7 +523,7 @@ void get_constraints(const struct route_query *rq,

static struct command_result *do_getroutes(struct command *cmd,
struct gossmap_localmods *localmods,
const struct getroutes_info *info)
struct getroutes_info *info)
{
struct askrene *askrene = get_askrene(cmd->plugin);
struct route_query *rq = tal(cmd, struct route_query);
Expand Down Expand Up @@ -586,15 +592,28 @@ static struct command_result *do_getroutes(struct command *cmd,
goto fail;
}

/* auto.no_mpp_support layer overrides any choice of algorithm. */
if (have_layer(info->layers, "auto.no_mpp_support") &&
info->dev_algo != ALGO_SINGLE_PATH) {
info->dev_algo = ALGO_SINGLE_PATH;
rq_log(tmpctx, rq, LOG_DBG,
"Layer no_mpp_support is active we switch to a "
"single path algorithm.");
}

/* Compute the routes. At this point we might select between multiple
* algorithms. Right now there is only one algorithm available. */
struct timemono time_start = time_mono();
assert(info->dev_algo == ALGO_DEFAULT);
err = default_routes(rq, rq, srcnode, dstnode, info->amount,
/* only one path? = */
have_layer(info->layers, "auto.no_mpp_support"),
info->maxfee, info->finalcltv, info->maxdelay,
&flows, &probability);
if (info->dev_algo == ALGO_SINGLE_PATH) {
err = single_path_routes(rq, rq, srcnode, dstnode, info->amount,
info->maxfee, info->finalcltv,
info->maxdelay, &flows, &probability);
} else {
assert(info->dev_algo == ALGO_DEFAULT);
err = default_routes(rq, rq, srcnode, dstnode, info->amount,
info->maxfee, info->finalcltv,
info->maxdelay, &flows, &probability);
}
struct timerel time_delta = timemono_between(time_mono(), time_start);

/* log the time of computation */
Expand Down
Loading