pyln-client: allow dynamic=True add_option to actually allow updates.

We didn't actually *change* the value you'd see, when we got a setconfig call!

Changelog-Added: pyln-client: implement setconfig hook for plugins so you can see changes in `dynamic` options.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2024-05-04 01:28:40 +09:30
parent ead211e5e4
commit 572ccac0e5
3 changed files with 10 additions and 3 deletions

View file

@ -974,11 +974,10 @@ class Plugin(object):
return self._exec_func(self.child_init, request)
return None
def _set_config(self, **_) -> None:
def _set_config(self, config: str, val: Optional[Any]) -> None:
"""Called when the value of a dynamic option is changed
For now we don't do anything.
"""
pass
self.options[config]['value'] = val
class PluginStream(object):

View file

@ -9,4 +9,10 @@ plugin.add_option(
default="initial",
dynamic=True)
@plugin.method('dynamic-option-report')
def record_lookup(plugin):
return {'test-dynamic-config': plugin.get_option('test-dynamic-config')}
plugin.run()

View file

@ -4314,8 +4314,10 @@ def test_dynamic_option_python_plugin(node_factory):
assert result["configs"]["test-dynamic-config"]["value_str"] == "initial"
assert ln.rpc.dynamic_option_report() == {'test-dynamic-config': 'initial'}
result = ln.rpc.setconfig("test-dynamic-config", "changed")
assert result["config"]["value_str"] == "changed"
assert ln.rpc.dynamic_option_report() == {'test-dynamic-config': 'changed'}
def test_renepay_not_important(node_factory):