Commit Graph

57 Commits

Author SHA1 Message Date
Rusty Russell c284b5bbf4 lightningd: always do incremental parsing of JSON inputs.
time lightning-cli -R --network=regtest --lightning-dir /tmp/ltests-k8jhvtty/test_pay_stress_1/lightning-1/ listpays > /dev/null

Before:
	real	0m42.741s
	user	0m0.149s
	sys	0m0.016s

After:
	real	0m13.674s
	user	0m0.131s
	sys	0m0.024s

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Fixed: JSON-RPC: significant speedups for plugins which create large JSON replies (e.g. listpays on large nodes).
2020-08-21 09:52:33 +09:30
Rusty Russell 7a7a849fc2 lightningd: allow plugin commands and options to mark themselves deprecated.
This lets us handle it the same way we handle builtin commands, and also
lets us warn if they use deprecated apis and allow-deprecated-apis=false.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Added: Plugins: can now mark their options and commands deprecated.
2020-08-11 08:43:18 +09:30
ZmnSCPxj jxPCSnmZ 1ded3fc52f lightningd/plugin.c: Add a `--dev-builtin-plugins-unimportant` for developers who want to mess around with the builtin plugins. 2020-08-04 13:27:51 -05:00
ZmnSCPxj jxPCSnmZ a847487bbe lightningd/plugin.c: Add important plugins, which if they terminate, lightningd also terminates.
Changelog-Added: New option `--important-plugin` loads a plugin is so important that if it dies, `lightningd` will exit rather than continue.  You can still `--disable-plugin` it, however, which trumps `--important-plugin` and it will not be started at all.
2020-08-04 13:27:51 -05:00
ZmnSCPxj jxPCSnmZ 3df2333d5d lightningd/plugin.c: Add specific function to give the directory for built-in plugins. 2020-08-04 13:27:51 -05:00
Rusty Russell fe365f930f lightningd: list disabled plugins in listconfig.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-05-05 13:45:17 +09:30
Rusty Russell 24063ca972 lightningd: have plugin-disable be more persistent.
The previous implementation was a bit lazy: in particular, since we didn't
remember the disabled plugins, we would load them on rescan.

Changelog-Changed: config: the `plugin-disable` option works even if specified before the plugin is found.
2020-05-05 13:45:17 +09:30
Rusty Russell 80f1f0ca15 lightningd: remove `stop` member from plugin.
It's not needed now that plugin_kill frees the plugin immediately.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-05-05 13:45:17 +09:30
Rusty Russell 8c59de5ee5 lightningd: make plugin_kill take a simple string.
That's more convenient for most callers, which don't need a fmt.

Fixed-by: Darosior <darosior@protonmail.com>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-05-05 13:45:17 +09:30
Rusty Russell 7223a9446e lightningd: have plugin_send_getmanifest return an error string.
This way the caller doesn't have to "know" that it should use strerror().

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-05-05 13:45:17 +09:30
Rusty Russell 69b07cf5a6 lightningd: plugin init routines return error string or NULL.
Once again, this unifies plugin_kill() into the caller.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-05-05 13:45:17 +09:30
Rusty Russell 1e4f85a539 lightningd: refactor to extract getmanifest paths.
This will allow the dynamic starting code to use them too.

Also lets us move dev_debug_subprocess under #if DEVELOPER.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-05-05 13:45:17 +09:30
Rusty Russell 9b9e830780 lightningd: attach plugins natively to the command which started it.
This will let us unify the startup and runtime-started infrastructure.

Note that there are two kinds of notifications:
1. Starting a single plugin (i.e. `plugin start`)
2. Starting multiple plugins (i.e. `plugin rescan` or `plugin startdir`).

In the latter case, we want the command to complete only once *all*
the plugins are dead/finished.

