Commit Graph

33 Commits

Author SHA1 Message Date
Christian Decker 77ad5525f5 cln-plugin: Re-export anyhow::anyhow macro
For now this makes reporting an error from plugins much simpler for
now.

Changelog-None
2022-12-24 11:32:22 +01:00
Vincenzo Palazzo 6c1e589ee8 cln-plugin: make available the configuration in plugin
There are several cases where you want to access to the configuration,
and given the nature of the rust API, there is no way to access to
the `configuration` field at any point after the configuration logic.

Suggested-by: Sergi Delgado Segura <@sr-gi>

Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
2022-12-24 11:32:22 +01:00
Sergi Delgado Segura 6939671a1b Adds helper functions to cast Value variants
This is heavily based on https://github.com/serde-rs/json/blob/master/src/value/mod.rs
2022-12-21 10:56:13 +01:00
Christian Decker 3d311c96b1 cln-plugin: Adjust visibility of some internals 2022-11-25 16:48:33 +01:00
Christian Decker db62d542e1 cln-plugin: Make the configuration in `init` public
It was set to crate level visibility for some reason, not all that
helpful :-)

Suggested-by: Sergi Delgado Segura <@sr-gi>
2022-11-25 16:48:33 +01:00
Rusty Russell ece77840f9 pyln-client, libplugin, rust cln-plugin: explicitly flag that we allow non-numeric JSON ids.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-11-21 11:23:54 +01:00
Justin Moon f111d6772d Plugin config options with no defaults 2022-11-03 11:28:22 +01:00
Christian Decker e1fc88ff70 cln-plugin: Prep the logging payload in a let
I wanted to debug why we weren't getting some log messages, and this
makes that a bit easier in future.
2022-09-25 15:13:12 +02:00
Christian Decker 064a5a6940 cln-plugin: Add log filtering support
We filter based on the environment variable `CLN_PLUGIN_LOG`,
defaulting to `info` as that is not as noisy as `debug` or `trace`, at
least libraries will not spam us too heavily.

Changelog-Added cln-plugin: The logs level from cln-plugins can be configured by the `CLN_PLUGIN_LOG` environment variable.
2022-09-25 15:13:12 +02:00
Christian Decker 8898511cf6 cln-plugin: Defer binding the plugin state until after configuring
We had a bit of a chicken-and-egg problem, where we instantiated the
`state` to be managed by the `Plugin` during the very first step when
creating the `Builder`, but then the state might depend on the
configuration we only get later. This would force developers to add
placeholders in the form of `Option` into the state, when really
they'd never be none after configuring.

This defers the binding until after we get the configuration and
cleans up the semantics:

 - `Builder`: declare options, hooks, etc
 - `ConfiguredPlugin`: we have exchanged the handshake with
   `lightningd`, now we can construct the `state` accordingly
 - `Plugin`: Running instance of the plugin

Changelog-Changed: cln-plugin: Moved the state binding to the plugin until after the configuration step
2022-09-25 15:13:12 +02:00
Rusty Russell ce0b765c96 cln-rpc: allow id to be any token.
Suggested-by: @cdecker
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-09-16 12:31:45 +09:30
Christian Decker 1efa5c37be cln-plugin: Notify waiting tasks if the lightningd connection closes
This is usually a signal that lightningd is shutting down, so notify
any instance that is waiting on `plugin.join()`.

Changelog-Fixed: cln-plugin: Fixed an issue where plugins would hang indefinitely despite `lightningd` closing the connection
2022-07-21 14:19:06 +09:30
Justin Moon 42783aaa92 cln_plugin: Configure "dynamic" field in "getmanifest" message 2022-07-11 11:05:50 +02:00
Christian Decker e6442d798e cln-plugin: Make the proxy-related configuration Option<>
These are only populated if a proxy was specified, see
lightningd/plugin.c:1855, so we were getting upset when we expected
them and they weren't set.
2022-06-22 12:07:55 +02:00
Justin Moon 5ec424bc86 cln-plugin: Configuration struct
Represents the "configuration" part of the "init" message during
plugin initialization.

