Skip to content

Commit 586ee3c

Browse files
devrandomksedgwic
authored andcommitted
Integrate lssd
1 parent a63c22c commit 586ee3c

File tree

4 files changed

+74
-8
lines changed

4 files changed

+74
-8
lines changed

contrib/pyln-testing/pyln/testing/fixtures.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from concurrent import futures
22
from pyln.testing.db import SqliteDbProvider, PostgresDbProvider
3-
from pyln.testing.utils import NodeFactory, BitcoinD, ElementsD, env, LightningNode, TEST_DEBUG
3+
from pyln.testing.utils import NodeFactory, BitcoinD, ElementsD, env, LightningNode, TEST_DEBUG, LssD
44
from pyln.client import Millisatoshi
55
from typing import Dict
66

@@ -167,6 +167,25 @@ def bitcoind(directory, teardown_checks):
167167
bitcoind.proc.wait()
168168

169169

170+
@pytest.fixture
171+
def lssd(directory, teardown_checks):
172+
lssd = LssD(directory)
173+
174+
try:
175+
lssd.start()
176+
except Exception:
177+
lssd.stop()
178+
raise
179+
180+
yield lssd
181+
182+
try:
183+
lssd.stop()
184+
except Exception:
185+
lssd.proc.kill()
186+
lssd.proc.wait()
187+
188+
170189
class TeardownErrors(object):
171190
def __init__(self):
172191
self.errors = []
@@ -449,11 +468,12 @@ def jsonschemas():
449468

450469

