Skip to content

Commit

Permalink
Merge pull request #14 from carver/manual-trin-launch
Browse files Browse the repository at this point in the history
Use existing trin node if it is already running
  • Loading branch information
carver committed May 27, 2022
2 parents e94166d + 9cf88fd commit e63931d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 16 deletions.
46 changes: 30 additions & 16 deletions eth_portal/trin.py
@@ -1,4 +1,5 @@
from contextlib import contextmanager
from pathlib import Path
import signal
import subprocess

Expand Down Expand Up @@ -26,25 +27,38 @@ def launch_trin(private_key: bytes, port: int):
ipc_path = f"/tmp/trin-jsonrpc-{node_id_hex[:20]}.ipc"
private_key_hex = remove_0x_prefix(private_key.hex())

print(f"Launching trin with node ID {node_id_hex[:10]}...")
try:
short_node_id = node_id_hex[:10]
trin_args = [
"./trin",
# fmt: off
"--discovery-port", str(port),
"--unsafe-private-key", private_key_hex,
"--web3-ipc-path", ipc_path,
"--kb", "20000",
"--networks", "history",
"--bootnodes", "default",
# fmt: on
]

if Path(ipc_path).exists():
print(f"trin already running for {short_node_id}, skipping launch...")
trin_proc = None
else:
print(f"Launching trin with node ID {short_node_id} using...")
print(" ".join(trin_args))
trin_proc = subprocess.Popen(
[
"./trin",
# fmt: off
"--discovery-port", str(port),
"--unsafe-private-key", private_key_hex,
"--web3-ipc-path", ipc_path,
"--kb", "20000",
"--networks", "history",
"--bootnodes", "default",
# fmt: on
],
trin_args,
env={"TRIN_INFURA_PROJECT_ID": "1"},
)

try:
yield Web3(Web3.IPCProvider(ipc_path))
finally:
print(f"Exiting trin with node ID {node_id_hex[:10]}...")
trin_proc.send_signal(signal.SIGINT)
trin_proc.wait()
if trin_proc:
print(f"Exiting trin with node ID {node_id_hex[:10]}...")
trin_proc.send_signal(signal.SIGINT)
trin_proc.wait()
else:
print(
f"Did not launch trin with node ID {node_id_hex[:10]}, so cannot exit."
)
2 changes: 2 additions & 0 deletions newsfragments/14.feature.rst
@@ -0,0 +1,2 @@
In bridge launcher, detect if trin "injector" node is already running, then use it. One benefit is
being able to observe the logs on trin during bridge operation.

0 comments on commit e63931d

Please sign in to comment.