Skip to content

Commit 10531d5

Browse files
committed
Remove all dependences on -cln or -lnd name to determine type - use pod metadata
1 parent f1d7b39 commit 10531d5

File tree

9 files changed

+51
-54
lines changed

9 files changed

+51
-54
lines changed

resources/charts/bitcoincore/charts/cln/templates/_helpers.tpl

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,7 @@ If release name contains chart name it will be used as a full name.
3535
{{- if .Values.fullnameOverride }}
3636
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
3737
{{- else }}
38-
{{- $name := default .Chart.Name .Values.nameOverride }}
39-
{{- if contains $name .Release.Name }}
40-
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
41-
{{- else }}
42-
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
43-
{{- end }}
38+
{{- printf "%s-ln" .Release.Name | trunc 63 | trimSuffix "-" }}
4439
{{- end }}
4540
{{- end }}
4641

resources/charts/bitcoincore/charts/lnd/templates/_helpers.tpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ If release name contains chart name it will be used as a full name.
2323
Expand the name of the chart.
2424
*/}}
2525
{{- define "lnd.name" -}}
26-
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}-lnd
26+
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
2727
{{- end }}
2828

2929
{{/*
@@ -35,7 +35,7 @@ If release name contains chart name it will be used as a full name.
3535
{{- if .Values.fullnameOverride }}
3636
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
3737
{{- else }}
38-
{{- printf "%s" .Release.Name | trunc 63 | trimSuffix "-" }}-lnd
38+
{{- printf "%s-ln" .Release.Name | trunc 63 | trimSuffix "-" }}
3939
{{- end }}
4040
{{- end }}
4141

resources/networks/hello/network.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ nodes:
2929
- id:
3030
block: 300
3131
index: 1
32-
target: tank-0004-lnd
32+
target: tank-0004-ln
3333
capacity: 100000
3434
push_amt: 50000
3535

@@ -43,7 +43,7 @@ nodes:
4343
- id:
4444
block: 300
4545
index: 2
46-
target: tank-0005-lnd
46+
target: tank-0005-ln
4747
capacity: 50000
4848
push_amt: 25000
4949

@@ -66,7 +66,7 @@ plugins: # Each plugin section has a number of hooks available (preDeploy, post
6666
helloTo: "postDeploy!"
6767
simln: # You can have multiple plugins per hook
6868
entrypoint: "../../plugins/simln"
69-
activity: '[{"source": "tank-0003-lnd", "destination": "tank-0005-lnd", "interval_secs": 1, "amount_msat": 2000}]'
69+
activity: '[{"source": "tank-0003-ln", "destination": "tank-0005-ln", "interval_secs": 1, "amount_msat": 2000}]'
7070
preNode: # preNode plugins run before each node is deployed
7171
hello:
7272
entrypoint: "../../plugins/hello"

resources/plugins/simln/README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ SimLN also requires access details for each node; however, the SimLN plugin will
1313

1414
```` JSON
1515
{
16-
"id": <node_id>-lnd,
16+
"id": <node_id>,
1717
"address": https://<ip:port or domain:port>,
1818
"macaroon": <path_to_selected_macaroon>,
1919
"cert": <path_to_tls_cert>
@@ -22,11 +22,11 @@ SimLN also requires access details for each node; however, the SimLN plugin will
2222
SimLN also supports Core Lightning (CLN). CLN nodes connection details are transfered from the CLN node to SimLN node during launch-activity processing.
2323
```` JSON
2424
{
25-
"id": <node_id>-cln,
25+
"id": <node_id>,
2626
"address": https://<domain:port>,
27-
"ca_cert": /working/<node_id>-cln-ca.pem,
28-
"client_cert": /working/<node_id>-cln-client.pem,
29-
"client_key": /working/<node_id>-cln-client-key.pem
27+
"ca_cert": /working/<node_id>-ca.pem,
28+
"client_cert": /working/<node_id>-client.pem,
29+
"client_key": /working/<node_id>-client-key.pem
3030
}
3131
````
3232

@@ -35,7 +35,7 @@ Since SimLN already has access to those LND and CLN connection details, it means
3535
### Launch activity definitions from the command line
3636
The SimLN plugin takes "activity" definitions like so:
3737

38-
`./simln/plugin.py launch-activity '[{\"source\": \"tank-0003-lnd\", \"destination\": \"tank-0005-lnd\", \"interval_secs\": 1, \"amount_msat\": 2000}]'"''`
38+
`./simln/plugin.py launch-activity '[{\"source\": \"tank-0003-ln\", \"destination\": \"tank-0005-ln\", \"interval_secs\": 1, \"amount_msat\": 2000}]'"''`
3939

4040
### Launch activity definitions from within `network.yaml`
4141
When you initialize a new Warnet network, Warnet will create a new `network.yaml` file. If your `network.yaml` file includes lightning nodes, then you can use SimLN to produce activity between those nodes like this:
@@ -75,7 +75,7 @@ nodes:
7575
- id:
7676
block: 300
7777
index: 1
78-
target: tank-0004-lnd
78+
target: tank-0004-ln
7979
capacity: 100000
8080
push_amt: 50000
8181

@@ -89,7 +89,7 @@ nodes:
8989
- id:
9090
block: 300
9191
index: 2
92-
target: tank-0005-lnd
92+
target: tank-0005-ln
9393
capacity: 50000
9494
push_amt: 25000
9595

@@ -103,7 +103,7 @@ plugins:
103103
postDeploy:
104104
simln:
105105
entrypoint: "../../plugins/simln" # This is the path to the simln plugin folder (relative to the network.yaml file).
106-
activity: '[{"source": "tank-0003-lnd", "destination": "tank-0005-lnd", "interval_secs": 1, "amount_msat": 2000}]'
106+
activity: '[{"source": "tank-0003-ln", "destination": "tank-0005-ln", "interval_secs": 1, "amount_msat": 2000}]'
107107
````
108108

109109
</details>

resources/plugins/simln/plugin.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ def _generate_activity_json(activity: Optional[list[dict]]) -> str:
168168
ln_name = i.metadata.name
169169
port = 10009
170170
node = {"id": ln_name}
171-
if "-cln" in ln_name:
171+
if "cln" in i.metadata.labels["app.kubernetes.io/name"]:
172172
port = 9736
173173
node["ca_cert"] = f"/working/{ln_name}-ca.pem"
174174
node["client_cert"] = f"/working/{ln_name}-client.pem"
@@ -192,7 +192,7 @@ def transfer_cln_certs(name):
192192
cln_root = "/root/.lightning/regtest"
193193
for i in get_mission(LIGHTNING_MISSION):
194194
ln_name = i.metadata.name
195-
if "cln" in ln_name:
195+
if "cln" in i.metadata.labels["app.kubernetes.io/name"]:
196196
copyfile(
197197
ln_name,
198198
"cln",

resources/scenarios/ln_framework/ln.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,8 @@ def to_lnd_chanpolicy(self, capacity):
112112

113113
class LNNode(ABC):
114114
@abstractmethod
115-
def __init__(self, pod_name):
116-
self.log = None
115+
def __init__(self, pod_name, logger=None):
116+
self.log = logger
117117
self.name = pod_name
118118

119119
def setLogger(self, logger):
@@ -164,8 +164,8 @@ def update(self, txid_hex: str, policy: dict, capacity: int) -> dict:
164164

165165

166166
class CLN(LNNode):
167-
def __init__(self, pod_name):
168-
super().__init__(pod_name)
167+
def __init__(self, pod_name, logger=None):
168+
super().__init__(pod_name, logger)
169169
self.headers = {}
170170
self.impl = "cln"
171171

@@ -329,8 +329,8 @@ def update(self, txid_hex: str, policy: dict, capacity: int, max_tries=2) -> dic
329329

330330

331331
class LND(LNNode):
332-
def __init__(self, pod_name):
333-
super().__init__(pod_name)
332+
def __init__(self, pod_name, logger=None):
333+
super().__init__(pod_name, logger)
334334
self.conn = http.client.HTTPSConnection(
335335
host=pod_name, port=8080, timeout=5, context=INSECURE_CONTEXT
336336
)

src/warnet/ln.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def _rpc(pod_name: str, method: str, params: str = "", namespace: Optional[str]
3232
namespace = get_default_namespace_or(namespace)
3333
chain = pod.metadata.labels["chain"]
3434
ln_client = "lncli"
35-
if "-cln" in pod_name:
35+
if "cln" in pod.metadata.labels["app.kubernetes.io/name"]:
3636
ln_client = "lightning-cli"
3737
cmd = f"kubectl -n {namespace} exec {pod_name} -- {ln_client} --network {chain} {method} {' '.join(map(str, params))}"
3838
return run_command(cmd)
@@ -49,10 +49,11 @@ def pubkey(
4949
print(_pubkey(pod))
5050

5151

52-
def _pubkey(pod: str):
53-
info = _rpc(pod, "getinfo")
52+
def _pubkey(pod_name: str):
53+
info = _rpc(pod_name, "getinfo")
54+
pod = get_pod(pod_name)
5455
pubkey_key = "identity_pubkey"
55-
if "-cln" in pod:
56+
if "cln" in pod.metadata.labels["app.kubernetes.io/name"]:
5657
pubkey_key = "id"
5758
return json.loads(info)[pubkey_key]
5859

@@ -68,9 +69,10 @@ def host(
6869
print(_host(pod))
6970

7071

71-
def _host(pod):
72-
info = _rpc(pod, "getinfo")
73-
if "-cln" in pod:
72+
def _host(pod_name: str):
73+
info = _rpc(pod_name, "getinfo")
74+
pod = get_pod(pod_name)
75+
if "cln" in pod.metadata.labels["app.kubernetes.io/name"]:
7476
return json.loads(info)["alias"]
7577
else:
7678
uris = json.loads(info)["uris"]

test/ln_basic_test.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ def __init__(self):
1616
self.network_dir = Path(os.path.dirname(__file__)) / "data" / "ln"
1717
self.scen_dir = Path(os.path.dirname(__file__)).parent / "resources" / "scenarios"
1818
self.lns = [
19-
"tank-0000-lnd",
20-
"tank-0001-lnd",
21-
"tank-0002-lnd",
22-
"tank-0003-lnd",
23-
"tank-0004-lnd",
24-
"tank-0005-lnd",
19+
"tank-0000-ln",
20+
"tank-0001-ln",
21+
"tank-0002-ln",
22+
"tank-0003-ln",
23+
"tank-0004-ln",
24+
"tank-0005-ln",
2525
]
2626

2727
def run_test(self):
@@ -30,13 +30,13 @@ def run_test(self):
3030
self.setup_network()
3131

3232
# Send a payment across channels opened automatically by ln_init
33-
self.pay_invoice(sender="tank-0005-lnd", recipient="tank-0003-lnd")
33+
self.pay_invoice(sender="tank-0005-ln", recipient="tank-0003-ln")
3434

3535
# Manually open two more channels between first three nodes
3636
# and send a payment using warnet RPC
3737
self.manual_open_channels()
3838
self.wait_for_gossip_sync(self.lns[:3], 2 + 2)
39-
self.pay_invoice(sender="tank-0000-lnd", recipient="tank-0002-lnd")
39+
self.pay_invoice(sender="tank-0000-ln", recipient="tank-0002-ln")
4040

4141
finally:
4242
self.cleanup()
@@ -63,27 +63,27 @@ def wait_for_two_txs(self):
6363

6464
def manual_open_channels(self):
6565
# 0 -> 1 -> 2
66-
pk1 = self.warnet("ln pubkey tank-0001-lnd")
67-
pk2 = self.warnet("ln pubkey tank-0002-lnd")
66+
pk1 = self.warnet("ln pubkey tank-0001-ln")
67+
pk2 = self.warnet("ln pubkey tank-0002-ln")
6868

6969
host1 = ""
7070
host2 = ""
7171

7272
while not host1 or not host2:
7373
if not host1:
74-
host1 = self.warnet("ln host tank-0001-lnd")
74+
host1 = self.warnet("ln host tank-0001-ln")
7575
if not host2:
76-
host2 = self.warnet("ln host tank-0002-lnd")
76+
host2 = self.warnet("ln host tank-0002-ln")
7777
sleep(1)
7878

7979
print(
8080
self.warnet(
81-
f"ln rpc tank-0000-lnd openchannel --node_key {pk1} --local_amt 100000 --connect {host1}"
81+
f"ln rpc tank-0000-ln openchannel --node_key {pk1} --local_amt 100000 --connect {host1}"
8282
)
8383
)
8484
print(
8585
self.warnet(
86-
f"ln rpc tank-0001-lnd openchannel --node_key {pk2} --local_amt 100000 --connect {host2}"
86+
f"ln rpc tank-0001-ln openchannel --node_key {pk2} --local_amt 100000 --connect {host2}"
8787
)
8888
)
8989

test/ln_mixed_test.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ def __init__(self):
1717
self.network_dir = Path(os.path.dirname(__file__)) / "data" / "ln_mixed"
1818
self.scen_dir = Path(os.path.dirname(__file__)).parent / "resources" / "scenarios"
1919
self.lns = [
20-
CLN("tank-0001-ln"),
21-
CLN("tank-0002-ln"),
22-
LND("tank-0003-ln"),
23-
LND("tank-0004-ln"),
24-
LND("tank-0005-ln"),
20+
CLN("tank-0001-ln", self.log),
21+
CLN("tank-0002-ln", self.log),
22+
LND("tank-0003-ln", self.log),
23+
LND("tank-0004-ln", self.log),
24+
LND("tank-0005-ln", self.log),
2525
]
2626

2727
def node(self, name: str) -> LNNode:

0 commit comments

Comments
 (0)