Skip to content
This repository was archived by the owner on Feb 23, 2021. It is now read-only.

Fix lnd safe shutdown. #1134

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions public/electron.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ ipcMain.on('lnd-restart-process', async event => {
lndProcess && lndProcess.kill('SIGINT');
let restartError;
try {
lndProcess = await startLndProcess({
lndProcess = startLndProcess({
isDev,
lndSettingsDir,
lndPort: LND_PORT,
Expand All @@ -151,15 +151,15 @@ ipcMain.on('lnd-restart-process', async event => {
event.sender.send('lnd-restart-error', { restartError });
});

const startLnd = async () => {
const startLnd = () => {
try {
btcdProcess = await startBtcdProcess({
btcdProcess = startBtcdProcess({
isDev,
logger: Logger,
btcdSettingsDir,
miningAddress: BTCD_MINING_ADDRESS,
});
lndProcess = await startLndProcess({
lndProcess = startLndProcess({
isDev,
lndSettingsDir,
lndPort: LND_PORT,
Expand Down
29 changes: 13 additions & 16 deletions public/lnd-child-process.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,18 @@ function getProcessName(binName) {
return fs.existsSync(filePath) ? filePath : filename;
}

async function startChildProcess(name, args, logger) {
return new Promise((resolve, reject) => {
const processName = getProcessName(name);
logger.info(`Using ${name} in path ${processName}`);
const childProcess = cp.spawn(processName, args);
childProcess.stdout.on('data', data => {
logger.info(`${name}: ${data}`);
resolve(childProcess);
});
childProcess.stderr.on('data', data => {
logger.error(`${name} Error: ${data}`);
reject(new Error(data));
});
childProcess.on('error', reject);
function startChildProcess(name, args, logger) {
const processName = getProcessName(name);
logger.info(`Using ${name} in path ${processName}`);
const childProcess = cp.spawn(processName, args, {
detached: true,
stdio: 'ignore',
});
childProcess.unref();
childProcess.on('error', err =>
logger.error(`Errored in child process: ${err}`)
);
return childProcess;
}

function startBlockingProcess(name, args, logger) {
Expand All @@ -45,7 +42,7 @@ function startBlockingProcess(name, args, logger) {
});
}

module.exports.startLndProcess = async function({
module.exports.startLndProcess = function({
isDev,
lndSettingsDir,
lndPort,
Expand Down Expand Up @@ -95,7 +92,7 @@ module.exports.startLndProcess = async function({
return startChildProcess(processName, args, logger);
};

module.exports.startBtcdProcess = async function({
module.exports.startBtcdProcess = function({
isDev,
logger,
btcdSettingsDir,
Expand Down
19 changes: 8 additions & 11 deletions test/integration/action/action-integration.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,26 +95,23 @@ describe('Action Integration Tests', function() {
let autopilot2;
let btcdArgs;

const startLnd = async () => {
const lndProcess1Promise = startLndProcess({
const startLnd = () => {
lndProcess1 = startLndProcess({
isDev,
lndSettingsDir: LND_SETTINGS_DIR_1,
lndPort: LND_PORT_1,
lndPeerPort: LND_PEER_PORT_1,
lndRestPort: LND_REST_PORT_1,
logger,
});
const lndProcess2Promise = startLndProcess({
lndProcess2 = startLndProcess({
isDev,
lndSettingsDir: LND_SETTINGS_DIR_2,
lndPort: LND_PORT_2,
lndPeerPort: LND_PEER_PORT_2,
lndRestPort: LND_REST_PORT_2,
logger,
});

lndProcess1 = await lndProcess1Promise;
lndProcess2 = await lndProcess2Promise;
};

before(async () => {
Expand All @@ -136,12 +133,12 @@ describe('Action Integration Tests', function() {
btcdSettingsDir: BTCD_SETTINGS_DIR,
miningAddress: BTCD_MINING_ADDRESS,
};
btcdProcess = await startBtcdProcess(btcdArgs);
btcdProcess = startBtcdProcess(btcdArgs);
await nap(NAP_TIME);
await retry(() => isPortOpen(BTCD_PORT));
await mineBlocks({ blocks: 400, logger });

await startLnd();
startLnd();

await grcpClient.init({
ipcMain: ipcMainStub1,
Expand Down Expand Up @@ -239,7 +236,7 @@ describe('Action Integration Tests', function() {
it('should reset password', async () => {
lndProcess1.kill('SIGINT');
lndProcess2.kill('SIGINT');
await startLnd();
startLnd();
ipcMainStub1.on('lnd-restart-process', async event => {
event.sender.send('lnd-restart-error', { restartError: undefined });
});
Expand All @@ -263,7 +260,7 @@ describe('Action Integration Tests', function() {
it('should unlock wallet with reset password', async () => {
lndProcess1.kill();
lndProcess2.kill();
await startLnd();
startLnd();

store1.walletUnlocked = false;
await grpc1.initUnlocker();
Expand Down Expand Up @@ -292,7 +289,7 @@ describe('Action Integration Tests', function() {
it('should fund wallet for node1', async () => {
await killProcess(btcdProcess.pid);
btcdArgs.miningAddress = store1.walletAddress;
btcdProcess = await startBtcdProcess(btcdArgs);
btcdProcess = startBtcdProcess(btcdArgs);
await nap(NAP_TIME);
await retry(() => isPortOpen(BTCD_PORT));
await mineAndSync({ blocks: 100 });
Expand Down