libplugin: allow plugins to register optional filters for each hook they want.
What changed, and why it matters
This commit adds a new plugin-library feature that lets plugin authors register optional filters when subscribing to hooks. It is a straightforward API extension: plugins can now declare string or integer filters in their hook manifest, which the main daemon can use to decide whether to invoke the hook. There is no indication in the commit that this fixes a bug or addresses a security issue; it appears to be a normal feature addition.
No security action required. Treat as a normal feature commit. If reviewing the broader hook-filter feature, verify that the daemon-side parser of the new `filters` array correctly validates filter types and rejects malformed or conflicting declarations.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The change extends struct plugin_hook in plugins/libplugin.h with two new optional filter fields (strfilters/num_strfilters and intfilters/num_intfilters) and serializes them into the getmanifest response in plugins/libplugin.c under a new filters array. The implementation enforces mutual exclusivity at the serialization layer (only one of string or integer filters is emitted). No validation, parsing, or consumption of these filters is visible in this diff.
Changed components
plugins/libplugin.cplugins/libplugin.hInspect captured patch +21 / −0
diff --git a/plugins/libplugin.c b/plugins/libplugin.c
index db49590d..8dfba2ce 100644
--- a/plugins/libplugin.c
+++ b/plugins/libplugin.c
@@ -1302,6 +1302,19 @@ handle_getmanifest(struct command *getmanifest_cmd,
p->hook_subs[i].after[j]);
json_array_end(params);
}
+ if (p->hook_subs[i].num_strfilters) {
+ json_array_start(params, "filters");
+ for (size_t j = 0; j < p->hook_subs[i].num_strfilters; j++)
+ json_add_string(params, NULL,
+ p->hook_subs[i].strfilters[j]);
+ json_array_end(params);
+ } else if (p->hook_subs[i].num_intfilters) {
+ json_array_start(params, "filters");
+ for (size_t j = 0; j < p->hook_subs[i].num_intfilters; j++)
+ json_add_u64(params, NULL,
+ p->hook_subs[i].intfilters[j]);
+ json_array_end(params);
+ }
json_object_end(params);
}
json_array_end(params);
diff --git a/plugins/libplugin.h b/plugins/libplugin.h
index cec028b2..bcc68dc0 100644
--- a/plugins/libplugin.h
+++ b/plugins/libplugin.h
@@ -99,6 +99,14 @@ struct plugin_hook {
const jsmntok_t *params);
/* If non-NULL, these are NULL-terminated arrays of deps */
const char **before, **after;
+
+ /* String filters (you can only set this *or* intfilters) */
+ const char **strfilters;
+ size_t num_strfilters;
+
+ /* Integer filters */
+ const u64 *intfilters;
+ size_t num_intfilters;
};
/* Return the feature set of the current lightning node */
Why this scored 12/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.