Skip to content

Commit f5aba7c

Browse files
committed
remove RPC requirements for CLN - fetch rune via http transfer from pod
other clean up for comments remove rbac exec change
1 parent 3d846d3 commit f5aba7c

File tree

8 files changed

+78
-124
lines changed

8 files changed

+78
-124
lines changed

resources/charts/bitcoincore/charts/cln/templates/pod.yaml

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,12 @@ spec:
4141
- /bin/sh
4242
- -c
4343
- |
44-
lightningd --conf=/root/.lightning/config
44+
lightningd --conf=/root/.lightning/config &
45+
sleep 1
46+
lightning-cli createrune > /working/rune.json
47+
echo "Here is the rune file contents"
48+
cat /working/rune.json
49+
wait
4550
livenessProbe:
4651
{{- toYaml .Values.livenessProbe | nindent 8 }}
4752
readinessProbe:
@@ -60,6 +65,20 @@ spec:
6065
{{- with .Values.extraContainers }}
6166
{{- toYaml . | nindent 4 }}
6267
{{- end }}
68+
- name: http-server
69+
image: busybox
70+
command: ["/bin/sh", "-c"]
71+
args:
72+
- |
73+
echo "Starting HTTP server..."
74+
busybox httpd -f -p 8080 -h /working
75+
ports:
76+
- containerPort: 8080
77+
name: http
78+
volumeMounts:
79+
{{- with .Values.volumeMounts }}
80+
{{- toYaml . | nindent 8 }}
81+
{{- end }}
6382
volumes:
6483
{{- with .Values.volumes }}
6584
{{- toYaml . | nindent 4 }}

resources/charts/bitcoincore/charts/cln/values.yaml

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ image:
88
pullPolicy: IfNotPresent
99
tag: "v25.02"
1010

11-
imagePullSecrets: []
1211
nameOverride: ""
1312
fullnameOverride: ""
1413

@@ -18,15 +17,8 @@ podLabels:
1817
mission: "lightning"
1918

2019
podSecurityContext: {}
21-
# fsGroup: 2000
2220

2321
securityContext: {}
24-
# capabilities:
25-
# drop:
26-
# - ALL
27-
# readOnlyRootFilesystem: true
28-
# runAsNonRoot: true
29-
# runAsUser: 1000
3022

3123
service:
3224
type: ClusterIP
@@ -35,22 +27,16 @@ P2PPort: 9735
3527
RPCPort: 9736
3628
RestPort: 3010
3729

38-
# This block is for setting up the ingress for more information can be found here: https://kubernetes.io/docs/concepts/services-networking/ingress/
3930
ingress:
4031
enabled: false
4132
className: ""
4233
annotations: {}
43-
# kubernetes.io/ingress.class: nginx
44-
# kubernetes.io/tls-acme: "true"
4534
hosts:
4635
- host: chart-example.local
4736
paths:
4837
- path: /
4938
pathType: ImplementationSpecific
5039
tls: []
51-
# - secretName: chart-example-tls
52-
# hosts:
53-
# - chart-example.local
5440

5541
resources: {}
5642
# We usually recommend not to specify default resources and to leave this as a conscious
@@ -69,7 +55,7 @@ livenessProbe:
6955
command:
7056
- "/bin/sh"
7157
- "-c"
72-
- "lightning-cli --network=regtest getinfo >/dev/null 2>&1"
58+
- "lightning-cli getinfo >/dev/null 2>&1"
7359
failureThreshold: 3
7460
initialDelaySeconds: 5
7561
periodSeconds: 5
@@ -84,16 +70,17 @@ readinessProbe:
8470
command:
8571
- "/bin/sh"
8672
- "-c"
87-
- "lightning-cli --network=regtest getinfo 2>/dev/null | grep -q 'id' || exit 1"
73+
- "lightning-cli getinfo 2>/dev/null | grep -q 'id' || exit 1"
8874

8975
# Additional volumes on the output Deployment definition.
90-
volumes: []
76+
volumes:
77+
- name: working
78+
emptyDir: {}
9179

9280
# Additional volumeMounts on the output Deployment definition.
93-
volumeMounts: []
94-
# - name: foo
95-
# mountPath: "/etc/foo"
96-
# readOnly: true
81+
volumeMounts:
82+
- name: working
83+
mountPath: "/working"
9784

9885
nodeSelector: {}
9986

resources/charts/commander/templates/rbac.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ metadata:
1515
app.kubernetes.io/name: {{ .Chart.Name }}
1616
rules:
1717
- apiGroups: [""]
18-
resources: ["pods", "configmaps", "pods/exec"]
19-
verbs: ["get", "list", "watch", "exec"]
18+
resources: ["pods", "configmaps"]
19+
verbs: ["get", "list", "watch"]
2020
---
2121
apiVersion: rbac.authorization.k8s.io/v1
2222
kind: RoleBinding

resources/plugins/simln/plugin.py

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111

