| 1197 | */ |
| 1198 | |
| 1199 | static struct command_result *channelfilter_cb(struct payment *payment) |
| 1200 | { |
| 1201 | assert(payment); |
| 1202 | assert(pay_plugin->gossmap); |
| 1203 | const double HTLC_MAX_FRACTION = 0.01; // 1% |
| 1204 | const u64 HTLC_MAX_STOP_MSAT = 1000000000; // 1M sats |
| 1205 | |
| 1206 | u64 disabled_count = 0; |
| 1207 | |
| 1208 | |
| 1209 | u64 htlc_max_threshold = HTLC_MAX_FRACTION * payment->payment_info |
| 1210 | .amount.millisatoshis; /* Raw: a fraction of this amount. */ |
| 1211 | /* Don't exclude channels with htlc_max above HTLC_MAX_STOP_MSAT even if |
| 1212 | * that represents a fraction of the payment smaller than |
| 1213 | * HTLC_MAX_FRACTION. */ |
| 1214 | htlc_max_threshold = MIN(htlc_max_threshold, HTLC_MAX_STOP_MSAT); |
| 1215 | |
| 1216 | gossmap_apply_localmods(pay_plugin->gossmap, payment->local_gossmods); |
| 1217 | for (const struct gossmap_node *node = |
| 1218 | gossmap_first_node(pay_plugin->gossmap); |
| 1219 | node; node = gossmap_next_node(pay_plugin->gossmap, node)) { |
| 1220 | for (size_t i = 0; i < node->num_chans; i++) { |
| 1221 | int dir; |
| 1222 | const struct gossmap_chan *chan = gossmap_nth_chan( |
| 1223 | pay_plugin->gossmap, node, i, &dir); |
| 1224 | const u64 htlc_max = |
| 1225 | fp16_to_u64(chan->half[dir].htlc_max); |
| 1226 | if (htlc_max < htlc_max_threshold) { |
| 1227 | struct short_channel_id_dir scidd = { |
| 1228 | .scid = gossmap_chan_scid( |
| 1229 | pay_plugin->gossmap, chan), |
| 1230 | .dir = dir}; |
| 1231 | disabledmap_add_channel(payment->disabledmap, |
| 1232 | scidd); |
| 1233 | disabled_count++; |
| 1234 | } |
| 1235 | } |
| 1236 | } |
| 1237 | gossmap_remove_localmods(pay_plugin->gossmap, payment->local_gossmods); |
| 1238 | // FIXME: prune the network over other parameters, eg. capacity, |
| 1239 | // fees, ... |
| 1240 | plugin_log(pay_plugin->plugin, LOG_DBG, |
| 1241 | "channelfilter: disabling %" PRIu64 " channels.", |
| 1242 | disabled_count); |
| 1243 | return payment_continue(payment); |
| 1244 | } |
| 1245 | |
| 1246 | REGISTER_PAYMENT_MODIFIER(channelfilter, channelfilter_cb); |
| 1247 |
nothing calls this directly
no test coverage detected