Skip to content

Commit 57074e7

Browse files
ca-ruziorch
authored andcommitted
sauron: prepare for mutinynet support
Co-authored-by: iorch <j.martinezortega@gmail.com>
1 parent d6ce822 commit 57074e7

File tree

4 files changed

+18
-8
lines changed

4 files changed

+18
-8
lines changed

sauron/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.venv/

sauron/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,14 @@ Here is a fully reptilian example running against [blockstream.info](https://blo
2424
lightningd --mainnet --disable-plugin bcli --plugin $PWD/sauron.py --sauron-api-endpoint https://blockstream.info/api/
2525
```
2626

27+
28+
Here is an example running against [mutinynet.com](https://mutinynet.com/):
29+
30+
```
31+
lightningd --signet --disable-plugin bcli --plugin $PWD/sauron.py --sauron-api-endpoint https://mutinynet.com/api/
32+
```
33+
34+
2735
You can use also proxy your requests through [Tor](https://www.torproject.org/) by
2836
specifying a SOCKS proxy to use with the `--sauron-tor-proxy` startup option, in
2937
the form `address:port`.

sauron/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
pyln-client>=23.2
1+
pyln-client>=23.2,<=24.5
22
requests[socks]>=2.23.0

sauron/sauron.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ def fetch(url):
4040

4141

4242
@plugin.init()
43-
def init(plugin, options, configuration, **kwargs):
44-
plugin.api_endpoint = options["sauron-api-endpoint"]
43+
def init(plugin, options, **kwargs):
44+
plugin.api_endpoint = options.get("sauron-api-endpoint", None)
4545
if not plugin.api_endpoint:
4646
raise SauronError("You need to specify the sauron-api-endpoint option.")
4747
sys.exit(1)
@@ -55,7 +55,8 @@ def init(plugin, options, configuration, **kwargs):
5555
}
5656
plugin.log("Using proxy {} for requests".format(socks5_proxy))
5757

58-
plugin.log("Sauron plugin initialized")
58+
api = "mempool.space" if "mutinynet.com" in plugin.api_endpoint else "Esplora"
59+
plugin.log(f"Sauron plugin initialized using {api} API")
5960
plugin.log(sauron_eye)
6061

6162

@@ -193,7 +194,7 @@ def estimatefees(plugin, **kwargs):
193194
feerate_req = fetch(feerate_url)
194195
assert feerate_req.status_code == 200
195196
feerates = feerate_req.json()
196-
if plugin.sauron_network == "test" or plugin.sauron_network == "signet":
197+
if plugin.sauron_network in ["test", "signet"]:
197198
# FIXME: remove the hack if the test API is "fixed"
198199
feerate = feerates.get("144", 1)
199200
slow = normal = urgent = very_urgent = int(feerate * 10**3)
@@ -204,7 +205,7 @@ def estimatefees(plugin, **kwargs):
204205
urgent = int(feerates["6"] * 10**3)
205206
very_urgent = int(feerates["2"] * 10**3)
206207

207-
feerate_floor = int(feerates["1008"] * 10**3)
208+
feerate_floor = int(feerates.get("1008", slow) * 10**3)
208209
feerates = [
209210
{"blocks": 2, "feerate": very_urgent},
210211
{"blocks": 6, "feerate": urgent},
@@ -229,15 +230,15 @@ def estimatefees(plugin, **kwargs):
229230
plugin.add_option(
230231
"sauron-api-endpoint",
231232
"",
232-
"The URL of the esplora instance to hit (including '/api').",
233+
"The URL of the esplora or mempool.space instance to hit (including '/api').",
233234
)
234235

235236
plugin.add_option(
236237
"sauron-tor-proxy",
237238
"",
238239
"Tor's SocksPort address in the form address:port, don't specify the"
239240
" protocol. If you didn't modify your torrc you want to put"
240-
"'localhost:9050' here.",
241+
" 'localhost:9050' here.",
241242
)
242243

243244

0 commit comments

Comments
 (0)