We also call plugin_kill() in all cases, and correctly return afterwards
(it matters once we use the same paths for dynamic plugins, which don't
cause a fatal error if they don't startup).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-05-05 13:45:17 +09:30
Rusty Russell ab8582036f lightningd: remove counter for pending_manifests in favor of checking for state.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-05-05 13:45:17 +09:30
Rusty Russell 7cda24509b lightningd: plugins_any_in_state and plugins_all_in_state helpers.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-05-05 13:45:17 +09:30
Rusty Russell ee401e62a2 lightningd: complete plugin state machine.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-05-05 13:45:17 +09:30
Rusty Russell b592d6fd8f lightningd: fix race where we do rescan before all plugins finish init.
The symptom (under heavy load and valgrind) in test_plugin_command:

	lightningd: common/json_stream.c:237: json_stream_output_: Assertion `!js->reader' failed.

This is because we try to call `getmanifest` again on `pay` which has not yet
responded to init.

The minimal fix for this is to keep proper state, so we can tell the
difference between "not yet called getmanifest" and "not yet finished
init".

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-05-05 13:45:17 +09:30
Christian Decker 27ea47ae37 plugins: Fix undefined deallocation order in `struct plugins`
We use the new function `plugins_free` to define the correct deallocation
order on shutdown, since under normal operation the allocation tree is
organized to allow plugins to terminate and automatically free all dependent
resources. During shutdown the deallocation order is under-defined since
siblings may get freed in any order, but we implicitly rely on them staying
around.
2020-04-16 18:03:35 +09:30
Christian Decker 197a144505 plugin: Ensure RPC passthrough calls are terminated when plugin dies
We now track all pending RPC passthrough calls, and terminate them with an
error if the plugin dies.

Changelog-Fixed: JSON-RPC: Pending RPC method calls are now terminated if the handling plugin exits prematurely.
2020-04-14 11:07:55 +09:30
Rusty Russell b7db588a8a plugin: remove boutique features.
We now manipulate the global features directly.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-03-31 13:36:02 +02:00
Rusty Russell a7cc6d33c3 plugins: actually change global features when plugins tell us to.
This cleans up the boutique handling of features, and importantly, it
means that if a plugin says to offer a feature in init, we will now
*accept* that feature.

Changelog-Fixed: Plugins: setting an 'init' feature bit allows us to accept it from peers.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-03-31 13:36:02 +02:00
lisa neigut 42cce55b45 plugins: add 'flag' type for plugin options
Updates the plugin docs to include more detailed info about how options
work.

Changelog-Added: Plugins: 'flag'-type option now available.
2020-03-21 16:29:52 +10:30
lisa neigut cac5a0cd1d plugins: use stricter parsing for option values
also: convert the stored int value from 'int' to 's64'

atoi fails silently, returning a zero. instead we use the more robust
strtoll which will allow us fail with an error.

we also make the parsing for bools stricter, only allowing plausibly
boolean values to parse.
2020-03-10 13:25:36 +10:30
darosior ae249a2294 chaintopology: check bitcoin plugin commands at startup
Exit early if we won't be able to fully communicate with our Bitcoin
backend.
2020-02-12 11:45:07 +10:30
Christian Decker 532bf1730f plugin: Add function to collect featurebits that plugins registered 2020-02-11 13:53:31 +10:30
Christian Decker ea62d97879 plugin: Store a plugin's featurebits in the plugin struct
We'll collect the featurebits on-demand from all currently active plugins when
needed.
2020-02-11 13:53:31 +10:30
Rusty Russell f6ed7f2e89 plugin: handle corner case where rpc_command is to stop the plugin.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2019-12-06 16:52:16 +01:00
Rusty Russell fe17acf07b TAGS: reformat to fix when PRINTF_FMT() used.
I was wondering why TAGS was missing some functions, and finally
tracked it down: PRINTF_FMT() confuses etags if it's at the start
of a function, and it ignores the rest of the file.

So we put PRINTF_FMT at the end, but that doesn't work for
*definitions*, only *declarations*.  So we remove it from definitions
and add gratuitous declarations in the few static places.1

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2019-11-01 17:27:20 -05:00
darosior 5bdf349771 plugins: make the default plugins directory a member of 'plugins' 2019-09-30 00:20:16 +00:00
darosior 73bbf4f6a3 plugins: cleanup shared headers between dynamic and static plugins 2019-09-30 00:20:16 +00:00
darosior 3491a98cca plugins: remove dynamic plugins configuration code from lightningd/plugin
This merges back plugins_init and plugins_start, removes conditions on
startup, and removes the CONFIGURING state.
2019-09-30 00:20:16 +00:00
darosior 603e2f0ca9 plugins: split manifest_cb and plugin_config
This reduces error details for getmanifest response,
but avoids too much code duplication in the next commit.
2019-09-30 00:20:16 +00:00
darosior 6694dda8a3 plugins: return also on register error in add_plugin_dir() 2019-09-30 00:20:16 +00:00
darosior fcc358c9bc plugins: return plugin in plugin_register, make conn initializers publics 2019-09-30 00:20:16 +00:00
Rusty Russell 79d32ec2f2 plugin: notice when plugin has *started* configuring.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2019-07-30 08:44:01 +08:00
darosior dda154612c doc: add the new init and getmanifest fields 2019-07-28 07:24:04 +00:00
darosior 12e28c2554 lightningd/plugin: Add a 'dynamic' field to getmanifest and a 'startup' field to init
This lets a plugin specify whether it can be restarted, and to know if it is started at lightningd startup
2019-07-28 07:24:04 +00:00
darosior ce12a37a2b lightningd/plugin: Add a 'configured' member to the plugin struct, split 'plugins_init'
This adds a 'configured' boolean member to the plugin struct so that we can add plugins to ld->plugins' list and differenciate fresh plugins.
This also adds 'plugins_start' so that new plugins can be started without calling 'plugins_init' and running an io loop
2019-07-28 07:24:04 +00:00
darosior 2e25c87bd4 lightningd/plugin: Move structs to header, make 'paths_match' and 'plugin_kill' non static 2019-07-28 07:24:04 +00:00
Rusty Russell 8f9c48254b plugins: do I/O logging.
I was trying to trace a problem with a plugin, and needed this.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2019-05-31 18:36:38 +02:00
darosior a497295f92 Add a default 'plugins' directory in the lightning dir
Automatically load all plugins from 'lightning_dir/plugins' (setting them as plugin_dir)
2019-05-21 07:05:43 +00:00
Rusty Russell 3729ad9914 plugin: plugin_exclusive_loop helper to service one plugin synchronously.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2019-04-08 01:56:17 +00:00
Richard Bondi 503360143a fix crash with lightning charge and plugin opts (#2358)
* fix crash with lightning charge and plugin opts
2019-02-17 21:44:10 +01:00
Rusty Russell c506d42679 plugins: don't keep redundant jsonrpc pointer.
We have ld already, just use that in the one place we need.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2019-02-07 20:33:50 +00:00
Christian Decker a2fa0788fc plugin: Remove plugin_request_new and expose plugin_request_send
plugin_request_new did nothing special aside from registering the
request ID with the dispatch code. This duty has now been moved to
plugin_request_send instead, which is also exposed so we can use that
code in plugin_hook.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
2019-01-17 05:42:49 +00:00
Christian Decker f8f76e3d31 plugin: Add hook registration
I might have gone a bit overboard with the type-checking, but
typesafe_cb_cast is quite nice to use, so why not. The macro to
register a new hook encapsulates the entire flow from param
serialization, to dispatch, parsing and callback dispatch in one
bundle. I was tempted to have the callback outside of the
registration, but it's unlikely that we'll have two calls to the same
hook with different callbacks.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
2019-01-17 05:42:49 +00:00
Christian Decker 5813567856 plugin: Dispatch notifications to subscribed plugins
Signed-off-by: Christian Decker <decker.christian@gmail.com>
2018-12-30 14:36:02 +01:00
Rusty Russell 6323cc1898 plugins: allow --dev-debugger=<pluginname>.
This currently just invokes GDB, but we could generalize it (though
pdb doesn't allow attaching to a running process, other python
debuggers seem to).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-12-10 00:00:50 +00:00
Christian Decker be7674ed6c plugin: Added .params.configuration to init call
This tells the plugin both the `lightning-dir` as well as the
`rpc-filename` to use to talk to `lightningd`. Prior to this they'd
had to guess.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
2018-12-07 17:17:53 +01:00
Rusty Russell eb03b33655 plugins: add and install built-in plugin dir, add clear and disable options.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-12-05 01:22:55 +01:00