| 749 | } |
| 750 | |
| 751 | static void add_localchan(struct gossmap_localmods *mods, |
| 752 | const struct node_id *self, |
| 753 | const struct node_id *peer, |
| 754 | const struct short_channel_id_dir *scidd, |
| 755 | struct amount_msat capacity_msat, |
| 756 | struct amount_msat htlcmin, |
| 757 | struct amount_msat htlcmax, |
| 758 | struct amount_msat spendable, |
| 759 | struct amount_msat max_total_htlc, |
| 760 | struct amount_msat fee_base, |
| 761 | u32 fee_proportional, |
| 762 | u16 cltv_delta, |
| 763 | bool enabled, |
| 764 | const char *buf, |
| 765 | const jsmntok_t *chantok, |
| 766 | struct getroutes_info *info) |
| 767 | { |
| 768 | u32 feerate; |
| 769 | const char *opener; |
| 770 | const char *err; |
| 771 | |
| 772 | /* We get called twice, once in each direction: only create once. */ |
| 773 | if (!layer_find_local_channel(info->local_layer, scidd->scid)) |
| 774 | layer_add_local_channel(info->local_layer, |
| 775 | self, peer, scidd->scid, capacity_msat); |
| 776 | layer_add_update_channel(info->local_layer, scidd, |
| 777 | &enabled, |
| 778 | &htlcmin, &htlcmax, |
| 779 | &fee_base, &fee_proportional, &cltv_delta); |
| 780 | |
| 781 | /* We also need to know the feerate and opener, so we can calculate per-HTLC cost */ |
| 782 | feerate = 0; /* Can be unset on unconfirmed channels */ |
| 783 | err = json_scan(tmpctx, buf, chantok, |
| 784 | "{feerate?:{perkw:%},opener:%}", |
| 785 | JSON_SCAN(json_to_u32, &feerate), |
| 786 | JSON_SCAN_TAL(tmpctx, json_strdup, &opener)); |
| 787 | if (err) { |
| 788 | plugin_log(info->cmd->plugin, LOG_BROKEN, |
| 789 | "Cannot scan channel for feerate and owner (%s): %.*s", |
| 790 | err, json_tok_full_len(chantok), json_tok_full(buf, chantok)); |
| 791 | return; |
| 792 | } |
| 793 | |
| 794 | if (feerate != 0 && streq(opener, "local")) { |
| 795 | /* BOLT #3: |
| 796 | * The base fee for a commitment transaction: |
| 797 | * - MUST be calculated to match: |
| 798 | * 1. Start with `weight` = 724 (1124 if `option_anchors` applies). |
| 799 | * 2. For each committed HTLC, if that output is not trimmed as specified in |
| 800 | * [Trimmed Outputs](#trimmed-outputs), add 172 to `weight`. |
| 801 | * 3. Multiply `feerate_per_kw` by `weight`, divide by 1000 (rounding down). |
| 802 | */ |
| 803 | struct per_htlc_cost *phc |
| 804 | = tal(info->additional_costs, struct per_htlc_cost); |
| 805 | |
| 806 | phc->scidd = *scidd; |
| 807 | if (!amount_sat_to_msat(&phc->per_htlc_cost, |
| 808 | amount_tx_fee(feerate, 172))) { |
nothing calls this directly
no test coverage detected