Skip to content

Commit

Permalink
allow custom LN images
Browse files Browse the repository at this point in the history
  • Loading branch information
pinheadmz committed Feb 26, 2024
1 parent 347a55c commit ec3d3d7
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 16 deletions.
5 changes: 3 additions & 2 deletions src/backends/compose/compose_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ def add_lnd_service(self, tank, services):
]
services[ln_container_name] = {
"container_name": ln_container_name,
"image": "lightninglabs/lnd:v0.17.0-beta",
"image": tank.lnnode.image,
"command": " ".join(args),
"networks": {
tank.network_name: {
Expand All @@ -464,6 +464,7 @@ def add_lnd_service(self, tank, services):
"lnnode_container_name": ln_container_name,
"lnnode_ipv4_address": tank.lnnode.ipv4,
"lnnode_impl": tank.lnnode.impl,
"lnnode_image": tank.lnnode.image,
}
}
)
Expand Down Expand Up @@ -502,7 +503,7 @@ def tank_from_deployment(self, service, warnet):

labels = service.get("labels", {})
if "lnnode_impl" in labels:
tank.lnnode = LNNode(warnet, tank, labels["lnnode_impl"], self)
tank.lnnode = LNNode(warnet, tank, labels["lnnode_impl"], labels["lnnode_image"], self)
tank.lnnode.ipv4 = labels.get("lnnode_ipv4_address")
return tank

Expand Down
21 changes: 13 additions & 8 deletions src/backends/kubernetes/kubernetes_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
from warnet.utils import default_bitcoin_conf_args, parse_raw_messages

DOCKER_REGISTRY_CORE = "bitcoindevproject/bitcoin"
DOCKER_REGISTRY_LND = "lightninglabs/lnd:v0.17.0-beta"
LOCAL_REGISTRY = "warnet/bitcoin-core"

POD_PREFIX = "tank"
Expand Down Expand Up @@ -344,11 +343,17 @@ def tank_from_deployment(self, pod, pods_by_name, warnet):
tank.version = f"{c_repo}#{c_branch}"
self.log.debug(f"Created tank {tank.index} from deployment: {tank=:}")

