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

Askrene algorithm switcher #8163

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

Lagrang3
Copy link
Collaborator

@Lagrang3 Lagrang3 commented Mar 14, 2025

This PR only does a bit of refactoring to askrene.

I would like to add the possibility to switch algorithms in askrene.
This would not be available from the user interface, it is just for developers.
It would allow us to test different algorithms for experimenting performance and reliability
without risking breaking the existing code.
This PR sets the stage for switching between multiple MCF algorithms.

This PR is built on top of #7932.

@Lagrang3 Lagrang3 marked this pull request as ready for review March 14, 2025 10:34
@Lagrang3 Lagrang3 force-pushed the askrene-algorithm-switcher branch 2 times, most recently from 089eed9 to b570166 Compare March 14, 2025 10:48
Copy link
Contributor

@rustyrussell rustyrussell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a bad idea! I'm just not sure about some of the refactorings.

Comment on lines -339 to -367
/* Returns an error message, or sets *routes */
static const char *get_routes(const tal_t *ctx,
struct command *cmd,
const struct node_id *source,
const struct node_id *dest,
struct amount_msat amount,
struct amount_msat maxfee,
u32 finalcltv,
u32 maxdelay,
const char **layers,
struct gossmap_localmods *localmods,
const struct layer *local_layer,
bool single_path,
struct route ***routes,
struct amount_msat **amounts,
const struct additional_cost_htable *additional_costs,
double *probability)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Handing arguments inside a struct (rather than using them explicitly) is an anti-pattern. We need to use this for callbacks, which is why we do it, but we try to constrain the damage to one location.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I don't understand your request here.
I didn't change the arguments passed to do_getroutes.
That function changed from this:

static struct command_result *do_getroutes(struct command *cmd,
					   struct gossmap_localmods *localmods,
					   const struct getroutes_info *info)
{
	...
	// unpack getroutes_info and calls get_routes
	err = get_routes(cmd, cmd,
			 info->source, info->dest,
			 *info->amount, *info->maxfee, *info->finalcltv,
			 *info->maxdelay, info->layers, localmods, info->local_layer,
			 have_layer(info->layers, "auto.no_mpp_support"),
			 &routes, &amounts, info->additional_costs, &probability);

	// write results in a json stream and returns
	...	
	return command_finished(cmd, response);
}

static struct command_result *json_getroutes(struct command *cmd,
					     const char *buffer,
					     const jsmntok_t *params)
{
	// packages all input data into getroutes_info
	struct getroutes_info *info = tal(cmd, struct getroutes_info);
	...
	return do_getroutes(cmd, gossmap_localmods_new(cmd), info);
}

to this

static struct command_result *do_getroutes(struct command *cmd,
					   struct gossmap_localmods *localmods,
					   const struct getroutes_info *info)
{
        // do some stuff that previously was done in get_routes
	...
	// unpack getroutes_info and calls default_routes
       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);


	// write results in a json stream and returns
	...	
	return command_finished(cmd, response);
}

static struct command_result *json_getroutes(struct command *cmd,
					     const char *buffer,
					     const jsmntok_t *params)
{
	// packages all input data into getroutes_info
	struct getroutes_info *info = tal(cmd, struct getroutes_info);
	...
	return do_getroutes(cmd, gossmap_localmods_new(cmd), info);
}

Some of the code in the definition of get_routes was moved to mcf.c under the name
default_routes and some was moved to do_getroutes.

Add log information about the runtime of getroutes.

Changelog-None: askrene: add runtime of getroutes to the logs

Signed-off-by: Lagrang3 <[email protected]>
@Lagrang3 Lagrang3 force-pushed the askrene-algorithm-switcher branch 2 times, most recently from c636e4d to da220a8 Compare March 24, 2025 07:34
Move the feature tuning algorithm to mcf.c, ie. the loops for searching
a good mu and delay_feefactor to satisfy the problem constraints.

We are looking to set the stage for an execution logic that allows for
multiple choices of routing algorithms, mainly for experimenting without
breaking the default working code.

Changelog-None

Signed-off-by: Lagrang3 <[email protected]>
@Lagrang3 Lagrang3 force-pushed the askrene-algorithm-switcher branch 2 times, most recently from 8a14144 to c194763 Compare March 24, 2025 08:29
Prefer the following programming pattern:

do_getroutes(){
        do_something1();
        do_something2();
        do_something3();
}

rather than

get_routes(){
        do_something1();
        do_something2();
}

do_getroutes(){
        get_routes();
        do_something3();
}

Changelog-None

Signed-off-by: Lagrang3 <[email protected]>
@Lagrang3 Lagrang3 force-pushed the askrene-algorithm-switcher branch from c194763 to 28dc007 Compare March 24, 2025 08:43
@Lagrang3 Lagrang3 requested a review from rustyrussell March 25, 2025 11:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants