reckless: improve config file handling

While loading the appropriate lightningconfig file, it is now checked
against the active config file in lightningd. Because a deviation from the
default file structure would not be possible, a -conf option is also added
to explicitly pass the lightningd config file into reckless.
This commit is contained in:
Alex Myers 2022-10-26 17:22:26 -05:00 committed by Christian Decker
parent 53ad1ee576
commit 2f4e862863
1 changed files with 20 additions and 13 deletions

View File

@ -541,8 +541,8 @@ def disable(plugin_name: str):
def load_config(reckless_dir: Union[str, None] = None, def load_config(reckless_dir: Union[str, None] = None,
network: str = 'bitcoin') -> Config: network: str = 'bitcoin') -> Config:
"""Initial directory discovery and config file creation.""" """Initial directory discovery and config file creation."""
# Does the lightning-cli already reference an explicit config?
net_conf = None net_conf = None
# Does the lightning-cli already reference an explicit config?
try: try:
active_config = lightning_cli('listconfigs', timeout=3) active_config = lightning_cli('listconfigs', timeout=3)
if 'conf' in active_config: if 'conf' in active_config:
@ -554,18 +554,20 @@ def load_config(reckless_dir: Union[str, None] = None,
else: else:
if not os.path.isabs(reckless_dir): if not os.path.isabs(reckless_dir):
reckless_dir = Path.cwd().joinpath(reckless_dir) reckless_dir = Path.cwd().joinpath(reckless_dir)
# Reckless applies to the bitcoin network configuration by default. if LIGHTNING_CONFIG:
if network == 'bitcoin': network_path = LIGHTNING_CONFIG
reck_conf_path = Path(reckless_dir).joinpath('bitcoin-reckless.conf') else:
if not net_conf: network_path = Path(LIGHTNING_DIR).joinpath(network, 'config')
# This config file inherits the RecklessConfig. reck_conf_path = Path(reckless_dir).joinpath(f'{network}-reckless.conf')
net_conf = LightningBitcoinConfig() if net_conf:
elif network == 'regtest': if str(network_path) != net_conf.conf_fp:
reck_conf_path = Path(reckless_dir).joinpath('regtest-reckless.conf') print('error: reckless configuration does not match lightningd:\n'
regtest_path = Path(LIGHTNING_DIR).joinpath('regtest', 'config') f'reckless network config path: {network_path}\n'
if not net_conf: f'lightningd active config: {net_conf.conf_fp}')
# Actually the regtest network config sys.exit(1)
net_conf = LightningBitcoinConfig(path=regtest_path) else:
# The network-specific config file (bitcoin by default)
net_conf = LightningBitcoinConfig(path=network_path)
# Reckless manages plugins here. # Reckless manages plugins here.
try: try:
reckless_conf = RecklessConfig(path=reck_conf_path) reckless_conf = RecklessConfig(path=reck_conf_path)
@ -650,6 +652,10 @@ if __name__ == '__main__':
help='lightning data directory (default:~/.lightning)', help='lightning data directory (default:~/.lightning)',
type=str, type=str,
default=Path.home().joinpath('.lightning')) default=Path.home().joinpath('.lightning'))
parser.add_argument('-c', '--conf',
help=' config file used by lightningd',
type=str,
default=None)
parser.add_argument('-r', '--regtest', action='store_true') parser.add_argument('-r', '--regtest', action='store_true')
parser.add_argument('-v', '--verbose', action='store_true') parser.add_argument('-v', '--verbose', action='store_true')
cmd1 = parser.add_subparsers(dest='cmd1', help='command', cmd1 = parser.add_subparsers(dest='cmd1', help='command',
@ -711,6 +717,7 @@ if __name__ == '__main__':
RECKLESS_DIR = args.reckless_dir RECKLESS_DIR = args.reckless_dir
else: else:
RECKLESS_DIR = Path(LIGHTNING_DIR).joinpath('reckless') RECKLESS_DIR = Path(LIGHTNING_DIR).joinpath('reckless')
LIGHTNING_CONFIG = args.conf
RECKLESS_CONFIG = load_config(reckless_dir=RECKLESS_DIR, RECKLESS_CONFIG = load_config(reckless_dir=RECKLESS_DIR,
network=NETWORK) network=NETWORK)
RECKLESS_SOURCES = loadSources() RECKLESS_SOURCES = loadSources()