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

Function chan_extra_relax

plugins/renepay/chan_extra.c:452–485  ·  view source on GitHub ↗

Forget a bit about this (channel,direction) state. */

Source from the content-addressed store, hash-verified

450
451/* Forget a bit about this (channel,direction) state. */
452static enum renepay_errorcode chan_extra_relax(struct chan_extra *ce, int dir,
453 struct amount_msat down,
454 struct amount_msat up)
455{
456 assert(ce);
457 assert(dir == 0 || dir == 1);
458 struct amount_msat new_a, new_b;
459 enum renepay_errorcode err;
460
461 if (!amount_msat_sub(&new_a, ce->half[dir].known_min, down))
462 new_a = AMOUNT_MSAT(0);
463 if (!amount_msat_add(&new_b, ce->half[dir].known_max, up))
464 new_b = ce->capacity;
465 new_b = amount_msat_min(new_b, ce->capacity);
466
467 // in case we fail, let's remember the original state
468 struct amount_msat known_min, known_max;
469 known_min = ce->half[dir].known_min;
470 known_max = ce->half[dir].known_max;
471
472 ce->half[dir].known_min = new_a;
473 ce->half[dir].known_max = new_b;
474
475 err = chan_extra_adjust_half(ce, !dir);
476 if (err != RENEPAY_NOERROR)
477 goto restore_and_fail;
478 return err;
479
480// we fail, thus restore the original state
481restore_and_fail:
482 ce->half[dir].known_min = known_min;
483 ce->half[dir].known_max = known_max;
484 return err;
485}
486
487/* Forget the channel information by a fraction of the capacity. */
488enum renepay_errorcode chan_extra_relax_fraction(struct chan_extra *ce,

Callers 1

Calls 4

amount_msat_subFunction · 0.85
amount_msat_addFunction · 0.85
amount_msat_minFunction · 0.85
chan_extra_adjust_halfFunction · 0.85

Tested by

no test coverage detected