Skip to content

Commit 574716d

Browse files
committed
plugins/renepay: convenience routing to log when we disable a chan.
Signed-off-by: Rusty Russell <[email protected]>
1 parent 00e9af5 commit 574716d

File tree

5 files changed

+73
-47
lines changed

5 files changed

+73
-47
lines changed

plugins/renepay/pay.c

Lines changed: 16 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,8 @@ static struct pf_result *handle_unhandleable_error(struct pay_flow *pf,
140140
/* Assume it's not the destination */
141141
n = pseudorand(n-1);
142142

143-
tal_arr_expand(&pf->payment->disabled, 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));
143+
payflow_disable_chan(pf, pf->path_scidds[n].scid,
144+
LOG_INFORM, "randomly chosen");
147145

148146
return pay_flow_failed(pf);
149147
}
@@ -175,14 +173,11 @@ static struct command_result *addgossip_failure(struct command *cmd,
175173
struct addgossip *adg)
176174

177175
{
178-
struct payment * payment = adg->pf->payment;
179176
plugin_log(pay_plugin->plugin,LOG_DBG,"calling %s",__PRETTY_FUNCTION__);
180177

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);
185-
tal_arr_expand(&payment->disabled, adg->scid);
178+
payflow_disable_chan(adg->pf, adg->scid,
179+
LOG_INFORM, "addgossip failed (%.*s)",
180+
err->end - err->start, buf + err->start);
186181

