Skip to content

Commit

Permalink
ln_init: up through opening all channels
Browse files Browse the repository at this point in the history
  • Loading branch information
pinheadmz committed Nov 22, 2024
1 parent fef2e67 commit 3f3ba13
Show file tree
Hide file tree
Showing 4 changed files with 404 additions and 179 deletions.
4 changes: 2 additions & 2 deletions resources/charts/bitcoincore/charts/lnd/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ readinessProbe:
timeoutSeconds: 1
startupProbe:
failureThreshold: 10
periodSeconds: 10
periodSeconds: 30
successThreshold: 1
timeoutSeconds: 10
timeoutSeconds: 60
exec:
command:
- /bin/sh
Expand Down
123 changes: 99 additions & 24 deletions resources/scenarios/commander.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import ssl
import sys
import tempfile
import time
from typing import Dict

from kubernetes import client, config
Expand Down Expand Up @@ -55,6 +56,7 @@
"rpc_port": int(pod.metadata.labels["RPCPort"]),
"rpc_user": "user",
"rpc_password": pod.metadata.labels["rpcpassword"],
"init_peers": pod.metadata.annotations["init_peers"]
}
)

Expand Down Expand Up @@ -82,41 +84,106 @@ def auth_proxy_request(self, method, path, postdata):

class LND:
def __init__(self, pod_name):
self.name = pod_name
self.conn = http.client.HTTPSConnection(
host=pod_name, port=8080, timeout=5, context=INSECURE_CONTEXT
)

def get(self, uri):
self.conn.request(
method="GET", url=uri, headers={"Grpc-Metadata-macaroon": ADMIN_MACAROON_HEX}
)
return self.conn.getresponse().read().decode("utf8")
while True:
try:
self.conn.request(
method="GET",
url=uri,
headers={
"Grpc-Metadata-macaroon": ADMIN_MACAROON_HEX,
"Connection": "close"
}
)
return self.conn.getresponse().read().decode("utf8")
except Exception:
time.sleep(1)

def post(self, uri, data):
body = json.dumps(data)
self.conn.request(
method="POST",
url=uri,
body=body,
headers={
"Content-Type": "application/json",
"Content-Length": str(len(body)),
"Grpc-Metadata-macaroon": ADMIN_MACAROON_HEX,
},
)
# Stream output, otherwise we get a timeout error
res = self.conn.getresponse()
stream = ""
attempt = 0
while True:
attempt += 1
try:
data = res.read(1)
if len(data) == 0:
break
else:
stream += data.decode("utf8")
self.conn.request(
method="POST",
url=uri,
body=body,
headers={
"Content-Type": "application/json",
"Content-Length": str(len(body)),
"Grpc-Metadata-macaroon": ADMIN_MACAROON_HEX,
"Connection": "close"
},
)
# Stream output, otherwise we get a timeout error
res = self.conn.getresponse()
stream = ""
while True:
try:
data = res.read(1)
if len(data) == 0:
break
else:
stream += data.decode("utf8")
except Exception:
break
return stream
except Exception:
break
return stream
time.sleep(1)

def newaddress(self):
res = self.get(
"/v1/newaddress"
)
return json.loads(res)

def walletbalance(self):
res = self.get(
"/v1/balance/blockchain"
)
return int(json.loads(res)["confirmed_balance"])

def uri(self):
res = self.get(
"/v1/getinfo"
)
info = json.loads(res)
if "uris" not in info or len(info["uris"]) == 0:
return None
return info["uris"][0]

def connect(self, target_uri):
pk, host = target_uri.split("@")
res = self.post(
"/v1/peers",
data= {
"addr": {
"pubkey": pk,
"host": host
}
}
)
return json.loads(res)

def channel(self, pk, local_amt, push_amt, fee_rate):
res = self.post(
"/v1/channels/stream",
data = {
"local_funding_amount": local_amt,
"push_sat": push_amt,
"node_pubkey": pk,
"sat_per_vbyte": fee_rate
}
)
return json.loads(res)




class Commander(BitcoinTestFramework):
Expand All @@ -139,6 +206,13 @@ def ensure_miner(node):
def hex_to_b64(hex):
return base64.b64encode(bytes.fromhex(hex)).decode()

@staticmethod
def b64_to_hex(b64, reverse=False):
if reverse:
return base64.b64decode(b64)[::-1].hex()
else:
return base64.b64decode(b64).hex()

def handle_sigterm(self, signum, frame):
print("SIGTERM received, stopping...")
self.shutdown()
Expand Down Expand Up @@ -193,6 +267,7 @@ def setup(self):
coveragedir=self.options.coveragedir,
)
node.rpc_connected = True
node.init_peers = int(tank["init_peers"])

self.nodes.append(node)
self.tanks[tank["tank"]] = node
Expand Down
Loading

0 comments on commit 3f3ba13

Please sign in to comment.