Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

setconfig: new command to set (a few!) config parameters dynamically #6303

Merged
merged 12 commits into from
Jun 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions common/configvar.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ struct configvar {
#define OPT_SHOWMSATS (1 << (OPT_USER_START+4))
/* listconfigs should treat as a literal boolean `true` or `false` */
#define OPT_SHOWBOOL (1 << (OPT_USER_START+5))
/* Can be changed at runtime */
#define OPT_DYNAMIC (1 << (OPT_USER_START+6))

/* Use this instead of opt_register_*_arg if you want OPT_* from above */
#define clnopt_witharg(names, type, cb, show, arg, desc) \
Expand Down
1 change: 1 addition & 0 deletions doc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ MANPAGES := doc/lightning-cli.1 \
doc/lightning-sendonionmessage.7 \
doc/lightning-sendpay.7 \
doc/lightning-setchannel.7 \
doc/lightning-setconfig.7 \
doc/lightning-setpsbtversion.7 \
doc/lightning-sendcustommsg.7 \
doc/lightning-signinvoice.7 \
Expand Down
10 changes: 3 additions & 7 deletions doc/PLUGINS.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ example:
"type": "string",
"default": "World",
"description": "What name should I call you?",
"deprecated": false
"deprecated": false,
"dynamic": false
}
],
"rpcmethods": [
Expand Down Expand Up @@ -143,7 +144,7 @@ example:
During startup the `options` will be added to the list of command line options that
`lightningd` accepts. If any `options` "name" is already taken startup will abort. The above will add a `--greeting` option with a
default value of `World` and the specified description. *Notice that
currently string, integers, bool, and flag options are supported.*
currently string, integers, bool, and flag options are supported.* If an option specifies `dynamic`: `true`, then it should allow a `setvalue` call for that option after initialization.

The `rpcmethods` are methods that will be exposed via `lightningd`'s
JSON-RPC over Unix-Socket interface, just like the builtin
Expand Down Expand Up @@ -254,11 +255,6 @@ Here's an example option set, as sent in response to `getmanifest`
],
```

**Note**: `lightningd` command line options are only parsed during startup and their
values are not remembered when the plugin is stopped or killed.
For dynamic plugins started with `plugin start`, options can be
passed as extra arguments to that [command][lightning-plugin].


#### Custom notifications

Expand Down
1 change: 1 addition & 0 deletions doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ Core Lightning Documentation
lightning-sendpay <lightning-sendpay.7.md>
lightning-sendpsbt <lightning-sendpsbt.7.md>
lightning-setchannel <lightning-setchannel.7.md>
lightning-setconfig <lightning-setconfig.7.md>
lightning-setpsbtversion <lightning-setpsbtversion.7.md>
lightning-signinvoice <lightning-signinvoice.7.md>
lightning-signmessage <lightning-signmessage.7.md>
Expand Down
24 changes: 20 additions & 4 deletions doc/lightning-listconfigs.7.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,27 @@ SYNOPSIS
DESCRIPTION
-----------

*config* (optional) is a configuration option name, or "plugin" to show plugin options
*config* (optional) is a configuration option name to restrict return.

The **listconfigs** RPC command to list all configuration options, or with *config* only a selection.
The **listconfigs** RPC command to list all configuration options, or with *config* only one.

The returned values reflect the current configuration, including
showing default values (`dev-` options are not shown).
showing default values (`dev-` options are not shown unless specified as *config* explicitly).

Note: as plugins can add options, not all configuration settings are
listed here! The format of each entry is as follows:

- **source** (string): source of configuration setting (`file`:`linenum`)
- **dynamic** (boolean, optional): true if this option is settable via setconfig
- **plugin** (string, optional): set if this is from a plugin

Depending on the option type, exactly one of the following is present:

- **set** (boolean, optional): for simple flag options
- **value\_str** (string, optional): for string options
- **value\_msat** (msat, optional): for msat options
- **value\_int** (integer, optional): for integer options
- **value\_bool** (boolean, optional): for boolean options

EXAMPLE JSON REQUEST
--------------------
Expand Down Expand Up @@ -177,6 +192,7 @@ On success, an object is returned, containing:
- **min-capacity-sat** (object, optional):
- **value\_int** (u64): field from config or cmdline, or default
- **source** (string): source of configuration setting
- **dynamic** (boolean, optional): Can this be set by setconfig() (always *true*)
- **addr** (object, optional):
- **values\_str** (array of strings):
- field from config or cmdline
Expand Down Expand Up @@ -447,4 +463,4 @@ RESOURCES

Main web site: <https://github.com/ElementsProject/lightning>

[comment]: # ( SHA256STAMP:2b3588b395919162c122cd386f0f4b320d906d0190e706bfa1b68db4126e7ee2)
[comment]: # ( SHA256STAMP:0440e4634e4a28681323f891307c7bb61143aacad4824f952f24f027a7543835)
59 changes: 59 additions & 0 deletions doc/lightning-setconfig.7.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
lightning-setconfig -- Dynamically change some config options
=============================================================

SYNOPSIS
--------

**setconfig** *config* [*val*]

DESCRIPTION
-----------

The **setconfig** RPC command allows you set the (dynamic) configuration option named by `config`: options which take a value (as separate from simple flag options) also need a `val` parameter.

This new value will *also* be written at the end of the config file, for persistence across restarts (and any old value commented out).

You can see what options are dynamically adjustable using lightning-listconfigs(7). Note that you can also adjust existing options for stopped plugins; they will have an effect when the plugin is restarted.


RETURN VALUE
------------

[comment]: # (GENERATE-FROM-SCHEMA-START)
On success, an object containing **config** is returned. It is an object containing:

- **config** (string): name of the config variable which was set
- **source** (string): source of configuration setting (`file`:`linenum`)
- **dynamic** (boolean): whether this option is settable via setconfig (always *true*)
- **plugin** (string, optional): the plugin this configuration setting is for
- **set** (boolean, optional): for simple flag options
- **value\_str** (string, optional): for string options
- **value\_msat** (msat, optional): for msat options
- **value\_int** (integer, optional): for integer options
- **value\_bool** (boolean, optional): for boolean options

[comment]: # (GENERATE-FROM-SCHEMA-END)

ERRORS
------

The following error codes may occur:
- -32602: JSONRPC2\_INVALID\_PARAMS, i.e. the parameter is not dynamic, or the val was invalid.

AUTHOR
------

Rusty Russell <<rusty@rustcorp.com.au>> is mainly responsible for this
feature.

SEE ALSO
--------

lightningd-config(5), lightning-listconfigs(7)

RESOURCES
---------

Main web site: <https://github.com/ElementsProject/lightning>

[comment]: # ( SHA256STAMP:d61e4e6eea7b8c214644334ee194b273aef2a8a26465adfcd685be0d70653966)
18 changes: 10 additions & 8 deletions doc/lightningd-config.5.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ file (default: **$HOME/.lightning/config**) then a network-specific
configuration file (default: **$HOME/.lightning/testnet/config**). This can
be changed: see *--conf* and *--lightning-dir*.

Note that some configuration options, marked *dynamic*m can be changed at runtime: see lightning-setconfig(7).

General configuration files are processed first, then network-specific
ones, then command line options: later options override earlier ones
except *addr* options and *log-level* with subsystems, which
Expand Down Expand Up @@ -316,7 +318,7 @@ millionths, so 10000 is 1%, 1000 is 0.1%. Changing this value will only
affect new channels and not existing ones. If you want to change fees
for existing channels, use the RPC call lightning-setchannel(7).

* **min-capacity-sat**=*SATOSHI*
* **min-capacity-sat**=*SATOSHI* [*dynamic*]

Default: 10000. This value defines the minimal effective channel
capacity in satoshi to accept for channel opening requests. This will
Expand Down Expand Up @@ -440,32 +442,32 @@ accepted, and ignored.

### Cleanup control options:

* **autoclean-cycle**=*SECONDS* [plugin `autoclean`]
* **autoclean-cycle**=*SECONDS* [plugin `autoclean`, *dynamic*]

Perform search for things to clean every *SECONDS* seconds (default
3600, or 1 hour, which is usually sufficient).

* **autoclean-succeededforwards-age**=*SECONDS* [plugin `autoclean`]
* **autoclean-succeededforwards-age**=*SECONDS* [plugin `autoclean`, *dynamic*]

How old successful forwards (`settled` in listforwards `status`) have to be before deletion (default 0, meaning never).

* **autoclean-failedforwards-age**=*SECONDS* [plugin `autoclean`]
* **autoclean-failedforwards-age**=*SECONDS* [plugin `autoclean`, *dynamic*]

How old failed forwards (`failed` or `local_failed` in listforwards `status`) have to be before deletion (default 0, meaning never).

* **autoclean-succeededpays-age**=*SECONDS* [plugin `autoclean`]
* **autoclean-succeededpays-age**=*SECONDS* [plugin `autoclean`, *dynamic*]

How old successful payments (`complete` in listpays `status`) have to be before deletion (default 0, meaning never).

* **autoclean-failedpays-age**=*SECONDS* [plugin `autoclean`]
* **autoclean-failedpays-age**=*SECONDS* [plugin `autoclean`, *dynamic*]

How old failed payment attempts (`failed` in listpays `status`) have to be before deletion (default 0, meaning never).

* **autoclean-paidinvoices-age**=*SECONDS* [plugin `autoclean`]
* **autoclean-paidinvoices-age**=*SECONDS* [plugin `autoclean`, *dynamic*]

How old invoices which were paid (`paid` in listinvoices `status`) have to be before deletion (default 0, meaning never).

* **autoclean-expiredinvoices-age**=*SECONDS* [plugin `autoclean`]
* **autoclean-expiredinvoices-age**=*SECONDS* [plugin `autoclean`, *dynamic*]

How old invoices which were not paid (and cannot be) (`expired` in listinvoices `status`) before deletion (default 0, meaning never).

Expand Down
7 changes: 7 additions & 0 deletions doc/schemas/listconfigs.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -834,6 +834,13 @@
"source": {
"type": "string",
"description": "source of configuration setting"
},
"dynamic": {
"type": "boolean",
"enum": [
true
],
"description": "Can this be set by setconfig()"
}
}
},
Expand Down
15 changes: 15 additions & 0 deletions doc/schemas/setconfig.request.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"additionalProperties": false,
"required": [
"config"
],
"added": "v23.08",
"properties": {
"config": {
"type": "string"
},
"val": {}
}
}
62 changes: 62 additions & 0 deletions doc/schemas/setconfig.schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"additionalProperties": false,
"added": "v23.08",
"required": [
"config"
],
"properties": {
"config": {
"type": "object",
"description": "config settings after completion",
"additionalProperties": false,
"required": [
"config",
"source",
"dynamic"
],
"properties": {
"config": {
"type": "string",
"description": "name of the config variable which was set"
},
"source": {
"type": "string",
"description": "source of configuration setting (`file`:`linenum`)"
},
"plugin": {
"type": "string",
"description": "the plugin this configuration setting is for"
},
"dynamic": {
"type": "boolean",
"enum": [
true
],
"description": "whether this option is settable via setconfig"
},
"set": {
"type": "boolean",
"description": "for simple flag options"
},
"value_str": {
"type": "string",
"description": "for string options"
},
"value_msat": {
"type": "msat",
"description": "for msat options"
},
"value_int": {
"type": "integer",
"description": "for integer options"
},
"value_bool": {
"type": "boolean",
"description": "for boolean options"
}
}
}
}
}
1 change: 1 addition & 0 deletions lightningd/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ LIGHTNINGD_SRC := \
lightningd/watch.c

LIGHTNINGD_SRC_NOHDR := \
lightningd/configs.c \
lightningd/datastore.c \
lightningd/ping.c \
lightningd/offer.c \
Expand Down
Loading