187182
return addgossip_done(cmd, buf, err, adg);
188183
}
@@ -307,12 +302,11 @@ static struct command_result *flow_sendpay_failed(struct command *cmd,
307302
plugin_err(cmd->plugin, "Strange error from sendpay: %.*s",
308303
json_tok_full_len(err), json_tok_full(buf, err));
309304

310-
payflow_note(pf, LOG_INFORM,
311-
"sendpay didn't like first hop, eliminated: %s", msg);
312-
313305
/* There is no new knowledge from this kind of failure.
314306
* We just disable this scid. */
315-
tal_arr_expand(&payment->disabled, pf->path_scidds[0].scid);
307+
payflow_disable_chan(pf, pf->path_scidds[0].scid,
308+
LOG_INFORM,
309+
"sendpay didn't like first hop: %s", msg);
316310

317311
pay_flow_failed(pf);
318312
return command_still_pending(cmd);
@@ -1075,13 +1069,6 @@ static struct pf_result *handle_sendpay_failure_payment(struct pay_flow *pf STEA
10751069
}
10761070

10771071
errscid = pf->path_scidds[erridx].scid;
1078-
debug_paynote(p,
1079-
"onion error %s from node #%u %s: %s",
1080-
onion_wire_name(onionerr),
1081-
erridx,
1082-
type_to_string(tmpctx, struct short_channel_id, &errscid),
1083-
message);
1084-
10851072
switch (onionerr) {
10861073
/* These definitely mean eliminate channel */
10871074
case WIRE_PERMANENT_CHANNEL_FAILURE:
@@ -1101,9 +1088,9 @@ static struct pf_result *handle_sendpay_failure_payment(struct pay_flow *pf STEA
11011088
case WIRE_INVALID_ONION_PAYLOAD:
11021089
case WIRE_INVALID_ONION_BLINDING:
11031090
case WIRE_EXPIRY_TOO_FAR:
1104-
debug_paynote(p, "we're removing scid %s",
1105-
type_to_string(tmpctx,struct short_channel_id,&errscid));
1106-
tal_arr_expand(&p->disabled, errscid);
1091+
payflow_disable_chan(pf, errscid, LOG_UNUSUAL,
1092+
"%s",
1093+
onion_wire_name(onionerr));
11071094
return pay_flow_failed(pf);
11081095

11091096
/* These can be fixed (maybe) by applying the included channel_update */
@@ -1118,9 +1105,8 @@ static struct pf_result *handle_sendpay_failure_payment(struct pay_flow *pf STEA
11181105
if (update)
11191106
return submit_update(pf, update, errscid);
11201107

1121-
debug_paynote(p, "missing an update, so we're removing scid %s",
1122-
type_to_string(tmpctx,struct short_channel_id,&errscid));
1123-
tal_arr_expand(&p->disabled, errscid);
1108+
payflow_disable_chan(pf, errscid,
1109+
LOG_UNUSUAL, "missing channel_update");
11241110
return pay_flow_failed(pf);
11251111

11261112
case WIRE_TEMPORARY_CHANNEL_FAILURE:
@@ -1140,10 +1126,9 @@ static struct pf_result *handle_sendpay_failure_payment(struct pay_flow *pf STEA
11401126
break;
11411127
}
11421128

1143-
debug_paynote(p,"unkown onion error code %u, removing scid %s",
1144-
onionerr,
1145-
type_to_string(tmpctx,struct short_channel_id,&errscid));
1146-
tal_arr_expand(&p->disabled, errscid);
1129+
payflow_disable_chan(pf, errscid,
1130+
LOG_UNUSUAL, "unexpected error code %u",
1131+
onionerr);
11471132
return pay_flow_failed(pf);
11481133
}
11491134

plugins/renepay/pay_flow.c

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -404,12 +404,7 @@ static bool disable_htlc_violations_oneflow(struct payment *p,
404404
continue;
405405

406406
scid = gossmap_chan_scid(gossmap, flow->path[i]);
407-
debug_paynote(p, "...disabling channel %s: %s",
408-
type_to_string(tmpctx, struct short_channel_id, &scid),
409-
reason);
410-
411-
/* Add this for future searches for this payment. */
412-
tal_arr_expand(&p->disabled, scid);
407+
payment_disable_chan(p, scid, LOG_INFORM, "%s", reason);
413408
/* Add to existing bitmap */
414409
bitmap_set_bit(disabled,
415410
gossmap_chan_idx(gossmap, flow->path[i]));
@@ -446,7 +441,7 @@ const char *add_payflows(const tal_t *ctx,
446441
bitmap *disabled;
447442
const struct gossmap_node *src, *dst;
448443

449-
disabled = make_disabled_bitmap(tmpctx, pay_plugin->gossmap, p->disabled);
444+
disabled = make_disabled_bitmap(tmpctx, pay_plugin->gossmap, p->disabled_scids);
450445
src = gossmap_find_node(pay_plugin->gossmap, &pay_plugin->my_id);
451446
if (!src) {
452447
debug_paynote(p, "We don't have any channels?");

plugins/renepay/payment.c

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,48 @@ struct payment *payment_new(const tal_t *ctx,
6565
p->groupid=1;
6666

6767
p->local_gossmods = gossmap_localmods_new(p);
68-
p->disabled = tal_arr(p,struct short_channel_id,0);
68+
p->disabled_scids = tal_arr(p,struct short_channel_id,0);
6969
p->next_partid=1;
7070
p->progress_deadline = NULL;
7171

7272
return p;
7373
}
7474

75+
/* Disable this scid for this payment, and tell me why! */
76+
void payflow_disable_chan(struct pay_flow *pf,
77+
struct short_channel_id scid,
78+
enum log_level lvl,
79+
const char *fmt, ...)
80+
{
81+
va_list ap;
82+
const char *str;
83+
84+
va_start(ap, fmt);
85+
str = tal_vfmt(tmpctx, fmt, ap);
86+
va_end(ap);
87+
payflow_note(pf, lvl, "disabling %s: %s",
88+
type_to_string(tmpctx, struct short_channel_id, &scid),
89+
str);
90+
tal_arr_expand(&pf->payment->disabled_scids, scid);
91+
}
92+
93+
void payment_disable_chan(struct payment *p,
94+
struct short_channel_id scid,
95+
enum log_level lvl,
96+
const char *fmt, ...)
97+
{
98+
va_list ap;
99+
const char *str;
100+
101+
va_start(ap, fmt);
102+
str = tal_vfmt(tmpctx, fmt, ap);
103+
va_end(ap);
104+
payment_note(p, lvl, "disabling %s: %s",
105+
type_to_string(tmpctx, struct short_channel_id, &scid),
106+
str);
107+
tal_arr_expand(&p->disabled_scids, scid);
108+
}
109+
75110
struct amount_msat payment_sent(const struct payment *p)
76111
{
77112
return p->total_sent;

plugins/renepay/payment.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ struct payment {
3030
struct gossmap_localmods *local_gossmods;
3131

3232
/* Channels we decided to disable for various reasons. */
33-
struct short_channel_id *disabled;
33+
struct short_channel_id *disabled_scids;
3434

3535
/* Used in get_payflows to set ids to each pay_flow. */
3636
u64 next_partid;
@@ -157,6 +157,18 @@ void payment_reconsider(struct payment *p);
157157

158158
u64 payment_parts(const struct payment *payment);
159159

160+
/* Disable this scid for this payment, and tell me why! */
161+
void payflow_disable_chan(struct pay_flow *pf,
162+
struct short_channel_id scid,
163+
enum log_level lvl,
164+
const char *fmt, ...);
165+
166+
/* Sometimes, disabling chan is independent of a flow. */
167+
void payment_disable_chan(struct payment *p,
168+
struct short_channel_id scid,
169+
enum log_level lvl,
170+
const char *fmt, ...);
171+
160172
struct command_result *payment_fail(
161173
struct payment *payment,
162174
enum jsonrpc_errcode code,

plugins/renepay/uncertainty_network.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -252,12 +252,8 @@ bool uncertainty_network_update_from_listpeerchannels(
252252
goto malformed;
253253

254254
if (!connected) {
255-
debug_paynote(p, "local channel %s disabled:"
256-
" peer disconnected",
257-
type_to_string(tmpctx,
258-
struct short_channel_id,
259-
&scidd.scid));
260-
tal_arr_expand(&p->disabled, scidd.scid);
255+
payment_disable_chan(p, scidd.scid, LOG_DBG,
256+
"peer disconnected");
261257
continue;
262258
}
263259

@@ -289,7 +285,10 @@ bool uncertainty_network_update_from_listpeerchannels(
289285
/* Don't report opening/closing channels */
290286
if (!json_tok_streq(buf, statetok, "CHANNELD_NORMAL")
291287
&& !json_tok_streq(buf, statetok, "CHANNELD_AWAITING_SPLICE")) {
292-
tal_arr_expand(&p->disabled, scidd.scid);
288+
payment_disable_chan(p, scidd.scid, LOG_DBG,
289+
"channel in state %.*s",
290+
statetok->end - statetok->start,
291+
buf + statetok->start);
293292
continue;
294293
}
295294

0 commit comments

Comments
 (0)