| 2584 | retry_step_cb); |
| 2585 | |
| 2586 | static struct command_result * |
| 2587 | local_channel_hints_listpeerchannels(struct command *cmd, |
| 2588 | const char *method, |
| 2589 | const char *buffer, |
| 2590 | const jsmntok_t *toks, struct payment *p) |
| 2591 | { |
| 2592 | struct listpeers_channel **chans; |
| 2593 | struct amount_msat capacity; |
| 2594 | |
| 2595 | chans = json_to_listpeers_channels(tmpctx, buffer, toks); |
| 2596 | |
| 2597 | for (size_t i = 0; i < tal_count(chans); i++) { |
| 2598 | bool enabled; |
| 2599 | u16 htlc_budget; |
| 2600 | |
| 2601 | /* Filter out local channels if they are |
| 2602 | * either a) disconnected, or b) not in normal |
| 2603 | * state. */ |
| 2604 | enabled = chans[i]->connected |
| 2605 | && (streq(chans[i]->state, "CHANNELD_NORMAL") |
| 2606 | || streq(chans[i]->state, "CHANNELD_AWAITING_SPLICE")); |
| 2607 | |
| 2608 | /* Take the configured number of max_htlcs and |
| 2609 | * subtract any HTLCs that might already be added to |
| 2610 | * the channel. This is a best effort estimate and |
| 2611 | * mostly considers stuck htlcs, concurrent payments |
| 2612 | * may throw us off a bit. */ |
| 2613 | if (chans[i]->num_htlcs > chans[i]->max_accepted_htlcs) |
| 2614 | htlc_budget = 0; |
| 2615 | else |
| 2616 | htlc_budget = chans[i]->max_accepted_htlcs - chans[i]->num_htlcs; |
| 2617 | |
| 2618 | capacity = chans[i]->total_msat; |
| 2619 | |
| 2620 | /* If we have both a scid and a local alias we want to |
| 2621 | * use the scid, and mark the alias as |
| 2622 | * unusable. Otherwise `getroute` might return the |
| 2623 | * alias, which we resolve correctly, but our |
| 2624 | * channel_hints would be off after updates, since |
| 2625 | * we'd only ever update one of the aliases. Causing |
| 2626 | * the other to be considered usable. |
| 2627 | */ |
| 2628 | if (chans[i]->scid != NULL) { |
| 2629 | channel_hints_update( |
| 2630 | p, *chans[i]->scid, chans[i]->direction, enabled, |
| 2631 | true, &chans[i]->spendable_msat, |
| 2632 | capacity, &htlc_budget); |
| 2633 | if (chans[i]->alias[LOCAL] != NULL) |
| 2634 | channel_hints_update(p, *chans[i]->alias[LOCAL], |
| 2635 | chans[i]->direction, |
| 2636 | false /* not enabled */, |
| 2637 | true, &AMOUNT_MSAT(0), |
| 2638 | capacity, |
| 2639 | &htlc_budget); |
| 2640 | } else { |
| 2641 | channel_hints_update( |
| 2642 | p, *chans[i]->alias[LOCAL], chans[i]->direction, |
| 2643 | enabled, true, &chans[i]->spendable_msat, |
nothing calls this directly
no test coverage detected