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

Function channel_hints_update

plugins/libplugin-pay.c:322–394  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

320}
321
322static void channel_hints_update(struct payment *p,
323 const struct short_channel_id scid,
324 int direction, bool enabled, bool local,
325 const struct amount_msat *estimated_capacity,
326 u16 *htlc_budget)
327{
328 struct payment *root = payment_root(p);
329 struct channel_hint newhint;
330
331 /* If the channel is marked as enabled it must have an estimate. */
332 assert(!enabled || estimated_capacity != NULL);
333
334 /* Try and look for an existing hint: */
335 for (size_t i=0; i<tal_count(root->channel_hints); i++) {
336 struct channel_hint *hint = &root->channel_hints[i];
337 if (short_channel_id_eq(&hint->scid.scid, &scid) &&
338 hint->scid.dir == direction) {
339 bool modified = false;
340 /* Prefer to disable a channel. */
341 if (!enabled && hint->enabled) {
342 hint->enabled = false;
343 modified = true;
344 }
345
346 /* Prefer the more conservative estimate. */
347 if (estimated_capacity != NULL &&
348 amount_msat_greater(hint->estimated_capacity,
349 *estimated_capacity)) {
350 hint->estimated_capacity = *estimated_capacity;
351 modified = true;
352 }
353 if (htlc_budget != NULL && *htlc_budget < hint->htlc_budget) {
354 hint->htlc_budget = *htlc_budget;
355 modified = true;
356 }
357
358 if (modified)
359 paymod_log(p, LOG_DBG,
360 "Updated a channel hint for %s: "
361 "enabled %s, "
362 "estimated capacity %s",
363 type_to_string(tmpctx,
364 struct short_channel_id_dir,
365 &hint->scid),
366 hint->enabled ? "true" : "false",
367 type_to_string(tmpctx,
368 struct amount_msat,
369 &hint->estimated_capacity));
370 return;
371 }
372 }
373
374 /* No hint found, create one. */
375 newhint.enabled = enabled;
376 newhint.scid.scid = scid;
377 newhint.scid.dir = direction;
378 newhint.local = local;
379 if (estimated_capacity != NULL)

Calls 4

payment_rootFunction · 0.85
amount_msat_greaterFunction · 0.85
paymod_logFunction · 0.85
type_to_stringClass · 0.50

Tested by

no test coverage detected