Skip to content

Commit 41a3643

Browse files
committed
make ln_init part of deploy() if ln channels are defined
1 parent 0e67280 commit 41a3643

File tree

8 files changed

+59
-222
lines changed

8 files changed

+59
-222
lines changed

.github/workflows/test.yml

-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ jobs:
4545
- graph_test.py
4646
- logging_test.py
4747
- ln_test.py
48-
- ln_basic_test.py
4948
- rpc_test.py
5049
- services_test.py
5150
- signet_test.py

resources/scenarios/ln_init.py

+26-24
Original file line numberDiff line numberDiff line change
@@ -322,30 +322,32 @@ def update_policy(self, ln, txid_hex, policy, capacity):
322322

323323
update_threads = []
324324
for ch in self.channels:
325-
ts = threading.Thread(
326-
target=update_policy,
327-
args=(
328-
self,
329-
self.lns[ch["source"]],
330-
ch["txid"],
331-
ch["source_policy"],
332-
ch["capacity"],
333-
),
334-
)
335-
ts.start()
336-
update_threads.append(ts)
337-
tt = threading.Thread(
338-
target=update_policy,
339-
args=(
340-
self,
341-
self.lns[ch["target"]],
342-
ch["txid"],
343-
ch["target_policy"],
344-
ch["capacity"],
345-
),
346-
)
347-
tt.start()
348-
update_threads.append(tt)
325+
if "source_policy" in ch:
326+
ts = threading.Thread(
327+
target=update_policy,
328+
args=(
329+
self,
330+
self.lns[ch["source"]],
331+
ch["txid"],
332+
ch["source_policy"],
333+
ch["capacity"],
334+
),
335+
)
336+
ts.start()
337+
update_threads.append(ts)
338+
if "target_policy" in ch:
339+
tt = threading.Thread(
340+
target=update_policy,
341+
args=(
342+
self,
343+
self.lns[ch["target"]],
344+
ch["txid"],
345+
ch["target_policy"],
346+
ch["capacity"],
347+
),
348+
)
349+
tt.start()
350+
update_threads.append(tt)
349351
count = len(update_threads)
350352

351353
all(thread.join() is None for thread in update_threads)

src/warnet/control.py

+10
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,16 @@ def run(
243243
Run a scenario from a file.
244244
Pass `-- --help` to get individual scenario help
245245
"""
246+
return _run(scenario_file, debug, source_dir, additional_args, namespace)
247+
248+
249+
def _run(
250+
scenario_file: str,
251+
debug: bool,
252+
source_dir,
253+
additional_args: tuple[str],
254+
namespace: Optional[str],
255+
):
246256
namespace = get_default_namespace_or(namespace)
247257

248258
scenario_path = Path(scenario_file).resolve()

src/warnet/deploy.py

+20
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@
2020
NAMESPACES_CHART_LOCATION,
2121
NAMESPACES_FILE,
2222
NETWORK_FILE,
23+
SCENARIOS_DIR,
2324
WARGAMES_NAMESPACE_PREFIX,
2425
)
26+
from .control import _run
2527
from .k8s import (
2628
get_default_namespace,
2729
get_default_namespace_or,
@@ -238,13 +240,22 @@ def deploy_network(directory: Path, debug: bool = False, namespace: Optional[str
238240
with network_file_path.open() as f:
239241
network_file = yaml.safe_load(f)
240242

243+
needs_ln_init = False
244+
241245
for node in network_file["nodes"]:
242246
click.echo(f"Deploying node: {node.get('name')}")
243247
try:
244248
temp_override_file_path = ""
245249
node_name = node.get("name")
246250
node_config_override = {k: v for k, v in node.items() if k != "name"}
247251

252+
if (
253+
"lnd" in node_config_override
254+
and "channels" in node_config_override["lnd"]
255+
and len(node_config_override["lnd"]["channels"]) > 0
256+
):
257+
needs_ln_init = True
258+
248259
cmd = f"{HELM_COMMAND} {node_name} {BITCOIN_CHART_LOCATION} --namespace {namespace} -f {defaults_file_path}"
249260
if debug:
250261
cmd += " --debug"
@@ -268,6 +279,15 @@ def deploy_network(directory: Path, debug: bool = False, namespace: Optional[str
268279
if temp_override_file_path:
269280
Path(temp_override_file_path).unlink()
270281

282+
if needs_ln_init:
283+
_run(
284+
scenario_file=SCENARIOS_DIR / "ln_init.py",
285+
debug=True,
286+
source_dir=SCENARIOS_DIR,
287+
additional_args=None,
288+
namespace=namespace,
289+
)
290+
271291

272292
def deploy_namespaces(directory: Path):
273293
namespaces_file_path = directory / NAMESPACES_FILE

src/warnet/ln.py

-28
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import click
55

66
from .k8s import (
7-
get_channels,
87
get_default_namespace_or,
98
get_pod,
109
)
@@ -70,30 +69,3 @@ def _host(pod):
7069
return uris[0].split("@")[1]
7170
else:
7271
return ""
73-
74-
75-
@ln.command()
76-
def open_all_channels():
77-
"""
78-
Open all channels with source policies defined in the network.yaml
79-
<!> IGNORES HARD CODED CHANNEL IDs <!>
80-
<!> Should only be run once or you'll end up with duplicate channels <!>
81-
"""
82-
channels = get_channels()
83-
commands = []
84-
for ch in channels:
85-
pk = _pubkey(ch["target"])
86-
host = _host(ch["target"])
87-
local_amt = ch["local_amt"]
88-
push_amt = ch.get("push_amt", 0)
89-
assert pk, f"{ch['target']} has no public key"
90-
assert host, f"{ch['target']} has no host"
91-
assert local_amt, "Channel has no local_amount"
92-
commands.append(
93-
(
94-
ch["source"],
95-
f"openchannel --node_key {pk} --connect {host} --local_amt {local_amt} --push_amt {push_amt}",
96-
)
97-
)
98-
for command in commands:
99-
_rpc(*command)

test/data/ln/network.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ nodes:
3030
block: 300
3131
index: 1
3232
target: tank-0004-ln
33-
local_amt: 100000
33+
capacity: 100000
3434
push_amt: 50000
3535

3636
- name: tank-0004
@@ -44,7 +44,7 @@ nodes:
4444
block: 300
4545
index: 2
4646
target: tank-0005-ln
47-
local_amt: 50000
47+
capacity: 50000
4848
push_amt: 25000
4949

5050
- name: tank-0005

test/ln_basic_test.py

-159
This file was deleted.

test/ln_test.py

+1-8
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ def run_test(self):
2020
try:
2121
self.import_network()
2222
self.setup_network()
23-
self.run_ln_init_scenario()
2423
self.test_channel_policies()
2524
self.test_payments()
2625
finally:
@@ -33,13 +32,7 @@ def import_network(self):
3332

3433
def setup_network(self):
3534
self.log.info("Setting up network...")
36-
self.log.info(self.warnet(f"deploy {self.imported_network_dir}"))
37-
self.wait_for_all_tanks_status(target="running")
38-
39-
def run_ln_init_scenario(self):
40-
self.log.info("Running LN Init scenario")
41-
stream_command(f"warnet run {self.scen_dir / 'ln_init.py'} --debug")
42-
self.wait_for_all_scenarios()
35+
stream_command(f"warnet deploy {self.imported_network_dir}")
4336

4437
def test_channel_policies(self):
4538
self.log.info("Ensuring node-level channel policy settings")

0 commit comments

Comments
 (0)