Skip to content

Commit 50949b7

Browse files
committed
askrene: hack in some padding so we don't overflow capacities.
Of course, we still will, since spendable is for a single HTLC, but this also shows why we should treat *minimum* as the incorrect answer if they cross, too. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au> Fixes: #7563
1 parent fafda82 commit 50949b7

File tree

2 files changed

+20
-13
lines changed

2 files changed

+20
-13
lines changed

plugins/askrene/mcf.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -453,9 +453,17 @@ static void linearize_channel(const struct pay_parameters *params,
453453

454454
/* This takes into account any payments in progress. */
455455
get_constraints(params->rq, c, dir, &mincap, &maxcap);
456-
/* Assume if min > max, max is wrong */
456+
457+
/* We seem to have some rounding error (perhaps due to our use
458+
* of sats and fee interactions?). Since it's unusual to see
459+
* a large unmber of flows, even if each overflows by 1 sat,
460+
* 5 sats should be plenty. */
461+
if (!amount_msat_sub(&maxcap, maxcap, AMOUNT_MSAT(5000)))
462+
maxcap = AMOUNT_MSAT(0);
463+
464+
/* Assume if min > max, min is wrong */
457465
if (amount_msat_greater(mincap, maxcap))
458-
maxcap = mincap;
466+
mincap = maxcap;
459467

460468
u64 a = mincap.millisatoshis/1000, /* Raw: linearize_channel */
461469
b = 1 + maxcap.millisatoshis/1000; /* Raw: linearize_channel */

tests/test_askrene.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,8 @@ def test_getroutes(node_factory):
169169
amount_msat=1000,
170170
layers=[],
171171
maxfee_msat=1000,
172-
final_cltv=99) == {'probability_ppm': 999999,
173-
'routes': [{'probability_ppm': 999999,
172+
final_cltv=99) == {'probability_ppm': 999998,
173+
'routes': [{'probability_ppm': 999998,
174174
'final_cltv': 99,
175175
'amount_msat': 1000,
176176
'path': [{'short_channel_id': '0x1x0',
@@ -184,8 +184,8 @@ def test_getroutes(node_factory):
184184
amount_msat=100000,
185185
layers=[],
186186
maxfee_msat=5000,
187-
final_cltv=99) == {'probability_ppm': 999798,
188-
'routes': [{'probability_ppm': 999798,
187+
final_cltv=99) == {'probability_ppm': 999797,
188+
'routes': [{'probability_ppm': 999797,
189189
'final_cltv': 99,
190190
'amount_msat': 100000,
191191
'path': [{'short_channel_id': '0x1x0',
@@ -247,11 +247,11 @@ def test_getroutes(node_factory):
247247
10000000,
248248
[[{'short_channel_id': '0x2x1',
249249
'next_node_id': nodemap[2],
250-
'amount_msat': 500000,
250+
'amount_msat': 505000,
251251
'delay': 99 + 6}],
252252
[{'short_channel_id': '0x2x3',
253253
'next_node_id': nodemap[2],
254-
'amount_msat': 9500009,
254+
'amount_msat': 9495009,
255255
'delay': 99 + 6}]])
256256

257257

@@ -313,8 +313,8 @@ def test_getroutes_auto_sourcefree(node_factory):
313313
amount_msat=1000,
314314
layers=['auto.sourcefree'],
315315
maxfee_msat=1000,
316-
final_cltv=99) == {'probability_ppm': 999999,
317-
'routes': [{'probability_ppm': 999999,
316+
final_cltv=99) == {'probability_ppm': 999998,
317+
'routes': [{'probability_ppm': 999998,
318318
'final_cltv': 99,
319319
'amount_msat': 1000,
320320
'path': [{'short_channel_id': '0x1x0',
@@ -328,8 +328,8 @@ def test_getroutes_auto_sourcefree(node_factory):
328328
amount_msat=100000,
329329
layers=['auto.sourcefree'],
330330
maxfee_msat=5000,
331-
final_cltv=99) == {'probability_ppm': 999798,
332-
'routes': [{'probability_ppm': 999798,
331+
final_cltv=99) == {'probability_ppm': 999797,
332+
'routes': [{'probability_ppm': 999797,
333333
'final_cltv': 99,
334334
'amount_msat': 100000,
335335
'path': [{'short_channel_id': '0x1x0',
@@ -451,7 +451,6 @@ def test_fees_dont_exceed_constraints(node_factory):
451451
assert amount <= max_msat
452452

453453

454-
@pytest.mark.xfail(strict=True)
455454
def test_live_spendable(node_factory, bitcoind):
456455
"""Test we don't exceed spendable limits on a real network on nodes"""
457456
l1, l2, l3 = node_factory.get_nodes(3)

0 commit comments

Comments
 (0)