Skip to content

Commit 577161a

Browse files
committed
renepay: remove custom debug, in favor of normal operations.
As a bonus, unit tests no longer leave files in /tmp. Reported-by: https://github.com/whitslack Signed-off-by: Rusty Russell <[email protected]>
1 parent 7c58294 commit 577161a

14 files changed

+62
-160
lines changed

plugins/renepay/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PLUGIN_RENEPAY_SRC := plugins/renepay/pay.c plugins/renepay/pay_flow.c plugins/renepay/flow.c plugins/renepay/mcf.c plugins/renepay/dijkstra.c \
2-
plugins/renepay/debug.c plugins/renepay/payment.c plugins/renepay/uncertainty_network.c
2+
plugins/renepay/payment.c plugins/renepay/uncertainty_network.c
33
PLUGIN_RENEPAY_HDRS := plugins/renepay/pay.h plugins/renepay/pay_flow.h plugins/renepay/flow.h plugins/renepay/mcf.h plugins/renepay/dijkstra.h \
4-
plugins/renepay/debug.h plugins/renepay/payment.h plugins/renepay/uncertainty_network.h
4+
plugins/renepay/payment.h plugins/renepay/uncertainty_network.h
55
PLUGIN_RENEPAY_OBJS := $(PLUGIN_RENEPAY_SRC:.c=.o)
66

77
# Make sure these depend on everything.

plugins/renepay/debug.c

Lines changed: 0 additions & 51 deletions
This file was deleted.

plugins/renepay/debug.h

Lines changed: 0 additions & 48 deletions
This file was deleted.

plugins/renepay/flow.c

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
#include <ccan/tal/tal.h>
66
#include <common/type_to_string.h>
77
#include <math.h>
8-
#include <plugins/renepay/debug.h>
98
#include <plugins/renepay/flow.h>
9+
#include <plugins/renepay/pay.h>
1010
#include <stdio.h>
1111

