pyln-client: support hook filters.
What changed, and why it matters
This is a small feature addition to the Python plugin client library for Core Lightning. It lets plugin authors optionally specify 'filters' when registering hooks, and passes those filters along to the lightningd daemon during plugin registration. There is no indication of a security bug or fix in the change itself.
No security action required. Treat as a normal feature update.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit extends pyln-client’s plugin.py to support an optional ‘filters’ parameter on hook registration (both the add_hook method and the @hook decorator). The filters are stored on the Method object and, if present, included in the ‘hooks’ manifest sent to lightningd. The change is additive and does not alter existing hook behavior when filters are absent. No security vulnerability or hardening is evident from the diff.
Changed components
contrib/pyln-client/pyln/client/plugin.pyInspect captured patch +13 / −6
diff --git a/contrib/pyln-client/pyln/client/plugin.py b/contrib/pyln-client/pyln/client/plugin.py
index 24277dca..5dfbaa20 100644
--- a/contrib/pyln-client/pyln/client/plugin.py
+++ b/contrib/pyln-client/pyln/client/plugin.py
@@ -59,6 +59,7 @@ class Method(object):
self.description = description
self.before: List[str] = []
self.after: List[str] = []
+ self.filters: Optional[List[Union[str, int]]] = None
def get_usage(self):
# Handles out-of-order use of parameters like:
@@ -546,7 +547,8 @@ class Plugin(object):
def add_hook(self, name: str, func: Callable[..., JSONType],
background: bool = False,
before: Optional[List[str]] = None,
- after: Optional[List[str]] = None) -> None:
+ after: Optional[List[str]] = None,
+ filters: Optional[List[Union[str, int]]] = None) -> None:
"""Register a hook that is called synchronously by lightningd on events
"""
if name in self.methods:
@@ -574,17 +576,19 @@ class Plugin(object):
method.after = []
if after:
method.after = after
+ method.filters = filters
self.methods[name] = method
def hook(self, method_name: str,
before: List[str] = None,
- after: List[str] = None) -> JsonDecoratorType:
+ after: List[str] = None,
+ filters: List[Union[str, int]] = None) -> JsonDecoratorType:
"""Decorator to add a plugin hook to the dispatch table.
Internally uses add_hook.
"""
def decorator(f: Callable[..., JSONType]) -> Callable[..., JSONType]:
- self.add_hook(method_name, f, background=False, before=before, after=after)
+ self.add_hook(method_name, f, background=False, before=before, after=after, filters=filters)
return f
return decorator
@@ -961,9 +965,12 @@ class Plugin(object):
continue
if method.mtype == MethodType.HOOK:
- hooks.append({'name': method.name,
- 'before': method.before,
- 'after': method.after})
+ hook = {'name': method.name,
+ 'before': method.before,
+ 'after': method.after}
+ if method.filters:
+ hook['filters'] = method.filters
+ hooks.append(hook)
continue
# For compatibility with lightningd prior to 24.08, we must
Why this scored 19/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.