From c9fd3383cc74128d93a4c4960fc6007c31fc6c8b Mon Sep 17 00:00:00 2001 From: Theophilus Date: Wed, 29 May 2024 14:28:48 +0100 Subject: [PATCH] feat: update simulation activity logic and volumes configuration --- docker/nodes.json | 4 --- .../default/cards/ActivityDesignerCard.tsx | 3 +- src/lib/docker/dockerService.ts | 36 ++++++++++++++----- src/lib/docker/nodeTemplates.ts | 6 +++- 4 files changed, 34 insertions(+), 15 deletions(-) diff --git a/docker/nodes.json b/docker/nodes.json index d88ce8a270..4c4b3cf0ed 100644 --- a/docker/nodes.json +++ b/docker/nodes.json @@ -59,10 +59,6 @@ "0.3.3-alpha": "0.16.0-beta", "0.3.2-alpha": "0.16.0-beta" } - }, - "simln": { - "latest": "0.2.0", - "versions": ["0.2.0"] } } } diff --git a/src/components/designer/default/cards/ActivityDesignerCard.tsx b/src/components/designer/default/cards/ActivityDesignerCard.tsx index ac890c86f9..d803ece136 100644 --- a/src/components/designer/default/cards/ActivityDesignerCard.tsx +++ b/src/components/designer/default/cards/ActivityDesignerCard.tsx @@ -186,9 +186,10 @@ const ActivityDesignerCard: React.FC = ({ visible, network }) => { useEffect(() => { isSimulationContainerRunning().then(isRunning => { + console.log('isRunning', isRunning); setIsStartSimulationActive(isRunning); }); - }, []); + }, [isSimulationContainerRunning]); const startSimulationActivity = () => { if (network.status !== Status.Started) { diff --git a/src/lib/docker/dockerService.ts b/src/lib/docker/dockerService.ts index c8a45d8b36..48419ed82c 100644 --- a/src/lib/docker/dockerService.ts +++ b/src/lib/docker/dockerService.ts @@ -178,17 +178,30 @@ class DockerService implements DockerLibrary { const nodes = new Set(); const activities = new Set(); network.simulationActivities.map(activity => { + const { source, destination } = activity; + // split the macaroon and cert path at "volumes/" to get the relative path + // to the docker volume. This is necessary because the docker volumes are + // mounted as a different path in the container + const sourceMacaroon = source.macaroon.split('volumes/').pop(); + const sourceCert = source?.tlsCert + ? source.tlsCert?.split('volumes/').pop() + : source?.clientKey?.split('volumes/').pop(); + const destMacaroon = destination.macaroon.split('volumes/').pop(); + const destCert = destination.tlsCert + ? destination.tlsCert?.split('volumes/').pop() + : destination?.clientKey?.split('volumes/').pop(); + info({ sourceMacaroon, sourceCert, destMacaroon, destCert }); nodes.add({ id: activity.source.id, address: activity.source.address, - macaroon: activity.source.macaroon, - cert: activity.source.clientCert ?? activity.source.clientKey, + macaroon: `/home/simln/.${sourceMacaroon}`, + cert: `/home/simln/.${sourceCert}`, }); nodes.add({ id: activity.destination.id, address: activity.destination.address, - macaroon: activity.destination.macaroon, - cert: activity.destination.clientCert ?? activity.destination.clientKey, + macaroon: `/home/simln/.${destMacaroon}`, + cert: `/home/simln/.${destCert}`, }); activities.add({ @@ -200,7 +213,7 @@ class DockerService implements DockerLibrary { }); return { nodes: Array.from(nodes), - activities: Array.from(activities) as SimulationActivity[], + activity: Array.from(activities) as SimulationActivity[], }; } @@ -210,8 +223,9 @@ class DockerService implements DockerLibrary { */ async startSimulationActivity(network: Network) { const simJson = await this.constructSimJson(network); - console.log('simJson', simJson); - info(`simJson: ${simJson}`); + info( + `simJson: ${simJson} simJson.nodes: ${simJson.nodes} simJson.activities: ${simJson.activity}`, + ); await this.ensureDirs(network, [ ...network.nodes.bitcoin, ...network.nodes.lightning, @@ -234,8 +248,12 @@ class DockerService implements DockerLibrary { info(`Simulation activity stopped:\n ${result.out || result.err}`); // remove container to avoid conflicts when starting the network again - await this.execute(compose.rm as any, this.getArgs(network), 'simln'); - info(`Removed simln container`); + const removedContainer = await this.execute( + compose.rm as any, + this.getArgs(network), + 'simln', + ); + info(`Removed simln container ${removedContainer.out || removedContainer.err}`); } /** diff --git a/src/lib/docker/nodeTemplates.ts b/src/lib/docker/nodeTemplates.ts index 6fb39de0fe..1c4954dc8e 100644 --- a/src/lib/docker/nodeTemplates.ts +++ b/src/lib/docker/nodeTemplates.ts @@ -18,7 +18,11 @@ export const simln = ( command: trimInside(command), environment, restart: 'always', - volumes: [`./volumes/${name}:/home/simln/.simln`], + volumes: [ + `./volumes/${name}:/home/simln/.simln`, + `./volumes/${dockerConfigs.LND.volumeDirName}:/home/simln/.lnd`, + `./volumes/${dockerConfigs['c-lightning'].volumeDirName}:/home/simln/.clightning`, + ], expose: [], ports: [], });