Skip to content

Commit cce3512

Browse files
committed
askrene: make children use child_log() instead of rq_log.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
1 parent 0ee92bd commit cce3512

File tree

8 files changed

+138
-153
lines changed

8 files changed

+138
-153
lines changed

plugins/askrene/askrene.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -314,12 +314,6 @@ const char *rq_log(const tal_t *ctx,
314314
msg = tal_vfmt(ctx, fmt, args);
315315
va_end(args);
316316

317-
/* FIXME: This is a hack! */
318-
if (am_child) {
319-
child_log(tmpctx, level, "%s", msg);
320-
return msg;
321-
}
322-
323317
plugin_notify_message(rq->cmd, level, "%s", msg);
324318

325319
/* Notifications already get logged at debug. Otherwise reduce

plugins/askrene/child/entry.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@
1414
#include <plugins/askrene/child/mcf.h>
1515
#include <unistd.h>
1616

17-
/* Temporary hack */
18-
bool am_child = false;
19-
2017
/* A single route. */
2118
struct route {
2219
/* Actual path to take */
@@ -177,7 +174,6 @@ int fork_router_child(struct route_query *rq,
177174
close(logfds[0]);
178175
close(replyfds[0]);
179176
set_child_log_fd(logfds[1]);
180-
am_child = true;
181177
if (single_path) {
182178
err = single_path_routes(rq, rq, deadline, srcnode, dstnode,
183179
amount, maxfee, finalcltv,

plugins/askrene/child/entry.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,4 @@ int fork_router_child(struct route_query *rq,
2222
struct json_filter *cmd_filter,
2323
int *log_fd,
2424
int *child_pid);
25-
26-
/* FIXME: Remove this */
27-
extern bool am_child;
2825
#endif /* LIGHTNING_PLUGINS_ASKRENE_CHILD_ENTRY_H */

plugins/askrene/child/explain_failure.c

Lines changed: 34 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <common/gossmap.h>
55
#include <common/route.h>
66
#include <plugins/askrene/askrene.h>
7+
#include <plugins/askrene/child/child_log.h>
78
#include <plugins/askrene/child/explain_failure.h>
89
#include <plugins/askrene/layer.h>
910
#include <plugins/askrene/reserve.h>
@@ -133,33 +134,33 @@ static const char *check_capacity(const tal_t *ctx,
133134

134135
node_stats(rq, node, node_direction, &stats);
135136
if (amount_msat_greater(amount, stats.total.capacity)) {
136-
return rq_log(ctx, rq, LOG_DBG,
137-
NO_USABLE_PATHS_STRING
138-
" Total %s capacity is only %s"
139-
" (in %zu channels).",
140-
name,
141-
fmt_amount_msat(tmpctx, stats.total.capacity),
142-
stats.total.num_channels);
137+
return child_log(ctx, LOG_DBG,
138+
NO_USABLE_PATHS_STRING
139+
" Total %s capacity is only %s"
140+
" (in %zu channels).",
141+
name,
142+
fmt_amount_msat(tmpctx, stats.total.capacity),
143+
stats.total.num_channels);
143144
}
144145
if (amount_msat_greater(amount, stats.gossip_known.capacity)) {
145-
return rq_log(ctx, rq, LOG_DBG,
146-
NO_USABLE_PATHS_STRING
147-
" Missing gossip for %s: only known %zu/%zu channels, leaving capacity only %s of %s.",
148-
name,
149-
stats.gossip_known.num_channels,
150-
stats.total.num_channels,
151-
fmt_amount_msat(tmpctx, stats.gossip_known.capacity),
152-
fmt_amount_msat(tmpctx, stats.total.capacity));
146+
return child_log(ctx, LOG_DBG,
147+
NO_USABLE_PATHS_STRING
148+
" Missing gossip for %s: only known %zu/%zu channels, leaving capacity only %s of %s.",
149+
name,
150+
stats.gossip_known.num_channels,
151+
stats.total.num_channels,
152+
fmt_amount_msat(tmpctx, stats.gossip_known.capacity),
153+
fmt_amount_msat(tmpctx, stats.total.capacity));
153154
}
154155
if (amount_msat_greater(amount, stats.enabled.capacity)) {
155-
return rq_log(ctx, rq, LOG_DBG,
156-
NO_USABLE_PATHS_STRING
156+
return child_log(ctx, LOG_DBG,
157+
NO_USABLE_PATHS_STRING
157158
" The %s has disabled %zu of %zu channels, leaving capacity only %s of %s.",
158-
name,
159-
stats.total.num_channels - stats.enabled.num_channels,
160-
stats.total.num_channels,
161-
fmt_amount_msat(tmpctx, stats.enabled.capacity),
162-
fmt_amount_msat(tmpctx, stats.total.capacity));
159+
name,
160+
stats.total.num_channels - stats.enabled.num_channels,
161+
stats.total.num_channels,
162+
fmt_amount_msat(tmpctx, stats.enabled.capacity),
163+
fmt_amount_msat(tmpctx, stats.total.capacity));
163164
}
164165
return NULL;
165166
}
@@ -236,7 +237,7 @@ const char *explain_failure(const tal_t *ctx,
236237
hops = route_from_dijkstra(tmpctx, rq->gossmap, dij, srcnode,
237238
AMOUNT_MSAT(0), 0);
238239
if (!hops)
239-
return rq_log(ctx, rq, LOG_INFORM,
240+
return child_log(ctx, LOG_INFORM,
240241
"There is no connection between source and destination at all");
241242

242243
/* Description of shortest path */
@@ -282,16 +283,16 @@ const char *explain_failure(const tal_t *ctx,
282283
else
283284
continue;
284285

285-
return rq_log(ctx, rq, LOG_INFORM,
286-
NO_USABLE_PATHS_STRING
287-
" The shortest path is %s, but %s %s",
288-
path,
289-
fmt_short_channel_id_dir(tmpctx, &scidd),
290-
explanation);
286+
return child_log(ctx, LOG_INFORM,
287+
NO_USABLE_PATHS_STRING
288+
" The shortest path is %s, but %s %s",
289+
path,
290+
fmt_short_channel_id_dir(tmpctx, &scidd),
291+
explanation);
291292
}
292293

293-
return rq_log(ctx, rq, LOG_BROKEN,
294-
"Actually, I'm not sure why we didn't find the"
295-
" obvious route %s: perhaps this is a bug?",
296-
path);
294+
return child_log(ctx, LOG_BROKEN,
295+
"Actually, I'm not sure why we didn't find the"
296+
" obvious route %s: perhaps this is a bug?",
297+
path);
297298
}

plugins/askrene/child/flow.c

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <common/overflows.h>
77
#include <math.h>
88
#include <plugins/askrene/askrene.h>
9+
#include <plugins/askrene/child/child_log.h>
910
#include <plugins/askrene/child/flow.h>
1011
#include <plugins/libplugin.h>
1112
#include <stdio.h>
@@ -17,16 +18,15 @@
1718
#endif
1819

1920
/* How much do we deliver to destination using this set of routes */
20-
struct amount_msat flowset_delivers(struct plugin *plugin,
21-
struct flow **flows)
21+
struct amount_msat flowset_delivers(struct flow **flows)
2222
{
2323
struct amount_msat final = AMOUNT_MSAT(0);
2424
for (size_t i = 0; i < tal_count(flows); i++) {
2525
if (!amount_msat_accumulate(&final, flows[i]->delivers)) {
26-
plugin_err(plugin, "Could not add flowsat %s to %s (%zu/%zu)",
27-
fmt_amount_msat(tmpctx, flows[i]->delivers),
28-
fmt_amount_msat(tmpctx, final),
29-
i, tal_count(flows));
26+
child_err("Could not add flowsat %s to %s (%zu/%zu)",
27+
fmt_amount_msat(tmpctx, flows[i]->delivers),
28+
fmt_amount_msat(tmpctx, final),
29+
i, tal_count(flows));
3030
}
3131
}
3232
return final;
@@ -68,7 +68,7 @@ static double edge_probability(const struct route_query *rq,
6868
return 1.0 - amount_msat_ratio(numerator, denominator);
6969
}
7070

71-
struct amount_msat flow_spend(struct plugin *plugin, const struct flow *flow)
71+
struct amount_msat flow_spend(const struct flow *flow)
7272
{
7373
const size_t pathlen = tal_count(flow->path);
7474
struct amount_msat spend = flow->delivers;
@@ -77,38 +77,38 @@ struct amount_msat flow_spend(struct plugin *plugin, const struct flow *flow)
7777
const struct half_chan *h = flow_edge(flow, i);
7878
if (!amount_msat_add_fee(&spend, h->base_fee,
7979
h->proportional_fee)) {
80-
plugin_err(plugin, "Could not add fee %u/%u to amount %s in %i/%zu",
81-
h->base_fee, h->proportional_fee,
82-
fmt_amount_msat(tmpctx, spend),
83-
i, pathlen);
80+
child_err("Could not add fee %u/%u to amount %s in %i/%zu",
81+
h->base_fee, h->proportional_fee,
82+
fmt_amount_msat(tmpctx, spend),
83+
i, pathlen);
8484
}
8585
}
8686

8787
return spend;
8888
}
8989

90-
struct amount_msat flow_fee(struct plugin *plugin, const struct flow *flow)
90+
struct amount_msat flow_fee(const struct flow *flow)
9191
{
92-
struct amount_msat spend = flow_spend(plugin, flow);
92+
struct amount_msat spend = flow_spend(flow);
9393
struct amount_msat fee;
9494
if (!amount_msat_sub(&fee, spend, flow->delivers)) {
95-
plugin_err(plugin, "Could not subtract %s from %s for fee",
96-
fmt_amount_msat(tmpctx, flow->delivers),
97-
fmt_amount_msat(tmpctx, spend));
95+
child_err("Could not subtract %s from %s for fee",
96+
fmt_amount_msat(tmpctx, flow->delivers),
97+
fmt_amount_msat(tmpctx, spend));
9898
}
9999

100100
return fee;
101101
}
102102

103-
struct amount_msat flowset_fee(struct plugin *plugin, struct flow **flows)
103+
struct amount_msat flowset_fee(struct flow **flows)
104104
{
105105
struct amount_msat fee = AMOUNT_MSAT(0);
106106
for (size_t i = 0; i < tal_count(flows); i++) {
107-
struct amount_msat this_fee = flow_fee(plugin, flows[i]);
107+
struct amount_msat this_fee = flow_fee(flows[i]);
108108
if (!amount_msat_accumulate(&fee, this_fee)) {
109-
plugin_err(plugin, "Could not add %s to %s for flowset fee",
110-
fmt_amount_msat(tmpctx, this_fee),
111-
fmt_amount_msat(tmpctx, fee));
109+
child_err("Could not add %s to %s for flowset fee",
110+
fmt_amount_msat(tmpctx, this_fee),
111+
fmt_amount_msat(tmpctx, fee));
112112
}
113113
}
114114
return fee;
@@ -144,10 +144,10 @@ double flow_probability(const struct flow *flow,
144144

145145
if (!amount_msat_add_fee(&spend, h->base_fee,
146146
h->proportional_fee)) {
147-
plugin_err(rq->plugin, "Could not add fee %u/%u to amount %s in %i/%zu",
148-
h->base_fee, h->proportional_fee,
149-
fmt_amount_msat(tmpctx, spend),
150-
i, pathlen);
147+
child_err("Could not add fee %u/%u to amount %s in %i/%zu",
148+
h->base_fee, h->proportional_fee,
149+
fmt_amount_msat(tmpctx, spend),
150+
i, pathlen);
151151
}
152152
}
153153

plugins/askrene/child/flow.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,16 @@ double flow_probability(const struct flow *flow,
4040
const struct route_query *rq);
4141

4242
/* How much do we need to send to make this flow arrive. */
43-
struct amount_msat flow_spend(struct plugin *plugin, const struct flow *flow);
43+
struct amount_msat flow_spend(const struct flow *flow);
4444

4545
/* How much do we pay in fees to make this flow arrive. */
46-
struct amount_msat flow_fee(struct plugin *plugin, const struct flow *flow);
46+
struct amount_msat flow_fee(const struct flow *flow);
4747

4848
/* What fee to we pay for this entire flow set? */
49-
struct amount_msat flowset_fee(struct plugin *plugin, struct flow **flows);
49+
struct amount_msat flowset_fee(struct flow **flows);
5050

5151
/* How much does this entire flowset deliver? */
52-
struct amount_msat flowset_delivers(struct plugin *plugin,
53-
struct flow **flows);
52+
struct amount_msat flowset_delivers(struct flow **flows);
5453

5554
/* How much CLTV does this flow require? */
5655
u64 flow_delay(const struct flow *flow);

0 commit comments

Comments
 (0)