Skip to content

Commit

Permalink
askrene: hack in some padding so we don't overflow capacities.
Browse files Browse the repository at this point in the history
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: ElementsProject#7563
  • Loading branch information
rustyrussell committed Aug 22, 2024
1 parent 2f36b22 commit 6f0d8b7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
12 changes: 10 additions & 2 deletions plugins/askrene/mcf.c
Original file line number Diff line number Diff line change
Expand Up @@ -456,9 +456,17 @@ static void linearize_channel(const struct pay_parameters *params,

/* This takes into account any payments in progress. */
get_constraints(params->rq, c, dir, &mincap, &maxcap);
/* Assume if min > max, max is wrong */

/* We seem to have some rounding error (perhaps due to our use
* of sats and fee interactions?). Since it's unusual to see
* a large unmber of flows, even if each overflows by 1 sat,
* 5 sats should be plenty. */
if (!amount_msat_sub(&maxcap, maxcap, AMOUNT_MSAT(5000)))
maxcap = AMOUNT_MSAT(0);

/* Assume if min > max, min is wrong */
if (amount_msat_greater(mincap, maxcap))
maxcap = mincap;
mincap = maxcap;

u64 a = mincap.millisatoshis/1000, /* Raw: linearize_channel */
b = 1 + maxcap.millisatoshis/1000; /* Raw: linearize_channel */
Expand Down
21 changes: 10 additions & 11 deletions tests/test_askrene.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,8 @@ def test_getroutes(node_factory):
amount_msat=1000,
layers=[],
maxfee_msat=1000,
final_cltv=99) == {'probability_ppm': 999999,
'routes': [{'probability_ppm': 999999,
final_cltv=99) == {'probability_ppm': 999998,
'routes': [{'probability_ppm': 999998,
'final_cltv': 99,
'amount_msat': 1000,
'path': [{'short_channel_id': '0x1x0',
Expand All @@ -184,8 +184,8 @@ def test_getroutes(node_factory):
amount_msat=100000,
layers=[],
maxfee_msat=5000,
final_cltv=99) == {'probability_ppm': 999798,
'routes': [{'probability_ppm': 999798,
final_cltv=99) == {'probability_ppm': 999797,
'routes': [{'probability_ppm': 999797,
'final_cltv': 99,
'amount_msat': 100000,
'path': [{'short_channel_id': '0x1x0',
Expand Down Expand Up @@ -247,11 +247,11 @@ def test_getroutes(node_factory):
10000000,
[[{'short_channel_id': '0x2x1',
'next_node_id': nodemap[2],
'amount_msat': 500000,
'amount_msat': 505000,
'delay': 99 + 6}],
[{'short_channel_id': '0x2x3',
'next_node_id': nodemap[2],
'amount_msat': 9500009,
'amount_msat': 9495009,
'delay': 99 + 6}]])


Expand Down Expand Up @@ -313,8 +313,8 @@ def test_getroutes_auto_sourcefree(node_factory):
amount_msat=1000,
layers=['auto.sourcefree'],
maxfee_msat=1000,
final_cltv=99) == {'probability_ppm': 999999,
'routes': [{'probability_ppm': 999999,
final_cltv=99) == {'probability_ppm': 999998,
'routes': [{'probability_ppm': 999998,
'final_cltv': 99,
'amount_msat': 1000,
'path': [{'short_channel_id': '0x1x0',
Expand All @@ -328,8 +328,8 @@ def test_getroutes_auto_sourcefree(node_factory):
amount_msat=100000,
layers=['auto.sourcefree'],
maxfee_msat=5000,
final_cltv=99) == {'probability_ppm': 999798,
'routes': [{'probability_ppm': 999798,
final_cltv=99) == {'probability_ppm': 999797,
'routes': [{'probability_ppm': 999797,
'final_cltv': 99,
'amount_msat': 100000,
'path': [{'short_channel_id': '0x1x0',
Expand Down Expand Up @@ -451,7 +451,6 @@ def test_fees_dont_exceed_constraints(node_factory):
assert amount <= max_msat


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

0 comments on commit 6f0d8b7

Please sign in to comment.