Commit Graph

113 Commits

Author SHA1 Message Date
darosior 87f0733965 lightningd/plugin: fix the "plugins" entry in 'listconfigs'
The value 'as_int' should not be added as a bool.
2020-01-21 22:38:14 +01:00
Vasil Dimov 742d764001 lightningd: fix formatting in comment
Changelog-None
2020-01-06 12:57:59 +01:00
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
Michael Schmoock 6ed320189e feat: restructure plugin and options in listconfigs
This will change the command `listconfigs` output in several ways:

 - Deprecated the duplicated "plugin" JSON output by replacing it with
 - a "plugins" array with substructures for each plugin with:
 - path, name and their options

Changelog-Changed: JSON-RPC: `listconfigs` now structures plugins and include their options
Changelog-Deprecated: JSON-RPC: `listconfigs` duplicated "plugin" paths
2019-11-25 18:15:02 +01:00
Rusty Russell aab83e729b lightningd: change config-dir from plugin / wallet / hsm POV into <network> subdir
Changelog-changed: .lightningd plugins and files moved into <network>/ subdir
Changelog-changed: WARNING: If you don't have a config file, you now may need to specify the network to lightning-cli
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2019-11-23 22:42:34 +00:00
Rusty Russell e433d4ddc1 lightningd: have logging include an optional node_id for each entry.
A log can have a default node_id, which can be overridden on a per-entry
basis.  This changes the format of logging, so some tests need rework.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2019-11-18 04:50:22 +00:00
darosior f075b87137 bitcoind: remove the chainparams member
We now have a global constant, prefer to use it instead of having
two variables with the same utility.
2019-11-15 13:14:08 +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 362775bc02 plugin: unregister hooks a plugin registered while freeing it 2019-10-11 10:05:08 -05:00
Christian Decker 14247283b2 plugin: Tell the plugin which network we run on
The fundchannel plugin needs to know how to build a transaction, so we need to
tell it which chainparams to use. Also adds `chainparams` as a global, since
that seems to be the way to do things in plugins.
2019-10-03 04:32:57 +00:00
darosior d0ccd15ac0 plugins: Add a destructor to the plugin request, in case it dies
Authored-by: @rustyrussell
2019-09-30 00:20:16 +00: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 b65cbc7dc3 plugins: fix false-positive memleak.
This moves field initialization into plugins_new(), and
adds a memleak helper to search the request map:

=================================== ERRORS ====================================
___________________ ERROR at teardown of test_plugin_command ___________________
[gw0] linux -- Python 3.7.1 /opt/python/3.7.1/bin/python3.7
>       lambda: ihook(item=item, **kwds),
        when=when,
    )
