Skip to content

Commit 3ac949d

Browse files
committed
listconfigs: add plugin field if config is for a plugin.
I chose the full path name, not just the basename. Suggested-by: @SimonVrouwe Signed-off-by: Rusty Russell <[email protected]>
1 parent 6275dd3 commit 3ac949d

File tree

7 files changed

+45
-1
lines changed

7 files changed

+45
-1
lines changed

doc/lightning-listconfigs.7.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ On success, an object is returned, containing:
4545
- **disable-mpp** (object, optional):
4646
- **set** (boolean): `true` if set in config or cmdline
4747
- **source** (string): source of configuration setting
48+
- **plugin** (string, optional): plugin which registered this configuration setting
4849
- **mainnet** (object, optional):
4950
- **set** (boolean): `true` if set in config or cmdline
5051
- **source** (string): source of configuration setting
@@ -446,4 +447,4 @@ RESOURCES
446447

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

449-
[comment]: # ( SHA256STAMP:1702f7c62fe10d63612fbbf56eeaf043cdfef6fa874d4fdbdcb81bbbbe5c98d8)
450+
[comment]: # ( SHA256STAMP:2b3588b395919162c122cd386f0f4b320d906d0190e706bfa1b68db4126e7ee2)

doc/schemas/listconfigs.schema.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@
6565
"source": {
6666
"type": "string",
6767
"description": "source of configuration setting"
68+
},
69+
"plugin": {
70+
"type": "string",
71+
"description": "plugin which registered this configuration setting"
6872
}
6973
}
7074
},

lightningd/options.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2066,6 +2066,7 @@ static void json_add_config(struct lightningd *ld,
20662066
json_object_start(response, names[0]);
20672067
json_add_bool(response, "set", cv != NULL);
20682068
json_add_source(response, "source", cv);
2069+
json_add_config_plugin(response, ld->plugins, "plugin", ot);
20692070
json_object_end(response);
20702071
return;
20712072
}
@@ -2089,6 +2090,7 @@ static void json_add_config(struct lightningd *ld,
20892090
json_add_source(response, NULL, cv);
20902091
}
20912092
json_array_end(response);
2093+
json_add_config_plugin(response, ld->plugins, "plugin", ot);
20922094
json_object_end(response);
20932095
return;
20942096
}
@@ -2101,6 +2103,7 @@ static void json_add_config(struct lightningd *ld,
21012103
json_object_start(response, names[0]);
21022104
json_add_configval(response, configval_fieldname(ot), ot, val);
21032105
json_add_source(response, "source", cv);
2106+
json_add_config_plugin(response, ld->plugins, "plugin", ot);
21042107
json_object_end(response);
21052108
}
21062109

lightningd/plugin.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1366,6 +1366,29 @@ static struct plugin_opt *plugin_opt_find(const struct plugin *plugin,
13661366
return NULL;
13671367
}
13681368

1369+
void json_add_config_plugin(struct json_stream *stream,
1370+
const struct plugins *plugins,
1371+
const char *fieldname,
1372+
const struct opt_table *ot)
1373+
{
1374+
struct plugin *plugin;
1375+
1376+
/* Shortcut */
1377+
if (!is_plugin_opt(ot))
1378+
return;
1379+
1380+
/* Find the plugin that registered this RPC call */
1381+
list_for_each(&plugins->plugins, plugin, list) {
1382+
struct plugin_opt *popt = plugin_opt_find(plugin, ot->names+2);
1383+
if (popt) {
1384+
json_add_string(stream, fieldname, plugin->cmd);
1385+
return;
1386+
}
1387+
}
1388+
1389+
/* Reaching here is possible, if a plugin was stopped! */
1390+
}
1391+
13691392
/* Start command might have included plugin-specific parameters.
13701393
* We make sure they *are* parameters for this plugin, then add them
13711394
* to our configvars. */

lightningd/plugin.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,4 +358,11 @@ void plugins_set_builtin_plugins_dir(struct plugins *plugins,
358358

359359
/* Is this option for a plugin? */
360360
bool is_plugin_opt(const struct opt_table *ot);
361+
362+
/* Add this field if this ot is owned by a plugin */
363+
void json_add_config_plugin(struct json_stream *stream,
364+
const struct plugins *plugins,
365+
const char *fieldname,
366+
const struct opt_table *ot);
367+
361368
#endif /* LIGHTNING_LIGHTNINGD_PLUGIN_H */

tests/test_misc.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -738,6 +738,7 @@ def test_listconfigs(node_factory, bitcoind, chainparams):
738738
c = configs[name]
739739
assert c['source'] == 'cmdline'
740740
assert c[valfield] == val
741+
assert 'plugin' not in c
741742

742743
# These are aliases, but we don't print the (unofficial!) wumbo.
743744
assert 'wumbo' not in configs

tests/test_plugin.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2441,6 +2441,7 @@ def test_dynamic_args(node_factory):
24412441

24422442
assert l1.rpc.call("hello") == "Test arg parsing world"
24432443
assert l1.rpc.listconfigs('greeting')['configs']['greeting']['value_str'] == 'Test arg parsing'
2444+
assert l1.rpc.listconfigs('greeting')['configs']['greeting']['plugin'] == plugin_path
24442445

24452446
l1.rpc.plugin_stop(plugin_path)
24462447
assert 'greeting' not in l1.rpc.listconfigs()['configs']
@@ -4166,6 +4167,7 @@ def test_plugin_persist_option(node_factory):
41664167
c = l1.rpc.listconfigs('greeting')['configs']['greeting']
41674168
assert c['source'] == "cmdline"
41684169
assert c['value_str'] == "Static option"
4170+
assert c['plugin'] == plugin_path
41694171
l1.rpc.plugin_stop(plugin_path)
41704172
assert 'greeting' not in l1.rpc.listconfigs()['configs']
41714173

@@ -4174,6 +4176,7 @@ def test_plugin_persist_option(node_factory):
41744176
c = l1.rpc.listconfigs('greeting')['configs']['greeting']
41754177
assert c['source'] == "cmdline"
41764178
assert c['value_str'] == "Static option"
4179+
assert c['plugin'] == plugin_path
41774180
assert l1.rpc.call("hello") == "Static option world"
41784181
l1.rpc.plugin_stop(plugin_path)
41794182
assert 'greeting' not in l1.rpc.listconfigs()['configs']
@@ -4183,6 +4186,7 @@ def test_plugin_persist_option(node_factory):
41834186
c = l1.rpc.listconfigs('greeting')['configs']['greeting']
41844187
assert c['source'] == "pluginstart"
41854188
assert c['value_str'] == "Dynamic option"
4189+
assert c['plugin'] == plugin_path
41864190
assert l1.rpc.call("hello") == "Dynamic option world"
41874191
l1.rpc.plugin_stop(plugin_path)
41884192
assert 'greeting' not in l1.rpc.listconfigs()['configs']
@@ -4192,4 +4196,5 @@ def test_plugin_persist_option(node_factory):
41924196
c = l1.rpc.listconfigs('greeting')['configs']['greeting']
41934197
assert c['source'] == "cmdline"
41944198
assert c['value_str'] == "Static option"
4199+
assert c['plugin'] == plugin_path
41954200
assert l1.rpc.call("hello") == "Static option world"

0 commit comments

Comments
 (0)