-
Notifications
You must be signed in to change notification settings - Fork 961
askrene: improving the MCF solver #7740
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
askrene: improving the MCF solver #7740
Conversation
8512473 to
8f2f2f2
Compare
b61480a to
917a48d
Compare
rustyrussell
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor tweaks.
Mainly concerned about performance regressions, and of course those test need re-enabling and fixing up (of course there will be differences, but the tests are there to ensure changes are deliberate at least!).
Would be interested in times of test_askrene.py::test_real_data before and after...
4971b9a to
d24e60a
Compare
There weren't meant to be differences in the results, but there was a bug in the median computation. Once it is fixed then the results in tests |
|
The fee_fallback test would fail after fixing the computation of the |
|
I went to double check the computation of the median fee and probability cost. Running after fixing it |
31ac881 to
7181635
Compare
|
Rebased on top of the master branch to fix the conflicts. Still have 3 more test cases that fail:
|
|
I have found one assertion in Finding an alternative set of routes does not imply that the biassed channel has less amount allocated. As a matter of fact for this case (n=83) the algorithm starts obtaining alternative routes for bias=8 and above. |
7181635 to
f36720b
Compare
f36720b to
f0dfb08
Compare
|
Rebased |
Actually, it shows how bad this generate graph is! In particular, the reverse edges (which all have tiny fees but are irrelevant), warp the median so badly the result is bogus (I ended up having to modify the code to dump these out, to see what was happening). Fix is simple: disable reverse edges. I also hardcoded an exception for the test_real_biases fail. It's actually the same-cost path, it's just that the slight change in values means we pay 1msat more due to fee rounding! No, median sucks because of this: We spend an annoying 3/8 of our time getting the median values! Maybe champagne problems, since the rest is so fast? But it annoys me! |
Changelog-EXPERIMENTAL: askrene new graph abstraction Signed-off-by: Lagrang3 <[email protected]>
It is just a copy-paste of "dijkstra" but the name implies what it actually is. Not an implementation of minimum cost path Dijkstra algorithm, but a helper data structure. I keep the old "dijkstra.h/c" files for the moment to avoid breaking the current code. Changelog-EXPERIMENTAL: askrene: add priorityqueue Signed-off-by: Lagrang3 <[email protected]>
Changelog-EXPERIMENTAL: askrene: add graph algorithms module Signed-off-by: Lagrang3 <[email protected]>
Changelog-EXPERIMENTAL: askrene: add dijkstra algorithm Signed-off-by: Lagrang3 <[email protected]>
Changelog-EXPERIMENTAL: askrene: add algorithm to compute feasible flow Signed-off-by: Lagrang3 <[email protected]>
Changelog-EXPERIMENTAL: askrene: add a simple MCF solver Signed-off-by: Lagrang3 <[email protected]>
Changelog-None: askrene algorithm add helper for flow conservation Signed-off-by: Lagrang3 <[email protected]>
Add a new function to compute a MCF using a more general description of the problem. I call it mcf_refinement because it can start with a feasible flow (though this is not necessary) and adapt it to achieve optimality. Changelog-None: askrene: add a MCF refinement Signed-off-by: Lagrang3 <[email protected]>
Using zlib to read big test case file. Changelog-None: askrene: add bigger test for MCF Signed-off-by: Lagrang3 <[email protected]>
We use an arc "array" in the graph structure, but not all arc indexes correspond to real topological arcs. We must be careful when iterating through all arcs, and check if they are enabled before making operations on them. Changelog-None: askrene: fix bug, not all arcs exists Signed-off-by: Lagrang3 <[email protected]>
Changelog-none: askrene: add mcf_refinement to the public API Signed-off-by: Lagrang3 <[email protected]>
Changelog-none: askrene: use the new MCF solver Signed-off-by: Lagrang3 <[email protected]>
check the return value of scanf in askrene unit tests, Changelog-none: askrene: fix CI Signed-off-by: Lagrang3 <[email protected]>
The calculation of the median values of probability and fee cost in the linear approximation had a bug by counting on non-existing arcs. Changelog-none: askrene: fix the median Signed-off-by: Lagrang3 <[email protected]>
Changelog-none: add ratio ceil and floor operators on amount_msat Signed-off-by: Lagrang3 <[email protected]>
Changelog-none: askrene: add arbitrary precision flow unit Signed-off-by: Lagrang3 <[email protected]>
- use graph_max_num_arcs/nodes instead of tal_count in bound checks, - don't use ccan/lqueue, use instead a minimalistic queue implementation with an array, - add missing const qualifiers to temporary tal allocators, - check preconditions with assert, - remove inline specifier for static functions, Changelog-None Signed-off-by: Lagrang3 <[email protected]>
Rusty: "We don't generally use NDEBUG in our code" Instead use a compile time flag ASKRENE_UNITTEST to make checks on unit tests that we don't normally need on release code. Changelog-none Signed-off-by: Lagrang3 <[email protected]>
Rusty: "allocations don't fail" Signed-off-by: Lagrang3 <[email protected]>
Changelog-none Signed-off-by: Lagrang3 <[email protected]>
The fee_fallback test would fail after fixing the computation of the median. Now by we can restore it by making the probability cost factor 1000x higher than the ratio of the median. This shows how hard it is to combine fee and probability costs and why is the current approach so fragile. Changelog-None Signed-off-by: Lagrang3 <[email protected]>
The ratio of the median of the fees and probability cost is overall not a bad factor to combine these two features. This is what the test_real_data shows. Changelog-None Signed-off-by: Lagrang3 <[email protected]>
We can fix the median calc by removing the (unused) reverse edges. Also analyze the failure case in test_real_data: it's a real edge case, so hardcode that one as "ok". Signed-off-by: Rusty Russell <[email protected]>
f0dfb08 to
6795ff3
Compare
|
Trivial rebase and new commit... |



This PR aims to improve the MCF solver.
The idea is to have an API that solves specifically the MCF and related problem variations
at a lower level that do not have to care about the several details that are inherent in our modeling of the payment problem.
This approach allows me to easily change the algorithms in the backend.
Now we are using the same linearization of the channel cost function that it is used in
renepay.Future improvements could include the treatment of additional constraints and activation costs to arcs (https://github.com/Lagrang3/mcf-algorithms).
In the translation from a lightning network payment problem to a graph theoretical optimization problem
I have added the possibility to choose the minimum unit of account, not necessarily msat but could be any other number
depending on the total amount to pay.