# check if we can find a corresponding lnd pod
lnd_pod = pods_by_name.get(self.get_pod_name(index, ServiceType.LIGHTNING))
if lnd_pod:
tank.lnnode = LNNode(warnet, tank, "lnd", self)
tank.lnnode.ipv4 = lnd_pod.status.pod_ip
# check if we can find a corresponding ln pod
ln_pod = pods_by_name.get(self.get_pod_name(index, ServiceType.LIGHTNING))
if ln_pod:
# Assuming only one container per LN pod
ln_container = ln_pod.spec.containers[0]
for env in ln_container.env:
if env.name == "LN_IMPL":
impl = env.value
image = ln_container.image
tank.lnnode = LNNode(warnet, tank, impl, image, self)
tank.lnnode.ipv4 = ln_pod.status.pod_ip
self.log.debug(
f"Created lightning for tank {tank.index} from deployment {tank.lnnode=:}"
)
Expand Down Expand Up @@ -512,10 +517,10 @@ def create_lnd_container(self, tank, bitcoind_service_name) -> client.V1Containe
self.log.debug(f"Creating lightning container for tank {tank.index} using {args=:}")
lightning_container = client.V1Container(
name=LN_CONTAINER_NAME,
image=f"{DOCKER_REGISTRY_LND}",
image=tank.lnnode.image,
args=args,
env=[
client.V1EnvVar(name="LND_NETWORK", value="regtest"),
client.V1EnvVar(name="LN_IMPL", value=tank.lnnode.impl),
],
readiness_probe=client.V1Probe(
failure_threshold=1,
Expand Down
3 changes: 2 additions & 1 deletion src/templates/node_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"exporter": {"type": "boolean", "default": false},
"collect_logs": {"type": "boolean", "default": false},
"build_args": {"type": "string"},
"ln": {"type": "string"}
"ln": {"type": "string"},
"ln-image": {"type": "string"}
},
"additionalProperties": false,
"oneOf": [
Expand Down
5 changes: 4 additions & 1 deletion src/warnet/lnnode.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@


class LNNode:
def __init__(self, warnet, tank, impl, backend: BackendInterface):
def __init__(self, warnet, tank, impl, image, backend: BackendInterface):
self.warnet = warnet
self.tank = tank
assert impl == "lnd"
self.impl = impl
self.image = "lightninglabs/lnd:v0.17.0-beta"
if image:
self.image = image
self.backend = backend
self.ipv4 = generate_ipv4_addr(self.warnet.subnet)
self.rpc_port = 10009
Expand Down
4 changes: 3 additions & 1 deletion src/warnet/tank.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ def parse_graph_node(self, node):

# Special handling for complex properties
if "ln" in node:
self.lnnode = LNNode(self.warnet, self, node["ln"], self.warnet.container_interface)
impl = node["ln"]
image = node.get("ln-image", None)
self.lnnode = LNNode(self.warnet, self, impl, image, self.warnet.container_interface)

self.config_dir = self.warnet.config_dir / str(self.suffix)
self.config_dir.mkdir(parents=True, exist_ok=True)
Expand Down
8 changes: 5 additions & 3 deletions src/warnet/warnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,15 @@ def __init__(self, config_dir, backend, network_name: str):
def __str__(self) -> str:
# TODO: bitcoin_conf and tc_netem can be added back in to this table
# if we write a helper function that can text-wrap inside a column
template = "\t" + "%-8.8s" + "%-25.24s" + "%-18.18s" + "%-18.18s" + "%-18.18s" + "\n"
tanks_str = template % ("Index", "Version", "IPv4", "LN", "LN IPv4")
template = "\t" + "%-8.8s" + "%-25.24s" + "%-18.18s" + "%-18.18s" + "%-18.18s" + "%-18.18s" + "\n"
tanks_str = template % ("Index", "Version", "IPv4", "LN", "LN Image", "LN IPv4")
for tank in self.tanks:
tanks_str += template % (
tank.index,
tank.version,
tank.ipv4,
tank.lnnode.impl if tank.lnnode is not None else None,
tank.lnnode.image if tank.lnnode is not None else None,
tank.lnnode.ipv4 if tank.lnnode is not None else None,
)
return (
Expand Down Expand Up @@ -82,7 +83,7 @@ def _warnet_dict_representation(self) -> dict:
]

# Tanks
tank_headers = ["Index", "Version", "IPv4", "bitcoin conf", "tc_netem", "LN", "LN IPv4"]
tank_headers = ["Index", "Version", "IPv4", "bitcoin conf", "tc_netem", "LN", "LN Image", "LN IPv4"]
has_ln = any(tank.lnnode and tank.lnnode.impl for tank in self.tanks)
tanks = []
for tank in self.tanks:
Expand All @@ -91,6 +92,7 @@ def _warnet_dict_representation(self) -> dict:
tank_data.extend(
[
tank.lnnode.impl if tank.lnnode else "",
tank.lnnode.image if tank.lnnode else "",
tank.lnnode.ipv4 if tank.lnnode else "",
]
)
Expand Down
2 changes: 2 additions & 0 deletions test/data/ln.graphml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<key attr.name="bitcoin_config" attr.type="string" for="node" id="bitcoin_config"/>
<key attr.name="tc_netem" attr.type="string" for="node" id="tc_netem"/>
<key attr.name="ln" attr.type="string" for="node" id="ln"/>
<key attr.name="ln-image" attr.type="string" for="node" id="ln-image"/>
<key attr.name="channel" attr.type="string" for="edge" id="channel"/>
<key attr.name="collect_logs" attr.type="boolean" for="node" id="collect_logs"/>
<key attr.name="image" attr.type="string" for="node" id="image"/>
Expand All @@ -17,6 +18,7 @@
<data key="version">26.0</data>
<data key="bitcoin_config">-uacomment=w1</data>
<data key="ln">lnd</data>
<data key="ln-image">lightninglabs/lnd:v0.15.5-beta</data>
<data key="collect_logs">true</data>
</node>
<node id="2">
Expand Down

0 comments on commit ec3d3d7

Please sign in to comment.