From 651c5b6de039e9cc92be48c7c4d277932d5ca665 Mon Sep 17 00:00:00 2001 From: Alex Myers Date: Tue, 18 Oct 2022 17:24:10 -0500 Subject: [PATCH] reckless: use config that was explicitly passed to lightningd Regtest environments commonly use explicit definition of the config file for lightningd. This can be queried and utilized by default, saving redundant definitions between lightning and reckless. --- tools/reckless | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/tools/reckless b/tools/reckless index fda32eaa8..53351a8f2 100755 --- a/tools/reckless +++ b/tools/reckless @@ -538,6 +538,18 @@ def disable(plugin_name): def load_config(reckless_dir=None, network='bitcoin'): """Initial directory discovery and config file creation.""" + # Does the lightning-cli already reference an explicit config? + net_conf = None + if lightning_cli_available(): + cmd = LIGHTNING_CLI_CALL + cmd.extend(['listconfigs']) + clncli = Popen(cmd, stdout=PIPE, stderr=PIPE) + clncli.wait(timeout=3) + if clncli.returncode == 0: + output = json.loads(clncli.stdout.read().decode() + .replace('\n', '').replace(' ', '')) + if 'conf' in output: + net_conf = LightningBitcoinConfig(path=output['conf']) if reckless_dir is None: reckless_dir = str(os.path.join(LIGHTNING_DIR, 'reckless')) else: @@ -546,13 +558,15 @@ def load_config(reckless_dir=None, network='bitcoin'): # Reckless applies to the bitcoin network configuration by default. if network == 'bitcoin': reck_conf_path = os.path.join(reckless_dir, 'bitcoin-reckless.conf') - # This config file inherits the RecklessConfig. - net_conf = LightningBitcoinConfig() + if not net_conf: + # This config file inherits the RecklessConfig. + net_conf = LightningBitcoinConfig() elif network == 'regtest': reck_conf_path = os.path.join(reckless_dir, 'regtest-reckless.conf') regtest_path = os.path.join(LIGHTNING_DIR, 'regtest', 'config') - # Actually the regtest network config - net_conf = LightningBitcoinConfig(path=regtest_path) + if not net_conf: + # Actually the regtest network config + net_conf = LightningBitcoinConfig(path=regtest_path) # Reckless manages plugins here. reckless_conf = RecklessConfig(path=reck_conf_path) if not reckless_conf: