Skip to content

Askrene: fix constraints #8358

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

Draft
wants to merge 23 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
41359e9
askrene: add runtime of getroutes to the logs
Lagrang3 Dec 11, 2024
7e44732
askrene: refactor get_routes ...
Lagrang3 Jul 8, 2025
938e58b
askrene: houst struct getroutes_info higher to clarify following patc…
rustyrussell Jul 8, 2025
0a59d2d
plugins/askrene: extract apply_layers into its own function.
rustyrussell Jul 8, 2025
2f48fd8
askrene: extracet convert_flows_to_routes into its own function.
rustyrussell Jul 8, 2025
7f7b74d
patch json.patch
rustyrussell Jul 8, 2025
9cafba2
askrene: move get_routes into do_getroutes.
rustyrussell Jul 8, 2025
a3172dc
askrene: fix up getroutes_info struct.
rustyrussell Jul 8, 2025
e4e79f0
askrene: add a dev parameter to switch algorithm
Lagrang3 Jul 8, 2025
11dba30
askrene: refactor MCF
Lagrang3 May 28, 2025
1990260
askrene: add internal API for single-path routes
Lagrang3 May 28, 2025
dbbd1d9
askrene: add algorithm for single path routing
Lagrang3 May 28, 2025
db179e1
askrene: update the docs on auto.no_mpp_support
Lagrang3 May 29, 2025
5778e06
common/amount: add ceil division operation on msat
Lagrang3 Jun 4, 2025
1b5e87a
askrene: prune some arcs for the MCF computation
Lagrang3 Jun 4, 2025
54dea92
askrene: add new functions to refine flows
Lagrang3 Jul 9, 2025
b826c5b
askrene: refine: remove flows with HTLC min faults
Lagrang3 Jul 9, 2025
1f0d488
askrene: refine: disable HTLC min violations
Lagrang3 Jul 9, 2025
453467a
askrene: refine: expose some of the refine API
Lagrang3 Jul 9, 2025
e61d0b3
askrene: rework the caller of the MCF solver
Lagrang3 Jul 9, 2025
73f7d9c
askrene: refine: remove refine_with_fee_and_limits
Lagrang3 Jul 9, 2025
fe5da2d
askrene: paranoid checks ...
Lagrang3 Jul 9, 2025
1d475e5
askrene: fix edge probability
Lagrang3 Jul 9, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions common/amount.c
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,13 @@ struct amount_msat amount_msat_div(struct amount_msat msat, u64 div)
return msat;
}

struct amount_msat amount_msat_div_ceil(struct amount_msat msat, u64 div)
{
u64 res = msat.millisatoshis / div;
msat.millisatoshis = res + (div * res == msat.millisatoshis ? 0 : 1);
return msat;
}

struct amount_sat amount_sat_div(struct amount_sat sat, u64 div)
{
sat.satoshis /= div;
Expand Down
6 changes: 6 additions & 0 deletions common/amount.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,13 @@ WARN_UNUSED_RESULT bool amount_sat_add_sat_s64(struct amount_sat *val,
WARN_UNUSED_RESULT bool amount_msat_accumulate(struct amount_msat *a,
struct amount_msat b);

/* returns floor(msat/div) */
struct amount_msat amount_msat_div(struct amount_msat msat, u64 div);

/* returns ceil(msat/div) */
struct amount_msat amount_msat_div_ceil(struct amount_msat msat, u64 div);

/* returns floor(sat/div) */
struct amount_sat amount_sat_div(struct amount_sat sat, u64 div);

bool amount_sat_mul(struct amount_sat *res, struct amount_sat sat, u64 mul);
Expand Down
70 changes: 70 additions & 0 deletions common/test/run-amount.c
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,75 @@ static void test_amount_with_fee(void)
2100000001234567890ULL);
}

static void test_case_amount_div(u64 input, u64 div, u64 expected)
{
struct amount_msat msat = amount_msat(input);
struct amount_msat expected_msat = amount_msat(expected);
struct amount_msat result_msat = amount_msat_div(msat, div);
assert(amount_msat_eq(result_msat, expected_msat));
}

static void test_case_amount_div_ceil(u64 input, u64 div, u64 expected)
{
struct amount_msat msat = amount_msat(input);
struct amount_msat expected_msat = amount_msat(expected);
struct amount_msat result_msat = amount_msat_div_ceil(msat, div);
assert(amount_msat_eq(result_msat, expected_msat));
}

