common: allow configvars to be marked dynamic.

To test, we do min-capacity-sat which is simple.  We also update the
listconfigs man page which contained some obsolete information.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2023-06-05 23:48:21 +09:30
parent 9f9f2f1493
commit aca893f1eb
5 changed files with 36 additions and 5 deletions

View File

@@ -58,6 +58,8 @@ struct configvar {
#define OPT_SHOWMSATS (1 << (OPT_USER_START+4)) #define OPT_SHOWMSATS (1 << (OPT_USER_START+4))
/* listconfigs should treat as a literal boolean `true` or `false` */ /* listconfigs should treat as a literal boolean `true` or `false` */
#define OPT_SHOWBOOL (1 << (OPT_USER_START+5)) #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 */ /* Use this instead of opt_register_*_arg if you want OPT_* from above */
#define clnopt_witharg(names, type, cb, show, arg, desc) \ #define clnopt_witharg(names, type, cb, show, arg, desc) \

View File

@@ -9,12 +9,27 @@ SYNOPSIS
DESCRIPTION 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 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 EXAMPLE JSON REQUEST
-------------------- --------------------
@@ -177,6 +192,7 @@ On success, an object is returned, containing:
- **min-capacity-sat** (object, optional): - **min-capacity-sat** (object, optional):
- **value\_int** (u64): field from config or cmdline, or default - **value\_int** (u64): field from config or cmdline, or default
- **source** (string): source of configuration setting - **source** (string): source of configuration setting
- **dynamic** (boolean, optional): Can this be set by setconfig() (always *true*)
- **addr** (object, optional): - **addr** (object, optional):
- **values\_str** (array of strings): - **values\_str** (array of strings):
- field from config or cmdline - field from config or cmdline
@@ -447,4 +463,4 @@ RESOURCES
Main web site: <https://github.com/ElementsProject/lightning> Main web site: <https://github.com/ElementsProject/lightning>
[comment]: # ( SHA256STAMP:2b3588b395919162c122cd386f0f4b320d906d0190e706bfa1b68db4126e7ee2) [comment]: # ( SHA256STAMP:0440e4634e4a28681323f891307c7bb61143aacad4824f952f24f027a7543835)

View File

@@ -834,6 +834,13 @@
"source": { "source": {
"type": "string", "type": "string",
"description": "source of configuration setting" "description": "source of configuration setting"
},
"dynamic": {
"type": "boolean",
"enum": [
true
],
"description": "Can this be set by setconfig()"
} }
} }
}, },

View File

@@ -143,6 +143,8 @@ static void json_add_config(struct lightningd *ld,
json_add_bool(response, "set", cv != NULL); json_add_bool(response, "set", cv != NULL);
json_add_source(response, "source", cv); json_add_source(response, "source", cv);
json_add_config_plugin(response, ld->plugins, "plugin", ot); json_add_config_plugin(response, ld->plugins, "plugin", ot);
if (ot->type & OPT_DYNAMIC)
json_add_bool(response, "dynamic", true);
json_object_end(response); json_object_end(response);
return; return;
} }
@@ -167,6 +169,8 @@ static void json_add_config(struct lightningd *ld,
} }
json_array_end(response); json_array_end(response);
json_add_config_plugin(response, ld->plugins, "plugin", ot); json_add_config_plugin(response, ld->plugins, "plugin", ot);
if (ot->type & OPT_DYNAMIC)
json_add_bool(response, "dynamic", true);
json_object_end(response); json_object_end(response);
return; return;
} }
@@ -180,6 +184,8 @@ static void json_add_config(struct lightningd *ld,
json_add_configval(response, configval_fieldname(ot), ot, val); json_add_configval(response, configval_fieldname(ot), ot, val);
json_add_source(response, "source", cv); json_add_source(response, "source", cv);
json_add_config_plugin(response, ld->plugins, "plugin", ot); json_add_config_plugin(response, ld->plugins, "plugin", ot);
if (ot->type & OPT_DYNAMIC)
json_add_bool(response, "dynamic", true);
json_object_end(response); json_object_end(response);
} }

View File

@@ -1352,7 +1352,7 @@ static void register_opts(struct lightningd *ld)
opt_set_msat, opt_set_msat,
opt_show_msat, &ld->config.max_dust_htlc_exposure_msat, opt_show_msat, &ld->config.max_dust_htlc_exposure_msat,
"Max HTLC amount that can be trimmed"); "Max HTLC amount that can be trimmed");
clnopt_witharg("--min-capacity-sat", OPT_SHOWINT, opt_set_u64, opt_show_u64, clnopt_witharg("--min-capacity-sat", OPT_SHOWINT|OPT_DYNAMIC, opt_set_u64, opt_show_u64,
&ld->config.min_capacity_sat, &ld->config.min_capacity_sat,
"Minimum capacity in satoshis for accepting channels"); "Minimum capacity in satoshis for accepting channels");
clnopt_witharg("--addr", OPT_MULTI, opt_add_addr, NULL, clnopt_witharg("--addr", OPT_MULTI, opt_add_addr, NULL,