What's the best channel to this peer? * If @hint is set, channel must match that one. */
| 636 | /* What's the best channel to this peer? |
| 637 | * If @hint is set, channel must match that one. */ |
| 638 | static 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). */ |
no test coverage detected