askrene: make children use child_log() instead of rq_log.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2026-02-16 17:32:33 +10:30
parent 33e2f0a47b
commit ac9aa975ad
8 changed files with 155 additions and 170 deletions

View File

@@ -315,12 +315,6 @@ const char *rq_log(const tal_t *ctx,
msg = tal_vfmt(ctx, fmt, args);
va_end(args);
/* FIXME: This is a hack! */
if (am_child) {
child_log(tmpctx, level, "%s", msg);
return msg;
}
plugin_notify_message(rq->cmd, level, "%s", msg);
/* Notifications already get logged at debug. Otherwise reduce

View File

@@ -14,9 +14,6 @@
#include <plugins/askrene/child/mcf.h>
#include <unistd.h>
/* Temporary hack */
bool am_child = false;
/* A single route. */
struct route {
/* Actual path to take */
@@ -222,7 +219,6 @@ int fork_router_child(struct route_query *rq,
close(logfds[0]);
close(replyfds[0]);
set_child_log_fd(logfds[1]);
am_child = true;
if (single_path) {
err = single_path_routes(rq, rq, deadline, srcnode, dstnode,
amount, maxfee, finalcltv,

View File

@@ -23,7 +23,4 @@ int fork_router_child(struct route_query *rq,
struct json_filter *cmd_filter,
int *log_fd,
int *child_pid);
/* FIXME: Remove this */
extern bool am_child;
#endif /* LIGHTNING_PLUGINS_ASKRENE_CHILD_ENTRY_H */

View File

@@ -4,6 +4,7 @@
#include <common/gossmap.h>
#include <common/route.h>
#include <plugins/askrene/askrene.h>
#include <plugins/askrene/child/child_log.h>
#include <plugins/askrene/child/explain_failure.h>
#include <plugins/askrene/layer.h>
#include <plugins/askrene/reserve.h>
@@ -133,7 +134,7 @@ static const char *check_capacity(const tal_t *ctx,
node_stats(rq, node, node_direction, &stats);
if (amount_msat_greater(amount, stats.total.capacity)) {
return rq_log(ctx, rq, LOG_DBG,
return child_log(ctx, LOG_DBG,
NO_USABLE_PATHS_STRING
" Total %s capacity is only %s"
" (in %zu channels).",
@@ -142,7 +143,7 @@ static const char *check_capacity(const tal_t *ctx,
stats.total.num_channels);
}
if (amount_msat_greater(amount, stats.gossip_known.capacity)) {
return rq_log(ctx, rq, LOG_DBG,
return child_log(ctx, LOG_DBG,
NO_USABLE_PATHS_STRING
" Missing gossip for %s: only known %zu/%zu channels, leaving capacity only %s of %s.",
name,
@@ -152,7 +153,7 @@ static const char *check_capacity(const tal_t *ctx,
fmt_amount_msat(tmpctx, stats.total.capacity));
}
if (amount_msat_greater(amount, stats.enabled.capacity)) {
return rq_log(ctx, rq, LOG_DBG,
return child_log(ctx, LOG_DBG,
NO_USABLE_PATHS_STRING
" The %s has disabled %zu of %zu channels, leaving capacity only %s of %s.",
name,
@@ -241,7 +242,7 @@ const char *explain_failure(const tal_t *ctx,
hops = route_from_dijkstra(tmpctx, rq->gossmap, dij, srcnode,
AMOUNT_MSAT(0), 0);
if (!hops)
return rq_log(ctx, rq, LOG_INFORM,
return child_log(ctx, LOG_INFORM,
"There is no connection between source and destination at all");
/* Description of shortest path */
@@ -268,7 +269,7 @@ const char *explain_failure(const tal_t *ctx,
explanation = tal_fmt(
tmpctx, "produces a fee overflow for amount %s",
fmt_amount_msat(tmpctx, rolling_amount));
return rq_log(ctx, rq, LOG_INFORM,
return child_log(ctx, LOG_INFORM,
NO_USABLE_PATHS_STRING
" The shortest path is %s, but %s %s",
path,
@@ -309,7 +310,7 @@ const char *explain_failure(const tal_t *ctx,
else
continue;
return rq_log(ctx, rq, LOG_INFORM,
return child_log(ctx, LOG_INFORM,
NO_USABLE_PATHS_STRING
" The shortest path is %s, but %s %s",
path,
@@ -317,7 +318,7 @@ const char *explain_failure(const tal_t *ctx,
explanation);
}
return rq_log(ctx, rq, LOG_BROKEN,
return child_log(ctx, LOG_BROKEN,
"Actually, I'm not sure why we didn't find the"
" obvious route %s: perhaps this is a bug?",
path);

View File

@@ -6,6 +6,7 @@
#include <common/overflows.h>
#include <math.h>
#include <plugins/askrene/askrene.h>
#include <plugins/askrene/child/child_log.h>
#include <plugins/askrene/child/flow.h>
#include <plugins/libplugin.h>
#include <stdio.h>
@@ -17,13 +18,12 @@
#endif
/* How much do we deliver to destination using this set of routes */
struct amount_msat flowset_delivers(struct plugin *plugin,
struct flow **flows)
struct amount_msat flowset_delivers(struct flow **flows)
{
struct amount_msat final = AMOUNT_MSAT(0);
for (size_t i = 0; i < tal_count(flows); i++) {
if (!amount_msat_accumulate(&final, flows[i]->delivers)) {
plugin_err(plugin, "Could not add flowsat %s to %s (%zu/%zu)",
child_err("Could not add flowsat %s to %s (%zu/%zu)",
fmt_amount_msat(tmpctx, flows[i]->delivers),
fmt_amount_msat(tmpctx, final),
i, tal_count(flows));
@@ -68,7 +68,7 @@ static double edge_probability(const struct route_query *rq,
return 1.0 - amount_msat_ratio(numerator, denominator);
}
struct amount_msat flow_spend(struct plugin *plugin, const struct flow *flow)
struct amount_msat flow_spend(const struct flow *flow)
{
const size_t pathlen = tal_count(flow->path);
struct amount_msat spend = flow->delivers;
@@ -77,7 +77,7 @@ struct amount_msat flow_spend(struct plugin *plugin, const struct flow *flow)
const struct half_chan *h = flow_edge(flow, i);
if (!amount_msat_add_fee(&spend, h->base_fee,
h->proportional_fee)) {
plugin_err(plugin, "Could not add fee %u/%u to amount %s in %i/%zu",
child_err("Could not add fee %u/%u to amount %s in %i/%zu",
h->base_fee, h->proportional_fee,
fmt_amount_msat(tmpctx, spend),
i, pathlen);
@@ -87,12 +87,12 @@ struct amount_msat flow_spend(struct plugin *plugin, const struct flow *flow)
return spend;
}
struct amount_msat flow_fee(struct plugin *plugin, const struct flow *flow)
struct amount_msat flow_fee(const struct flow *flow)
{
struct amount_msat spend = flow_spend(plugin, flow);
struct amount_msat spend = flow_spend(flow);
struct amount_msat fee;
if (!amount_msat_sub(&fee, spend, flow->delivers)) {
plugin_err(plugin, "Could not subtract %s from %s for fee",
child_err("Could not subtract %s from %s for fee",
fmt_amount_msat(tmpctx, flow->delivers),
fmt_amount_msat(tmpctx, spend));
}
@@ -100,13 +100,13 @@ struct amount_msat flow_fee(struct plugin *plugin, const struct flow *flow)
return fee;
}
struct amount_msat flowset_fee(struct plugin *plugin, struct flow **flows)
struct amount_msat flowset_fee(struct flow **flows)
{
struct amount_msat fee = AMOUNT_MSAT(0);
for (size_t i = 0; i < tal_count(flows); i++) {
struct amount_msat this_fee = flow_fee(plugin, flows[i]);
struct amount_msat this_fee = flow_fee(flows[i]);
if (!amount_msat_accumulate(&fee, this_fee)) {
plugin_err(plugin, "Could not add %s to %s for flowset fee",
child_err("Could not add %s to %s for flowset fee",
fmt_amount_msat(tmpctx, this_fee),
fmt_amount_msat(tmpctx, fee));
}
@@ -144,7 +144,7 @@ double flow_probability(const struct flow *flow,
if (!amount_msat_add_fee(&spend, h->base_fee,
h->proportional_fee)) {
plugin_err(rq->plugin, "Could not add fee %u/%u to amount %s in %i/%zu",
child_err("Could not add fee %u/%u to amount %s in %i/%zu",
h->base_fee, h->proportional_fee,
fmt_amount_msat(tmpctx, spend),
i, pathlen);

View File

@@ -40,17 +40,16 @@ double flow_probability(const struct flow *flow,
const struct route_query *rq);
/* How much do we need to send to make this flow arrive. */
struct amount_msat flow_spend(struct plugin *plugin, const struct flow *flow);
struct amount_msat flow_spend(const struct flow *flow);
/* How much do we pay in fees to make this flow arrive. */
struct amount_msat flow_fee(struct plugin *plugin, const struct flow *flow);
struct amount_msat flow_fee(const struct flow *flow);
/* What fee to we pay for this entire flow set? */
struct amount_msat flowset_fee(struct plugin *plugin, struct flow **flows);
struct amount_msat flowset_fee(struct flow **flows);
/* How much does this entire flowset deliver? */
struct amount_msat flowset_delivers(struct plugin *plugin,
struct flow **flows);
struct amount_msat flowset_delivers(struct flow **flows);
/* How much CLTV does this flow require? */
u64 flow_delay(const struct flow *flow);

View File

@@ -11,6 +11,7 @@
#include <math.h>
#include <plugins/askrene/askrene.h>
#include <plugins/askrene/child/algorithm.h>
#include <plugins/askrene/child/child_log.h>
#include <plugins/askrene/child/dijkstra.h>
#include <plugins/askrene/child/explain_failure.h>
#include <plugins/askrene/child/flow.h>
@@ -1015,7 +1016,7 @@ static struct flow **minflow(const tal_t *ctx,
if (!simple_feasibleflow(working_ctx, graph, src, dst,
arc_capacity, pay_amount)) {
rq_log(tmpctx, rq, LOG_INFORM,
child_log(tmpctx, LOG_INFORM,
"%s failed: unable to find a feasible flow.", __func__);
goto fail;
}
@@ -1029,7 +1030,7 @@ static struct flow **minflow(const tal_t *ctx,
arc_capacity,
arc_cost,
node_potential)) {
rq_log(tmpctx, rq, LOG_BROKEN,
child_log(tmpctx, LOG_BROKEN,
"%s: MCF optimization step failed", __func__);
goto fail;
}
@@ -1040,7 +1041,7 @@ static struct flow **minflow(const tal_t *ctx,
flow_paths = get_flow_paths(ctx, working_ctx, params,
graph, arc_capacity);
if (!flow_paths) {
rq_log(tmpctx, rq, LOG_BROKEN,
child_log(tmpctx, LOG_BROKEN,
"%s: failed to extract flow paths from the MCF solution",
__func__);
goto fail;
@@ -1211,7 +1212,7 @@ static struct flow **single_path_flow(const tal_t *ctx, const struct route_query
distance)) {
/* This might fail if we are unable to find a suitable route, it
* doesn't mean the plugin is broken, that's why we LOG_INFORM. */
rq_log(tmpctx, rq, LOG_INFORM,
child_log(tmpctx, LOG_INFORM,
"%s: could not find a feasible single path", __func__);
goto fail;
}
@@ -1224,15 +1225,14 @@ static struct flow **single_path_flow(const tal_t *ctx, const struct route_query
flow_paths = get_flow_singlepath(ctx, params, graph, rq->gossmap,
src, dst, pay_amount, prev);
if (!flow_paths) {
rq_log(tmpctx, rq, LOG_BROKEN,
child_log(tmpctx, LOG_BROKEN,
"%s: failed to extract flow paths from the single-path "
"solution",
__func__);
goto fail;
}
if (tal_count(flow_paths) != 1) {
rq_log(
tmpctx, rq, LOG_BROKEN,
child_log(tmpctx, LOG_BROKEN,
"%s: single-path solution returned a multi route solution",
__func__);
goto fail;
@@ -1369,7 +1369,7 @@ linear_routes(const tal_t *ctx, struct route_query *rq,
while (!amount_msat_is_zero(amount_to_deliver)) {
if (timemono_after(time_mono(), deadline)) {
error_message = rq_log(ctx, rq, LOG_BROKEN,
error_message = child_log(ctx, LOG_BROKEN,
"%s: timed out after deadline",
__func__);
goto fail;
@@ -1408,7 +1408,7 @@ linear_routes(const tal_t *ctx, struct route_query *rq,
goto fail;
/* we finished removing flows and excess */
all_deliver = flowset_delivers(rq->plugin, new_flows);
all_deliver = flowset_delivers(new_flows);
if (amount_msat_is_zero(all_deliver)) {
/* We removed all flows and we have not modified the
* MCF parameters. We will not have an infinite loop
@@ -1437,15 +1437,14 @@ linear_routes(const tal_t *ctx, struct route_query *rq,
* flows deliver with respect to the total remaining amount,
* ie. we avoid "consuming" all the feebudget if we still need
* to run MCF again for some remaining amount. */
struct amount_msat all_fees =
flowset_fee(rq->plugin, new_flows);
struct amount_msat all_fees = flowset_fee(new_flows);
const double deliver_fraction =
amount_msat_ratio(all_deliver, amount_to_deliver);
struct amount_msat partial_feebudget;
if (!amount_msat_scale(&partial_feebudget, feebudget,
deliver_fraction)) {
error_message =
rq_log(ctx, rq, LOG_BROKEN,
child_log(ctx, LOG_BROKEN,
"%s: failed to scale the fee budget (%s) by "
"fraction (%lf)",
__func__, fmt_amount_msat(tmpctx, feebudget),
@@ -1461,8 +1460,8 @@ linear_routes(const tal_t *ctx, struct route_query *rq,
else
mu += 10;
mu = MIN(mu, MU_MAX);
rq_log(
tmpctx, rq, LOG_INFORM,
child_log(
tmpctx, LOG_INFORM,
"The flows had a fee of %s, greater than "
"max of %s, retrying with mu of %u%%...",
fmt_amount_msat(tmpctx, all_fees),
@@ -1473,7 +1472,7 @@ linear_routes(const tal_t *ctx, struct route_query *rq,
/* we cannot increase mu anymore and all_fees
* already exceeds feebudget we fail. */
error_message =
rq_log(ctx, rq, LOG_UNUSUAL,
child_log(ctx, LOG_UNUSUAL,
"Could not find route without "
"excessive cost");
goto fail;
@@ -1481,8 +1480,8 @@ linear_routes(const tal_t *ctx, struct route_query *rq,
/* mu cannot be increased but at least all_fees
* does not exceed feebudget, we give it a shot.
*/
rq_log(
tmpctx, rq, LOG_UNUSUAL,
child_log(
tmpctx, LOG_UNUSUAL,
"The flows had a fee of %s, greater than "
"max of %s, but still within the fee "
"budget %s, we accept those flows.",
@@ -1496,14 +1495,14 @@ linear_routes(const tal_t *ctx, struct route_query *rq,
if (finalcltv + flows_worst_delay(new_flows) > maxdelay) {
if (delay_feefactor > 10) {
error_message =
rq_log(ctx, rq, LOG_UNUSUAL,
child_log(ctx, LOG_UNUSUAL,
"Could not find route without "
"excessive delays");
goto fail;
}
delay_feefactor *= 2;
rq_log(tmpctx, rq, LOG_INFORM,
child_log(tmpctx, LOG_INFORM,
"The worst flow delay is %" PRIu64
" (> %i), retrying with delay_feefactor %f...",
flows_worst_delay(new_flows), maxdelay - finalcltv,
@@ -1526,7 +1525,7 @@ linear_routes(const tal_t *ctx, struct route_query *rq,
&all_deliver, new_flows[i]->delivers) ||
!amount_msat_accumulate(
&all_fees,
flow_fee(rq->plugin, new_flows[i])))
flow_fee(new_flows[i])))
abort();
}
}
@@ -1534,7 +1533,7 @@ linear_routes(const tal_t *ctx, struct route_query *rq,
if (!amount_msat_deduct(&feebudget, all_fees) ||
!amount_msat_deduct(&amount_to_deliver, all_deliver)) {
error_message =
rq_log(ctx, rq, LOG_BROKEN,
child_log(ctx, LOG_BROKEN,
"%s: unexpected arithmetic operation "
"failure on amount_msat",
__func__);
@@ -1562,21 +1561,19 @@ linear_routes(const tal_t *ctx, struct route_query *rq,
}
/* Check fee budget! */
fee = flowset_fee(rq->plugin, *flows);
fee = flowset_fee(*flows);
if (amount_msat_greater(fee, maxfee)) {
error_message = rq_log(rq, rq, LOG_INFORM,
error_message = child_log(rq, LOG_INFORM,
"After reducing the flows to %zu (i.e. maxparts),"
" we had a fee of %s, greater than "
"max of %s.",
tal_count(*flows),
fmt_amount_msat(tmpctx, fee),
fmt_amount_msat(tmpctx, maxfee));
if (error_message) {
*flows = tal_free(*flows);
return error_message;
}
}
}
/* flows_probability re-does a temporary reservation so we need to call
* it after we have cleaned the reservations we used to build the flows
@@ -1587,20 +1584,20 @@ linear_routes(const tal_t *ctx, struct route_query *rq,
* verify" */
if (!check_htlc_min_limits(rq, *flows)) {
error_message =
rq_log(rq, rq, LOG_BROKEN,
child_log(rq, LOG_BROKEN,
"%s: check_htlc_min_limits failed", __func__);
*flows = tal_free(*flows);
return error_message;
}
if (!check_htlc_max_limits(rq, *flows)) {
*flows = tal_free(*flows);
return rq_log(rq, rq, LOG_BROKEN,
return child_log(rq, LOG_BROKEN,
"%s: check_htlc_max_limits failed", __func__);
}
if (tal_count(*flows) > rq->maxparts) {
size_t num_flows = tal_count(*flows);
*flows = tal_free(*flows);
return rq_log(rq, rq, LOG_BROKEN,
return child_log(rq, LOG_BROKEN,
"%s: the number of flows (%zu) exceeds the limit set "
"on payment parts (%" PRIu32
"), please submit a bug report",

View File

@@ -4,6 +4,7 @@
#include <ccan/tal/str/str.h>
#include <common/gossmap.h>
#include <plugins/askrene/askrene.h>
#include <plugins/askrene/child/child_log.h>
#include <plugins/askrene/child/flow.h>
#include <plugins/askrene/child/refine.h>
#include <plugins/askrene/reserve.h>
@@ -109,7 +110,7 @@ void create_flow_reservations(const struct route_query *rq,
amount_to_reserve);
if (!amount_msat_add_fee(&msat,
h->base_fee, h->proportional_fee))
plugin_err(rq->plugin, "Adding fee to amount");
child_err("Adding fee to amount");
}
}
@@ -281,8 +282,8 @@ remove_htlc_min_violations(const tal_t *ctx, struct route_query *rq,
+ 2 * gossmap_chan_idx(rq->gossmap, flow->path[i]);
get_scidd(rq->gossmap, flow, i, &scidd);
rq_log(
ctx, rq, LOG_INFORM,
child_log(
ctx, LOG_INFORM,
"Sending %s across %s would violate htlc_min "
"(~%s), disabling this channel",
fmt_amount_msat(ctx, msat),
@@ -295,7 +296,7 @@ remove_htlc_min_violations(const tal_t *ctx, struct route_query *rq,
&msat, hc->base_fee,
hc->proportional_fee)) {
error_message =
rq_log(ctx, rq, LOG_BROKEN,
child_log(ctx, LOG_BROKEN,
"%s: Adding fee to amount", __func__);
break;
}
@@ -325,13 +326,13 @@ static const char *remove_bottleneck(const tal_t *ctx, struct route_query *rq,
}
}
if (min_pos >= tal_count(flow->path)) {
error_message = rq_log(
ctx, rq, LOG_BROKEN,
error_message = child_log(
ctx, LOG_BROKEN,
"%s: failed to find any bottleneck, flow has no hops? %s",
__func__, fmt_flow_full(tmpctx, rq, flow));
} else {
get_scidd(rq->gossmap, flow, min_pos, &scidd);
rq_log(ctx, rq, LOG_INFORM,
child_log(tmpctx, LOG_INFORM,
"Disabling bottleneck channel %s with "
"htlc_max/known_max at %s",
fmt_short_channel_id_dir(ctx, &scidd),
@@ -489,7 +490,7 @@ static bool increase_flows(const struct route_query *rq,
* capacity. That shouldn't happen, but if it does,
* we don't crash */
if (!amount_msat_sub(&remaining, capacity, flows[i]->delivers)) {
rq_log(rq, rq, LOG_BROKEN,
child_log(rq, LOG_BROKEN,
"%s: flow %s delivers %s which is more than the path's capacity %s", __func__,
fmt_flow_full(tmpctx, rq, flows[i]),
fmt_amount_msat(tmpctx, flows[i]->delivers),
@@ -541,7 +542,7 @@ const char *refine_flows(const tal_t *ctx, struct route_query *rq,
/* We don't expect to have a zero flow amount here. Just report
* it. */
if (amount_msat_is_zero(try_deliver)) {
rq_log(ctx, rq, LOG_UNUSUAL,
child_log(tmpctx, LOG_UNUSUAL,
"Tried to refine a flow with zero amount: %s",
fmt_flow_full(tmpctx, rq, (*flows)[i]));
del_flow_from_arr(flows, i);
@@ -715,7 +716,7 @@ const char *reduce_num_flows(const tal_t *ctx,
del_flow_from_arr(flows, tal_count(*flows) - 1);
if (!increase_flows(rq, *flows, deliver, -1.0))
return rq_log(ctx, rq, LOG_INFORM,
return child_log(ctx, LOG_INFORM,
"Failed to reduce %zu flows down to maxparts (%zu)",
orig_num_flows, num_parts);