../../../.local/lib/python3.7/site-packages/flaky/flaky_pytest_plugin.py:306:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
tests/fixtures.py:112: in node_factory
    ok = nf.killall([not n.may_fail for n in nf.nodes])
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <utils.NodeFactory object at 0x7f873b245278>, expected_successes = [True]
    def killall(self, expected_successes):
        """Returns true if every node we expected to succeed actually succeeded""
        unexpected_fail = False
        for i in range(len(self.nodes)):
            leaks = None
            # leak detection upsets VALGRIND by reading uninitialized mem.
            # If it's dead, we'll catch it below.
            if not VALGRIND:
                try:
                    # This also puts leaks in log.
                    leaks = self.nodes[i].rpc.dev_memleak()['leaks']
                except Exception:
                    pass

            try:
                self.nodes[i].stop()
            except Exception:
                if expected_successes[i]:
                    unexpected_fail = True

            if leaks is not None and len(leaks) != 0:
                raise Exception("Node {} has memory leaks: {}".format(
                    self.nodes[i].daemon.lightning_dir,
>                   json.dumps(leaks, sort_keys=True, indent=4)
                ))
E               Exception: Node /tmp/ltests-qm87my20/test_plugin_command_1/lightnng-1/ has memory leaks: [
E                   {
E                       "backtrace": [
E                           "ccan/ccan/tal/tal.c:437 (tal_alloc_)",
E                           "lightningd/jsonrpc.c:1112 (jsonrpc_request_start_)",
E                           "lightningd/plugin.c:1041 (plugin_config)",
E                           "lightningd/plugin.c:1072 (plugins_config)",
E                           "lightningd/plugin.c:846 (plugin_manifest_cb)",
E                           "lightningd/plugin.c:252 (plugin_response_handle)",
E                           "lightningd/plugin.c:342 (plugin_read_json_one)",
E                           "lightningd/plugin.c:367 (plugin_read_json)",
E                           "ccan/ccan/io/io.c:59 (next_plan)",
E                           "ccan/ccan/io/io.c:407 (do_plan)",
E                           "ccan/ccan/io/io.c:417 (io_ready)",
E                           "ccan/ccan/io/poll.c:445 (io_loop)",
E                           "lightningd/io_loop_with_timers.c:24 (io_loop_with_tiers)",
E                           "lightningd/lightningd.c:840 (main)"
E                       ],
E                       "label": "lightningd/jsonrpc.c:1112:struct jsonrpc_reques",
E                       "parents": [
E                           "lightningd/plugin.c:66:struct plugin",
E                           "lightningd/lightningd.c:103:struct lightningd"
E                       ],
E                       "value": "0x55d6385e4088"
E                   },
E                   {
E                       "backtrace": [
E                           "ccan/ccan/tal/tal.c:437 (tal_alloc_)",
E                           "lightningd/jsonrpc.c:1112 (jsonrpc_request_start_)",
E                           "lightningd/plugin.c:1041 (plugin_config)",
E                           "lightningd/plugin.c:1072 (plugins_config)",
E                           "lightningd/plugin.c:846 (plugin_manifest_cb)",
E                           "lightningd/plugin.c:252 (plugin_response_handle)",
E                           "lightningd/plugin.c:342 (plugin_read_json_one)",
E                           "lightningd/plugin.c:367 (plugin_read_json)",
E                           "ccan/ccan/io/io.c:59 (next_plan)",
E                           "ccan/ccan/io/io.c:407 (do_plan)",
E                           "ccan/ccan/io/io.c:417 (io_ready)",
E                           "ccan/ccan/io/poll.c:445 (io_loop)",
E                           "lightningd/io_loop_with_timers.c:24 (io_loop_with_tiers)",
E                           "lightningd/lightningd.c:840 (main)"
E                       ],
E                       "label": "lightningd/jsonrpc.c:1112:struct jsonrpc_reques",
E                       "parents": [
E                           "lightningd/plugin.c:66:struct plugin",
E                           "lightningd/lightningd.c:103:struct lightningd"
E                       ],
E                       "value": "0x55d6386529d8"
E                   }
E               ]

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2019-09-07 16:54:03 +02:00
Simon Vrouwe 5b5d70d640 lightningd/plugin: extend plugins->startup window to include plugins_config
Fixes incorrect configuration[`startup`] in plugin `init`, modified tests
to test this.
2019-08-27 00:02:20 +00:00
Simon Vrouwe da74f0118d lightningd/plugin: at plugin start, set env LIGHTNINGD_VERSION
So plugins can know what version they are dealing with.
2019-08-26 15:39:03 -07:00
darosior a2c00d42f2 Remove the 'signal_startup' member of the plugin struct
It's set but not used
2019-08-05 23:06:55 -05:00
Rusty Russell b460590278 plugins: detect and fixup old relative paths.
Note that we move adding the plugin to the plugins list to the end, otherwise
the hook from logging can examine the (uninitialized) plugin.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2019-08-03 09:10:11 +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
Rusty Russell a477c69d46 lightningd: fix crash on dynamic plugin startup
2019-07-29T04:25:31.503Z DEBUG plugin-manager started(25413) /home/rusty/text/webinar/lightning-2019-07/helloworld.py
2019-07-29T04:25:39.168Z UNUSUAL lightningd(24972): Unable to estimate CONSERVATIVE/2 fee
2019-07-29T04:25:39.193Z **BROKEN** lightningd(24972): FATAL SIGNAL 6 (version v0.7.1-144-g6bb8525)
2019-07-29T04:25:39.193Z **BROKEN** lightningd(24972): backtrace: common/daemon.c:45 (send_backtrace) 0x5581b809d7d6
2019-07-29T04:25:39.193Z **BROKEN** lightningd(24972): backtrace: common/daemon.c:53 (crashdump) 0x5581b809d823
2019-07-29T04:25:39.193Z **BROKEN** lightningd(24972): backtrace: (null):0 ((null)) 0x7f4ecd46af5f
2019-07-29T04:25:39.193Z **BROKEN** lightningd(24972): backtrace: (null):0 ((null)) 0x7f4ecd46aed7
2019-07-29T04:25:39.193Z **BROKEN** lightningd(24972): backtrace: (null):0 ((null)) 0x7f4ecd44c534
2019-07-29T04:25:39.193Z **BROKEN** lightningd(24972): backtrace: ccan/ccan/tal/tal.c:93 (call_error) 0x5581b80da741
2019-07-29T04:25:39.193Z **BROKEN** lightningd(24972): backtrace: ccan/ccan/tal/tal.c:165 (check_bounds) 0x5581b80da81d
2019-07-29T04:25:39.193Z **BROKEN** lightningd(24972): backtrace: ccan/ccan/tal/tal.c:174 (to_tal_hdr) 0x5581b80da845
2019-07-29T04:25:39.193Z **BROKEN** lightningd(24972): backtrace: ccan/ccan/tal/tal.c:186 (to_tal_hdr_or_null) 0x5581b80da88e
2019-07-29T04:25:39.193Z **BROKEN** lightningd(24972): backtrace: ccan/ccan/tal/tal.c:632 (tal_bytelen) 0x5581b80db59c
2019-07-29T04:25:39.193Z **BROKEN** lightningd(24972): backtrace: lightningd/plugin.c:1056 (plugin_subscriptions_contains) 0x5581b8095aca
2019-07-29T04:25:39.193Z **BROKEN** lightningd(24972): backtrace: lightningd/plugin.c:1071 (plugins_notify) 0x5581b80972f4
2019-07-29T04:25:39.193Z **BROKEN** lightningd(24972): backtrace: lightningd/notification.c:63 (notify_warning) 0x5581b808615a
2019-07-29T04:25:39.193Z **BROKEN** lightningd(24972): backtrace: lightningd/log.c:269 (logv) 0x5581b8085393
2019-07-29T04:25:39.193Z **BROKEN** lightningd(24972): backtrace: lightningd/log.c:329 (log_) 0x5581b8085233
2019-07-29T04:25:39.193Z **BROKEN** lightningd(24972): backtrace: lightningd/bitcoind.c:372 (process_estimatefee) 0x5581b80759d7
2019-07-29T04:25:39.193Z **BROKEN** lightningd(24972): backtrace: lightningd/bitcoind.c:226 (bcli_finished) 0x5581b8075cfb
2019-07-29T04:25:39.193Z **BROKEN** lightningd(24972): backtrace: ccan/ccan/io/poll.c:244 (destroy_conn) 0x5581b80d2413
2019-07-29T04:25:39.193Z **BROKEN** lightningd(24972): backtrace: ccan/ccan/io/poll.c:250 (destroy_conn_close_fd) 0x5581b80d2435
2019-07-29T04:25:39.193Z **BROKEN** lightningd(24972): backtrace: ccan/ccan/tal/tal.c:235 (notify) 0x5581b80dabb0
2019-07-29T04:25:39.193Z **BROKEN** lightningd(24972): backtrace: ccan/ccan/tal/tal.c:397 (del_tree) 0x5581b80dac7a
2019-07-29T04:25:39.193Z **BROKEN** lightningd(24972): backtrace: ccan/ccan/tal/tal.c:481 (tal_free) 0x5581b80db1c5
2019-07-29T04:25:39.193Z **BROKEN** lightningd(24972): backtrace: ccan/ccan/io/io.c:450 (io_close) 0x5581b80d1147
2019-07-29T04:25:39.193Z **BROKEN** lightningd(24972): backtrace: ccan/ccan/io/poll.c:449 (io_loop) 0x5581b80d29ff
2019-07-29T04:25:39.193Z **BROKEN** lightningd(24972): backtrace: lightningd/io_loop_with_timers.c:24 (io_loop_with_timers) 0x5581b808058d
2019-07-29T04:25:39.193Z **BROKEN** lightningd(24972): backtrace: lightningd/lightningd.c:830 (main) 0x5581b8084396
2019-07-29T04:25:39.193Z **BROKEN** lightningd(24972): backtrace: (null):0 ((null)) 0x7f4ecd44db6a
2019-07-29T04:25:39.193Z **BROKEN** lightningd(24972): backtrace: (null):0 ((null)) 0x5581b8075059
2019-07-29T04:25:39.193Z **BROKEN** lightningd(24972): backtrace: (null):0 ((null)) 0xffffffffffffffff

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2019-07-30 08:44:01 +08:00
Rusty Russell 310d806dd3 plugins: document and extend the ~/.lightning/plugins/ dir.
Load any plugins directly as well as subdirs.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2019-07-29 14:32:07 +02: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 2864b4de01 lightningd/plugin_control: add a 'plugin' command
This adds a new pair of files : lightningd/plugin_control, along with a new RPC
command : 'plugin'. This command can be used to manage plugins without restarting lightningd:

lightning-cli plugin start helloworld.py
lightning-cli plugin stop helloworld.py
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
Simon Vrouwe 0abbbbb588 plugins: when plugins start, log their PID and path 2019-07-27 05:14:34 +00:00
Rusty Russell 98de92c50b lightningd/plugin: use ld's timer loop.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2019-06-30 16:41:30 +09:30
Rusty Russell 5a520f4a07 plugin: don't call notification after free.
This is an old bug, where a plugin can get called while we're shutting
down (and have freed plugins), but it's triggered more reliably by the
new warning notification hook.

For good measure, we also make freeing a plugin self-delete.

Valgrind error file: valgrind-errors.16763
==16886== Invalid read of size 8
==16886==    at 0x422919: plugins_notify (plugin.c:1096)
==16886==    by 0x413919: notify_warning (notification.c:61)
==16886==    by 0x412BDE: logv (log.c:251)
==16886==    by 0x412A98: log_ (log.c:311)
==16886==    by 0x4044BE: bcli_finished (bitcoind.c:178)
==16886==    by 0x459480: destroy_conn (poll.c:244)
==16886==    by 0x459499: destroy_conn_close_fd (poll.c:250)
==16886==    by 0x4619E1: notify (tal.c:235)
==16886==    by 0x461A7E: del_tree (tal.c:397)
==16886==    by 0x461AB5: del_tree (tal.c:407)
==16886==    by 0x461AB5: del_tree (tal.c:407)
==16886==    by 0x461AB5: del_tree (tal.c:407)
==16886==  Address 0x634a578 is 40 bytes inside a block of size 352 free'd
==16886==    at 0x4C2EDEB: free (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==16886==    by 0x461AFD: del_tree (tal.c:416)
==16886==    by 0x461FB7: tal_free (tal.c:481)
==16886==    by 0x411E0A: main (lightningd.c:841)
==16886==  Block was alloc'd at
==16886==    at 0x4C2DB8F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==16886==    by 0x4617CE: allocate (tal.c:245)
==16886==    by 0x461E4C: tal_alloc_ (tal.c:423)
==16886==    by 0x42255E: plugins_new (plugin.c:106)
==16886==    by 0x41133D: new_lightningd (lightningd.c:218)
==16886==    by 0x411AD4: main (lightningd.c:649)

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2019-06-12 02:00:15 +00:00
Rusty Russell 7f75043ab2 lightningd: tighten interal json_stream API.
Move it closer to ccan/json_out, in preparation for using that as a
replacement.

In particular:

1. Add a 'quote' field in json_add_member.
2. json_add_member now always escapes if 'quote' is true.
3. json_member_direct is exposed to allow avoiding of escaping.
4. json_add_hex can use this, so no longer needs to be in json_stream.c.
5. We don't make JSON manually, but always use helpers.
6. We now flush the stream (wake reader) only when we close it, or mark
   command as pending.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2019-06-12 02:00:15 +00:00
trueptolemy 96135dab5e log: add 'warning' notification when log
- Related Changes for `warning` notification

Add a `bool` type parameter in `log_()` and `lov()`, this `bool` flag
 indicates if we should call `warning` notifier.

1) The process of copying `log_book` of every peer to the `log_book` of
`ld` is usually included in `log_()` and `lov()`, and it may lead to
repeated `warning` notification. So a `bool`, which explicitly indicates
if the `warning` notification is disabled during this call, is necessary
.
2) The `LOG_INFO` and `LOG_DEBUG` level don't need to call
warning, so set that `bool` paramater as `FALSE` for these log level and
only set it as `TRUE` for `LOG_UNUAUSL`/`LOG_BROKEN`. As for `LOG_IO`,
it use `log_io()` to log, so we needn't think about notifier for it.
2019-06-07 01:23:51 +00:00
darosior a6753fd812 Plugins: accept options of different types
A new struct containing the plugin options value as different types is created and appended to the plugin_option structure
2019-06-03 00:06:12 +00:00
darosior 5b0bf0ba1f jsonrpc: allow to set the command category plugin side 2019-06-03 00:02:25 +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
ZmnSCPxj 8ecc6c7743 lightningd/plugin.c: Do not call `closedir` with NULL DIR*.
Fixes: #2667

Really-by: @darwin
2019-05-23 17:45:57 -07:00
Rusty Russell 8b2a84a0c7 plugins: don't hand empty strings for unset options.
This was deeply surprising to me; there's a difference between a value not being
specified, and it being specified as "".

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2019-05-22 00:18:29 +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
lisa neigut f48fe03815 plugins: patch in empty string when no default given
If a plugin fails to pass in a default value for an option,
c-lightning crashes. this fixes the crash.

Patches #2515
2019-03-31 20:07:27 +02:00
Michael Schmoock 6f71564bdd fix: missing closedir in plugin.c 2019-03-06 23:27:07 +00:00
Rusty Russell e3bdc32ee8 plugin: give *some* clue in the logs of getmanifest raises an exception!
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2019-02-25 21:45:21 +00:00
Rusty Russell 53423e8a55 lightningd: re-enable IO logging for JSON output.
Hex format is terrible, but sometimes it's the only way to tell WTF is
going on.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2019-02-21 00:44:57 +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 53c0a21d2c plugins: get usage from plugins (required unless deprecated_apis == True).
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2019-02-07 20:33:50 +00:00
Rusty Russell 5770e0c700 jsonrpc: probe sites for usage information once, at start.
We store it in a strmap.  This means we call the jsonrpc handler earlier,
so all callers need to call param() before they do anything else; only
json_listaddrs and json_help needed fixing.

Plugins still use '[usage]' for now.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2019-02-07 20:33:50 +00: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