Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new notifications: plugin_stopped and plugin_started #7508

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions doc/developers-guide/plugin-development/event-notifications.md
Original file line number Diff line number Diff line change
Expand Up @@ -483,3 +483,51 @@ In the shutdown case, plugins should not interact with lightnind except via (id-
}
}
```

### `plugin_started` and

Emitted when a plugin has completed startup.

```json
{
"plugin_started": {
"plugin_name": "example_plugin",
"plugin_path": "/path/to/example_plugin.py",
"methods": [
"example_method1",
"example_method2",
"example_method3"
]
}
}
```

Where:

- `plugin_name`: The short name of the plugin.
- `plugin_path`: The full file path to the plugin executable.
- `methods`: An array of RPC method names that the plugin registered.

### `plugin_stopped`

Emitted when a plugin has been stopped or has exited.

```json
{
"plugin_stopped": {
"plugin_name": "example_plugin",
"plugin_path": "/path/to/example_plugin.py",
"methods": [
"example_method1",
"example_method2",
"example_method3"
]
}
}
```

Where:

- `plugin_name`: The short name of the plugin.
- `plugin_path`: The full file path to the plugin executable.
- `methods`: An array of RPC method names that the plugin registered.
30 changes: 30 additions & 0 deletions lightningd/notification.c
Original file line number Diff line number Diff line change
Expand Up @@ -638,3 +638,33 @@ void notify_log(struct lightningd *ld, const struct log_entry *l)
log_notification_serialize(n->stream, l);
notify_send(ld, n);
}

static void plugin_notification_serialize(struct json_stream *stream,
struct plugin *plugin)
{
json_add_string(stream, "plugin_name", plugin->shortname);
json_add_string(stream, "plugin_path", plugin->cmd);
json_array_start(stream, "methods");
for (size_t i = 0; i < tal_count(plugin->methods); i++) {
json_add_string(stream, NULL, plugin->methods[i]);
}
json_array_end(stream);
}
gudnuf marked this conversation as resolved.
Show resolved Hide resolved

REGISTER_NOTIFICATION(plugin_started);

void notify_plugin_started(struct lightningd *ld, struct plugin *plugin)
{
struct jsonrpc_notification *n = notify_start("plugin_started");
plugin_notification_serialize(n->stream, plugin);
notify_send(ld, n);
}

REGISTER_NOTIFICATION(plugin_stopped);

void notify_plugin_stopped(struct lightningd *ld, struct plugin *plugin)
{
struct jsonrpc_notification *n = notify_start("plugin_stopped");
plugin_notification_serialize(n->stream, plugin);
notify_send(ld, n);
}
3 changes: 3 additions & 0 deletions lightningd/notification.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,7 @@ bool notify_deprecated_oneshot(struct lightningd *ld,
bool notify_plugin_shutdown(struct lightningd *ld, struct plugin *p);
/* Inform the plugin when a log line is emitted */
void notify_log(struct lightningd *ld, const struct log_entry *l);

void notify_plugin_started(struct lightningd *ld, struct plugin *plugin);
void notify_plugin_stopped(struct lightningd *ld, struct plugin *plugin);
#endif /* LIGHTNING_LIGHTNINGD_NOTIFICATION_H */
3 changes: 3 additions & 0 deletions lightningd/plugin.c
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,8 @@ static void destroy_plugin(struct plugin *p)

if (tal_count(p->custom_msgs))
tell_connectd_custommsgs(p->plugins);

notify_plugin_stopped(p->plugins->ld, p);
}

static u32 file_checksum(struct lightningd *ld, const char *path)
Expand Down Expand Up @@ -2140,6 +2142,7 @@ static void plugin_config_cb(const char *buffer,
}
if (tal_count(plugin->custom_msgs))
tell_connectd_custommsgs(plugin->plugins);
notify_plugin_started(plugin->plugins->ld, plugin);
check_plugins_initted(plugin->plugins);
}

Expand Down