Skip to content

Commit b7f3d7b

Browse files
Lagrang3rustyrussell
authored andcommitted
askrene: prune un-used arcs
From the multiple arcs that derive from the same channel we consider only those with the smallest cost such that the payment amount and HTLC max can fit in their combined capacity, ie. we prune high cost arcs that surely will never be used by the optimal solution. This reduces the number of arcs in the graph approximately from 8 arcs per channel to approximately 2 arcs per channel. No pruning. amount: 100 1000 10000 100000 1000000 channels: 104741 106163 106607 106654 106666 arcs: 837928 849304 852856 853232 853328 Prune, limit the channel capacity by its HTLC max amount: 100 1000 10000 100000 1000000 channels: 104741 106163 106607 106654 106666 arcs: 255502 259314 260538 260676 260704 Prune, limit the channel capacity to the payment amount amount: 100 1000 10000 100000 1000000 channels: 104741 106163 106607 106654 106666 arcs: 209482 216270 228618 295450 432468 Prune, limit the channel capacity to the payment amount and its HTLC max amount: 100 1000 10000 100000 1000000 channels: 104741 106163 106607 106654 106666 arcs: 209480 212324 213242 215726 228018 This produces a slight speedup for MCF computations: Amount (sats) | speedup ----------------------- 100 | 1.89 1000 | 1.77 10000 | 1.25 100000 | 1.25 1000000 | 1.18 Changelog-None Signed-off-by: Lagrang3 <lagrang3@protonmail.com>
1 parent fae176f commit b7f3d7b

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

plugins/askrene/mcf.c

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -360,9 +360,18 @@ 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+
* The cap con capacity is not greater than the amount of payment units
365+
* (msat/accuracy). The way a channel is decomposed into linear cost
366+
* arcs (code below) in ascending cost order ensures that the only the
367+
* necessary capacity to forward the payment is allocated in the lower
368+
* cost arcs. This may lead to some arcs in the decomposition (at the
369+
* high cost end) to have a capacity of 0, and we can prune them while
370+
* keeping the solution optimal. */
364371
u64 cap_on_capacity =
365-
amount_msat_ratio_floor(gossmap_chan_htlc_max(c, dir), params->accuracy);
372+
MIN(amount_msat_ratio_floor(gossmap_chan_htlc_max(c, dir),
373+
params->accuracy),
374+
amount_msat_ratio_ceil(params->amount, params->accuracy));
366375

367376
set_capacity(&capacity[0], a, &cap_on_capacity);
368377
cost[0]=0;
@@ -598,8 +607,9 @@ static void init_linear_network(const tal_t *ctx,
598607
// when the `i` hits the `next` node.
599608
for(size_t k=0;k<CHANNEL_PARTS;++k)
600609
{
601-
/* FIXME: Can we prune arcs with 0 capacity?
602-
* if(capacity[k]==0)continue; */
610+
/* prune arcs with 0 capacity */
611+
if (capacity[k] == 0)
612+
continue;
603613

604614
struct arc arc = arc_from_parts(chan_id, half, k, false);
605615

tests/test_askrene.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1204,10 +1204,10 @@ 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, 1567535, 142772, 91)
12081208
else:
12091209
limit = 100
1210-
expected = (9, 95, 6347877, 566288, 92)
1210+
expected = (9, 96, 6563767, 629671, 91)
12111211

12121212
fees = {}
12131213
for n in range(0, limit):
@@ -1321,10 +1321,10 @@ 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
1327-
expected = ({1: 23, 2: 31, 4: 40, 8: 53, 16: 70, 32: 82, 64: 96, 100: 96}, 0)
1327+
expected = ({1: 22, 2: 25, 4: 36, 8: 52, 16: 69, 32: 80, 64: 96, 100: 96}, 0)
13281328

13291329
l1.rpc.askrene_create_layer('biases')
13301330
num_changed = {}

0 commit comments

Comments
 (0)