Skip to content

Commit bc89897

Browse files
Add troubleshooting script to test Commando connection
1 parent ba4832a commit bc89897

6 files changed

Lines changed: 122 additions & 1 deletion

File tree

.github/docs/Contributing.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ source env-local.sh
3232
- OR Run the setup script. Note that it requires `socat` and `jq` to run successfully:
3333

3434
```sh
35-
source entrypoint.sh
35+
source ./scripts/entrypoint.sh
3636
```
3737

3838
Running the Application
@@ -100,6 +100,7 @@ git push
100100
```sh
101101
git checkout main
102102
git merge Release-yy.mm.n
103+
git push
103104
```
104105
- Create versioned tag:
105106

.github/docs/Troubleshooting.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
Debugging Commando Connection
2+
-----------------------------
3+
4+
#### Configure the environment (if not already done):
5+
6+
```sh
7+
cp env.sh env-local.sh
8+
# Edit env-local.sh with your local configuration
9+
source env-local.sh
10+
```
11+
12+
#### Set up Commando authentication (if not already done):
13+
14+
- You can configure Commando credentials in one of the following ways:
15+
- Manual setup: Update LIGHTNING_PUBKEY and LIGHTNING_RUNE in your LIGHTNING_VARS_FILE.
16+
- Automated setup: Run the setup script (requires socat and jq): `source ./scripts/entrypoint.sh`
17+
18+
#### Verify the Commando connection:
19+
20+
After all environment variables are set, run the following script to verify that Commando environment variables are configured and loaded correctly
21+
22+
```sh
23+
node ./scripts/check-commando-connection.js
24+
```

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,8 @@
157157
158158
- Click [here](./.github/docs/Contributing.md) for instructions on how to run it in development mode.
159159
160+
- Follow the steps outlined in [troubleshooting](./.github/docs/Troubleshooting.md) to verify that your Commando connection is successfully established with your current environment setup.
161+
160162
---
161163
162164
# Acknowledgements

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"description": "Core lightning application",
55
"private": true,
66
"license": "MIT",
7+
"type": "module",
78
"scripts": {
89
"frontend:dev": "npm run start -w cln-application-frontend",
910
"frontend:build": "npm run build -w cln-application-frontend",
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
import Lnmessage from 'lnmessage';
2+
import WebSocket from 'ws';
3+
import fs from 'fs';
4+
import crypto from 'crypto';
5+
import { exit } from 'process';
6+
7+
const LIGHTNING_VARS_FILE = process.env.LIGHTNING_VARS_FILE || `${process.cwd()}/.commando`;
8+
const WS_PROTOCOL = process.env.LIGHTNING_WS_PROTOCOL;
9+
const NODE_IP = process.env.LIGHTNING_WS_HOST;
10+
const WS_PORT = process.env.LIGHTNING_WS_PORT;
11+
let NODE_PUBKEY;
12+
let RUNE;
13+
14+
if (!LIGHTNING_VARS_FILE) {
15+
console.error(`[ERROR - ${new Date().toISOString()}]: LIGHTNING_VARS_FILE environment variable not set`);
16+
exit(1);
17+
}
18+
19+
try {
20+
const fileContent = fs.readFileSync(LIGHTNING_VARS_FILE, 'utf8');
21+
const lines = fileContent.split('\n');
22+
23+
for (const line of lines) {
24+
const trimmedLine = line.trim();
25+
if (trimmedLine.startsWith('LIGHTNING_PUBKEY=')) {
26+
NODE_PUBKEY = trimmedLine.split('=')[1].replace(/"/g, '');
27+
} else if (trimmedLine.startsWith('LIGHTNING_RUNE=')) {
28+
RUNE = trimmedLine.split('=')[1].replace(/"/g, '');
29+
}
30+
}
31+
} catch (err) {
32+
console.error(`[ERROR - ${new Date().toISOString()}]: Failed to read file ${LIGHTNING_VARS_FILE}:`, err.message);
33+
exit(1);
34+
}
35+
36+
if (!NODE_PUBKEY) {
37+
console.error(`[ERROR - ${new Date().toISOString()}]: LIGHTNING_PUBKEY not found in file`);
38+
exit(1);
39+
}
40+
if (!RUNE) {
41+
console.error(`[ERROR - ${new Date().toISOString()}]: LIGHTNING_RUNE not found in file`);
42+
exit(1);
43+
}
44+
45+
class SecureWebSocket extends WebSocket {
46+
constructor(url) {
47+
const options = {};
48+
options.rejectUnauthorized = false;
49+
options.cert = fs.readFileSync(process.env.LIGHTNING_WS_CLIENT_CERT_FILE);
50+
options.key = fs.readFileSync(process.env.LIGHTNING_WS_CLIENT_KEY_FILE);
51+
super(url, options);
52+
}
53+
}
54+
55+
if (WS_PROTOCOL === 'wss') { globalThis.WebSocket = SecureWebSocket; }
56+
57+
let lnmessageOptions = {
58+
ip: NODE_IP,
59+
remoteNodePublicKey: NODE_PUBKEY,
60+
privateKey: crypto.randomBytes(32).toString('hex'),
61+
wsProxy: `${WS_PROTOCOL}://${NODE_IP}:${WS_PORT}`,
62+
port: WS_PORT,
63+
logger: { info: console.log, warn: console.log, error: console.error }
64+
}
65+
console.log(`[INFO - ${new Date().toISOString()}]: lnMessage Options `, lnmessageOptions);
66+
67+
const ln = new Lnmessage(lnmessageOptions)
68+
console.log(`[INFO - ${new Date().toISOString()}]: Initialized lnMessage`);
69+
70+
ln.connectionStatus$.subscribe(status => {
71+
if (status === 'failed') {
72+
console.error(`[ERROR - ${new Date().toISOString()}]: Failed to reconnect after maximum attempts`);
73+
exit(1);
74+
}
75+
});
76+
77+
console.log(`[INFO - ${new Date().toISOString()}]: Connecting...`);
78+
try {
79+
await ln.connect();
80+
console.log(`[INFO - ${new Date().toISOString()}]: Connected`);
81+
} catch (err) {
82+
console.error(`[ERROR - ${new Date().toISOString()}]: Connection failed! Error:\n`, err);
83+
exit(1);
84+
}
85+
86+
try {
87+
const getinfoResponse = await ln.commando({reqId: crypto.randomBytes(8).toString('hex'), method: 'getinfo', params: [], rune: RUNE});
88+
console.log(`[INFO - ${new Date().toISOString()}]: Connection successful! Getinfo Response:\n`, getinfoResponse);
89+
exit(0);
90+
} catch (err) {
91+
console.error(`[ERROR - ${new Date().toISOString()}]: Connection failed! Getinfo Error:\n`, err);
92+
exit(1);
93+
}
File renamed without changes.

0 commit comments

Comments
 (0)