Skip to content

Commit 7287ade

Browse files
committed
plugins/renepay: use struct short_channel_id_dir.
No changes, just use this convenience type for handing around, and arrays. Signed-off-by: Rusty Russell <[email protected]>
1 parent a6c2cd7 commit 7287ade

File tree

6 files changed

+88
-104
lines changed

6 files changed

+88
-104
lines changed

plugins/renepay/flow.c

Lines changed: 44 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -120,39 +120,38 @@ static void chan_extra_can_send_(
120120

121121
chan_extra_adjust_half(ce,!dir);
122122
}
123+
123124
void chan_extra_can_send(
124125
struct chan_extra_map *chan_extra_map,
125-
struct short_channel_id scid,
126-
int dir,
126+
const struct short_channel_id_dir *scidd,
127127
struct amount_msat x)
128128
{
129129
struct chan_extra *ce = chan_extra_map_get(chan_extra_map,
130-
scid);
130+
scidd->scid);
131131
if(!ce)
132132
{
133133
debug_err("%s unexpected chan_extra ce is NULL",
134134
__PRETTY_FUNCTION__);
135135
}
136-
if(!amount_msat_add(&x,x,ce->half[dir].htlc_total))
136+
if(!amount_msat_add(&x,x,ce->half[scidd->dir].htlc_total))
137137
{
138138
debug_err("%s (line %d) cannot add x=%s and htlc_total=%s",
139139
__PRETTY_FUNCTION__,__LINE__,
140140
type_to_string(tmpctx,struct amount_msat,&x),
141-
type_to_string(tmpctx,struct amount_msat,&ce->half[dir].htlc_total));
141+
type_to_string(tmpctx,struct amount_msat,&ce->half[scidd->dir].htlc_total));
142142
}
143-
chan_extra_can_send_(ce,dir,x);
143+
chan_extra_can_send_(ce,scidd->dir,x);
144144
}
145145

