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

Function best_channel

lightningd/peer_htlcs.c:638–671  ·  view source on GitHub ↗

What's the best channel to this peer? * If @hint is set, channel must match that one. */

Source from the content-addressed store, hash-verified

636/* What's the best channel to this peer?
637 * If @hint is set, channel must match that one. */
638static struct channel *best_channel(struct lightningd *ld,
639 const struct peer *next_peer,
640 struct amount_msat amt_to_forward,
641 struct channel *hint)
642{
643 struct amount_msat best_spendable = AMOUNT_MSAT(0);
644 struct channel *channel, *best = hint;
645
646 /* Seek channel with largest spendable! */
647 list_for_each(&next_peer->channels, channel, list) {
648 struct amount_msat spendable;
649 if (!channel_can_add_htlc(channel))
650 continue;
651 spendable = channel_amount_spendable(channel);
652 if (!amount_msat_greater(spendable, best_spendable))
653 continue;
654
655 /* Don't override if fees differ... */
656 if (hint) {
657 if (hint->feerate_base != channel->feerate_base
658 || hint->feerate_ppm != channel->feerate_ppm)
659 continue;
660 }
661
662 /* Or if this would be below min for channel! */
663 if (amount_msat_less(amt_to_forward,
664 channel->channel_info.their_config.htlc_minimum))
665 continue;
666
667 best = channel;
668 best_spendable = spendable;
669 }
670 return best;
671}
672
673/* forward_to is where we're actually sending it (or NULL), and
674 * forward_scid is where they asked to send it (or NULL). */

Callers 1

calc_forwarding_channelFunction · 0.85

Calls 4

channel_can_add_htlcFunction · 0.85
channel_amount_spendableFunction · 0.85
amount_msat_greaterFunction · 0.85
amount_msat_lessFunction · 0.85

Tested by

no test coverage detected