Skip to content

Commit 67432c7

Browse files
committed
[WIP] check for htlc min/max violations
Signed-off-by: Lagrang3 <[email protected]>
1 parent a471749 commit 67432c7

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

plugins/askrene/mcf.c

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1310,6 +1310,56 @@ static bool check_htlc_limits(struct route_query *rq, struct flow **flows)
13101310
return true;
13111311
}
13121312

1313+
static bool check_htlc_min_limits(struct route_query *rq, struct flow **flows)
1314+
{
1315+
1316+
for (size_t k = 0; k < tal_count(flows); k++) {
1317+
struct flow *flow = flows[k];
1318+
size_t pathlen = tal_count(flow->path);
1319+
struct amount_msat hop_amt = flow->delivers;
1320+
for (size_t i = pathlen - 1; i < pathlen; i--) {
1321+
const struct half_chan *h = flow_edge(flow, i);
1322+
struct short_channel_id_dir scidd;
1323+
1324+
get_scidd(rq->gossmap, flow, i, &scidd);
1325+
struct amount_msat htlc_min =
1326+
get_chan_htlc_min(rq, flow->path[i], &scidd);
1327+
if (amount_msat_less(hop_amt, htlc_min))
1328+
return false;
1329+
1330+
if (!amount_msat_add_fee(&hop_amt, h->base_fee,
1331+
h->proportional_fee))
1332+
abort();
1333+
}
1334+
}
1335+
return true;
1336+
}
1337+
1338+
static bool check_htlc_max_limits(struct route_query *rq, struct flow **flows)
1339+
{
1340+
1341+
for (size_t k = 0; k < tal_count(flows); k++) {
1342+
struct flow *flow = flows[k];
1343+
size_t pathlen = tal_count(flow->path);
1344+
struct amount_msat hop_amt = flow->delivers;
1345+
for (size_t i = pathlen - 1; i < pathlen; i--) {
1346+
const struct half_chan *h = flow_edge(flow, i);
1347+
struct short_channel_id_dir scidd;
1348+
1349+
get_scidd(rq->gossmap, flow, i, &scidd);
1350+
struct amount_msat htlc_max =
1351+
get_chan_htlc_max(rq, flow->path[i], &scidd);
1352+
if (amount_msat_greater(hop_amt, htlc_max))
1353+
return false;
1354+
1355+
if (!amount_msat_add_fee(&hop_amt, h->base_fee,
1356+
h->proportional_fee))
1357+
abort();
1358+
}
1359+
}
1360+
return true;
1361+
}
1362+
13131363
/* FIXME: add extra constraint maximum route length, use an activation
13141364
* probability cost for each channel. Recall that every activation cost, eg.
13151365
* base fee and activation probability can only be properly added modifying the
@@ -1399,6 +1449,8 @@ linear_routes(const tal_t *ctx, struct route_query *rq,
13991449

14001450
/* we should have fixed all htlc violations, "don't trust,
14011451
* verify" */
1452+
assert(check_htlc_min_limits(rq, new_flows));
1453+
assert(check_htlc_max_limits(rq, new_flows));
14021454
assert(check_htlc_limits(rq, new_flows));
14031455

14041456
/* no flows should send 0 amount */

0 commit comments

Comments
 (0)