static void test_amount_div(void)
{
test_case_amount_div(1, 1, 1);
test_case_amount_div(1, 2, 0);
test_case_amount_div(1, 3, 0);

test_case_amount_div(2, 1, 2);
test_case_amount_div(2, 2, 1);
test_case_amount_div(2, 3, 0);

test_case_amount_div(3, 1, 3);
test_case_amount_div(3, 2, 1);
test_case_amount_div(3, 3, 1);
test_case_amount_div(3, 4, 0);

test_case_amount_div(10, 1, 10);
test_case_amount_div(10, 2, 5);
test_case_amount_div(10, 3, 3);
test_case_amount_div(10, 4, 2);
test_case_amount_div(10, 5, 2);
test_case_amount_div(10, 6, 1);
test_case_amount_div(10, 7, 1);
test_case_amount_div(10, 8, 1);
test_case_amount_div(10, 9, 1);
test_case_amount_div(10, 10, 1);
test_case_amount_div(10, 11, 0);

test_case_amount_div_ceil(1, 1, 1);
test_case_amount_div_ceil(1, 2, 1);
test_case_amount_div_ceil(1, 3, 1);

test_case_amount_div_ceil(2, 1, 2);
test_case_amount_div_ceil(2, 2, 1);
test_case_amount_div_ceil(2, 3, 1);

test_case_amount_div_ceil(3, 1, 3);
test_case_amount_div_ceil(3, 2, 2);
test_case_amount_div_ceil(3, 3, 1);
test_case_amount_div_ceil(3, 4, 1);

test_case_amount_div_ceil(10, 1, 10);
test_case_amount_div_ceil(10, 2, 5);
test_case_amount_div_ceil(10, 3, 4);
test_case_amount_div_ceil(10, 4, 3);
test_case_amount_div_ceil(10, 5, 2);
test_case_amount_div_ceil(10, 6, 2);
test_case_amount_div_ceil(10, 7, 2);
test_case_amount_div_ceil(10, 8, 2);
test_case_amount_div_ceil(10, 9, 2);
test_case_amount_div_ceil(10, 10, 1);
test_case_amount_div_ceil(10, 11, 1);
}

#define FAIL_MSAT(msatp, str) \
assert(!parse_amount_msat((msatp), (str), strlen(str)))
#define PASS_MSAT(msatp, str, val) \
Expand Down Expand Up @@ -330,5 +399,6 @@ int main(int argc, char *argv[])
}

test_amount_with_fee();
test_amount_div();
common_shutdown();
}
2 changes: 1 addition & 1 deletion contrib/msggen/msggen/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -15045,7 +15045,7 @@
"",
"Layers are generally maintained by plugins, either to contain persistent information about capacities which have been discovered, or to contain transient information for this particular payment (such as blinded paths or routehints).",
"",
"There are three automatic layers: *auto.localchans* contains information on local channels from this node (including non-public ones), and their exact current spendable capacities. *auto.sourcefree* overrides all channels (including those from previous layers) leading out of the *source* to be zero fee and zero delay. These are both useful in the case where the source is the current node. And *auto.no_mpp_support* forces getroutes to return a single flow, though only basic checks are done that the result is useful."
"There are three automatic layers: *auto.localchans* contains information on local channels from this node (including non-public ones), and their exact current spendable capacities. *auto.sourcefree* overrides all channels (including those from previous layers) leading out of the *source* to be zero fee and zero delay. These are both useful in the case where the source is the current node. And *auto.no_mpp_support* forces getroutes to return a single path solution which is useful for payments for which MPP is not supported."
],
"categories": [
"readonly"
Expand Down
2 changes: 1 addition & 1 deletion doc/schemas/getroutes.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"",
"Layers are generally maintained by plugins, either to contain persistent information about capacities which have been discovered, or to contain transient information for this particular payment (such as blinded paths or routehints).",
"",
"There are three automatic layers: *auto.localchans* contains information on local channels from this node (including non-public ones), and their exact current spendable capacities. *auto.sourcefree* overrides all channels (including those from previous layers) leading out of the *source* to be zero fee and zero delay. These are both useful in the case where the source is the current node. And *auto.no_mpp_support* forces getroutes to return a single flow, though only basic checks are done that the result is useful."
"There are three automatic layers: *auto.localchans* contains information on local channels from this node (including non-public ones), and their exact current spendable capacities. *auto.sourcefree* overrides all channels (including those from previous layers) leading out of the *source* to be zero fee and zero delay. These are both useful in the case where the source is the current node. And *auto.no_mpp_support* forces getroutes to return a single path solution which is useful for payments for which MPP is not supported."
],
"categories": [
"readonly"
Expand Down
Loading