Skip to content
This repository was archived by the owner on Jun 26, 2024. It is now read-only.

Commit 00e9af5

Browse files
committed
plugins/renepay: neaten the command notifications.
It now looks like (for test_hardmpp): ``` # we have computed a set of 1 flows with probability 0.328, fees 0msat and delay 23 # Flow 1: amount=1800000000msat prob=0.328 fees=0msat delay=12 path=-103x2x0/1(min=max=4294967295msat)->-103x5x0/0->-103x3x0/1-> # Flow 1: Failed at node #1 (WIRE_TEMPORARY_CHANNEL_FAILURE): failed: WIRE_TEMPORARY_CHANNEL_FAILURE (reply from remote) # Flow 1: Failure of 1800000000msat for 103x5x0/0 capacity [0msat,3000000000msat] -> [0msat,1799999999msat] # we have computed a set of 2 flows with probability 0.115, fees 0msat and delay 23 # Flow 2: amount=500000000msat prob=0.475 fees=0msat delay=12 path=-103x6x0/0(min=max=4294967295msat)->-103x1x0/1->-103x4x0/1-> # Flow 3: amount=1300000000msat prob=0.242 fees=0msat delay=12 path=-103x2x0/1(min=max=4294967295msat)->-103x5x0/0(max=1799999999msat)->-103x3x0/1-> # Flow 3: Failed at node #1 (WIRE_TEMPORARY_CHANNEL_FAILURE): failed: WIRE_TEMPORARY_CHANNEL_FAILURE (reply from remote) # Flow 3: Failure of 1300000000msat for 103x5x0/0 capacity [0msat,1799999999msat] -> [0msat,1299999999msat] # we have computed a set of 2 flows with probability 0.084, fees 0msat and delay 23 # Flow 4: amount=260000000msat prob=0.467 fees=0msat delay=12 path=-103x6x0/0(500000000msat in 1 htlcs,min=max=4294967295msat)->-103x1x0/1(500000000msat in 1 htlcs)->-103x4x0/1(500000000msat in 1 htlcs)-> # Flow 5: amount=1040000000msat prob=0.179 fees=0msat delay=12 path=-103x2x0/1(min=max=4294967295msat)->-103x5x0/0(max=1299999999msat)->-103x3x0/1-> # Flow 5: Failed at node #1 (WIRE_TEMPORARY_CHANNEL_FAILURE): failed: WIRE_TEMPORARY_CHANNEL_FAILURE (reply from remote) # Flow 5: Failure of 1040000000msat for 103x5x0/0 capacity [0msat,1299999999msat] -> [0msat,1039999999msat] # we have computed a set of 2 flows with probability 0.052, fees 0msat and delay 23 # Flow 6: amount=120000000msat prob=0.494 fees=0msat delay=12 path=-103x6x0/0(760000000msat in 2 htlcs,min=max=4294967295msat)->-103x1x0/1(760000000msat in 2 htlcs)->-103x4x0/1(760000000msat in 2 htlcs)-> # Flow 7: amount=920000000msat prob=0.105 fees=0msat delay=12 path=-103x2x0/1(min=max=4294967295msat)->-103x5x0/0(max=1039999999msat)->-103x3x0/1-> # Flow 7: Success ``` Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
1 parent 7db6aaa commit 00e9af5

File tree

6 files changed

+155
-76
lines changed

6 files changed

+155
-76
lines changed

plugins/renepay/flow.c

Lines changed: 87 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,52 @@ const char *fmt_chan_extra_map(
4848
return buff;
4949
}
5050

