Skip to content

Commit b7a56f0

Browse files
cdeckerniftynei
authored andcommitted
plugin: Gate the plugin subsystem with the --enable-plugins configure flag
Since we are planning to release a bug fix release, and the plugin subsystem is not yet complete, it is better to make plugin support opt-in while we continue testing. Signed-off-by: Christian Decker <[email protected]> Signed-off-by: Rusty Russell <[email protected]>
1 parent a01342a commit b7a56f0

File tree

9 files changed

+33
-10
lines changed

9 files changed

+33
-10
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
1414
- JSON API: use `\n\n` to terminate responses, for simplified parsing (pylightning now relies on this)
1515
- JSON API: `fundchannel` now includes an `announce` option, when false it will keep channel private. Defaults to true.
1616
- JSON API: `listpeers`'s `channels` now includes a `private` flag to indicate if channel is announced or not.
17-
- Plugins: Added plugins to `lightningd`, including option passthrough and JSON-RPC passthrough.
17+
- Plugins: experimental plugin support for `lightningd`, including option passthrough and JSON-RPC passthrough.
1818

1919
### Changed
2020

configure

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ CWARNFLAGS=${CWARNFLAGS:--Werror -Wall -Wundef -Wmissing-prototypes -Wmissing-de
1010
CDEBUGFLAGS=${CDEBUGFLAGS:--std=gnu11 -g -fstack-protector}
1111
DEVELOPER=${DEVELOPER:-0}
1212
EXPERIMENTAL_FEATURES=${EXPERIMENTAL_FEATURES:-0}
13+
PLUGINS=${PLUGINS:-0}
1314
COMPAT=${COMPAT:-1}
1415
STATIC=${STATIC:-0}
1516
CONFIGURATOR_CC=${CONFIGURATOR_CC:-$CC}
@@ -55,6 +56,10 @@ usage()
5556
echo " Compatibility mode, good to disable to see if your software breaks"
5657
usage_with_default "--enable/disable-valgrind" "(autodetect)"
5758
echo " Valgrind binary to use for tests"
59+
usage_with_default "--enable/disable-experimental-features" "disable"
60+
echo " Experimental features (not for network use!)"
61+
usage_with_default "--enable/disable-plugins" "disable"
62+
echo " Support for plugins"
5863
usage_with_default "--enable/disable-static" "$STATIC" "enable" "disable"
5964
echo " Static link binary"
6065
exit 1
@@ -113,6 +118,8 @@ for opt in "$@"; do
113118
--disable-developer) DEVELOPER=0;;
114119
--enable-experimental-features) EXPERIMENTAL_FEATURES=1;;
115120
--disable-experimental-features) EXPERIMENTAL_FEATURES=0;;
121+
--enable-plugins) PLUGINS=1;;
122+
--disable-plugins) PLUGINS=0;;
116123
--enable-compat) COMPAT=1;;
117124
--disable-compat) COMPAT=0;;
118125
--enable-valgrind) VALGRIND=1;;
@@ -151,6 +158,7 @@ add_var CDEBUGFLAGS "$CDEBUGFLAGS"
151158
add_var VALGRIND "$VALGRIND"
152159
add_var DEVELOPER "$DEVELOPER" $CONFIG_HEADER
153160
add_var EXPERIMENTAL_FEATURES "$EXPERIMENTAL_FEATURES" $CONFIG_HEADER
161+
add_var PLUGINS "$PLUGINS" $CONFIG_HEADER
154162
add_var COMPAT "$COMPAT" $CONFIG_HEADER
155163
add_var PYTEST "$PYTEST"
156164
add_var STATIC "$STATIC"

doc/plugins.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ variety of ways:
1616
internal events in `lightningd` and alter its behavior or inject
1717
custom behaviors.
1818

19-
*Notice: at the time of writing only command line option passthrough
20-
is implemented, the other features are under active development.*
19+
*Notice: you need to pass `--enable-plugins` to `./configure` to turn on plugins for now, and hooks are not yet implemented. The API is under active development.*
2120

2221
A plugin may be written in any language, and communicates with
2322
`lightningd` through the plugin's `stdin` and `stdout`. JSON-RPCv2 is

lightningd/lightningd.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -215,8 +215,9 @@ static struct lightningd *new_lightningd(const tal_t *ctx)
215215
*code. Here we initialize the context that will keep track and control
216216
*the plugins.
217217
*/
218+
#ifdef PLUGINS
218219
ld->plugins = plugins_new(ld, ld->log_book, ld->jsonrpc, ld);
219-
220+
#endif
220221
return ld;
221222
}
222223

