Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
itsneski committed Feb 14, 2022
2 parents 0f04c88 + aa9817e commit d77e974
Show file tree
Hide file tree
Showing 11 changed files with 287 additions and 61 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Lightning Jet 🚀⚡️, or simply Jet
General-purpose automated rebalancer for LND Lightning nodes. Helps get an insight into peers' classification based on routing history, missed routing opportunities, and stuck htlcs.
Fully automated rebalancer for LND Lightning nodes. Helps get an insight into peers' classification based on routing history, missed routing opportunities, and stuck htlcs.

Join [Lightning Jet telegram chat](https://t.me/lnjet).

Expand Down
23 changes: 23 additions & 0 deletions api/htlc-analyzer.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,29 @@ module.exports = {
}
return res;
},
cumulativeHtlcs(days = 1) {
let htlcs = listHtlcsSync({days:days});

if (htlcs.length === 0) return console.log('no htlc records found');
let channelMap = {};
htlcs.forEach(h => {
if (h.from_chan == '0') return; // skip rebalances
let entry = channelMap[h.to_chan];
if (!entry) {
entry = { total:0, count:0 };
channelMap[h.to_chan] = entry;
}
entry.total += h.sats;
entry.count++;
})
let chans = [];
Object.keys(channelMap).forEach(c => {
let entry = channelMap[c];
chans.push({chan:c, total:entry.total, count:entry.count});
})
chans.sort((a, b) => {return b.total - a.total});
return chans;
},
htlcAnalyzer(days = 1) {
let curr;
let htlcs = listHtlcsSync({days:days});
Expand Down
5 changes: 3 additions & 2 deletions api/rebalance.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ module.exports = ({from, to, amount, ppm = config.rebalancer.maxPpm || constants

// record for jet monitor
const rebalanceId = recordActiveRebalanceSync({from: outId, to: inId, amount: remainingAmount, ppm, mins: timeLeft});
if (rebalanceId === undefined) console.error('rebalance db record id is undefined');

// call bos rebalance in sync mode
let rbSuccess, rbError;
Expand All @@ -239,7 +240,7 @@ module.exports = ({from, to, amount, ppm = config.rebalancer.maxPpm || constants
continue;
} finally {
// remove the record
deleteActiveRebalance(rebalanceId);
if (rebalanceId != undefined) deleteActiveRebalance(rebalanceId);
}

if (rbError) {
Expand Down Expand Up @@ -403,7 +404,7 @@ module.exports = ({from, to, amount, ppm = config.rebalancer.maxPpm || constants
lastError = 'unknownError';
lastMessage = 'unidentified error';
console.log('\n-------------------------------------------');
console.log(lastMessage + ', retrying');
console.log(lastMessage, rbError, ' retrying');
rep++;
}
} else { // !stderr
Expand Down
14 changes: 8 additions & 6 deletions api/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,10 @@ module.exports = {
channels.forEach(c => {
let entry = inbound[c.chan_id] || outbound[c.chan_id] || balanced[c.chan_id];
if (entry) {
entry.capacity = c.capacity;
entry.local = c.local_balance;
entry.remote = c.remote_balance;
entry.active = c.active;
entry.capacity = parseInt(c.capacity);
entry.local = parseInt(c.local_balance);
entry.remote = parseInt(c.remote_balance);
return;
}
let map;
Expand All @@ -140,13 +141,14 @@ module.exports = {
}
if (map) {
map[c.chan_id] = {
active: c.active,
id: c.chan_id,
peer: c.remote_pubkey,
name: peers[c.remote_pubkey].name,
lifetime: c.lifetime,
capacity: c.capacity,
local: c.local_balance,
remote: c.remote_balance
capacity: parseInt(c.capacity),
local: parseInt(c.local_balance),
remote: parseInt(c.remote_balance)
}

if (c.p != undefined) map[c.chan_id].p = c.p;
Expand Down
30 changes: 29 additions & 1 deletion lnd-api/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,30 @@ const deasync = require('deasync');
const round = n => Math.round(n);

module.exports = {
forwardHistorySync: function(lndClient, secs = 5 * 60, max = 1000) {
if (!lndClient) throw new Error('forwardHistorySync: need lndClient');
let done = false;
let response;
let error;
try {
const start = Math.floor(+new Date() / 1000) - secs;
const req = {start_time:start, num_max_events:max};
lndClient.forwardingHistory(req, (err, resp) => {
if (err) error = err; else response = resp;
done = true;
})
} catch(err) {
error = err;
done = true;
}
while(!done) {
require('deasync').runLoopOnce();
}
return {error, events:response && response.forwarding_events};
},
// return true if lnd is alive, false otherwise
isLndAlive: function(lndClient) {
if (!lndClient) throw new Error('isLndAlive: lndClient is null');
if (!lndClient) throw new Error('isLndAlive: need lndClient');
// do a simple ping (perhaps replace it with getVersion)
const {getInfoSync} = module.exports;
try {
Expand Down Expand Up @@ -111,6 +132,7 @@ module.exports = {
return;
}
inPeers.push({
active: channels[n].active,
id: channels[n].chan_id,
peer: channels[n].remote_pubkey,
name: peers[channels[n].remote_pubkey].name,
Expand All @@ -130,6 +152,7 @@ module.exports = {
return;
}
outPeers.push({
active: channels[n].active,
id: channels[n].chan_id,
peer: channels[n].remote_pubkey,
name: peers[channels[n].remote_pubkey].name,
Expand Down Expand Up @@ -242,6 +265,11 @@ module.exports = {
id: r.peer,
name: peers[r.peer].name,
}
if (!r.node1_policy || !r.node2_policy) {
// likely that a channel has been added but fees haven't yet
// been propagated by gossip
return console.warn('undefined fee policy:', r);
}
if (r.node1_pub === info.identity_pubkey) {
fee.local = {
base: parseInt(r.node1_policy.fee_base_msat),
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"run-parallel": "1.2.0",
"sqlite3": "^4.2.0"
},
"description": "General-purpose automated rebalancer for LND Lightning nodes. Helps get an insight into peers' classification based on routing history, missed routing opportunities, and stuck htlcs.",
"description": "Fully automated rebalancer for LND Lightning nodes. Helps get an insight into peers' classification based on routing history, missed routing opportunities, and stuck htlcs.",
"engines": {
"node": ">=12"
},
Expand All @@ -41,5 +41,5 @@
"scripts": {
"postinstall": "./tools/genconfig"
},
"version": "1.4.0"
"version": "1.4.1"
}
9 changes: 9 additions & 0 deletions service/queue.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,15 @@ module.exports = class RebalanceQueue {
})
return included;
}
sats(peer) { // returns outstanding sats for the peer, inbound and outbound
let inbound = 0;
let outbound = 0;
this.queue.forEach(entry => {
if (entry.from === peer) outbound += entry.amount;
if (entry.to === peer) inbound += entry.amount;
})
return {inbound, outbound};
}
list() { return this.queue; }
count() { return this.queue.length; }
}
Loading

0 comments on commit d77e974

Please sign in to comment.