Skip to content

Commit

Permalink
feat: update simulation activity logic and volumes configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
Extheoisah committed May 29, 2024
1 parent 825123c commit c9fd338
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 15 deletions.
4 changes: 0 additions & 4 deletions docker/nodes.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,10 @@ const ActivityDesignerCard: React.FC<Props> = ({ visible, network }) => {

useEffect(() => {
isSimulationContainerRunning().then(isRunning => {
console.log('isRunning', isRunning);
setIsStartSimulationActive(isRunning);
});
}, []);
}, [isSimulationContainerRunning]);

const startSimulationActivity = () => {
if (network.status !== Status.Started) {
Expand Down
36 changes: 27 additions & 9 deletions src/lib/docker/dockerService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -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[],
};
}

Expand All @@ -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,
Expand All @@ -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}`);
}

/**
Expand Down
6 changes: 5 additions & 1 deletion src/lib/docker/nodeTemplates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: [],
});
Expand Down

0 comments on commit c9fd338

Please sign in to comment.