Skip to content

Commit

Permalink
sauron: prepare for mutinynet support
Browse files Browse the repository at this point in the history
Co-authored-by: sip21 <[email protected]>
Co-authored-by: iorch <[email protected]>
  • Loading branch information
3 people committed Oct 22, 2024
1 parent 2436719 commit ece41a9
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 9 deletions.
3 changes: 2 additions & 1 deletion .ci/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,13 +241,14 @@ def run_one(p: Plugin, workflow: str) -> bool:

logging.info(f"Virtualenv at {vpath}")

num_workers = 1 if p.name == "sauron" else 5
cmd = [
str(pytest_path),
"-vvv",
"--timeout=600",
"--timeout-method=thread",
"--color=yes",
"-n=5",
f"-n={num_workers}",
]

logging.info(f"Running `{' '.join(cmd)}` in directory {p.path.resolve()}")
Expand Down
1 change: 1 addition & 0 deletions sauron/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.venv/
8 changes: 8 additions & 0 deletions sauron/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down
2 changes: 1 addition & 1 deletion sauron/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
pyln-client>=23.2
pyln-client>=23.2,<=24.5
requests[socks]>=2.23.0
15 changes: 8 additions & 7 deletions sauron/sauron.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)


Expand Down Expand Up @@ -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)
Expand All @@ -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},
Expand All @@ -229,15 +230,15 @@ 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(
"sauron-tor-proxy",
"",
"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.",
)


Expand Down

0 comments on commit ece41a9

Please sign in to comment.