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

Function plugin_hook_make_ordered

lightningd/plugin_hook.c:611–697  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

609}
610
611static struct plugin **plugin_hook_make_ordered(const tal_t *ctx,
612 struct logger *log,
613 struct plugin_hook *hook)
614{
615 struct hook_node *graph, *n;
616 struct hook_instance **done;
617
618 /* Populate graph nodes */
619 graph = tal_arr(tmpctx, struct hook_node, 0);
620 for (size_t i = 0; i < tal_count(hook->hooks); i++) {
621 struct hook_node hn;
622
623 if (!hook->hooks[i])
624 continue;
625 hn.finished = false;
626 hn.hook = hook->hooks[i];
627 hn.num_incoming = 0;
628 hn.outgoing = tal_arr(graph, struct hook_node *, 0);
629 tal_arr_expand(&graph, hn);
630 }
631
632 if (tal_count(graph) == 0)
633 return NULL;
634
635 /* Add edges. */
636 for (size_t i = 0; i < tal_count(graph); i++) {
637 for (size_t j = 0; j < tal_count(graph[i].hook->before); j++) {
638 n = find_hook(graph, graph[i].hook->before[j]);
639 if (!n) {
640 /* This is useful for typos! */
641 log_debug(graph[i].hook->plugin->log,
642 "hook %s before unknown plugin %s",
643 hook->name,
644 graph[i].hook->before[j]);
645 continue;
646 }
647 tal_arr_expand(&graph[i].outgoing, n);
648 n->num_incoming++;
649 }
650 for (size_t j = 0; j < tal_count(graph[i].hook->after); j++) {
651 n = find_hook(graph, graph[i].hook->after[j]);
652 if (!n) {
653 /* This is useful for typos! */
654 log_debug(graph[i].hook->plugin->log,
655 "hook %s after unknown plugin %s",
656 hook->name,
657 graph[i].hook->after[j]);
658 continue;
659 }
660 tal_arr_expand(&n->outgoing, &graph[i]);
661 graph[i].num_incoming++;
662 }
663 }
664
665 done = tal_arr(tmpctx, struct hook_instance *, 0);
666 while ((n = get_best_candidate(graph)) != NULL) {
667 tal_arr_expand(&done, n->hook);
668 n->finished = true;

Callers 1

Calls 3

find_hookFunction · 0.85
get_best_candidateFunction · 0.85
tal_freeFunction · 0.85

Tested by

no test coverage detected