MCPcopy Create free account
hub / github.com/ElementsProject/lightning / chan_extra_cannot_send

Function chan_extra_cannot_send

plugins/renepay/chan_extra.c:305–347  ·  view source on GitHub ↗

Update the knowledge that this (channel,direction) cannot send.*/

Source from the content-addressed store, hash-verified

303
304/* Update the knowledge that this (channel,direction) cannot send.*/
305enum renepay_errorcode
306chan_extra_cannot_send(struct chan_extra_map *chan_extra_map,
307 const struct short_channel_id_dir *scidd)
308{
309 assert(scidd);
310 assert(chan_extra_map);
311 struct amount_msat x;
312 enum renepay_errorcode err;
313 struct chan_extra *ce = chan_extra_map_get(chan_extra_map, scidd->scid);
314 if (!ce)
315 return RENEPAY_CHANNEL_NOT_FOUND;
316
317 /* Note: sent is already included in htlc_total! */
318 if (!amount_msat_sub(&x, ce->half[scidd->dir].htlc_total,
319 AMOUNT_MSAT(1)))
320 return RENEPAY_AMOUNT_OVERFLOW;
321
322 struct amount_msat known_min, known_max;
323 // in case we fail, let's remember the original state
324 known_min = ce->half[scidd->dir].known_min;
325 known_max = ce->half[scidd->dir].known_max;
326
327 /* If we "knew" the capacity was at least this, we just showed we're
328 * wrong! */
329 if (amount_msat_less(x, ce->half[scidd->dir].known_min)) {
330 /* Skip to half of x, since we don't know (rounds down) */
331 ce->half[scidd->dir].known_min = amount_msat_div(x, 2);
332 }
333
334 ce->half[scidd->dir].known_max =
335 amount_msat_min(ce->half[scidd->dir].known_max, x);
336
337 err = chan_extra_adjust_half(ce, !scidd->dir);
338 if (err != RENEPAY_NOERROR)
339 goto restore_and_fail;
340 return err;
341
342restore_and_fail:
343 // we fail, thus restore the original state
344 ce->half[scidd->dir].known_min = known_min;
345 ce->half[scidd->dir].known_max = known_max;
346 return err;
347}
348
349/* Update the knowledge that this (channel,direction) has liquidity x.*/
350// FIXME for being this low level API, I thinkg it's too much to have verbose

Callers 1

Calls 5

amount_msat_subFunction · 0.85
amount_msat_divFunction · 0.85
amount_msat_minFunction · 0.85
chan_extra_adjust_halfFunction · 0.85
amount_msat_lessFunction · 0.50

Tested by

no test coverage detected