451470
@pytest.fixture
452-
def node_factory(request, directory, test_name, bitcoind, executor, db_provider, teardown_checks, node_cls, jsonschemas):
471+
def node_factory(request, directory, test_name, bitcoind, lssd, executor, db_provider, teardown_checks, node_cls, jsonschemas):
453472
nf = NodeFactory(
454473
request,
455474
test_name,
456475
bitcoind,
476+
lssd,
457477
executor,
458478
directory=directory,
459479
db_provider=db_provider,

contrib/pyln-testing/pyln/testing/utils.py

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,45 @@ def f(*args):
384384
return f
385385

386386

387+
class LssD(TailableProc):
388+
def __init__(self, directory, rpcport=None):
389+
lss_dir = os.path.join(directory, 'lss')
390+
TailableProc.__init__(self, lss_dir, verbose=False)
391+
392+
if rpcport is None:
393+
self.reserved_rpcport = reserve_unused_port()
394+
rpcport = self.reserved_rpcport
395+
else:
396+
self.reserved_rpcport = None
397+
398+
self.rpcport = rpcport
399+
self.prefix = 'lss'
400+
401+
if not os.path.exists(lss_dir):
402+
os.makedirs(lss_dir)
403+
404+
self.cmd_line = [
405+
'lssd',
406+
'--datadir={}'.format(lss_dir),
407+
'--port={}'.format(rpcport),
408+
]
409+
410+
def __del__(self):
411+
if self.reserved_rpcport is not None:
412+
drop_unused_port(self.reserved_rpcport)
413+
414+
def start(self):
415+
self.env['RUST_LOG'] = 'debug'
416+
TailableProc.start(self)
417+
self.wait_for_log("ready on", timeout=TIMEOUT)
418+
419+
logging.info("LssD started")
420+
421+
def stop(self):
422+
logging.info("Stopping LssD")
423+
return TailableProc.stop(self)
424+
425+
387426
class BitcoinD(TailableProc):
388427

389428
def __init__(self, bitcoin_dir="/tmp/bitcoind-test", rpcport=None):
@@ -625,6 +664,7 @@ def __init__(
625664
self,
626665
lightning_dir,
627666
bitcoindproxy,
667+
lssd_port,
628668
port=9735,
629669
random_hsm=False,
630670
node_id=0,
@@ -645,6 +685,7 @@ def __init__(
645685

646686
self.rpcproxy = bitcoindproxy
647687
self.env['CLN_PLUGIN_LOG'] = "cln_plugin=trace,cln_rpc=trace,cln_grpc=trace,debug"
688+
self.lssd_port = lssd_port
648689

649690
self.opts = LIGHTNINGD_CONFIG.copy()
650691
opts = {
@@ -759,6 +800,8 @@ def start(self, stdin=None, wait_for_initialized=True, stderr_redir=False):
759800
# We can't do this in the constructor because we need a new port on each restart.
760801
self.env['REMOTE_HSMD_ENDPOINT'] = '127.0.0.1:{}'.format(self.vlsd_port)
761802

803+
self.env['VLS_LSS'] = f"http://localhost:{self.lssd_port}"
804+
self.env['RUST_LOG'] = 'debug'
762805
# Some of the remote hsmd proxies need a bitcoind RPC connection
763806
self.env['BITCOIND_RPC_URL'] = 'http://{}:{}@localhost:{}'.format(
764807
BITCOIND_CONFIG['rpcuser'],
@@ -873,7 +916,7 @@ def call(self, method, payload=None, cmdprefix=None, filter=None):
873916

874917

875918
class LightningNode(object):
876-
def __init__(self, node_id, lightning_dir, bitcoind, executor, valgrind, may_fail=False,
919+
def __init__(self, node_id, lightning_dir, bitcoind, lssd, executor, valgrind, may_fail=False,
877920
may_reconnect=False,
878921
allow_broken_log=False,
879922
allow_warning=False,
@@ -883,6 +926,7 @@ def __init__(self, node_id, lightning_dir, bitcoind, executor, valgrind, may_fai
883926
valgrind_plugins=True,
884927
**kwargs):
885928
self.bitcoin = bitcoind
929+
self.lssd = lssd
886930
self.executor = executor
887931
self.may_fail = may_fail
888932
self.may_reconnect = may_reconnect
@@ -902,6 +946,7 @@ def __init__(self, node_id, lightning_dir, bitcoind, executor, valgrind, may_fai
902946

903947
self.daemon = LightningD(
904948
lightning_dir, bitcoindproxy=bitcoind.get_proxy(),
949+
lssd_port=lssd.rpcport,
905950
port=port, random_hsm=random_hsm, node_id=node_id,
906951
grpc_port=self.grpc_port,
907952
)
@@ -1606,7 +1651,7 @@ def flock(directory: Path):
16061651
class NodeFactory(object):
16071652
"""A factory to setup and start `lightningd` daemons.
16081653
"""
1609-
def __init__(self, request, testname, bitcoind, executor, directory,
1654+
def __init__(self, request, testname, bitcoind, lssd, executor, directory,
16101655
db_provider, node_cls, jsonschemas):
16111656
if request.node.get_closest_marker("slow_test") and SLOW_MACHINE:
16121657
self.valgrind = False
@@ -1618,6 +1663,7 @@ def __init__(self, request, testname, bitcoind, executor, directory,
16181663
self.reserved_ports = []
16191664
self.executor = executor
16201665
self.bitcoind = bitcoind
1666+
self.lssd = lssd
16211667
self.directory = directory
16221668
self.lock = threading.Lock()
16231669
self.db_provider = db_provider
@@ -1703,7 +1749,7 @@ def get_node(self, node_id=None, options=None, dbfile=None,
17031749
db = self.db_provider.get_db(os.path.join(lightning_dir, TEST_NETWORK), self.testname, node_id)
17041750
db.provider = self.db_provider
17051751
node = self.node_cls(
1706-
node_id, lightning_dir, self.bitcoind, self.executor, self.valgrind, db=db,
1752+
node_id, lightning_dir, self.bitcoind, self.lssd, self.executor, self.valgrind, db=db,
17071753
port=port, options=options, may_fail=may_fail or expect_fail,
17081754
jsonschemas=self.jsonschemas,
17091755
**kwargs

tests/fixtures.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from utils import TEST_NETWORK, VALGRIND # noqa: F401,F403
2-
from pyln.testing.fixtures import directory, test_base_dir, test_name, chainparams, node_factory, bitcoind, teardown_checks, db_provider, executor, setup_logging, jsonschemas # noqa: F401,F403
2+
from pyln.testing.fixtures import directory, test_base_dir, test_name, chainparams, node_factory, bitcoind, lssd, teardown_checks, db_provider, executor, setup_logging, jsonschemas # noqa: F401,F403
33
from pyln.testing import utils
44
from utils import COMPAT
55
from pathlib import Path

tests/test_misc.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2549,13 +2549,13 @@ def test_unicode_rpc(node_factory, executor, bitcoind):
25492549

25502550

25512551
@unittest.skipIf(VALGRIND, "Testing pyln doesn't exercise anything interesting in the c code.")
2552-
def test_unix_socket_path_length(node_factory, bitcoind, directory, executor, db_provider, test_base_dir):
2552+
def test_unix_socket_path_length(node_factory, bitcoind, lssd, directory, executor, db_provider, test_base_dir):
25532553
lightning_dir = os.path.join(directory, "anode" + "far" * 30 + "away")
25542554
os.makedirs(lightning_dir)
25552555
db = db_provider.get_db(lightning_dir, "test_unix_socket_path_length", 1)
25562556
db.provider = db_provider
25572557

2558-
l1 = LightningNode(1, lightning_dir, bitcoind, executor, VALGRIND, db=db, port=reserve())
2558+
l1 = LightningNode(1, lightning_dir, bitcoind, lssd, executor, VALGRIND, db=db, port=reserve())
25592559

25602560
# `LightningNode.start()` internally calls `LightningRpc.getinfo()` which
25612561
# exercises the socket logic, and raises an issue if it fails.

0 commit comments

Comments
 (0)