Skip to content

Commit e2aee63

Browse files
committed
feat: add simln support to CLN
1 parent ce47c27 commit e2aee63

File tree

5 files changed

+58
-5
lines changed

5 files changed

+58
-5
lines changed

src/components/designer/default/AddSimulationModal.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ const AddSimulationModal: React.FC<Props> = ({ network }) => {
105105
name="source"
106106
label={l('source')}
107107
nodeStatus={Status.Started}
108-
implementation={['LND', 'eclair']}
108+
implementation={['LND', 'eclair', 'c-lightning']}
109109
nodes={nodes}
110110
/>
111111
</Col>
@@ -115,7 +115,7 @@ const AddSimulationModal: React.FC<Props> = ({ network }) => {
115115
name="destination"
116116
label={l('destination')}
117117
nodeStatus={Status.Started}
118-
implementation={['LND', 'eclair']}
118+
implementation={['LND', 'eclair', 'c-lightning']}
119119
nodes={nodes}
120120
/>
121121
</Col>

src/lib/docker/dockerService.spec.ts

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -885,7 +885,7 @@ describe('DockerService', () => {
885885
name: 'my network',
886886
description: 'network description',
887887
lndNodes: 1,
888-
clightningNodes: 0,
888+
clightningNodes: 1,
889889
eclairNodes: 1,
890890
bitcoindNodes: 1,
891891
tapdNodes: 0,
@@ -899,6 +899,9 @@ describe('DockerService', () => {
899899
const eclairNodes = network.nodes.lightning.filter(
900900
n => n.implementation === 'eclair',
901901
);
902+
const clightningNodes = network.nodes.lightning.filter(
903+
n => n.implementation === 'c-lightning',
904+
);
902905
beforeEach(() => {
903906
// Add simulation config to the test network
904907
network.simulation = {
@@ -960,9 +963,9 @@ describe('DockerService', () => {
960963
});
961964

962965
it('should handle errors when using unsupported node types', async () => {
963-
network.nodes.lightning[0].implementation = 'c-lightning';
966+
network.nodes.lightning[0].implementation = 'litd';
964967
await expect(dockerService.startSimulation(network)).rejects.toThrow(
965-
'unsupported node implementation: c-lightning',
968+
'unsupported node implementation: litd',
966969
);
967970
});
968971

@@ -984,5 +987,40 @@ describe('DockerService', () => {
984987
expect.stringContaining(`container_name: polar-n1-simln`),
985988
);
986989
});
990+
991+
// Now we should be able to use c-lightning in the simulation
992+
it('should add c-lightning to the docker-compose.yml file', async () => {
993+
network.simulation = {
994+
networkId: 1,
995+
source: clightningNodes[0],
996+
destination: eclairNodes[0],
997+
intervalSecs: 60,
998+
amountMsat: 1000,
999+
status: Status.Stopped,
1000+
};
1001+
dockerService.saveComposeFile(network);
1002+
expect(filesMock.write).toHaveBeenCalledWith(
1003+
expect.stringContaining('docker-compose.yml'),
1004+
expect.stringContaining(`container_name: polar-n1-simln`),
1005+
);
1006+
1007+
composeMock.upOne.mockResolvedValue(mockResult);
1008+
await dockerService.startSimulation(network);
1009+
1010+
// Verify directories were created
1011+
expect(fsMock.ensureDir).toHaveBeenCalled();
1012+
1013+
// Verify sim.json was written with correct config
1014+
expect(filesMock.write).toHaveBeenCalledWith(
1015+
expect.stringContaining('sim.json'),
1016+
expect.stringContaining(clightningNodes[0].name),
1017+
);
1018+
1019+
// Verify docker compose command was called
1020+
expect(composeMock.upOne).toHaveBeenCalledWith(
1021+
'simln',
1022+
expect.objectContaining({ cwd: network.path }),
1023+
);
1024+
});
9871025
});
9881026
});

src/lib/docker/dockerService.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,19 @@ class DockerService implements DockerLibrary {
446446
};
447447
break;
448448

449+
case 'c-lightning':
450+
const cln = node as CLightningNode;
451+
simNode = {
452+
id: cln.name,
453+
address: `host.docker.internal:${cln.ports.grpc}`,
454+
ca_cert: `/home/simln/.${cln.paths.tlsCert?.split('volumes/').pop()}`,
455+
client_cert: `/home/simln/.${cln.paths.tlsClientCert
456+
?.split('volumes/')
457+
.pop()}`,
458+
client_key: `/home/simln/.${cln.paths.tlsClientKey?.split('volumes/').pop()}`,
459+
};
460+
break;
461+
449462
default:
450463
throw new Error(`unsupported node implementation: ${node.implementation}`);
451464
}

src/lib/docker/nodeTemplates.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ export const simln = (
198198
volumes: [
199199
`./volumes/${name}:/home/simln/.simln`,
200200
`./volumes/${dockerConfigs.LND.volumeDirName}:/home/simln/.lnd`,
201+
`./volumes/${dockerConfigs['c-lightning'].volumeDirName}:/home/simln/.c-lightning`,
201202
],
202203
expose: [],
203204
ports: [],

src/utils/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ export const dockerConfigs: Record<NodeImplementationWithSimln, DockerConfig> =
150150
'--log-level=debug',
151151
'--dev-bitcoind-poll=2',
152152
'--dev-fast-gossip',
153+
'--grpc-host=0.0.0.0',
153154
'--grpc-port=11001',
154155
'--log-file=-', // log to stdout
155156
'--log-file=/home/clightning/.lightning/debug.log',

0 commit comments

Comments
 (0)