Skip to content

Commit eb81d96

Browse files
devrandomksedgwic
authored andcommitted
Integrate lssd
1 parent a0cea28 commit eb81d96

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, DEVELOPER, LightningNode, TEST_DEBUG
3+
from pyln.testing.utils import NodeFactory, BitcoinD, ElementsD, env, DEVELOPER, LightningNode, TEST_DEBUG, LssD
44
from pyln.client import Millisatoshi
55
from typing import Dict
66

@@ -164,6 +164,25 @@ def bitcoind(directory, teardown_checks):
164164
bitcoind.proc.wait()
165165

166166

167+
@pytest.fixture
168+
def lssd(directory, teardown_checks):
169+
lssd = LssD(directory)
170+
171+
try:
172+
lssd.start()
173+
except Exception:
174+
lssd.stop()
175+
raise
176+
177+
yield lssd
178+
179+
try:
180+
lssd.stop()
181+
except Exception:
182+
lssd.proc.kill()
183+
lssd.proc.wait()
184+
185+
167186
class TeardownErrors(object):
168187
def __init__(self):
169188
self.errors = []
@@ -446,11 +465,12 @@ def jsonschemas():
446465

447466

448467
@pytest.fixture
449-
def node_factory(request, directory, test_name, bitcoind, executor, db_provider, teardown_checks, node_cls, jsonschemas):
468+
def node_factory(request, directory, test_name, bitcoind, lssd, executor, db_provider, teardown_checks, node_cls, jsonschemas):
450469
nf = NodeFactory(
451470
request,
452471
test_name,
453472
bitcoind,
473+
lssd,
454474
executor,
455475
directory=directory,
456476
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
@@ -385,6 +385,45 @@ def f(*args):
385385
return f
386386

387387

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

390429
def __init__(self, bitcoin_dir="/tmp/bitcoind-test", rpcport=None):
@@ -626,6 +665,7 @@ def __init__(
626665
self,
627666
lightning_dir,
628667
bitcoindproxy,
668+
lssd_port,
629669
port=9735,
630670
random_hsm=False,
631671
node_id=0,
@@ -647,6 +687,7 @@ def __init__(
647687

648688
self.rpcproxy = bitcoindproxy
649689
self.env['CLN_PLUGIN_LOG'] = "cln_plugin=trace,cln_rpc=trace,cln_grpc=trace,debug"
690+
self.lssd_port = lssd_port
650691

651692
self.opts = LIGHTNINGD_CONFIG.copy()
652693
opts = {
@@ -762,6 +803,8 @@ def start(self, stdin=None, wait_for_initialized=True, stderr_redir=False):
762803
# We can't do this in the constructor because we need a new port on each restart.
763804
self.env['REMOTE_HSMD_ENDPOINT'] = '127.0.0.1:{}'.format(self.vlsd_port)
764805

806+
self.env['VLS_LSS'] = f"http://localhost:{self.lssd_port}"
807+
self.env['RUST_LOG'] = 'debug'
765808
# Some of the remote hsmd proxies need a bitcoind RPC connection
766809
self.env['BITCOIND_RPC_URL'] = 'http://{}:{}@localhost:{}'.format(
767810
BITCOIND_CONFIG['rpcuser'],
@@ -860,7 +903,7 @@ def call(self, method, payload=None, cmdprefix=None, filter=None):
860903

861904

862905
class LightningNode(object):
863-
def __init__(self, node_id, lightning_dir, bitcoind, executor, valgrind, may_fail=False,
906+
def __init__(self, node_id, lightning_dir, bitcoind, lssd, executor, valgrind, may_fail=False,
864907
may_reconnect=False,
865908
allow_broken_log=False,
866909
allow_warning=False,
@@ -870,6 +913,7 @@ def __init__(self, node_id, lightning_dir, bitcoind, executor, valgrind, may_fai
870913
valgrind_plugins=True,
871914
**kwargs):
872915
self.bitcoin = bitcoind
916+
self.lssd = lssd
873917
self.executor = executor
874918
self.may_fail = may_fail
875919
self.may_reconnect = may_reconnect
@@ -889,6 +933,7 @@ def __init__(self, node_id, lightning_dir, bitcoind, executor, valgrind, may_fai
889933

890934
self.daemon = LightningD(
891935
lightning_dir, bitcoindproxy=bitcoind.get_proxy(),
936+
lssd_port=lssd.rpcport,
892937
port=port, random_hsm=random_hsm, node_id=node_id,
893938
grpc_port=self.grpc_port,
894939
)
@@ -1555,7 +1600,7 @@ def flock(directory: Path):
15551600
class NodeFactory(object):
15561601
"""A factory to setup and start `lightningd` daemons.
15571602
"""
1558-
def __init__(self, request, testname, bitcoind, executor, directory,
1603+
def __init__(self, request, testname, bitcoind, lssd, executor, directory,
15591604
db_provider, node_cls, jsonschemas):
15601605
if request.node.get_closest_marker("slow_test") and SLOW_MACHINE:
15611606
self.valgrind = False
@@ -1567,6 +1612,7 @@ def __init__(self, request, testname, bitcoind, executor, directory,
15671612
self.reserved_ports = []
15681613
self.executor = executor
15691614
self.bitcoind = bitcoind
1615+
self.lssd = lssd
15701616
self.directory = directory
15711617
self.lock = threading.Lock()
15721618
self.db_provider = db_provider
@@ -1652,7 +1698,7 @@ def get_node(self, node_id=None, options=None, dbfile=None,
16521698
db = self.db_provider.get_db(os.path.join(lightning_dir, TEST_NETWORK), self.testname, node_id)
16531699
db.provider = self.db_provider
16541700
node = self.node_cls(
1655-
node_id, lightning_dir, self.bitcoind, self.executor, self.valgrind, db=db,
1701+
node_id, lightning_dir, self.bitcoind, self.lssd, self.executor, self.valgrind, db=db,
16561702
port=port, options=options, may_fail=may_fail or expect_fail,
16571703
jsonschemas=self.jsonschemas,
16581704
**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 DEVELOPER, 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
@@ -2459,13 +2459,13 @@ def test_unicode_rpc(node_factory, executor, bitcoind):
24592459

24602460

24612461
@unittest.skipIf(VALGRIND, "Testing pyln doesn't exercise anything interesting in the c code.")
2462-
def test_unix_socket_path_length(node_factory, bitcoind, directory, executor, db_provider, test_base_dir):
2462+
def test_unix_socket_path_length(node_factory, bitcoind, lssd, directory, executor, db_provider, test_base_dir):
24632463
lightning_dir = os.path.join(directory, "anode" + "far" * 30 + "away")
24642464
os.makedirs(lightning_dir)
24652465
db = db_provider.get_db(lightning_dir, "test_unix_socket_path_length", 1)
24662466
db.provider = db_provider
24672467

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

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

0 commit comments

Comments
 (0)