Skip to content

Commit b7f1ae2

Browse files
committed
askrene: prune some arcs for the MCF computation
Constraint the number of flow units to 1M and prune arcs that are provably not used in the MCF computation. Changelog-None. Signed-off-by: Lagrang3 <[email protected]>
1 parent 67afbac commit b7f1ae2

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

plugins/askrene/mcf.c

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -360,9 +360,13 @@ static void linearize_channel(const struct pay_parameters *params,
360360
b = 1 + amount_msat_ratio_floor(maxcap, params->accuracy);
361361

362362
/* An extra bound on capacity, here we use it to reduce the flow such
363-
* that it does not exceed htlcmax. */
363+
* that it does not exceed htlcmax.
364+
* Also there is no need to keep track of more capacity than the payment
365+
* amount, this can help us prune some arcs. */
364366
u64 cap_on_capacity =
365-
amount_msat_ratio_floor(gossmap_chan_htlc_max(c, dir), params->accuracy);
367+
MIN(amount_msat_ratio_floor(gossmap_chan_htlc_max(c, dir),
368+
params->accuracy),
369+
amount_msat_ratio_ceil(params->amount, params->accuracy));
366370

367371
set_capacity(&capacity[0], a, &cap_on_capacity);
368372
cost[0]=0;
@@ -598,8 +602,9 @@ static void init_linear_network(const tal_t *ctx,
598602
// when the `i` hits the `next` node.
599603
for(size_t k=0;k<CHANNEL_PARTS;++k)
600604
{
601-
/* FIXME: Can we prune arcs with 0 capacity?
602-
* if(capacity[k]==0)continue; */
605+
/* prune arcs with 0 capacity */
606+
if (capacity[k] == 0)
607+
continue;
603608

604609
struct arc arc = arc_from_parts(chan_id, half, k, false);
605610

@@ -960,10 +965,14 @@ struct flow **minflow(const tal_t *ctx,
960965
params->source = source;
961966
params->target = target;
962967
params->amount = amount;
963-
params->accuracy = AMOUNT_MSAT(1000);
964-
/* FIXME: params->accuracy = amount_msat_max(amount_msat_div(amount,
965-
* 1000), AMOUNT_MSAT(1));
968+
/* -> At most 1M units of flow are allowed, that reduces the
969+
* computational burden for algorithms that depend on it, eg. "capacity
970+
* scaling" and "successive shortest path".
971+
* -> Using Ceil operation instead of Floor so that
972+
* accuracy x 1M >= amount
966973
* */
974+
params->accuracy = amount_msat_max(
975+
AMOUNT_MSAT(1), amount_msat_div_ceil(amount, 1000000));
967976

968977
// template the channel partition into linear arcs
969978
params->cap_fraction[0]=0;

tests/test_askrene.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1204,7 +1204,7 @@ def test_real_data(node_factory, bitcoind):
12041204
# CI, it's slow.
12051205
if SLOW_MACHINE:
12061206
limit = 25
1207-
expected = (6, 25, 1544756, 142986, 91)
1207+
expected = (5, 25, 1567536, 142772, 91)
12081208
else:
12091209
limit = 100
12101210
expected = (9, 95, 6347877, 566288, 92)
@@ -1321,7 +1321,7 @@ def test_real_biases(node_factory, bitcoind):
13211321
# CI, it's slow.
13221322
if SLOW_MACHINE:
13231323
limit = 25
1324-
expected = ({1: 5, 2: 7, 4: 7, 8: 11, 16: 14, 32: 19, 64: 25, 100: 25}, 0)
1324+
expected = ({1: 6, 2: 6, 4: 7, 8: 12, 16: 14, 32: 19, 64: 25, 100: 25}, 0)
13251325
else:
13261326
limit = 100
13271327
expected = ({1: 23, 2: 31, 4: 40, 8: 53, 16: 70, 32: 82, 64: 96, 100: 96}, 0)

0 commit comments

Comments
 (0)