Skip to content

Commit 19ae57b

Browse files
committed
[wip] refine: delete channels that violate htlcmin
Signed-off-by: Lagrang3 <[email protected]>
1 parent d2be1a8 commit 19ae57b

File tree

1 file changed

+27
-12
lines changed

1 file changed

+27
-12
lines changed

plugins/askrene/refine.c

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ struct channel_data {
1212
struct amount_msat htlc_min, htlc_max, liquidity_max;
1313
u32 fee_base_msat, fee_proportional_millionths;
1414
struct short_channel_id_dir scidd;
15+
u32 idx;
1516
};
1617

1718

@@ -148,31 +149,36 @@ enum why_capped {
148149
CAPPED_CAPACITY,
149150
};
150151

151-
static void remove_htlc_min_violations(const tal_t *ctx, struct route_query *rq,
152-
const struct flow *flow,
153-
const struct channel_data *channels)
152+
static const char *
153+
remove_htlc_min_violations(const tal_t *ctx, struct route_query *rq,
154+
const struct flow *flow,
155+
const struct channel_data *channels)
154156
{
155-
157+
const char *error_message = NULL;
156158
struct amount_msat msat = flow->delivers;
157159
for (size_t i = tal_count(flow->path) - 1; i < tal_count(flow->path);
158160
i--) {
159161
if (amount_msat_less(msat, channels[i].htlc_min)) {
160162
rq_log(
161-
ctx, rq, LOG_UNUSUAL,
162-
"Sending %s across %s would violate htlc_min (~%s)",
163+
ctx, rq, LOG_DBG,
164+
"Sending %s across %s would violate htlc_min "
165+
"(~%s), disabling this channel",
163166
fmt_amount_msat(ctx, msat),
164167
fmt_short_channel_id_dir(ctx, &channels[i].scidd),
165168
fmt_amount_msat(ctx, channels[i].htlc_min));
169+
bitmap_set_bit(rq->disabled_chans, channels[i].idx);
166170
break;
167171
}
168172
if (!amount_msat_add_fee(
169173
&msat, channels[i].fee_base_msat,
170174
channels[i].fee_proportional_millionths)) {
171-
plugin_err(rq->plugin, "%s: Adding fee to amount",
172-
__func__);
173-
// TODO: fail this function and report to caller
175+
error_message =
176+
rq_log(ctx, rq, LOG_BROKEN,
177+
"%s: Adding fee to amount", __func__);
178+
break;
174179
}
175180
}
181+
return error_message;
176182
}
177183

178184
/* Cache channel data along the path used by this flow. */
@@ -199,6 +205,8 @@ static struct channel_data *new_channel_path_cache(const tal_t *ctx,
199205
path[i].fee_proportional_millionths = h->proportional_fee;
200206
path[i].liquidity_max = known_max;
201207
path[i].scidd = scidd;
208+
path[i].idx = scidd.dir +
209+
2 * gossmap_chan_idx(rq->gossmap, flow->path[i]);
202210
}
203211
return path;
204212
}
@@ -380,7 +388,8 @@ const char *refine_with_fees_and_limits(const tal_t *ctx,
380388
struct flow ***flows)
381389
{
382390
const tal_t *working_ctx = tal(ctx, tal_t);
383-
struct amount_msat *max_deliverable;
391+
const char *error_message = NULL;
392+
struct amount_msat *max_deliverable;
384393
struct amount_msat *min_deliverable;
385394
struct channel_data **channel_mpp_cache;
386395
size_t *flows_index;
@@ -423,8 +432,10 @@ const char *refine_with_fees_and_limits(const tal_t *ctx,
423432
}
424433
/* htlc_min is not met for this flow */
425434
tal_arr_remove(&flows_index, i);
426-
remove_htlc_min_violations(working_ctx, rq, (*flows)[k],
427-
channel_mpp_cache[k]);
435+
error_message = remove_htlc_min_violations(
436+
working_ctx, rq, (*flows)[k], channel_mpp_cache[k]);
437+
if (error_message)
438+
goto fail;
428439
}
429440

430441
/* remove 0 amount flows if any */
@@ -451,4 +462,8 @@ const char *refine_with_fees_and_limits(const tal_t *ctx,
451462

452463
tal_free(working_ctx);
453464
return NULL;
465+
466+
fail:
467+
tal_free(working_ctx);
468+
return error_message;
454469
}

0 commit comments

Comments
 (0)