1212
#ifndef SUPERVERBOSE
@@ -128,15 +128,16 @@ void chan_extra_adjust_half(struct chan_extra *ce,
128128
{
129129
if(!amount_msat_sub(&ce->half[dir].known_max,ce->capacity,ce->half[!dir].known_min))
130130
{
131-
debug_err("%s cannot substract capacity=%s and known_min=%s",
131+
plugin_err(pay_plugin->plugin,
132+
"%s cannot substract capacity=%s and known_min=%s",
132133
__PRETTY_FUNCTION__,
133134
type_to_string(tmpctx,struct amount_msat,&ce->capacity),
134135
type_to_string(tmpctx,struct amount_msat,&ce->half[!dir].known_min)
135136
);
136137
}
137138
if(!amount_msat_sub(&ce->half[dir].known_min,ce->capacity,ce->half[!dir].known_max))
138139
{
139-
debug_err("%s cannot substract capacity=%s and known_max=%s",
140+
plugin_err(pay_plugin->plugin,"%s cannot substract capacity=%s and known_max=%s",
140141
__PRETTY_FUNCTION__,
141142
type_to_string(tmpctx,struct amount_msat,&ce->capacity),
142143
type_to_string(tmpctx,struct amount_msat,&ce->half[!dir].known_max)
@@ -153,7 +154,7 @@ static void chan_extra_can_send_(
153154
{
154155
if(amount_msat_greater(x,ce->capacity))
155156
{
156-
debug_err("%s unexpected capacity=%s is less than x=%s",
157+
plugin_err(pay_plugin->plugin,"%s unexpected capacity=%s is less than x=%s",
157158
__PRETTY_FUNCTION__,
158159
type_to_string(tmpctx,struct amount_msat,&ce->capacity),
159160
type_to_string(tmpctx,struct amount_msat,&x)
@@ -176,12 +177,12 @@ void chan_extra_can_send(
176177
scidd->scid);
177178
if(!ce)
178179
{
179-
debug_err("%s unexpected chan_extra ce is NULL",
180+
plugin_err(pay_plugin->plugin,"%s unexpected chan_extra ce is NULL",
180181
__PRETTY_FUNCTION__);
181182
}
182183
if(!amount_msat_add(&x,x,ce->half[scidd->dir].htlc_total))
183184
{
184-
debug_err("%s (line %d) cannot add x=%s and htlc_total=%s",
185+
plugin_err(pay_plugin->plugin,"%s (line %d) cannot add x=%s and htlc_total=%s",
185186
__PRETTY_FUNCTION__,__LINE__,
186187
type_to_string(tmpctx,struct amount_msat,&x),
187188
type_to_string(tmpctx,struct amount_msat,&ce->half[scidd->dir].htlc_total));
@@ -201,14 +202,14 @@ void chan_extra_cannot_send(
201202
scidd->scid);
202203
if(!ce)
203204
{
204-
debug_err("%s (line %d) unexpected chan_extra ce is NULL",
205+
plugin_err(pay_plugin->plugin,"%s (line %d) unexpected chan_extra ce is NULL",
205206
__PRETTY_FUNCTION__,__LINE__);
206207
}
207208

208209
/* Note: sent is already included in htlc_total! */
209210
if(!amount_msat_sub(&x,ce->half[scidd->dir].htlc_total,AMOUNT_MSAT(1)))
210211
{
211-
debug_err("%s (line %d) unexpected htlc_total=%s is less than 0msat",
212+
plugin_err(pay_plugin->plugin,"%s (line %d) unexpected htlc_total=%s is less than 0msat",
212213
__PRETTY_FUNCTION__,__LINE__,
213214
type_to_string(tmpctx,struct amount_msat,
214215
&ce->half[scidd->dir].htlc_total)
@@ -246,7 +247,7 @@ static void chan_extra_set_liquidity_(
246247
{
247248
if(amount_msat_greater(x,ce->capacity))
248249
{
249-
debug_err("%s unexpected capacity=%s is less than x=%s",
250+
plugin_err(pay_plugin->plugin,"%s unexpected capacity=%s is less than x=%s",
250251
__PRETTY_FUNCTION__,
251252
type_to_string(tmpctx,struct amount_msat,&ce->capacity),
252253
type_to_string(tmpctx,struct amount_msat,&x)
@@ -268,7 +269,7 @@ void chan_extra_set_liquidity(
268269
scidd->scid);
269270
if(!ce)
270271
{
271-
debug_err("%s unexpected chan_extra ce is NULL",
272+
plugin_err(pay_plugin->plugin,"%s unexpected chan_extra ce is NULL",
272273
__PRETTY_FUNCTION__);
273274
}
274275
chan_extra_set_liquidity_(ce,scidd->dir,x);
@@ -284,13 +285,13 @@ void chan_extra_sent_success(
284285
scidd->scid);
285286
if(!ce)
286287
{
287-
debug_err("%s unexpected chan_extra ce is NULL",
288+
plugin_err(pay_plugin->plugin,"%s unexpected chan_extra ce is NULL",
288289
__PRETTY_FUNCTION__);
289290
}
290291

291292
if(amount_msat_greater(x,ce->capacity))
292293
{
293-
debug_err("%s unexpected capacity=%s is less than x=%s",
294+
plugin_err(pay_plugin->plugin,"%s unexpected capacity=%s is less than x=%s",
294295
__PRETTY_FUNCTION__,
295296
type_to_string(tmpctx,struct amount_msat,&ce->capacity),
296297
type_to_string(tmpctx,struct amount_msat,&x)
@@ -349,7 +350,7 @@ void chan_extra_relax(
349350
scidd->scid);
350351
if(!ce)
351352
{
352-
debug_err("%s unexpected chan_extra ce is NULL",
353+
plugin_err(pay_plugin->plugin,"%s unexpected chan_extra ce is NULL",
353354
__PRETTY_FUNCTION__);
354355
}
355356
chan_extra_relax_(ce,scidd->dir,x,y);
@@ -427,7 +428,7 @@ get_chan_extra_half_by_chan_verify(
427428
if (!gossmap_chan_get_capacity(gossmap,chan, &cap) ||
428429
!amount_sat_to_msat(&cap_msat, cap))
429430
{
430-
debug_err("%s (line %d) unable convert sat to msat or "
431+
plugin_err(pay_plugin->plugin,"%s (line %d) unable convert sat to msat or "
431432
"get channel capacity",
432433
__PRETTY_FUNCTION__,
433434
__LINE__);
@@ -488,7 +489,7 @@ static double edge_probability(struct amount_msat min, struct amount_msat max,
488489
// one past the last known value, makes computations simpler
489490
if(!amount_msat_add(&B,B,one))
490491
{
491-
debug_err("%s (line %d) cannot add B=%s and %s",
492+
plugin_err(pay_plugin->plugin,"%s (line %d) cannot add B=%s and %s",
492493
__PRETTY_FUNCTION__,
493494
__LINE__,
494495
type_to_string(this_ctx, struct amount_msat, &B),
@@ -497,7 +498,7 @@ static double edge_probability(struct amount_msat min, struct amount_msat max,
497498
// in_flight cannot be greater than max
498499
if(!amount_msat_sub(&B,B,in_flight))
499500
{
500-
debug_err("%s (line %d) in_flight=%s cannot be greater than B=%s",
501+
plugin_err(pay_plugin->plugin,"%s (line %d) in_flight=%s cannot be greater than B=%s",
501502
__PRETTY_FUNCTION__,
502503
__LINE__,
503504
type_to_string(this_ctx, struct amount_msat, &in_flight),
@@ -513,7 +514,7 @@ static double edge_probability(struct amount_msat min, struct amount_msat max,
513514
// B cannot be smaller than or equal A
514515
if(!amount_msat_sub(&denominator,B,A) || amount_msat_less_eq(B,A))
515516
{
516-
debug_err("%s (line %d) B=%s must be greater than A=%s",
517+
plugin_err(pay_plugin->plugin,"%s (line %d) B=%s must be greater than A=%s",
517518
__PRETTY_FUNCTION__,
518519
__LINE__,
519520
type_to_string(this_ctx, struct amount_msat, &B),
@@ -545,7 +546,7 @@ void remove_completed_flow(const struct gossmap *gossmap,
545546
flow->dirs[i]);
546547
if (!amount_msat_sub(&h->htlc_total, h->htlc_total, flow->amounts[i]))
547548
{
548-
debug_err("%s could not substract HTLC amounts, "
549+
plugin_err(pay_plugin->plugin,"%s could not substract HTLC amounts, "
549550
"half total htlc amount = %s, "
550551
"flow->amounts[%lld] = %s.",
551552
__PRETTY_FUNCTION__,
@@ -555,7 +556,7 @@ void remove_completed_flow(const struct gossmap *gossmap,
555556
}
556557
if (h->num_htlcs == 0)
557558
{
558-
debug_err("%s could not decrease HTLC count.",
559+
plugin_err(pay_plugin->plugin,"%s could not decrease HTLC count.",
559560
__PRETTY_FUNCTION__);
560561
}
561562
h->num_htlcs--;
@@ -586,7 +587,7 @@ void commit_flow(
586587
flow->dirs[i]);
587588
if (!amount_msat_add(&h->htlc_total, h->htlc_total, flow->amounts[i]))
588589
{
589-
debug_err("%s could not add HTLC amounts, "
590+
plugin_err(pay_plugin->plugin,"%s could not add HTLC amounts, "
590591
"flow->amounts[%lld] = %s.",
591592
__PRETTY_FUNCTION__,
592593
i,
@@ -631,7 +632,7 @@ void flow_complete(struct flow *flow,
631632

632633
if(!h)
633634
{
634-
debug_err("%s unexpected chan_extra_half is NULL",
635+
plugin_err(pay_plugin->plugin,"%s unexpected chan_extra_half is NULL",
635636
__PRETTY_FUNCTION__);
636637
}
637638

@@ -645,7 +646,7 @@ void flow_complete(struct flow *flow,
645646
flow_edge(flow, i)->base_fee,
646647
flow_edge(flow, i)->proportional_fee))
647648
{
648-
debug_err("%s fee overflow",
649+
plugin_err(pay_plugin->plugin,"%s fee overflow",
649650
__PRETTY_FUNCTION__);
650651
}
651652
}
@@ -716,7 +717,7 @@ double flow_set_probability(
716717
struct amount_msat prev_flow;
717718
if(!amount_msat_add(&prev_flow,h->htlc_total,in_flight[c_idx].half[c_dir]))
718719
{
719-
debug_err("%s (line %d) in-flight amount_msat overflow",
720+
plugin_err(pay_plugin->plugin,"%s (line %d) in-flight amount_msat overflow",
720721
__PRETTY_FUNCTION__,
721722
__LINE__);
722723
}
@@ -728,7 +729,7 @@ double flow_set_probability(
728729
in_flight[c_idx].half[c_dir],
729730
deliver))
730731
{
731-
debug_err("%s (line %d) in-flight amount_msat overflow",
732+
plugin_err(pay_plugin->plugin,"%s (line %d) in-flight amount_msat overflow",
732733
__PRETTY_FUNCTION__,
733734
__LINE__);
734735
}
@@ -810,7 +811,7 @@ static void get_medians(const struct gossmap *gossmap,
810811
*median_capacity = amount;
811812
else if (!amount_sat_to_msat(median_capacity, caps[num_caps / 2]))
812813
{
813-
debug_err("%s (line %d) amount_msat overflow",
814+
plugin_err(pay_plugin->plugin,"%s (line %d) amount_msat overflow",
814815
__PRETTY_FUNCTION__,
815816
__LINE__);
816817
}
@@ -877,13 +878,13 @@ struct amount_msat flow_set_fee(struct flow **flows)
877878
flows[i]->amounts[0],
878879
flows[i]->amounts[n-1]))
879880
{
880-
debug_err("%s (line %d) amount_msat overflow",
881+
plugin_err(pay_plugin->plugin,"%s (line %d) amount_msat overflow",
881882
__PRETTY_FUNCTION__,
882883
__LINE__);
883884
}
884885
if(!amount_msat_add(&fee, this_fee,fee))
885886
{
886-
debug_err("%s (line %d) amount_msat overflow",
887+
plugin_err(pay_plugin->plugin,"%s (line %d) amount_msat overflow",
887888
__PRETTY_FUNCTION__,
888889
__LINE__);
889890
}

plugins/renepay/mcf.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
#include <ccan/tal/tal.h>
66
#include <common/type_to_string.h>
77
#include <math.h>
8-
#include <plugins/renepay/debug.h>
98
#include <plugins/renepay/dijkstra.h>
109
#include <plugins/renepay/flow.h>
1110
#include <plugins/renepay/mcf.h>
11+
#include <plugins/renepay/pay.h>
1212
#include <stdint.h>
1313

1414
/* # Optimal payments
@@ -457,7 +457,7 @@ static void linearize_channel(
457457

458458
if(!extra_half)
459459
{
460-
debug_err("%s (line %d) unexpected, extra_half is NULL",
460+
plugin_err(pay_plugin->plugin,"%s (line %d) unexpected, extra_half is NULL",
461461
__PRETTY_FUNCTION__,
462462
__LINE__);
463463
}
@@ -1242,7 +1242,7 @@ static struct flow **
12421242
struct amount_msat delivered = amount_msat(delta*1000);
12431243
if(!amount_msat_sub(&delivered,delivered,excess))
12441244
{
1245-
debug_err("%s (line %d) unable to substract excess.",
1245+
plugin_err(pay_plugin->plugin,"%s (line %d) unable to substract excess.",
12461246
__PRETTY_FUNCTION__,
12471247
__LINE__);
12481248
}

0 commit comments

Comments
 (0)