1212
from warnet.constants import LIGHTNING_MISSION, PLUGIN_ANNEX, AnnexMember, HookValue, WarnetContent
1313
from warnet.k8s import (
14+
copyfile,
1415
download,
1516
get_default_namespace,
1617
get_mission,
1718
get_static_client,
18-
read_file_from_container,
1919
wait_for_init,
2020
write_file_to_container,
2121
)
@@ -189,7 +189,7 @@ def _generate_activity_json(activity: Optional[list[dict]]) -> str:
189189

190190
def transfer_cln_certs(name):
191191
dst_container = "init"
192-
cln_root = "/root/.lightning/regtest"
192+
cln_root = "/root/.lightning/regtest" # FIXME: figure out chain
193193
for i in get_mission(LIGHTNING_MISSION):
194194
ln_name = i.metadata.name
195195
if "cln" in i.metadata.labels["app.kubernetes.io/name"]:
@@ -219,22 +219,6 @@ def transfer_cln_certs(name):
219219
)
220220

221221

222-
def copyfile(pod_name, src_container, source_path, dst_name, dst_container, dst_path):
223-
namespace = get_default_namespace()
224-
file_data = read_file_from_container(pod_name, source_path, src_container, namespace)
225-
if write_file_to_container(
226-
dst_name,
227-
dst_container,
228-
dst_path,
229-
file_data,
230-
namespace=namespace,
231-
quiet=True,
232-
):
233-
log.info(f"Copied {source_path} to {dst_path}")
234-
else:
235-
log.error(f"Failed to copy {source_path} from {pod_name} to {dst_name}:{dst_path}")
236-
237-
238222
def _sh(pod, method: str, params: tuple[str, ...]) -> str:
239223
namespace = get_default_namespace()
240224

resources/scenarios/commander.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,9 @@
7070
)
7171

7272
if pod.metadata.labels["mission"] == "lightning":
73-
lnnode = LND(pod.metadata.name)
73+
lnnode = LND(pod.metadata.name, pod.status.pod_ip)
7474
if "cln" in pod.metadata.labels["app.kubernetes.io/name"]:
75-
lnnode = CLN(pod.metadata.name)
75+
lnnode = CLN(pod.metadata.name, pod.status.pod_ip)
7676
WARNET["lightning"].append(lnnode)
7777

7878
for cm in cmaps.items:

resources/scenarios/ln_framework/ln.py

Lines changed: 20 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,11 @@
22
import http.client
33
import json
44
import logging
5-
import os
65
import ssl
76
from abc import ABC, abstractmethod
87
from time import sleep
9-
from typing import Optional
108

11-
from kubernetes import client, config
12-
from kubernetes.stream import stream
9+
import requests
1310

1411
# hard-coded deterministic lnd credentials
1512
ADMIN_MACAROON_HEX = "0201036c6e6402f801030a1062beabbf2a614b112128afa0c0b4fdd61201301a160a0761646472657373120472656164120577726974651a130a04696e666f120472656164120577726974651a170a08696e766f69636573120472656164120577726974651a210a086d616361726f6f6e120867656e6572617465120472656164120577726974651a160a076d657373616765120472656164120577726974651a170a086f6666636861696e120472656164120577726974651a160a076f6e636861696e120472656164120577726974651a140a057065657273120472656164120577726974651a180a067369676e6572120867656e657261746512047265616400000620b17be53e367290871681055d0de15587f6d1cd47d1248fe2662ae27f62cfbdc6"
@@ -19,36 +16,6 @@
1916
INSECURE_CONTEXT.verify_mode = ssl.CERT_NONE
2017

2118

22-
# execute kubernetes command
23-
def run_command(name, command: list[str], namespace: Optional[str] = "default") -> str:
24-
if os.getenv("KUBERNETES_SERVICE_HOST") and os.getenv("KUBERNETES_SERVICE_PORT"):
25-
config.load_incluster_config()
26-
else:
27-
config.load_kube_config()
28-
sclient = client.CoreV1Api()
29-
resp = stream(
30-
sclient.connect_get_namespaced_pod_exec,
31-
name,
32-
namespace,
33-
command=command,
34-
stderr=True,
35-
stdin=False,
36-
stdout=True,
37-
tty=False,
38-
_request_timeout=20,
39-
_preload_content=False,
40-
)
41-
result = ""
42-
while resp.is_open():
43-
resp.update(timeout=5)
44-
if resp.peek_stdout():
45-
result += resp.read_stdout()
46-
if resp.peek_stderr():
47-
raise Exception(resp.read_stderr())
48-
resp.close()
49-
return result
50-
51-
5219
# https://github.com/lightningcn/lightning-rfc/blob/master/07-routing-gossip.md#the-channel_update-message
5320
# We use the field names as written in the BOLT as our canonical, internal field names.
5421
# In LND, Policy objects returned by DescribeGraph have completely different labels
@@ -113,19 +80,16 @@ def to_lnd_chanpolicy(self, capacity):
11380

