Browse Source

refactor LND initial connect

dependabot/npm_and_yarn/ini-1.3.7
Evan Feenstra 4 years ago
parent
commit
a66568b0b9
  1. 23
      app.ts
  2. 24
      dist/app.js
  3. 2
      dist/app.js.map
  4. 36
      dist/src/grpc/index.js
  5. 2
      dist/src/grpc/index.js.map
  6. 35
      src/grpc/index.ts

23
app.ts

@ -11,6 +11,7 @@ import * as controllers from './src/controllers'
import * as socket from './src/utils/socket'
import * as network from './src/network'
import {authModule, unlocker} from './src/auth'
import * as grpc from './src/grpc'
const env = process.env.NODE_ENV || 'development';
const config = require(path.join(__dirname, 'config/app.json'))[env];
@ -22,8 +23,6 @@ console.log('=> config.node_http_port:',config.node_http_port)
process.env.GRPC_SSL_CIPHER_SUITES = 'HIGH+ECDSA'
var i = 0
// START SETUP!
async function start(){
await setupDatabase()
@ -33,25 +32,13 @@ async function start(){
start()
async function connectToLND(){
i++
console.log(`=> [lnd] connecting... attempt #${i}`)
try {
await network.initGrpcSubscriptions() // LND
await mainSetup() // DB + express
await network.initTribesSubscriptions() // MQTT
} catch(e) {
if(e.details) {
console.log(`=> [lnd] error details: ${e.details}`)
} else {
console.log(`=> [lnd] error: ${e.message}`)
}
setTimeout(async()=>{ // retry each 2 secs
await connectToLND()
},2000)
}
await grpc.reconnectToLND(Math.random()) // recursive
console.log(">> SETUP MAIN")
await mainSetup()
}
async function mainSetup(){
await network.initTribesSubscriptions()
if (config.hub_api_url) {
// pingHubInterval(15000)
checkInvitesHubInterval(5000)

24
dist/app.js

@ -22,6 +22,7 @@ const controllers = require("./src/controllers");
const socket = require("./src/utils/socket");
const network = require("./src/network");
const auth_1 = require("./src/auth");
const grpc = require("./src/grpc");
const env = process.env.NODE_ENV || 'development';
const config = require(path.join(__dirname, 'config/app.json'))[env];
const port = process.env.PORT || config.node_http_port || 3001;
@ -29,7 +30,6 @@ console.log("=> env:", env);
console.log('=> process.env.PORT:', process.env.PORT);
console.log('=> config.node_http_port:', config.node_http_port);
process.env.GRPC_SSL_CIPHER_SUITES = 'HIGH+ECDSA';
var i = 0;
// START SETUP!
function start() {
return __awaiter(this, void 0, void 0, function* () {
@ -41,28 +41,14 @@ function start() {
start();
function connectToLND() {
return __awaiter(this, void 0, void 0, function* () {
i++;
console.log(`=> [lnd] connecting... attempt #${i}`);
try {
yield network.initGrpcSubscriptions(); // LND
yield mainSetup(); // DB + express
yield network.initTribesSubscriptions(); // MQTT
}
catch (e) {
if (e.details) {
console.log(`=> [lnd] error details: ${e.details}`);
}
else {
console.log(`=> [lnd] error: ${e.message}`);
}
setTimeout(() => __awaiter(this, void 0, void 0, function* () {
yield connectToLND();
}), 2000);
}
yield grpc.reconnectToLND(Math.random()); // recursive
console.log(">> SETUP MAIN");
yield mainSetup();
});
}
function mainSetup() {
return __awaiter(this, void 0, void 0, function* () {
yield network.initTribesSubscriptions();
if (config.hub_api_url) {
// pingHubInterval(15000)
hub_1.checkInvitesHubInterval(5000);

2
dist/app.js.map

@ -1 +1 @@
{"version":3,"file":"app.js","sourceRoot":"","sources":["../app.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,mCAAkC;AAClC,0CAAyC;AACzC,iCAAgC;AAChC,8CAA6C;AAC7C,6BAA4B;AAC5B,6BAA4B;AAC5B,+CAAuC;AACvC,mCAAkE;AAClE,6CAA0D;AAC1D,iDAAgD;AAChD,6CAA4C;AAC5C,yCAAwC;AACxC,qCAA+C;AAE/C,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,QAAQ,IAAI,aAAa,CAAC;AAClD,MAAM,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,iBAAiB,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;AACrE,MAAM,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC,IAAI,IAAI,MAAM,CAAC,cAAc,IAAI,IAAI,CAAA;AAE9D,OAAO,CAAC,GAAG,CAAC,SAAS,EAAC,GAAG,CAAC,CAAA;AAC1B,OAAO,CAAC,GAAG,CAA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aAAa,EAAE;YACzB,GAAG,CAAC,GAAG,CAAC,iBAAU,CAAC,CAAC;SACpB;QACD,GAAG,CAAC,GAAG,CAAC,SAAS,EAAE,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC;QAC7C,GAAG,CAAC,GAAG,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAA;QAEhD,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,GAAG,EAAE,EAAE;YAC3B,IAAI,GAAG;gBAAE,MAAM,GAAG,CAAC;YACnB,+BAA+B;YAC/B,OAAO,CAAC,GAAG,CAAC,qBAAqB,IAAI,GAAG,CAAC,CAAC;QAC3C,CAAC,CAAC,CAAC;QAEH,oBAAoB;QACpB,IAAG,CAAC,MAAM,CAAC,MAAM,EAAE;YAClB,WAAW,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;YACrB,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAA;SACtB;aAAM;YACN,GAAG,CAAC,IAAI,CAAC,SAAS,EAAE,UAAe,GAAG,EAAC,GAAG;;oBACzC,MAAM,EAAE,GAAG,MAAM,eAAQ,CAAC,GAAG,EAAC,GAAG,CAAC,CAAA;oBAClC,IAAG,EAAE,EAAE;wBACN,WAAW,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;wBACrB,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAA;qBACtB;gBACF,CAAC;aAAA,CAAC,CAAA;SACF;IACF,CAAC;CAAA"}

36
dist/src/grpc/index.js

@ -136,23 +136,27 @@ var i = 0;
var ctx = 0;
function reconnectToLND(innerCtx) {
return __awaiter(this, void 0, void 0, function* () {
ctx = innerCtx;
i++;
const now = moment().format('YYYY-MM-DD HH:mm:ss').trim();
console.log(`=> ${now} [lnd] reconnecting... attempt #${i}`);
try {
yield network.initGrpcSubscriptions();
return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
ctx = innerCtx;
i++;
const now = moment().format('YYYY-MM-DD HH:mm:ss').trim();
console.log(`=> [lnd] reconnected! ${now}`);
}
catch (e) {
console.log("COULD NOT RECONNECT", e, e.message, e.code);
setTimeout(() => __awaiter(this, void 0, void 0, function* () {
if (ctx === innerCtx) { // if another retry fires, then this will not run
yield reconnectToLND(innerCtx);
}
}), 2000);
}
console.log(`=> ${now} [lnd] reconnecting... attempt #${i}`);
try {
yield network.initGrpcSubscriptions();
const now = moment().format('YYYY-MM-DD HH:mm:ss').trim();
console.log(`=> [lnd] connected! ${now}`);
resolve();
}
catch (e) {
console.log("COULD NOT RECONNECT", e, e.message, e.code);
setTimeout(() => __awaiter(this, void 0, void 0, function* () {
if (ctx === innerCtx) { // if another retry fires, then this will not run
yield reconnectToLND(innerCtx);
}
}), 2000);
}
}));
});
}
exports.reconnectToLND = reconnectToLND;
//# sourceMappingURL=index.js.map

2
dist/src/grpc/index.js.map

File diff suppressed because one or more lines are too long

35
src/grpc/index.ts

@ -129,22 +129,25 @@ export function subscribeInvoices(parseKeysendInvoice) {
var i = 0
var ctx = 0
async function reconnectToLND(innerCtx:number){
ctx = innerCtx
i++
const now = moment().format('YYYY-MM-DD HH:mm:ss').trim();
console.log(`=> ${now} [lnd] reconnecting... attempt #${i}`)
try {
await network.initGrpcSubscriptions()
export async function reconnectToLND(innerCtx:number) {
return new Promise( async (resolve,reject)=>{
ctx = innerCtx
i++
const now = moment().format('YYYY-MM-DD HH:mm:ss').trim();
console.log(`=> [lnd] reconnected! ${now}`)
} catch(e) {
console.log("COULD NOT RECONNECT",e,e.message,e.code)
setTimeout(async()=>{ // retry each 2 secs
if(ctx===innerCtx) { // if another retry fires, then this will not run
await reconnectToLND(innerCtx)
}
},2000)
}
console.log(`=> ${now} [lnd] reconnecting... attempt #${i}`)
try {
await network.initGrpcSubscriptions()
const now = moment().format('YYYY-MM-DD HH:mm:ss').trim();
console.log(`=> [lnd] connected! ${now}`)
resolve()
} catch(e) {
console.log("COULD NOT RECONNECT",e,e.message,e.code)
setTimeout(async()=>{ // retry each 2 secs
if(ctx===innerCtx) { // if another retry fires, then this will not run
await reconnectToLND(innerCtx)
}
},2000)
}
})
}

Loading…
Cancel
Save