From f19336e4de773a6a27f16e6a9f525241fec474cd Mon Sep 17 00:00:00 2001 From: Carlos Ruz Date: Mon, 21 Oct 2024 18:00:07 -0600 Subject: [PATCH] sauron: prepare for mutinynet support Co-authored-by: iorch --- sauron/.gitignore | 1 + sauron/README.md | 8 ++++++++ sauron/requirements.txt | 2 +- sauron/sauron.py | 15 ++++++++------- 4 files changed, 18 insertions(+), 8 deletions(-) create mode 100644 sauron/.gitignore diff --git a/sauron/.gitignore b/sauron/.gitignore new file mode 100644 index 000000000..21d0b898f --- /dev/null +++ b/sauron/.gitignore @@ -0,0 +1 @@ +.venv/ diff --git a/sauron/README.md b/sauron/README.md index d02dbe10e..ce023c808 100644 --- a/sauron/README.md +++ b/sauron/README.md @@ -24,6 +24,14 @@ Here is a fully reptilian example running against [blockstream.info](https://blo lightningd --mainnet --disable-plugin bcli --plugin $PWD/sauron.py --sauron-api-endpoint https://blockstream.info/api/ ``` + +Here is an example running against [mutinynet.com](https://mutinynet.com/): + +``` +lightningd --signet --disable-plugin bcli --plugin $PWD/sauron.py --sauron-api-endpoint https://mutinynet.com/api/ +``` + + You can use also proxy your requests through [Tor](https://www.torproject.org/) by specifying a SOCKS proxy to use with the `--sauron-tor-proxy` startup option, in the form `address:port`. diff --git a/sauron/requirements.txt b/sauron/requirements.txt index 1794cb833..7fd22f35e 100644 --- a/sauron/requirements.txt +++ b/sauron/requirements.txt @@ -1,2 +1,2 @@ -pyln-client>=23.2 +pyln-client>=23.2,<=24.5 requests[socks]>=2.23.0 diff --git a/sauron/sauron.py b/sauron/sauron.py index 3e2e34c9a..1033a999e 100755 --- a/sauron/sauron.py +++ b/sauron/sauron.py @@ -40,8 +40,8 @@ def fetch(url): @plugin.init() -def init(plugin, options, configuration, **kwargs): - plugin.api_endpoint = options["sauron-api-endpoint"] +def init(plugin, options, **kwargs): + plugin.api_endpoint = options.get("sauron-api-endpoint", None) if not plugin.api_endpoint: raise SauronError("You need to specify the sauron-api-endpoint option.") sys.exit(1) @@ -55,7 +55,8 @@ def init(plugin, options, configuration, **kwargs): } plugin.log("Using proxy {} for requests".format(socks5_proxy)) - plugin.log("Sauron plugin initialized") + api = "mempool.space" if "mutinynet.com" in plugin.api_endpoint else "Esplora" + plugin.log(f"Sauron plugin initialized using {api} API") plugin.log(sauron_eye) @@ -193,7 +194,7 @@ def estimatefees(plugin, **kwargs): feerate_req = fetch(feerate_url) assert feerate_req.status_code == 200 feerates = feerate_req.json() - if plugin.sauron_network == "test" or plugin.sauron_network == "signet": + if plugin.sauron_network in ["test", "signet"]: # FIXME: remove the hack if the test API is "fixed" feerate = feerates.get("144", 1) slow = normal = urgent = very_urgent = int(feerate * 10**3) @@ -204,7 +205,7 @@ def estimatefees(plugin, **kwargs): urgent = int(feerates["6"] * 10**3) very_urgent = int(feerates["2"] * 10**3) - feerate_floor = int(feerates["1008"] * 10**3) + feerate_floor = int(feerates.get("1008", slow) * 10**3) feerates = [ {"blocks": 2, "feerate": very_urgent}, {"blocks": 6, "feerate": urgent}, @@ -229,7 +230,7 @@ def estimatefees(plugin, **kwargs): plugin.add_option( "sauron-api-endpoint", "", - "The URL of the esplora instance to hit (including '/api').", + "The URL of the esplora or mempool.space instance to hit (including '/api').", ) plugin.add_option( @@ -237,7 +238,7 @@ def estimatefees(plugin, **kwargs): "", "Tor's SocksPort address in the form address:port, don't specify the" " protocol. If you didn't modify your torrc you want to put" - "'localhost:9050' here.", + " 'localhost:9050' here.", )