11481
class LNNode(ABC):
11582
@abstractmethod
116-
def __init__(self, pod_name):
83+
def __init__(self, pod_name, ip_address):
11784
self.name = pod_name
85+
self.ip_address = ip_address
11886
self.log = logging.getLogger(pod_name)
11987
handler = logging.StreamHandler()
120-
formatter = logging.Formatter(f'%(name)-8s - %(levelname)s: %(message)s')
88+
formatter = logging.Formatter("%(name)-8s - %(levelname)s: %(message)s")
12189
handler.setFormatter(formatter)
12290
self.log.addHandler(handler)
12391
self.log.setLevel(logging.INFO)
12492

125-
@staticmethod
126-
def param_dict_to_list(params: dict) -> list[str]:
127-
return [f"{k}={v}" for k, v in params.items()]
128-
12993
@staticmethod
13094
def hex_to_b64(hex):
13195
return base64.b64encode(bytes.fromhex(hex)).decode()
@@ -167,23 +131,20 @@ def update(self, txid_hex: str, policy: dict, capacity: int) -> dict:
167131

168132

169133
class CLN(LNNode):
170-
def __init__(self, pod_name):
171-
super().__init__(pod_name)
172-
self.conn = http.client.HTTPSConnection(
173-
host=pod_name, port=8080, timeout=5, context=INSECURE_CONTEXT
174-
)
134+
def __init__(self, pod_name, ip_address):
135+
super().__init__(pod_name, ip_address)
136+
self.conn = None
175137
self.headers = {}
176138
self.impl = "cln"
139+
self.reset_connection()
177140

178141
def reset_connection(self):
179142
self.conn = http.client.HTTPSConnection(
180143
host=self.name, port=3010, timeout=5, context=INSECURE_CONTEXT
181144
)
182145

183146
def setRune(self, rune):
184-
self.headers = {
185-
"Rune": rune
186-
}
147+
self.headers = {"Rune": rune}
187148

188149
def get(self, uri):
189150
attempt = 0
@@ -204,7 +165,9 @@ def get(self, uri):
204165
return None
205166
sleep(1)
206167

207-
def post(self, uri, data={}):
168+
def post(self, uri, data=None):
169+
if not data:
170+
data = {}
208171
body = json.dumps(data)
209172
post_header = self.headers
210173
post_header["Content-Length"] = str(len(body))
@@ -239,37 +202,15 @@ def post(self, uri, data={}):
239202
return None
240203
sleep(1)
241204

242-
def rpc(
243-
self,
244-
method: str,
245-
params: list[str] = None,
246-
namespace: Optional[str] = "default",
247-
max_tries=5,
248-
):
249-
cmd = ["lightning-cli", method]
250-
if params:
251-
cmd.extend(params)
252-
attempt = 0
253-
while attempt < max_tries:
254-
attempt += 1
255-
try:
256-
response = run_command(self.name, cmd, namespace)
257-
if not response:
258-
continue
259-
return response
260-
except Exception as e:
261-
self.log.error(f"CLN rpc error: {e}, wait and retry...")
262-
sleep(2)
263-
return None
264-
265205
def createrune(self, max_tries=2):
266206
attempt = 0
267207
while attempt < max_tries:
268208
attempt += 1
269-
response = self.rpc("createrune")
209+
response = requests.get(f"http://{self.ip_address}:8080/rune.json", timeout=5).text
270210
if not response:
271211
sleep(2)
272212
continue
213+
self.log.debug(response)
273214
res = json.loads(response)
274215
self.setRune(res["rune"])
275216
return
@@ -367,14 +308,16 @@ def channel(self, pk, capacity, push_amt, fee_rate, max_tries=5) -> dict:
367308
return None
368309

369310
def createinvoice(self, sats, label, description="new invoice") -> str:
370-
response = self.post("invoice", {"amount_msat": sats * 1000, "label": label, "description": description})
311+
response = self.post(
312+
"invoice", {"amount_msat": sats * 1000, "label": label, "description": description}
313+
)
371314
if response:
372315
res = json.loads(response)
373316
return res["bolt11"]
374317
return None
375318

376319
def payinvoice(self, payment_request) -> str:
377-
response = self.rpc("pay", {"bolt11": payment_request})
320+
response = self.post("/v1/pay", {"bolt11": payment_request})
378321
if response:
379322
res = json.loads(response)
380323
if "code" in res:
@@ -413,8 +356,8 @@ def update(self, txid_hex: str, policy: dict, capacity: int, max_tries=2) -> dic
413356

414357

415358
class LND(LNNode):
416-
def __init__(self, pod_name):
417-
super().__init__(pod_name)
359+
def __init__(self, pod_name, ip_address):
360+
super().__init__(pod_name, ip_address)
418361
self.conn = http.client.HTTPSConnection(
419362
host=pod_name, port=8080, timeout=5, context=INSECURE_CONTEXT
420363
)

0 commit comments

Comments
 (0)