Skip to content

Commit 538d302

Browse files
committed
askrene: implement 10-second deadline.
We have another report of looping. This maxparts code is being completely rewritten, but it's good to have a catchall for any other cases which might emerge. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
1 parent 0e73118 commit 538d302

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

plugins/askrene/askrene.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -614,13 +614,14 @@ static struct command_result *do_getroutes(struct command *cmd,
614614
/* Compute the routes. At this point we might select between multiple
615615
* algorithms. Right now there is only one algorithm available. */
616616
struct timemono time_start = time_mono();
617+
struct timemono deadline = timemono_add(time_start, time_from_sec(10));
617618
if (info->dev_algo == ALGO_SINGLE_PATH) {
618-
err = single_path_routes(rq, rq, srcnode, dstnode, info->amount,
619+
err = single_path_routes(rq, rq, deadline, srcnode, dstnode, info->amount,
619620
info->maxfee, info->finalcltv,
620621
info->maxdelay, &flows, &probability);
621622
} else {
622623
assert(info->dev_algo == ALGO_DEFAULT);
623-
err = default_routes(rq, rq, srcnode, dstnode, info->amount,
624+
err = default_routes(rq, rq, deadline, srcnode, dstnode, info->amount,
624625
info->maxfee, info->finalcltv,
625626
info->maxdelay, &flows, &probability);
626627
}

plugins/askrene/mcf.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1346,6 +1346,7 @@ static bool check_htlc_max_limits(struct route_query *rq, struct flow **flows)
13461346
*/
13471347
static const char *
13481348
linear_routes(const tal_t *ctx, struct route_query *rq,
1349+
struct timemono deadline,
13491350
const struct gossmap_node *srcnode,
13501351
const struct gossmap_node *dstnode, struct amount_msat amount,
13511352
struct amount_msat maxfee, u32 finalcltv, u32 maxdelay,
@@ -1379,6 +1380,13 @@ linear_routes(const tal_t *ctx, struct route_query *rq,
13791380
size_t num_parts, parts_slots, excess_parts;
13801381
u32 bottleneck_idx;
13811382

1383+
if (timemono_after(time_mono(), deadline)) {
1384+
error_message = rq_log(ctx, rq, LOG_BROKEN,
1385+
"%s: timed out after deadline",
1386+
__func__);
1387+
goto fail;
1388+
}
1389+
13821390
/* FIXME: This algorithm to limit the number of parts is dumb
13831391
* for two reasons:
13841392
* 1. it does not take into account that several loop
@@ -1641,25 +1649,27 @@ linear_routes(const tal_t *ctx, struct route_query *rq,
16411649
}
16421650

16431651
const char *default_routes(const tal_t *ctx, struct route_query *rq,
1652+
struct timemono deadline,
16441653
const struct gossmap_node *srcnode,
16451654
const struct gossmap_node *dstnode,
16461655
struct amount_msat amount, struct amount_msat maxfee,
16471656
u32 finalcltv, u32 maxdelay, struct flow ***flows,
16481657
double *probability)
16491658
{
1650-
return linear_routes(ctx, rq, srcnode, dstnode, amount, maxfee,
1659+
return linear_routes(ctx, rq, deadline, srcnode, dstnode, amount, maxfee,
16511660
finalcltv, maxdelay, flows, probability, minflow);
16521661
}
16531662

16541663
const char *single_path_routes(const tal_t *ctx, struct route_query *rq,
1664+
struct timemono deadline,
16551665
const struct gossmap_node *srcnode,
16561666
const struct gossmap_node *dstnode,
16571667
struct amount_msat amount,
16581668
struct amount_msat maxfee, u32 finalcltv,
16591669
u32 maxdelay, struct flow ***flows,
16601670
double *probability)
16611671
{
1662-
return linear_routes(ctx, rq, srcnode, dstnode, amount, maxfee,
1672+
return linear_routes(ctx, rq, deadline, srcnode, dstnode, amount, maxfee,
16631673
finalcltv, maxdelay, flows, probability,
16641674
single_path_flow);
16651675
}

plugins/askrene/mcf.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ struct amount_msat linear_flow_cost(const struct flow *flow,
6464
/* A wrapper to the min. cost flow solver that actually takes into consideration
6565
* the extra msats per channel needed to pay for fees. */
6666
const char *default_routes(const tal_t *ctx, struct route_query *rq,
67+
struct timemono deadline,
6768
const struct gossmap_node *srcnode,
6869
const struct gossmap_node *dstnode,
6970
struct amount_msat amount,
@@ -73,6 +74,7 @@ const char *default_routes(const tal_t *ctx, struct route_query *rq,
7374

7475
/* A wrapper to the single-path constrained solver. */
7576
const char *single_path_routes(const tal_t *ctx, struct route_query *rq,
77+
struct timemono deadline,
7678
const struct gossmap_node *srcnode,
7779
const struct gossmap_node *dstnode,
7880
struct amount_msat amount,

0 commit comments

Comments
 (0)