mirror of
https://github.com/ElementsProject/lightning.git
synced 2026-08-13 12:32:55 +02:00
We had an assert(!(ot->type & OPT_MULTI)) which crashed when using setconfig on a plugin option marked as both dynamic and multi. The fix changes plugin_set_dynamic_opt to accept an array of values (scalar options pass a 1-element array, multi options pass the complete set). For multi options, setconfig replaces ALL values atomically - an empty array clears them. Fixes: #8295 Changelog-Fixed: setconfig no longer crashes on dynamic multi-value plugin options
35 lines
1 KiB
Python
Executable file
35 lines
1 KiB
Python
Executable file
#!/usr/bin/env python3
|
|
"""Plugin for testing setconfig with multi-value dynamic options (issue #8295)."""
|
|
from pyln.client import Plugin, RpcException
|
|
from typing import Any, Optional
|
|
|
|
plugin = Plugin()
|
|
|
|
|
|
@plugin.method('dynamic-multi-report')
|
|
def report(plugin):
|
|
"""Report current values for the dynamic multi option."""
|
|
return {'test-multi-dynamic': plugin.get_option('test-multi-dynamic')}
|
|
|
|
|
|
def on_config_change(plugin, config: str, value: Optional[Any]) -> None:
|
|
"""Callback when config value changes."""
|
|
plugin.log(f"Setting config {config} to {value} (type: {type(value).__name__})")
|
|
if isinstance(value, list):
|
|
for v in value:
|
|
if v == 'reject-me':
|
|
raise RpcException("I don't like reject-me!")
|
|
elif value == 'reject-me':
|
|
raise RpcException("I don't like reject-me!")
|
|
|
|
|
|
plugin.add_option(
|
|
name="test-multi-dynamic",
|
|
description="A multi-value config option which can be changed at run-time",
|
|
default=None,
|
|
multi=True,
|
|
dynamic=True,
|
|
on_change=on_config_change,
|
|
)
|
|
|
|
plugin.run()
|