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 31, 2022
2 parents c06b041 + f6b0448 commit 8885512
Show file tree
Hide file tree
Showing 10 changed files with 223 additions and 143 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ npm install --build-from-source --python=/usr/bin/python3
nano ./api/config.json
```
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`.

> On umbrel0.5.0+, macaroons are located at `/home/umbrel/umbrel/app-data/lightning/data/lnd/data/chain/bitcoin/mainnet/admin.macaroon` and tls cert at `/home/umbrel/umbrel/app-data/lightning/data/lnd/tls.cert`.
```bash
nano ~/.profile
```
Expand All @@ -56,6 +59,14 @@ Next, execute the updated `.profile` for your current terminal session. The path
```
Test your path by running `jet -v`. Your path is set correctly if it prints out help. Fix the `PATH` in `~/.profile` in case of an error.

#### Upgrade to Umbrel0.5.0 (Umbrel5)

Umbrel5 changed the location of macaroons and tls cert files. Edit config file to set correct paths for macaroons at `/home/umbrel/umbrel/app-data/lightning/data/lnd/data/chain/bitcoin/mainnet/admin.macaroon` and tls cert at `/home/umbrel/umbrel/app-data/lightning/data/lnd/tls.cert`.

```bash
nano ./api/config.json
```

#### RaspiBlitz

- Install JET (following the [above steps](#node-and-npm))
Expand Down
9 changes: 6 additions & 3 deletions api/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ exports.services = {
launcher: {
lndTelegramNotify: 5 * 60, // seconds
txnInterval: 1 // mins
},
worker: {
loopInterval: 5 // minutes
}
}

Expand All @@ -65,9 +68,9 @@ exports.channeldb = {
sizeThreshold: { // in gb
notfound: -1, // channel.db not found
normal: 0,
warning: 2, // >2
serious: 5,
urgent: 8
warning: 4, // >4
serious: 8,
urgent: 16
},
telegramNotify: {
category: 'telegram.notify.channeldb',
Expand Down
3 changes: 3 additions & 0 deletions api/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ module.exports = {
return (self) ? res.length > 1 : res.length > 0;
},
listPeersFormattedSync(days = 7) {
const pref = 'listPeersFormattedSync:';
let IN_PEERS = {};
let OUT_PEERS = {};
let BALANCED_PEERS = {};
Expand Down Expand Up @@ -288,6 +289,7 @@ module.exports = {
let inPeers = [];
peers.forEach(p => {
if (IN_PEERS[p.id]) {
if (!feeMap[p.id]) return console.warn(pref, 'couldnt find fee for', p.id);
let peer = convertPeer(p, IN_PEERS[p.id], true);
peer.ppm = parseInt(feeMap[p.id].local.rate);
inPeers.push(peer);
Expand Down Expand Up @@ -316,6 +318,7 @@ module.exports = {
let balancedPeers = [];
peers.forEach(p => {
if (BALANCED_PEERS[p.id]) {
if (!feeMap[p.id]) return console.warn(pref, 'couldnt find fee for', p.id);
let peer = convertPeer(p, BALANCED_PEERS[p.id]);
peer.ppm = parseInt(feeMap[p.id].local.rate);
balancedPeers.push(peer);
Expand Down
32 changes: 19 additions & 13 deletions lnd-api/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,17 @@ module.exports = {
},
stuckHtlcsSync: function(lndClient) {
let data;
let error;
let done;
lndClient.listChannels({}, function(err, response) {
if (err) {
throw new Error(err);
}
error = err;
data = response;
done = true;
})
while(data === undefined) {
while(done === undefined) {
require('deasync').runLoopOnce();
}
if (error) throw new Error(error);
let htlcs = [];
data.channels.forEach(c => {
if (c.pending_htlcs.length === 0) return;
Expand All @@ -123,15 +125,17 @@ module.exports = {
},
listPendingChannelsSync: function(lndClient) {
let channels;
let error;
let done;
lndClient.pendingChannels({}, function(err, response) {
if (err) {
throw new Error(err);
}
error = err;
channels = response;
done = true;
})
while(channels === undefined) {
while(done === undefined) {
require('deasync').runLoopOnce();
}
if (error) throw new Error(error);
return channels;
},
htlcHistorySync: function(lndClient, days = 7) {
Expand Down Expand Up @@ -430,15 +434,17 @@ module.exports = {
},
listChannelsSync: function(lndClient) {
let channels;
let error;
let done;
lndClient.listChannels({}, function(err, response) {
if (err) {
throw new Error(err);
}
channels = response.channels;
error = err;
channels = response && response.channels;
done = true;
})
while(channels === undefined) {
while(done === undefined) {
require('deasync').runLoopOnce();
}
if (error) throw new Error(error);
return channels;
},
getNodesInfo: function(lndClient, nodes, callback) {
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.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,5 @@
"scripts": {
"postinstall": "./tools/genconfig"
},
"version": "1.5.1"
"version": "1.5.2"
}
95 changes: 76 additions & 19 deletions service/htlc-logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,26 @@
// logs channel state updates into the jet db.
//
// jet start logger
// jet stop logger
// jet restart logger


const date = require('date-and-time');
const constants = require('../api/constants');
const routerRpc = require('../api/router-rpc');
const lnRpc = require('../api/ln-rpc');
const lndClient = require('../api/connect');
const {recordHtlc} = require('../db/utils');
const {isRunningSync} = require('../api/utils');
const {setPropSync} = require('../db/utils');
const {recordChannelEvent} = require('../db/utils');
const constants = require('../api/constants');
const date = require('date-and-time');
const {isLndAlive} = require('../lnd-api/utils');

const loopInterval = 20; // secs

var lastError;
var lndOffline;

const formattedDate = () => date.format(new Date, 'MM/DD hh:mm:ss A');

// only one instance allowed
const fileName = require('path').basename(__filename);
Expand All @@ -22,9 +32,7 @@ if (isRunningSync(fileName, true)) {
}

async function subscribeToHtlcs() {
console.log('\n---------------------------------------');
console.log(date.format(new Date, 'MM/DD hh:mm:ss A'));
console.log('subscribing to htlc events');
console.log(formattedDate() + ' subscribing to htlc events');
for await (const event of routerRpc.subscribeHtlcEvents()) {
let lf = event.link_fail_event;
// filter events
Expand All @@ -35,9 +43,7 @@ async function subscribeToHtlcs() {
}

async function subscribeToChannelEvents() {
console.log('\n---------------------------------------');
console.log(date.format(new Date, 'MM/DD hh:mm:ss A'));
console.log('subscribing to channel events');
console.log(formattedDate() + ' subscribing to channel events');
for await (const event of lnRpc.subscribeChannelEvents()) {
try {
logChannelUpdate(event);
Expand Down Expand Up @@ -83,16 +89,67 @@ function logChannelUpdate(event) {
}

function processError(error) {
console.error(date.format(new Date, 'MM/DD hh:mm:ss A'));
console.error('log error:', error.toString());
// record in the db so that the service will be restarted
setPropSync(constants.services.logger.errorProp, error.toString());
const pref = 'processError:';
console.error(formattedDate(), pref, error.toString());

// trigger lnd [is alive] check
lastError = error;
}

function runLoop() {
const pref = 'runLoop:';
try {
runLoopImpl();
} catch(err) {
// trigger restart?
console.error(formattedDate(), pref, error);
console.error(formattedDate(), pref, 'triggering restart');
setPropSync(constants.services.logger.errorProp, err.toString());
}
}

function runLoopImpl() {
const pref = 'runLoopImpl:';

// run the loop on first lnd check or when lnd is offline or when there was an error
if (lndOffline === undefined || lndOffline || lastError) {
const prev = lndOffline;
try {
lndOffline = !isLndAlive(lndClient);
} catch(err) {
console.error(formattedDate(), pref, err.toString(), 'assuming lnd is offline');
lndOffline = true;
}
if (lndOffline) {
if (prev || prev === undefined) console.warn(constants.colorYellow, formattedDate() + ' lnd is offline');
else console.error(constants.colorRed, formattedDate() + ' lnd went offline');
} else if (lastError) {
// lnd is online, but there was an error; trigger restart just in case
console.warn(constants.colorYellow, formattedDate() + ' error detected ' + lastError.toString() + '; triggering restart');
setPropSync(constants.services.logger.errorProp, lastError.toString());
} else if (prev) {
console.log(constants.colorGreen, formattedDate() + ' lnd is back online');
init();
} else if (prev === undefined) {
console.log(constants.colorGreen, formattedDate() + ' lnd is online');
init();
}
lastError = undefined; // reset
} else {
// skip
}
}

function init() {
subscribeToHtlcs().catch(error => {
processError(error);
})

subscribeToChannelEvents().catch(error => {
processError(error);
})
}

subscribeToHtlcs().catch(error => {
processError(error);
})

subscribeToChannelEvents().catch(error => {
processError(error);
})
runLoop();
setInterval(runLoop, loopInterval * 1000);
Loading

0 comments on commit 8885512

Please sign in to comment.