Changelog-Added: cln_plugin: persist cln configuration from init msg
2022-06-22 12:07:55 +02:00
Justin Moon 318b6e803e cln-plugin: Add unittest for parsing "init" message 2022-06-22 12:07:55 +02:00
Justin Moon 14483901cd cln-plugin: Save "configuration" from "init" method 2022-06-22 12:07:55 +02:00
Christian Decker b359a24772 cln-plugin: Handle --help invocations better
We now have ternary outcomes for `Builder.configure()` and
`Builder.start()`:

 - Ok(Some(p)) means we were configured correctly, and can continue
   with our work normally
 - Ok(None) means that `lightningd` was invoked with `--help`, we
   weren't configured (which is not an error since the `lightningd` just
   implicitly told us to shut down) and user code should clean up and
   exit as well
 - Err(e) something went wrong, user code may report an error and exit.
2022-04-11 15:20:32 +09:30
Christian Decker 8717c4e5a2 cln-grpc: Add midstate between configuration and replying to init
This is a bit special, in that it allows us to configure the plugin,
but then still abort startup by sending `init` with the `disable` flag
set.
2022-04-10 14:16:35 +09:30
Christian Decker 767da45037 cln-grpc: Do not log an error when called with `--help`
Changelog-None
2022-04-08 11:30:10 +09:30
Rusty Russell 836c1b805b doc: update c-lightning to Core Lightning almost everywhere.
Mostly comments and docs: some places are actually paths, which
I have avoided changing.  We may migrate them slowly, particularly
when they're user-visible.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-04-07 06:53:26 +09:30
Christian Decker dd66c85fcb grpc-plugin: Make the grpc port to listen on configurable
Changelog-Added: cln-grpc-plugin: The plugin can be configured to listen on a specific port using the `grpc-port` option
2022-03-30 12:15:55 +10:30
Christian Decker 6706384c50 cln-plugin: Ensure we cleanly shut down when we lose the master conn 2022-03-10 10:21:41 +10:30
Christian Decker 1bd2b8c9f7 cln-plugin: Make notification handlers asynchronous 2022-03-10 10:21:41 +10:30
Christian Decker af4eed3787 cln-plugin: Make hooks asynchronous 2022-03-10 10:21:41 +10:30
Christian Decker a7ef38732f cln-plugin: Make rpcmethod handlers async 2022-03-10 10:21:41 +10:30
Christian Decker 60e773239c cln-plugin: Add notification subscriptions and hooks to the plugins
For now hooks are treated identically to rpcmethods, with the
exception of not being returned in the `getmanifest` call. Later on we
can add typed handlers as well.
2022-03-10 10:21:41 +10:30
Christian Decker 8c6af21169 cln-plugin: Add support for synchronous RPC methods
Changelog-Experimental: cln-plugin: Added support for non-async RPC method passthrough (async support coming soon)
2022-03-10 10:21:41 +10:30
Christian Decker 22618a2f94 cln-plugin: Rework the plugin library using a Builder 2022-03-10 10:21:41 +10:30
Christian Decker fbcb4c33ad cln-plugin: Populate the options when we get an `init` call 2022-03-10 10:21:41 +10:30
Christian Decker 249fa8675a cln-plugin: Add options to the `getmanifest` call 2022-03-10 10:21:41 +10:30
Christian Decker f5e1829117 cln-plugin: Implement logging facade adapter for cln plugins
We wrap emitted messages into a JSON-RPC notification envelope and
write them to stdout. We use an indirection over an mpsc channel in
order to avoid deadlocks if we emit logs while holding the writer lock
on stdout.
2022-03-10 10:21:41 +10:30
Christian Decker 9ae1f33992 cln-plugin: Get started with the plugin interface 2022-03-10 10:21:41 +10:30