ElementsProject / lightning

Core Lightning — Lightning Network implementation focusing on spec compliance and performance
Other
2.83k stars 899 forks source link

Support dynamic reloading of plugins #2325

Closed renepickhardt closed 5 years ago

renepickhardt commented 5 years ago

Currently every time I change the code of the plugin I need to restart the lightning node which takes some time. It would be cool if there was a way to reload plugins in a running lightning node

conscott commented 5 years ago

The correct way to do this in lightningd is to get inotify events from the filesystem for registered plugins, and I suppose it's an option that should only be compiled in debug mode, HOWEVER, there is a poor man's version of this that will work just fine (for simple testing in regtest)

Here is my hacky version: https://github.com/conscott/lightning/blob/plugin_restarter/reload_plugins.py

I just made a wrapper for lightningd that will kill it and restart it when any of your registered plugins are modified. You can use its like:

./reload_plugins.py lightningd/lightningd --plugin-dir ~/c-lightning-plugins/

For now I hardcoded that plugindir, but with just a bit more work you can make it pull from command line args or from the lightning config file

Edit: Updated the script so it can detect your plugins from config file and command line.

Seems to work okay. If there is more interest in this, I can pull the script out to separate repo (or in c-lightning if there is a good place to put it) and polish it up a bit.

conscott commented 5 years ago

I've also wanted this for myself, so this issue has given me the motivation :)

cdecker commented 5 years ago

There are three ways I can see that'd allow a plugin to dynamically reload:

Since this is mostly useful for plugin developers I think I'd vote against the first, in favor of the runner or the self-reloading plugins.

Notice however that there are a few things that cannot be changed when reloading the plugin:

Lastly I think I see 2 possible reload triggers:

ZmnSCPxj commented 5 years ago

Closed in #2771