146146
/* Update the knowledge that this (channel,direction) cannot send x msat.*/
147147
void chan_extra_cannot_send(
148148
struct payment *p,
149149
struct chan_extra_map *chan_extra_map,
150-
struct short_channel_id scid,
151-
int dir,
150+
const struct short_channel_id_dir *scidd,
152151
struct amount_msat x)
153152
{
154153
struct chan_extra *ce = chan_extra_map_get(chan_extra_map,
155-
scid);
154+
scidd->scid);
156155
if(!ce)
157156
{
158157
debug_err("%s (line %d) unexpected chan_extra ce is NULL",
@@ -161,12 +160,12 @@ void chan_extra_cannot_send(
161160

162161
/* If a channel cannot send x it means that the upper bound for the
163162
* liquidity is MAX_L < x + htlc_total */
164-
if(!amount_msat_add(&x,x,ce->half[dir].htlc_total))
163+
if(!amount_msat_add(&x,x,ce->half[scidd->dir].htlc_total))
165164
{
166165
debug_err("%s (line %d) cannot add x=%s and htlc_total=%s",
167166
__PRETTY_FUNCTION__,__LINE__,
168167
type_to_string(tmpctx,struct amount_msat,&x),
169-
type_to_string(tmpctx,struct amount_msat,&ce->half[dir].htlc_total));
168+
type_to_string(tmpctx,struct amount_msat,&ce->half[scidd->dir].htlc_total));
170169
}
171170

172171
if(!amount_msat_sub(&x,x,AMOUNT_MSAT(1)))
@@ -179,23 +178,21 @@ void chan_extra_cannot_send(
179178
}
180179

181180
/* If we "knew" the capacity was at least this, we just showed we're wrong! */
182-
if (amount_msat_less_eq(x, ce->half[dir].known_min)) {
183-
debug_paynote(p, "Expected scid=%s, dir=%d min %s, but %s failed! Setting min to 0",
184-
type_to_string(tmpctx,struct short_channel_id,&scid),
185-
dir,
186-
type_to_string(tmpctx,struct amount_msat,&ce->half[dir].known_min),
181+
if (amount_msat_less_eq(x, ce->half[scidd->dir].known_min)) {
182+
debug_paynote(p, "Expected scid=%s min %s, but %s failed! Setting min to 0",
183+
type_to_string(tmpctx,struct short_channel_id_dir,scidd),
184+
type_to_string(tmpctx,struct amount_msat,&ce->half[scidd->dir].known_min),
187185
type_to_string(tmpctx,struct amount_msat,&x));
188-
ce->half[dir].known_min = AMOUNT_MSAT(0);
186+
ce->half[scidd->dir].known_min = AMOUNT_MSAT(0);
189187
}
190-
ce->half[dir].known_max = amount_msat_min(ce->half[dir].known_max,x);
188+
ce->half[scidd->dir].known_max = amount_msat_min(ce->half[scidd->dir].known_max,x);
191189

192-
debug_paynote(p,"Update chan knowledge scid=%s, dir=%d: [%s,%s]",
193-
type_to_string(tmpctx,struct short_channel_id,&scid),
194-
dir,
195-
type_to_string(tmpctx,struct amount_msat,&ce->half[dir].known_min),
196-
type_to_string(tmpctx,struct amount_msat,&ce->half[dir].known_max));
190+
debug_paynote(p,"Update chan knowledge scid=%s: [%s,%s]",
191+
type_to_string(tmpctx,struct short_channel_id_dir,scidd),
192+
type_to_string(tmpctx,struct amount_msat,&ce->half[scidd->dir].known_min),
193+
type_to_string(tmpctx,struct amount_msat,&ce->half[scidd->dir].known_max));
197194

198-
chan_extra_adjust_half(ce,!dir);
195+
chan_extra_adjust_half(ce,!scidd->dir);
199196
}
200197
/* Update the knowledge that this (channel,direction) has liquidity x.*/
201198
static void chan_extra_set_liquidity_(
@@ -220,18 +217,17 @@ static void chan_extra_set_liquidity_(
220217
}
221218
void chan_extra_set_liquidity(
222219
struct chan_extra_map *chan_extra_map,
223-
struct short_channel_id scid,
224-
int dir,
220+
const struct short_channel_id_dir *scidd,
225221
struct amount_msat x)
226222
{
227223
struct chan_extra *ce = chan_extra_map_get(chan_extra_map,
228-
scid);
224+
scidd->scid);
229225
if(!ce)
230226
{
231227
debug_err("%s unexpected chan_extra ce is NULL",
232228
__PRETTY_FUNCTION__);
233229
}
234-
chan_extra_set_liquidity_(ce,dir,x);
230+
chan_extra_set_liquidity_(ce,scidd->dir,x);
235231
}
236232
/* Update the knowledge that this (channel,direction) has sent x msat.*/
237233
static void chan_extra_sent_success_(
@@ -263,18 +259,17 @@ static void chan_extra_sent_success_(
263259
}
264260
void chan_extra_sent_success(
265261
struct chan_extra_map *chan_extra_map,
266-
struct short_channel_id scid,
267-
int dir,
262+
const struct short_channel_id_dir *scidd,
268263
struct amount_msat x)
269264
{
270265
struct chan_extra *ce = chan_extra_map_get(chan_extra_map,
271-
scid);
266+
scidd->scid);
272267
if(!ce)
273268
{
274269
debug_err("%s unexpected chan_extra ce is NULL",
275270
__PRETTY_FUNCTION__);
276271
}
277-
chan_extra_sent_success_(ce,dir,x);
272+
chan_extra_sent_success_(ce,scidd->dir,x);
278273
}
279274
/* Forget a bit about this (channel,direction) state. */
280275
static void chan_extra_relax_(
@@ -298,19 +293,18 @@ static void chan_extra_relax_(
298293
}
299294
void chan_extra_relax(
300295
struct chan_extra_map *chan_extra_map,
301-
struct short_channel_id scid,
302-
int dir,
296+
const struct short_channel_id_dir *scidd,
303297
struct amount_msat x,
304298
struct amount_msat y)
305299
{
306300
struct chan_extra *ce = chan_extra_map_get(chan_extra_map,
307-
scid);
301+
scidd->scid);
308302
if(!ce)
309303
{
310304
debug_err("%s unexpected chan_extra ce is NULL",
311305
__PRETTY_FUNCTION__);
312306
}
313-
chan_extra_relax_(ce,dir,x,y);
307+
chan_extra_relax_(ce,scidd->dir,x,y);
314308
}
315309

316310
/* Forget the channel information by a fraction of the capacity. */
@@ -334,15 +328,14 @@ void chan_extra_relax_fraction(
334328
/* Returns either NULL, or an entry from the hash */
335329
struct chan_extra_half *
336330
get_chan_extra_half_by_scid(struct chan_extra_map *chan_extra_map,
337-
const struct short_channel_id scid,
338-
int dir)
331+
const struct short_channel_id_dir *scidd)
339332
{
340333
struct chan_extra *ce;
341334

342-
ce = chan_extra_map_get(chan_extra_map, scid);
335+
ce = chan_extra_map_get(chan_extra_map, scidd->scid);
343336
if (!ce)
344337
return NULL;
345-
return &ce->half[dir];
338+
return &ce->half[scidd->dir];
346339
}
347340
/* Helper if we have a gossmap_chan */
348341
struct chan_extra_half *
@@ -351,9 +344,11 @@ get_chan_extra_half_by_chan(const struct gossmap *gossmap,
351344
const struct gossmap_chan *chan,
352345
int dir)
353346
{
354-
return get_chan_extra_half_by_scid(chan_extra_map,
355-
gossmap_chan_scid(gossmap, chan),
356-
dir);
347+
struct short_channel_id_dir scidd;
348+
349+
scidd.scid = gossmap_chan_scid(gossmap, chan);
350+
scidd.dir = dir;
351+
return get_chan_extra_half_by_scid(chan_extra_map, &scidd);
357352
}
358353

359354

@@ -371,9 +366,12 @@ get_chan_extra_half_by_chan_verify(
371366
int dir)
372367
{
373368

374-
const struct short_channel_id scid = gossmap_chan_scid(gossmap,chan);
369+
struct short_channel_id_dir scidd;
370+
371+
scidd.scid = gossmap_chan_scid(gossmap,chan);
372+
scidd.dir = dir;
375373
struct chan_extra_half *h = get_chan_extra_half_by_scid(
376-
chan_extra_map,scid,dir);
374+
chan_extra_map,&scidd);
377375
if (!h) {
378376
struct amount_sat cap;
379377
struct amount_msat cap_msat;
@@ -386,7 +384,7 @@ get_chan_extra_half_by_chan_verify(
386384
__PRETTY_FUNCTION__,
387385
__LINE__);
388386
}
389-
h = & new_chan_extra(chan_extra_map,scid,cap_msat)->half[dir];
387+
h = & new_chan_extra(chan_extra_map,scidd.scid,cap_msat)->half[scidd.dir];
390388

391389
}
392390
return h;

plugins/renepay/flow.h

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -148,33 +148,28 @@ static inline struct amount_msat amount_msat_max(
148148

149149
/* Update the knowledge that this (channel,direction) can send x msat.*/
150150
void chan_extra_can_send(struct chan_extra_map *chan_extra_map,
151-
struct short_channel_id scid,
152-
int dir,
151+
const struct short_channel_id_dir *scidd,
153152
struct amount_msat x);
154153

155154
/* Update the knowledge that this (channel,direction) cannot send x msat.*/
156155
void chan_extra_cannot_send(struct payment* p,
157156
struct chan_extra_map *chan_extra_map,
158-
struct short_channel_id scid,
159-
int dir,
157+
const struct short_channel_id_dir *scidd,
160158
struct amount_msat x);
161159

162160
/* Update the knowledge that this (channel,direction) has liquidity x.*/
163161
void chan_extra_set_liquidity(struct chan_extra_map *chan_extra_map,
164-
struct short_channel_id scid,
165-
int dir,
162+
const struct short_channel_id_dir *scidd,
166163
struct amount_msat x);
167164

168165
/* Update the knowledge that this (channel,direction) has sent x msat.*/
169166
void chan_extra_sent_success(struct chan_extra_map *chan_extra_map,
170-
struct short_channel_id scid,
171-
int dir,
167+
const struct short_channel_id_dir *scidd,
172168
struct amount_msat x);
173169

174170
/* Forget a bit about this (channel,direction) state. */
175171
void chan_extra_relax(struct chan_extra_map *chan_extra_map,
176-
struct short_channel_id scid,
177-
int dir,
172+
const struct short_channel_id_dir *scidd,
178173
struct amount_msat down,
179174
struct amount_msat up);
180175

@@ -186,8 +181,7 @@ void chan_extra_relax_fraction(
186181

187182
/* Returns either NULL, or an entry from the hash */
188183
struct chan_extra_half *get_chan_extra_half_by_scid(struct chan_extra_map *chan_extra_map,
189-
const struct short_channel_id scid,
190-
int dir);
184+
const struct short_channel_id_dir *scidd);
191185
/* If the channel is not registered, then a new entry is created. scid must be
192186
* present in the gossmap. */
193187
struct chan_extra_half *

plugins/renepay/pay.c

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,10 @@ static struct pf_result *handle_unhandleable_error(struct pay_flow *pf,
144144
/* Assume it's not the destination */
145145
n = pseudorand(n-1);
146146

147-
tal_arr_expand(&pf->payment->disabled, pf->path_scids[n]);
147+
tal_arr_expand(&pf->payment->disabled, pf->path_scidds[n].scid);
148148
debug_paynote(pf->payment, "... eliminated %s",
149149
type_to_string(tmpctx, struct short_channel_id,
150-
&pf->path_scids[n]));
150+
&pf->path_scidds[n].scid));
151151

152152
return pay_flow_failed(pf);
153153
}
@@ -317,7 +317,7 @@ static struct command_result *flow_sendpay_failed(struct command *cmd,
317317

318318
/* There is no new knowledge from this kind of failure.
319319
* We just disable this scid. */
320-
tal_arr_expand(&payment->disabled, pf->path_scids[0]);
320+
tal_arr_expand(&payment->disabled, pf->path_scidds[0].scid);
321321

322322
pay_flow_failed(pf);
323323
return command_still_pending(cmd);
@@ -350,11 +350,11 @@ static void sendpay_new_flows(struct payment *p)
350350
json_add_node_id(req->js, "id",
351351
&pf->path_nodes[j]);
352352
json_add_short_channel_id(req->js, "channel",
353-
&pf->path_scids[j]);
353+
&pf->path_scidds[j].scid);
354354
json_add_amount_msat(req->js, "amount_msat",
355355
pf->amounts[j]);
356356
json_add_num(req->js, "direction",
357-
pf->path_dirs[j]);
357+
pf->path_scidds[j].dir);
358358
json_add_u32(req->js, "delay",
359359
pf->cltv_delays[j]);
360360
json_add_string(req->js,"style","tlv");
@@ -1068,7 +1068,7 @@ static struct pf_result *handle_sendpay_failure_payment(struct pay_flow *pf STEA
10681068
debug_assert(p);
10691069

10701070
/* Final node is usually a hard failure */
1071-
if (erridx == tal_count(pf->path_scids)) {
1071+
if (erridx == tal_count(pf->path_scidds)) {
10721072
debug_paynote(p,
10731073
"onion error %s from final node #%u: %s",
10741074
onion_wire_name(onionerr),
@@ -1083,7 +1083,7 @@ static struct pf_result *handle_sendpay_failure_payment(struct pay_flow *pf STEA
10831083
return pay_flow_failed_final(pf, PAY_DESTINATION_PERM_FAIL, message);
10841084
}
10851085

1086-
errscid = pf->path_scids[erridx];
1086+
errscid = pf->path_scidds[erridx].scid;
10871087
debug_paynote(p,
10881088
"onion error %s from node #%u %s: %s",
10891089
onion_wire_name(onionerr),
@@ -1170,9 +1170,9 @@ static void handle_sendpay_failure_flow(struct pay_flow *pf,
11701170
"%s",
11711171
onion_wire_name(onionerr),
11721172
erridx,
1173-
erridx == tal_count(pf->path_scids)
1173+
erridx == tal_count(pf->path_scidds)
11741174
? "final"
1175-
: type_to_string(tmpctx, struct short_channel_id, &pf->path_scids[erridx]),
1175+
: type_to_string(tmpctx, struct short_channel_id_dir, &pf->path_scidds[erridx]),
11761176
msg);
11771177

11781178
/* we know that all channels before erridx where able to commit to this payment */
@@ -1183,14 +1183,13 @@ static void handle_sendpay_failure_flow(struct pay_flow *pf,
11831183

11841184
/* Insufficient funds (not from final, that's weird!) */
11851185
if((enum onion_wire)onionerr == WIRE_TEMPORARY_CHANNEL_FAILURE
1186-
&& erridx < tal_count(pf->path_scids))
1186+
&& erridx < tal_count(pf->path_scidds))
11871187
{
11881188
plugin_log(pay_plugin->plugin,LOG_DBG,
11891189
"sendpay_failure says insufficient funds!");
11901190

11911191
chan_extra_cannot_send(p,pay_plugin->chan_extra_map,
1192-
pf->path_scids[erridx],
1193-
pf->path_dirs[erridx],
1192+
&pf->path_scidds[erridx],
11941193
/* This channel can't send all that was
11951194
* commited in HTLCs.
11961195
* Had we removed the commited amount then
@@ -1300,10 +1299,10 @@ static struct pf_result *sendpay_failure(struct pay_flow *pf,
13001299
return handle_unhandleable_error(pf, err);
13011300

13021301
/* Answer must be sane: but note, erridx can be final node! */
1303-
if (erridx > tal_count(pf->path_scids)) {
1302+
if (erridx > tal_count(pf->path_scidds)) {
13041303
plugin_err(pay_plugin->plugin,
13051304
"Erring channel %u/%zu in path %s",
1306-
erridx, tal_count(pf->path_scids),
1305+
erridx, tal_count(pf->path_scidds),
13071306
flow_path_to_str(tmpctx, pf));
13081307
}
13091308

0 commit comments

Comments
 (0)