51+
const char *fmt_chan_extra_details(const tal_t *ctx,
52+
struct chan_extra_map* chan_extra_map,
53+
const struct short_channel_id_dir *scidd)
54+
{
55+
const struct chan_extra *ce = chan_extra_map_get(chan_extra_map,
56+
scidd->scid);
57+
const struct chan_extra_half *ch;
58+
char *str = tal_strdup(ctx, "");
59+
char sep = '(';
60+
61+
if (!ce)
62+
return str;
63+
64+
ch = &ce->half[scidd->dir];
65+
if (ch->num_htlcs != 0) {
66+
tal_append_fmt(&str, "%c%s in %zu htlcs",
67+
sep,
68+
fmt_amount_msat(tmpctx, ch->htlc_total),
69+
ch->num_htlcs);
70+
sep = ',';
71+
}
72+
/* Happens with local channels, where we're certain. */
73+
if (amount_msat_eq(ch->known_min, ch->known_max)) {
74+
tal_append_fmt(&str, "%cmin=max=%s",
75+
sep,
76+
fmt_amount_msat(tmpctx, ch->known_min));
77+
sep = ',';
78+
} else {
79+
if (amount_msat_greater(ch->known_min, AMOUNT_MSAT(0))) {
80+
tal_append_fmt(&str, "%cmin=%s",
81+
sep,
82+
fmt_amount_msat(tmpctx, ch->known_min));
83+
sep = ',';
84+
}
85+
if (!amount_msat_eq(ch->known_max, ce->capacity)) {
86+
tal_append_fmt(&str, "%cmax=%s",
87+
sep,
88+
fmt_amount_msat(tmpctx, ch->known_max));
89+
sep = ',';
90+
}
91+
}
92+
if (!streq(str, ""))
93+
tal_append_fmt(&str, ")");
94+
return str;
95+
}
96+
5197
struct chan_extra *new_chan_extra(
5298
struct chan_extra_map *chan_extra_map,
5399
const struct short_channel_id scid,
@@ -145,12 +191,12 @@ void chan_extra_can_send(
145191

146192
/* Update the knowledge that this (channel,direction) cannot send.*/
147193
void chan_extra_cannot_send(
148-
struct payment *p,
194+
struct pay_flow *pf,
149195
struct chan_extra_map *chan_extra_map,
150196
const struct short_channel_id_dir *scidd,
151197
struct amount_msat sent)
152198
{
153-
struct amount_msat x;
199+
struct amount_msat oldmin, oldmax, x;
154200
struct chan_extra *ce = chan_extra_map_get(chan_extra_map,
155201
scidd->scid);
156202
if(!ce)
@@ -170,20 +216,23 @@ void chan_extra_cannot_send(
170216
x = AMOUNT_MSAT(0);
171217
}
172218

219+
oldmin = ce->half[scidd->dir].known_min;
220+
oldmax = ce->half[scidd->dir].known_max;
221+
173222
/* If we "knew" the capacity was at least this, we just showed we're wrong! */
174-
if (amount_msat_less(x, ce->half[scidd->dir].known_min)) {
175-
debug_paynote(p, "Expected scid=%s min %s, but %s failed! Setting min to 0",
176-
type_to_string(tmpctx,struct short_channel_id_dir,scidd),
177-
type_to_string(tmpctx,struct amount_msat,&ce->half[scidd->dir].known_min),
178-
type_to_string(tmpctx,struct amount_msat,&x));
223+
if (amount_msat_less(x, ce->half[scidd->dir].known_min))
179224
ce->half[scidd->dir].known_min = AMOUNT_MSAT(0);
180-
}
225+
181226
ce->half[scidd->dir].known_max = amount_msat_min(ce->half[scidd->dir].known_max,x);
182227

183-
debug_paynote(p,"Update chan knowledge scid=%s: [%s,%s]",
184-
type_to_string(tmpctx,struct short_channel_id_dir,scidd),
185-
type_to_string(tmpctx,struct amount_msat,&ce->half[scidd->dir].known_min),
186-
type_to_string(tmpctx,struct amount_msat,&ce->half[scidd->dir].known_max));
228+
payflow_note(pf, LOG_INFORM,
229+
"Failure of %s for %s capacity [%s,%s] -> [%s,%s]",
230+
fmt_amount_msat(tmpctx, sent),
231+
type_to_string(tmpctx,struct short_channel_id_dir,scidd),
232+
fmt_amount_msat(tmpctx, oldmin),
233+
fmt_amount_msat(tmpctx, oldmax),
234+
fmt_amount_msat(tmpctx, ce->half[scidd->dir].known_min),
235+
fmt_amount_msat(tmpctx, ce->half[scidd->dir].known_max));
187236

188237
chan_extra_adjust_half(ce,!scidd->dir);
189238
}
@@ -223,11 +272,20 @@ void chan_extra_set_liquidity(
223272
chan_extra_set_liquidity_(ce,scidd->dir,x);
224273
}
225274
/* Update the knowledge that this (channel,direction) has sent x msat.*/
226-
static void chan_extra_sent_success_(
227-
struct chan_extra *ce,
228-
int dir,
275+
void chan_extra_sent_success(
276+
struct pay_flow *pf,
277+
struct chan_extra_map *chan_extra_map,
278+
const struct short_channel_id_dir *scidd,
229279
struct amount_msat x)
230280
{
281+
struct chan_extra *ce = chan_extra_map_get(chan_extra_map,
282+
scidd->scid);
283+
if(!ce)
284+
{
285+
debug_err("%s unexpected chan_extra ce is NULL",
286+
__PRETTY_FUNCTION__);
287+
}
288+
231289
if(amount_msat_greater(x,ce->capacity))
232290
{
233291
debug_err("%s unexpected capacity=%s is less than x=%s",
@@ -240,29 +298,24 @@ static void chan_extra_sent_success_(
240298

241299
struct amount_msat new_a, new_b;
242300

243-
if(!amount_msat_sub(&new_a,ce->half[dir].known_min,x))
301+
if(!amount_msat_sub(&new_a,ce->half[scidd->dir].known_min,x))
244302
new_a = AMOUNT_MSAT(0);
245-
if(!amount_msat_sub(&new_b,ce->half[dir].known_max,x))
303+
if(!amount_msat_sub(&new_b,ce->half[scidd->dir].known_max,x))
246304
new_b = AMOUNT_MSAT(0);
247305

248-
ce->half[dir].known_min = new_a;
249-
ce->half[dir].known_max = new_b;
306+
payflow_note(pf, LOG_DBG,
307+
"Success of %s for %s capacity [%s,%s] -> [%s,%s]",
308+
fmt_amount_msat(tmpctx, x),
309+
type_to_string(tmpctx,struct short_channel_id_dir,scidd),
310+
fmt_amount_msat(tmpctx, ce->half[scidd->dir].known_min),
311+
fmt_amount_msat(tmpctx, ce->half[scidd->dir].known_max),
312+
fmt_amount_msat(tmpctx, new_a),
313+
fmt_amount_msat(tmpctx, new_b));
250314

251-
chan_extra_adjust_half(ce,!dir);
252-
}
253-
void chan_extra_sent_success(
254-
struct chan_extra_map *chan_extra_map,
255-
const struct short_channel_id_dir *scidd,
256-
struct amount_msat x)
257-
{
258-
struct chan_extra *ce = chan_extra_map_get(chan_extra_map,
259-
scidd->scid);
260-
if(!ce)
261-
{
262-
debug_err("%s unexpected chan_extra ce is NULL",
263-
__PRETTY_FUNCTION__);
264-
}
265-
chan_extra_sent_success_(ce,scidd->dir,x);
315+
ce->half[scidd->dir].known_min = new_a;
316+
ce->half[scidd->dir].known_max = new_b;
317+
318+
chan_extra_adjust_half(ce,!scidd->dir);
266319
}
267320
/* Forget a bit about this (channel,direction) state. */
268321
static void chan_extra_relax_(

plugins/renepay/flow.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,12 @@ const char *fmt_chan_extra_map(
118118
const tal_t *ctx,
119119
struct chan_extra_map* chan_extra_map);
120120

121+
/* Returns "" if nothing useful known about channel, otherwise
122+
* "(details)" */
123+
const char *fmt_chan_extra_details(const tal_t *ctx,
124+
struct chan_extra_map* chan_extra_map,
125+
const struct short_channel_id_dir *scidd);
126+
121127
/* Creates a new chan_extra and adds it to the chan_extra_map. */
122128
struct chan_extra *new_chan_extra(
123129
struct chan_extra_map *chan_extra_map,
@@ -152,7 +158,7 @@ void chan_extra_can_send(struct chan_extra_map *chan_extra_map,
152158
struct amount_msat x);
153159

154160
/* Update the knowledge that this (channel,direction) cannot send x msat.*/
155-
void chan_extra_cannot_send(struct payment* p,
161+
void chan_extra_cannot_send(struct pay_flow* pf,
156162
struct chan_extra_map *chan_extra_map,
157163
const struct short_channel_id_dir *scidd,
158164
struct amount_msat x);
@@ -163,7 +169,8 @@ void chan_extra_set_liquidity(struct chan_extra_map *chan_extra_map,
163169
struct amount_msat x);
164170

165171
/* Update the knowledge that this (channel,direction) has sent x msat.*/
166-
void chan_extra_sent_success(struct chan_extra_map *chan_extra_map,
172+
void chan_extra_sent_success(struct pay_flow *pf,
173+
struct chan_extra_map *chan_extra_map,
167174
const struct short_channel_id_dir *scidd,
168175
struct amount_msat x);
169176

plugins/renepay/pay.c

Lines changed: 19 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -121,12 +121,8 @@ static struct pf_result *handle_unhandleable_error(struct pay_flow *pf,
121121
size_t n = tal_count(pf);
122122

123123
/* We got a mangled reply. We don't know who to penalize! */
124-
debug_paynote(pf->payment, "%s on route %s", what, flow_path_to_str(tmpctx, pf));
125-
126-
// TODO(eduardo): does LOG_BROKEN finish the plugin execution?
127-
plugin_log(pay_plugin->plugin, LOG_BROKEN,
128-
"%s on route %s",
129-
what, flow_path_to_str(tmpctx, pf));
124+
payflow_note(pf, LOG_UNUSUAL, "%s on route %s",
125+
what, flow_path_to_str(tmpctx, pf));
130126

131127
if (n == 1)
132128
{
@@ -145,9 +141,9 @@ static struct pf_result *handle_unhandleable_error(struct pay_flow *pf,
145141
n = pseudorand(n-1);
146142

147143
tal_arr_expand(&pf->payment->disabled, pf->path_scidds[n].scid);
148-
debug_paynote(pf->payment, "... eliminated %s",
149-
type_to_string(tmpctx, struct short_channel_id,
150-
&pf->path_scidds[n].scid));
144+
payflow_note(pf, LOG_DBG, "... eliminated %s",
145+
type_to_string(tmpctx, struct short_channel_id,
146+
&pf->path_scidds[n].scid));
151147

152148
return pay_flow_failed(pf);
153149
}
@@ -182,9 +178,10 @@ static struct command_result *addgossip_failure(struct command *cmd,
182178
struct payment * payment = adg->pf->payment;
183179
plugin_log(pay_plugin->plugin,LOG_DBG,"calling %s",__PRETTY_FUNCTION__);
184180

185-
debug_paynote(payment, "addgossip failed, removing channel %s (%.*s)",
186-
type_to_string(tmpctx, struct short_channel_id, &adg->scid),
187-
err->end - err->start, buf + err->start);
181+
payflow_note(adg->pf, LOG_UNUSUAL,
182+
"addgossip failed, removing channel %s (%.*s)",
183+
type_to_string(tmpctx, struct short_channel_id, &adg->scid),
184+
err->end - err->start, buf + err->start);
188185
tal_arr_expand(&payment->disabled, adg->scid);
189186

190187
return addgossip_done(cmd, buf, err, adg);
@@ -195,7 +192,6 @@ static struct pf_result *submit_update(struct pay_flow *pf,
195192
struct short_channel_id errscid)
196193
{
197194
plugin_log(pay_plugin->plugin,LOG_DBG,"calling %s",__PRETTY_FUNCTION__);
198-
struct payment *payment = pf->payment;
199195
struct out_req *req;
200196
struct addgossip *adg = tal(pf, struct addgossip);
201197

@@ -204,8 +200,7 @@ static struct pf_result *submit_update(struct pay_flow *pf,
204200
adg->scid = errscid;
205201
adg->pf = pf;
206202

207-
debug_paynote(payment, "... extracted channel_update, telling gossipd");
208-
plugin_log(pay_plugin->plugin, LOG_DBG, "(update = %s)", tal_hex(tmpctx, update));
203+
payflow_note(pf, LOG_DBG, "... extracted channel_update %s, telling gossipd", tal_hex(tmpctx, update));
209204

210205
req = jsonrpc_request_start(pay_plugin->plugin, NULL, "addgossip",
211206
addgossip_done,
@@ -312,8 +307,8 @@ static struct command_result *flow_sendpay_failed(struct command *cmd,
312307
plugin_err(cmd->plugin, "Strange error from sendpay: %.*s",
313308
json_tok_full_len(err), json_tok_full(buf, err));
314309

315-
debug_paynote(payment,
316-
"sendpay didn't like first hop, eliminated: %s", msg)
310+
payflow_note(pf, LOG_INFORM,
311+
"sendpay didn't like first hop, eliminated: %s", msg);
317312

318313
/* There is no new knowledge from this kind of failure.
319314
* We just disable this scid. */
@@ -329,15 +324,11 @@ static void sendpay_new_flows(struct payment *p)
329324
struct pay_flow *pf;
330325

331326
list_for_each(&p->flows, pf, list) {
327+
struct out_req *req;
328+
332329
if (pf->state != PAY_FLOW_NOT_STARTED)
333330
continue;
334331

335-
debug_paynote(p, "sendpay flow groupid=%"PRIu64", partid=%"PRIu64", delivering=%s, probability=%.3lf",
336-
pf->key.groupid,
337-
pf->key.partid,
338-
fmt_amount_msat(tmpctx, payflow_delivered(pf)),
339-
pf->success_prob);
340-
struct out_req *req;
341332
/* FIXME: We don't actually want cmd to own this sendpay, so we use NULL here,
342333
* but we should use a variant which allows us to set json id! */
343334
req = jsonrpc_request_start(pay_plugin->plugin, NULL, "sendpay",
@@ -1163,18 +1154,6 @@ static void handle_sendpay_failure_flow(struct pay_flow *pf,
11631154
{
11641155
debug_assert(pf);
11651156

1166-
struct payment * const p = pf->payment;
1167-
1168-
plugin_log(pay_plugin->plugin, LOG_UNUSUAL,
1169-
"onion error %s from node #%u %s: "
1170-
"%s",
1171-
onion_wire_name(onionerr),
1172-
erridx,
1173-
erridx == tal_count(pf->path_scidds)
1174-
? "final"
1175-
: type_to_string(tmpctx, struct short_channel_id_dir, &pf->path_scidds[erridx]),
1176-
msg);
1177-
11781157
/* we know that all channels before erridx where able to commit to this payment */
11791158
uncertainty_network_channel_can_send(
11801159
pay_plugin->chan_extra_map,
@@ -1185,10 +1164,7 @@ static void handle_sendpay_failure_flow(struct pay_flow *pf,
11851164
if((enum onion_wire)onionerr == WIRE_TEMPORARY_CHANNEL_FAILURE
11861165
&& erridx < tal_count(pf->path_scidds))
11871166
{
1188-
plugin_log(pay_plugin->plugin,LOG_DBG,
1189-
"sendpay_failure says insufficient funds!");
1190-
1191-
chan_extra_cannot_send(p,pay_plugin->chan_extra_map,
1167+
chan_extra_cannot_send(pf,pay_plugin->chan_extra_map,
11921168
&pf->path_scidds[erridx],
11931169
pf->amounts[erridx]);
11941170
}
@@ -1244,6 +1220,8 @@ static struct command_result *notification_sendpay_success(
12441220
json_tok_full(buf, params));
12451221
}
12461222

1223+
payflow_note(pf, LOG_INFORM, "Success");
1224+
12471225
// 2. update information
12481226
uncertainty_network_flow_success(pay_plugin->chan_extra_map, pf);
12491227

@@ -1302,6 +1280,8 @@ static struct pf_result *sendpay_failure(struct pay_flow *pf,
13021280
flow_path_to_str(tmpctx, pf));
13031281
}
13041282

1283+
payflow_note(pf, LOG_INFORM, "Failed at node #%u (%s): %s",
1284+
erridx, onion_wire_name(onionerr), msg);
13051285
handle_sendpay_failure_flow(pf, msg, erridx, onionerr);
13061286

13071287
return handle_sendpay_failure_payment(pf, msg, erridx, onionerr, raw);

plugins/renepay/pay_flow.c

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,23 @@ static void destroy_payment_flow(struct pay_flow *pf)
264264
list_del_from(&pf->payment->flows, &pf->list);
265265
}
266266

267+
/* Print out flow, and any information we already know */
268+
static const char *flow_path_annotated(const tal_t *ctx,
269+
const struct pay_flow *flow)
270+
{
271+
char *s = tal_strdup(ctx, "");
272+
for (size_t i = 0; i < tal_count(flow->path_scidds); i++) {
273+
tal_append_fmt(&s, "-%s%s->",
274+
type_to_string(tmpctx,
275+
struct short_channel_id_dir,
276+
&flow->path_scidds[i]),
277+
fmt_chan_extra_details(tmpctx,
278+
pay_plugin->chan_extra_map,
279+
&flow->path_scidds[i]));
280+
}
281+
return s;
282+
}
283+
267284
/* Calculates delays and converts to scids, and links to the payment.
268285
* Frees flows. */
269286
static void convert_and_attach_flows(struct payment *payment,
@@ -310,6 +327,15 @@ static void convert_and_attach_flows(struct payment *payment,
310327
/* Payment keeps a list of its flows. */
311328
list_add(&payment->flows, &pf->list);
312329

330+
/* First time they see this: annotate important points */
331+
payflow_note(pf, LOG_INFORM,
332+
"amount=%s prob=%.3lf fees=%s delay=%u path=%s",
333+
fmt_amount_msat(tmpctx, payflow_delivered(pf)),
334+
pf->success_prob,
335+
fmt_amount_msat(tmpctx, payflow_fee(pf)),
336+
pf->cltv_delays[0] - pf->cltv_delays[plen-1],
337+
flow_path_annotated(tmpctx, pf));
338+
313339
/* Increase totals for payment */
314340
amount_msat_accumulate(&payment->total_sent, pf->amounts[0]);
315341
amount_msat_accumulate(&payment->total_delivering,
@@ -551,6 +577,16 @@ struct amount_msat payflow_delivered(const struct pay_flow *flow)
551577
return flow->amounts[tal_count(flow->amounts)-1];
552578
}
553579

580+
/* How much does this flow pay in fees? */
581+
struct amount_msat payflow_fee(const struct pay_flow *pf)
582+
{
583+
struct amount_msat fee;
584+
585+
if (!amount_msat_sub(&fee, pf->amounts[0], payflow_delivered(pf)))
586+
abort();
587+
return fee;
588+
}
589+
554590
static struct pf_result *pf_resolve(struct pay_flow *pf,
555591
enum pay_flow_state oldstate,
556592
enum pay_flow_state newstate,

0 commit comments

Comments
 (0)