Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
itsneski committed Aug 5, 2022
2 parents 29e2f00 + 6a09e66 commit 7a66d8e
Show file tree
Hide file tree
Showing 15 changed files with 3,631 additions and 4,804 deletions.
21 changes: 10 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@


# Lightning Jet 🚀⚡️, or simply Jet

Lightning Jet is a fully automated rebalancer for Lightning nodes. Jet optimizes channel liquidity allocation based on routing volume, missed routing opportunities (htlcs), and other variables.
Expand All @@ -16,7 +15,7 @@ You can [install Lightning Jet](#prerequisites) on a laptop, desktop, Raspberry

You can use Lightning Jet to rebalance your node in [Voltage Cloud](#voltage-cloud). In this setup, Jet will connect to your node remotely via a secure connection.

You can install and run Lightning Jet in [Docker](#docker) - for advanced users with prior Docker experience.
You can install and run Lightning Jet in [Docker](#docker) (for advanced users with prior Docker experience).

Jet is available on [EmbassyOS](https://github.com/Start9Labs/embassy-os) and can rebalance channels on [Start9](https://start9.com/latest/) products that run the OS.

Expand All @@ -41,7 +40,7 @@ cd lightning-jet
npm install --build-from-source --python=/usr/bin/python3
nano ./api/config.json
```
Edit `config.json`: set correct paths for `macaroonPath` and `tlsCertPath`. On umbrel, macaroons are typically located at `~/umbrel/lnd/data/chain/bitcoin/mainnet/readonly.macaroon`, tls cert is at `~/umbrel/lnd/tls.cert`. Optional: you can list expensive nodes to avoid in the `avoid` section of the config file (can be done later).
Edit `config.json`: set correct absolute (not relative) paths for `macaroonPath` and `tlsCertPath`. On umbrel, macaroons are typically located at `/home/umbrel/umbrel/lnd/data/chain/bitcoin/mainnet/admin.macaroon`, tls cert is at `/home/umbrel/umbrel/lnd/tls.cert`.
```bash
nano ~/.profile
```
Expand All @@ -62,14 +61,14 @@ Test your path by running `jet -v`. Your path is set correctly if it prints out
- Install JET (following the [above steps](#node-and-npm))
- Set the following in `config.json`:
```
"macaroonPath": "/home/bos/.lnd/data/chain/bitcoin/mainnet/readonly.macaroon"
"macaroonPath": "/home/bos/.lnd/data/chain/bitcoin/mainnet/admin.macaroon"
"tlsCertPath": "/home/bos/.lnd/tls.cert"
```

The following step may not be necessary in case you get read access to channel.db via a symlink.

```bash
chmod +r /home/bos/.lnd/data/chain/bitcoin/mainnet/readonly.macaroon
chmod +r /home/bos/.lnd/data/chain/bitcoin/mainnet/admin.macaroon
```

## Post-Installation
Expand Down Expand Up @@ -121,7 +120,7 @@ cd lightning-jet
. docker/genconfig.sh
```

Edit `$HOME/.lightning-jet/config.json`: set correct paths for `macaroonPath` and `tlsCertPath`. On Umbrel, macaroons are typically located at `~/umbrel/lnd/data/chain/bitcoin/mainnet/readonly.macaroon`, tls cert is at `~/umbrel/lnd/tls.cert`. Optional: list expensive nodes to avoid in the `avoid` section.
Edit `$HOME/.lightning-jet/config.json`: set correct paths for `macaroonPath` and `tlsCertPath`. On Umbrel, macaroons are located at `/home/umbrel/umbrel/lnd/data/chain/bitcoin/mainnet/admin.macaroon`, tls cert is at `/home/umbrel/umbrel/lnd/tls.cert`. Optional: list expensive nodes to avoid in the `avoid` section.

```bash
nano $HOME/.lightning-jet/config.json
Expand Down Expand Up @@ -165,7 +164,7 @@ Lightning Jet can rebalance your node in Voltage Cloud by connecting to it remot

Next, update `config.json` by `nano api/config.json`:

1. Set `macaroonPath` to the absolute path of `admin.macaroon` file from the previous step, e.g. `/home/umbrel/lightning-jet/voltage/admin.macaroon` if on umbrel.
1. Set `macaroonPath` to the absolute (not relative) path of `admin.macaroon` file from the previous step, e.g. `/home/umbrel/lightning-jet/voltage/admin.macaroon` if on umbrel.

2. Remove `tlsCertPath` from the config.

Expand Down Expand Up @@ -210,10 +209,10 @@ Copy the telegram token from the Telegram app chat with BotFather (right under '
A list of config settings under `./api/config.json`:
|||
|--|--|
|`macaroonPath`|Macaroon path to enable LND API calls. Most calls will work with `readonly.macaroon` except for `jet update-channel` that requires `admin.macaroon`.|
|`tlsCertPath`|Path to the tls cert to enable LND API calls.|
|`avoid`|A list of nodes to avoid during manual and automated rebalances. `jet rebalance` avoids expensive nodes automatically. the `avoid` setting can help speed things up by providing a static list of nodes to avoid.|
|`macaroonPath`|`admin.macaroon` absolute path for Jet connect to LND.|
|`tlsCertPath`|tls cert absolute path for Jet connect to LND.|
|`telegramToken`|The telegram bot token.|
|`avoid`|A list of nodes to avoid during manual and automated rebalances. `jet rebalance` avoids expensive nodes automatically. the `avoid` setting can help speed things up by providing a static list of nodes to avoid.|

Settings under `rebalancer` section:
|||
Expand All @@ -238,7 +237,7 @@ Settings under `rebalancer` section:
"03d2e20bc19d995098ba357157a9cfbfbfdff4b78fce5ec713128e988e0115d776",
"03f80288f858251aed6f70142fab79dede5427a0ff4b618707bd0a616527a8cec7"
],
"macaroonPath": "/home/umbrel/umbrel/lnd/data/chain/bitcoin/mainnet/readonly.macaroon",
"macaroonPath": "/home/umbrel/umbrel/lnd/data/chain/bitcoin/mainnet/admin.macaroon",
"tlsCertPath": "/home/umbrel/umbrel/lnd/tls.cert",
"debugMode": false,
"telegramToken": "123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11",
Expand Down
2 changes: 1 addition & 1 deletion api/channeldb.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ if (!global.channelDbFile) {
const conf = config.macaroonPath;
if (!conf) return console.error('macaroonPath is not defined in the config.json');
const base = path.normalize(path.dirname(conf) + '/../../../');
let cmd = 'find ' + base + ' -name channel.db';
let cmd = 'find ' + base + ' -name channel.db 2> /dev/null';
try {
global.channelDbFile = execSync(cmd).toString().trim();
} catch(error) {
Expand Down
2 changes: 1 addition & 1 deletion api/ln-rpc.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ const {lnrpc} = require('../lnd-api/connect');

const PROTO = __dirname + '/proto/lightning.proto';

const lnRpc = lnrpc(config.lightningProto || PROTO, config.macaroonPath, config.tlsCertPath);
const lnRpc = lnrpc(config.lightningProto || PROTO, config.macaroonPath, config.tlsCertPath, config.serverAddress);

module.exports = lnRpc;
2 changes: 1 addition & 1 deletion api/router-rpc.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ const {routerrpc} = require('../lnd-api/connect');

const PROTO = __dirname + '/proto/router.proto';

const routerRpc = routerrpc(config.routerProto || PROTO, config.macaroonPath, config.tlsCertPath);
const routerRpc = routerrpc(config.routerProto || PROTO, config.macaroonPath, config.tlsCertPath, config.serverAddress);

module.exports = routerRpc;
22 changes: 20 additions & 2 deletions api/utils.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const fs = require('node:fs');
const {spawn, execSync} = require('node:child_process');
const importLazy = require('import-lazy')(require);
const {execSync} = require('child_process');
const lndClient = importLazy('./connect');
const {listPeersMapSync} = require('../lnd-api/utils');
const {listChannelsSync} = require('../lnd-api/utils');
Expand All @@ -19,10 +20,25 @@ const config = importLazy('./config');
const findProc = require('find-process');
const date = require('date-and-time');


const round = n => Math.round(n);
const pThreshold = 1; // %

module.exports = {
// spawns and detaches child process
spawnDetached({cmd, arg, log}) {
let parg = {
detached: true,
shell: process.env.SHELL
}
if (log) {
parg.stdio = [ 'ignore', fs.openSync(log, 'a'), fs.openSync(log, 'a') ];
} else {
parg.stdio = 'ignore';
}
const subprocess = spawn(cmd, arg, parg);
subprocess.unref();
},
rebalanceHistoryConsolidated(hours = 1) {
let history = listRebalancesSync(hours * 60 * 60); // in secs
if (!history || history.length === 0) return;
Expand Down Expand Up @@ -452,9 +468,11 @@ module.exports = {
return formatted;
},
readLastLineSync: function(file) {
const fs = require('fs');
if (!fs.existsSync(file)) return;

let lastLine;
let done;
const fs = require('fs');
const readline = require('readline');
const readInterface = readline.createInterface({
input: fs.createReadStream(file),
Expand Down
11 changes: 7 additions & 4 deletions bos/connect.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@ const config = require('../api/config');
const lnService = require('ln-service');

const macaroon = fs.readFileSync(config.macaroonPath).toString('base64');
const tlsCert = fs.readFileSync(config.tlsCertPath).toString('base64');
const tlsCert = config.tlsCertPath && fs.readFileSync(config.tlsCertPath).toString('base64');
const address = config.serverAddress || 'localhost:10009';

const {lnd} = lnService.authenticatedLndGrpc({
cert: tlsCert,
let props = {
macaroon: macaroon,
socket: address
})
}
// set only if tls cert exists; e.g. cert is not required for voltage.cloud
if (tlsCert) props.cert = tlsCert;

const {lnd} = lnService.authenticatedLndGrpc(props);

module.exports = lnd;
2 changes: 1 addition & 1 deletion docker/genconfig.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ mkdir -p $HOME/.lightning-jet
[ -f "$CONFIG_FILE" ] || cat << 'CONFIG' > $CONFIG_FILE
{
"avoid": [],
"macaroonPath": "/home/umbrel/umbrel/lnd/data/chain/bitcoin/mainnet/readonly.macaroon",
"macaroonPath": "/home/umbrel/umbrel/lnd/data/chain/bitcoin/mainnet/admin.macaroon",
"tlsCertPath": "/home/umbrel/umbrel/lnd/tls.cert",
"rebalancer": {
"maxTime": 30,
Expand Down
12 changes: 11 additions & 1 deletion jet
Original file line number Diff line number Diff line change
Expand Up @@ -223,10 +223,12 @@ cap
console.log('-------------------------------------------------------------')
console.log(msg);
console.log('-------------------------------------------------------------')


let unknownPeers = [];
let count = 0;
classified.outbound.forEach(c => {
console.log(); // newline
if (!feeMap[c.peer]) unknownPeers.push({name: c.name, id: c.peer});
let num = printFeeAnalysis(c.name, c.peer, feeMap[c.peer].local, feeMap[c.peer].remote, options.profit);
count += num;
})
Expand All @@ -241,10 +243,18 @@ cap
count = 0;
classified.balanced.forEach(c => {
console.log(); // newline
if (!feeMap[c.peer]) unknownPeers.push({name: c.name, id: c.peer});
let num = printFeeAnalysis(c.name, c.peer, feeMap[c.peer].local, feeMap[c.peer].remote, options.profit);
count += num;
})
if (count === 0) console.log('no issues to report');

if (unknownPeers.length > 0) {
console.log(constants.colorYellow, '\nunknown fee data for the following peers (excluded):');
unknownPeers.forEach(p => {
console.log(p.name, p.id);
})
}
})
})

Expand Down
4 changes: 2 additions & 2 deletions lnd-api/connect.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ const loaderOptions = {
};

module.exports = {
routerrpc(protoPath, macaroonPath, tlsCertPath) {
routerrpc(protoPath, macaroonPath, tlsCertPath, serverAddress = 'localhost:10009') {
let descriptor = generateDescriptor(protoPath, macaroonPath, tlsCertPath);
let routerrpc = descriptor.desc.routerrpc;
let client = new routerrpc.Router('localhost:10009', descriptor.creds);
let client = new routerrpc.Router(serverAddress, descriptor.creds);
return client;
},
lnrpc(protoPath, macaroonPath, tlsCertPath, serverAddress = 'localhost:10009') {
Expand Down
Loading

0 comments on commit 7a66d8e

Please sign in to comment.