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

Function best_channel

lightningd/peer_htlcs.c:775–808  ·  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

773/* What's the best channel to this peer?
774 * If @hint is set, channel must match that one. */
775struct channel *best_channel(struct lightningd *ld,
776 const struct peer *next_peer,
777 struct amount_msat amt_to_forward,
778 const struct channel *hint)
779{
780 struct amount_msat best_spendable = AMOUNT_MSAT(0);
781 struct channel *channel, *best = cast_const(struct channel *, hint);
782
783 /* Seek channel with largest spendable! */
784 list_for_each(&next_peer->channels, channel, list) {
785 struct amount_msat spendable;
786 if (!channel_state_can_add_htlc(channel->state))
787 continue;
788 spendable = channel_amount_spendable(channel);
789 if (!amount_msat_greater(spendable, best_spendable))
790 continue;
791
792 /* Don't override if fees differ... */
793 if (hint) {
794 if (hint->feerate_base != channel->feerate_base
795 || hint->feerate_ppm != channel->feerate_ppm)
796 continue;
797 }
798
799 /* Or if this would be below min for channel! */
800 if (amount_msat_less(amt_to_forward,
801 channel->channel_info.their_config.htlc_minimum))
802 continue;
803
804 best = channel;
805 best_spendable = spendable;
806 }
807 return best;
808}
809
810/* forward_to is where we're actually sending it (or NULL), and
811 * forward_scid is where they asked to send it (or NULL). */

Callers 2

json_injectpaymentonionFunction · 0.85
calc_forwarding_channelFunction · 0.85

Calls 4

channel_amount_spendableFunction · 0.85
amount_msat_greaterFunction · 0.85
amount_msat_lessFunction · 0.50

Tested by

no test coverage detected