@@ -361,10 +362,11 @@ static const char *find_my_pkglibexec_path(struct lightningd *ld,
361362

362363
/*~ The plugin dir is in ../libexec/c-lightning/plugins, which (unlike
363364
* those given on the command line) does not need to exist. */
365+
#ifdef PLUGINS
364366
add_plugin_dir(ld->plugins,
365367
path_join(tmpctx, pkglibexecdir, "plugins"),
366368
true);
367-
369+
#endif
368370
/*~ Sometimes take() can be more efficient, since the routine can
369371
* manipulate the string in place. This is the case here. */
370372
return path_simplify(ld, take(pkglibexecdir));
@@ -377,9 +379,11 @@ static const char *find_daemon_dir(struct lightningd *ld, const char *argv0)
377379
/* If we're running in-tree, all the subdaemons are with lightningd. */
378380
if (has_all_subdaemons(my_path)) {
379381
/* In this case, look in ../plugins */
382+
#ifdef PLUGINS
380383
add_plugin_dir(ld->plugins,
381384
path_join(tmpctx, my_path, "../plugins"),
382385
true);
386+
#endif
383387
return my_path;
384388
}
385389

@@ -661,8 +665,9 @@ int main(int argc, char *argv[])
661665
/*~ Initialize all the plugins we just registered, so they can
662666
* do their thing and tell us about themselves (including
663667
* options registration). */
668+
#ifdef PLUGINS
664669
plugins_init(ld->plugins, ld->dev_debug_subprocess);
665-
670+
#endif
666671
/*~ Handle options and config; move to .lightningd (--lightning-dir) */
667672
handle_opts(ld, argc, argv);
668673

@@ -762,8 +767,9 @@ int main(int argc, char *argv[])
762767

763768
/*~ Now that the rpc path exists, we can start the plugins and they
764769
* can start talking to us. */
770+
#ifdef PLUGINS
765771
plugins_config(ld->plugins);
766-
772+
#endif
767773
/*~ We defer --daemon until we've completed most initialization: that
768774
* way we'll exit with an error rather than silently exiting 0, then
769775
* realizing we can't start and forcing the confused user to read the

lightningd/lightningd.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,9 @@ struct lightningd {
205205
bool use_proxy_always;
206206
char *tor_service_password;
207207
bool pure_tor_setup;
208-
208+
#ifdef PLUGINS
209209
struct plugins *plugins;
210+
#endif
210211
};
211212

212213
const struct chainparams *get_chainparams(const struct lightningd *ld);

lightningd/options.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,7 @@ static void config_register_opts(struct lightningd *ld)
318318
&ld->config_filename,
319319
"Specify configuration file. Relative paths will be prefixed by lightning-dir location. (default: config)");
320320

321+
#ifdef PLUGINS
321322
/* Register plugins as an early args, so we can initialize them and have
322323
* them register more command line options */
323324
opt_register_early_arg("--plugin", opt_add_plugin, NULL, ld,
@@ -331,7 +332,7 @@ static void config_register_opts(struct lightningd *ld)
331332
opt_register_early_arg("--disable-plugin", opt_disable_plugin,
332333
NULL, ld,
333334
"Disable a particular plugin by filename/name");
334-
335+
#endif
335336
opt_register_noarg("--daemon", opt_set_bool, &ld->daemon,
336337
"Run in the background, suppress stdout/stderr");
337338
opt_register_arg("--ignore-fee-limits", opt_set_bool_arg, opt_show_bool,

tests/fixtures.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
DEVELOPER = os.getenv("DEVELOPER", config['DEVELOPER']) == "1"
1818
TEST_DEBUG = os.getenv("TEST_DEBUG", "0") == "1"
1919

20-
2120
if TEST_DEBUG:
2221
logging.basicConfig(level=logging.DEBUG, stream=sys.stdout)
2322

tests/test_plugin.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
from collections import OrderedDict
22
from fixtures import * # noqa: F401,F403
33
from lightning import RpcError
4+
from utils import PLUGINS
45

56
import pytest
67
import subprocess
8+
import unittest
79

810

11+
@unittest.skipIf(not PLUGINS, "plugin subsystem requires PLUGINS flag")
912
def test_option_passthrough(node_factory):
1013
""" Ensure that registering options works.
1114
@@ -32,6 +35,7 @@ def test_option_passthrough(node_factory):
3235
n.stop()
3336

3437

38+
@unittest.skipIf(not PLUGINS, "plugin subsystem requires PLUGINS flag")
3539
def test_rpc_passthrough(node_factory):
3640
"""Starting with a plugin exposes its RPC methods.
3741
@@ -58,12 +62,14 @@ def test_rpc_passthrough(node_factory):
5862
n.rpc.fail()
5963

6064

65+
@unittest.skipIf(not PLUGINS, "plugin subsystem requires PLUGINS flag")
6166
def test_plugin_dir(node_factory):
6267
"""--plugin-dir works"""
6368
plugin_dir = 'contrib/plugins'
6469
node_factory.get_node(options={'plugin-dir': plugin_dir, 'greeting': 'Mars'})
6570

6671

72+
@unittest.skipIf(not PLUGINS, "plugin subsystem requires PLUGINS flag")
6773
def test_plugin_disable(node_factory):
6874
"""--disable-plugin works"""
6975
plugin_dir = 'contrib/plugins'
@@ -83,6 +89,7 @@ def test_plugin_disable(node_factory):
8389
n.rpc.hello(name='Sun')
8490

8591

92+
@unittest.skipIf(not PLUGINS, "plugin subsystem requires PLUGINS flag")
8693
def test_plugin_notifications(node_factory):
8794
l1, l2 = node_factory.get_nodes(2, opts={'plugin': 'contrib/plugins/helloworld.py'})
8895

@@ -95,6 +102,7 @@ def test_plugin_notifications(node_factory):
95102
l2.daemon.wait_for_log(r'Received disconnect event')
96103

97104

105+
@unittest.skipIf(not PLUGINS, "plugin subsystem requires PLUGINS flag")
98106
def test_failing_plugins():
99107
fail_plugins = [
100108
'contrib/plugins/fail/failtimeout.py',

tests/utils.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
TIMEOUT = int(os.getenv("TIMEOUT", "60"))
4242
VALGRIND = os.getenv("VALGRIND", config['VALGRIND']) == "1"
4343
SLOW_MACHINE = os.getenv("SLOW_MACHINE", "0") == "1"
44+
PLUGINS = os.getenv("PLUGINS", config['PLUGINS']) == "1"
4445

4546

4647
def wait_for(success, timeout=TIMEOUT):

0 commit comments

Comments
 (0)