@@ -120,39 +120,38 @@ static void chan_extra_can_send_(
120120
121121 chan_extra_adjust_half (ce ,!dir );
122122}
123+
123124void 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.*/
147147void 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.*/
201198static void chan_extra_set_liquidity_ (
@@ -220,18 +217,17 @@ static void chan_extra_set_liquidity_(
220217}
221218void 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.*/
237233static void chan_extra_sent_success_ (
@@ -263,18 +259,17 @@ static void chan_extra_sent_success_(
263259}
264260void 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. */
280275static void chan_extra_relax_ (
@@ -298,19 +293,18 @@ static void chan_extra_relax_(
298293}
299294void 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 */
335329struct chan_extra_half *
336330get_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 */
348341struct 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 ;
0 commit comments