Skip to content
Open
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
48 changes: 3 additions & 45 deletions plugins/askrene/askrene.c
Original file line number Diff line number Diff line change
Expand Up @@ -257,44 +257,6 @@ static struct layer *source_free_layer(const tal_t *ctx,
return layer;
}

/* We're going to abuse MCF, and take the largest flow it gives and ram everything
* through it. This is more effective if there's at least a *chance* that can handle
* the full amount.
*
* It's far from perfect, but I have very little sympathy: if you want
* to receive amounts reliably, enable MPP.
*/
static struct layer *remove_small_channel_layer(const tal_t *ctx,
struct askrene *askrene,
struct amount_msat min_amount,
struct gossmap_localmods *localmods)
{
/* We use the prefix auto. to avoid clashing */
struct layer *layer = new_temp_layer(ctx, askrene, "auto.remove_small_channels");
struct gossmap *gossmap = askrene->gossmap;
struct gossmap_chan *c;

/* We apply this so we see any created channels */
gossmap_apply_localmods(gossmap, localmods);

for (c = gossmap_first_chan(gossmap); c; c = gossmap_next_chan(gossmap, c)) {
struct short_channel_id_dir scidd;
if (amount_msat_greater_eq(gossmap_chan_get_capacity(gossmap, c),
min_amount))
continue;

scidd.scid = gossmap_chan_scid(gossmap, c);
/* Layer will disable this in both directions */
for (scidd.dir = 0; scidd.dir < 2; scidd.dir++) {
const bool enabled = false;
layer_add_update_channel(layer, &scidd, &enabled,
NULL, NULL, NULL, NULL, NULL);
}
}
gossmap_remove_localmods(gossmap, localmods);

return layer;
}

PRINTF_FMT(4, 5)
static const char *cmd_log(const tal_t *ctx,
Expand Down Expand Up @@ -604,13 +566,9 @@ static struct command_result *do_getroutes(struct command *cmd,
info->layers, info->local_layer, capacities);


/* no parallel payments means we can drop any smaller channels */
if (info->maxparts == 1) {
add_layer(&layers,
remove_small_channel_layer(layers, askrene, info->amount, localmods),
askrene->gossmap,
localmods, capacities);
}
/* Note: For maxparts == 1, single-path routing (init_linear_network_single_path)
* natively skips channels with insufficient capacity in O(1) time without
* building an artificial disabling layer (see issue #9739). */

/* Clear scids with reservations, too, so we don't have to look up
* all the time! */
Expand Down
74 changes: 70 additions & 4 deletions tests/test_askrene.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import os
import pytest
import random
import re
import subprocess
import time
import tempfile
Expand Down Expand Up @@ -941,8 +942,7 @@ def test_getroutes_single_path(node_factory):

# To be able to route this amount two parts are needed, therefore a single
# pay search will fail.
# FIXME: the explanation for the failure is wrong
with pytest.raises(RpcError):
with pytest.raises(RpcError, match=r"isn't big enough to carry 10000001msat"):
l1.rpc.getroutes(
source=nodemap[1],
destination=nodemap[2],
Expand Down Expand Up @@ -974,8 +974,7 @@ def test_getroutes_single_path(node_factory):

# To be able to route this amount two parts are needed, therefore a single
# pay search will fail.
# FIXME: the explanation for the failure is wrong
with pytest.raises(RpcError):
with pytest.raises(RpcError, match=r"isn't big enough to carry 10000001msat"):
l1.rpc.getroutes(
source=nodemap[0],
destination=nodemap[2],
Expand Down Expand Up @@ -3490,3 +3489,70 @@ def test_flow_fee_adjustment_fallback(node_factory, bitcoind):
)
msg = "Could not find routes with enough capacity, retrying without a flow_fee_adjustment"
assert l1.daemon.is_in_log(msg, start=0)


def test_single_part_setup_time(node_factory, bitcoind):
"""getroutes with maxparts=1 on real gossip: time of the whole call
against the search time askrene logs for it (issue #9739)."""
node_key = (
'--node-map=2134='
'033845802d25b4e074ccfd7cd8b339a41dc75bf9978a034800444b51d42b07799a'
)
outfile = tempfile.NamedTemporaryFile(prefix='gossip-store-')
nodeids = subprocess.check_output(
[
'devtools/gossmap-compress',
'decompress',
node_key,
'tests/data/gossip-store-2026-02-03.compressed',
outfile.name,
]
).decode('utf-8').splitlines()
l1, l2 = node_factory.line_graph(
2,
fundamount=100000000,
opts=[
{
'gossip_store_file': outfile.name,
'allow_warning': True,
'dev-throttle-gossip': None,
'broken_log': '.*',
'askrene-timeout': 600,
},
{'allow_warning': True},
],
)
for amount_sat in (10_000, 100_000, 500_000, 2_000_000):
for maxparts in (None, 1):
l1.daemon.logs_catchup()
start = len(l1.daemon.logs)
args = dict(
source=l1.info['id'],
destination=nodeids[0],
amount_msat=amount_sat * 1000,
layers=['auto.sourcefree', 'auto.localchans'],
maxfee_msat=amount_sat * 10,
final_cltv=18,
)
if maxparts is not None:
args['maxparts'] = maxparts
t0 = time.time()
try:
l1.rpc.getroutes(**args)
except RpcError:
pass
call = time.time() - t0
l1.daemon.logs_catchup()
pattern = (
r'get_routes (?:failed after|completed in) (\d+) ms'
)
searches = [
int(m.group(1))
for line in l1.daemon.logs[start:]
for m in [re.search(pattern, line)]
if m
]
assert len(searches) > 0
# Ensure maxparts=1 call doesn't stall with quadratic lag:
# whole call should complete well under 2 seconds.
assert call < 2.0