Skip to content
This repository was archived by the owner on Jan 7, 2022. It is now read-only.

Commit d7a1adb

Browse files
authored
feature/add-detecting-and-handling-zcashd-unresponsive-state (#146)
* feature/add-detecting-and-handling-zcashd-unresponsive-state * remove leftover * check rescanning status * add missed dependencies * change check order Co-authored-by: jk <Janusz Kornaga>
1 parent f133369 commit d7a1adb

File tree

5 files changed

+90
-11
lines changed

5 files changed

+90
-11
lines changed

package-lock.json

Lines changed: 21 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@
197197
"material-ui-formik-components": "^0.5.2",
198198
"notistack": "^0.8.2",
199199
"prop-types": "^15.7.1",
200+
"ps-node": "^0.1.6",
200201
"qrcode.react": "^0.9.3",
201202
"ramda": "^0.26.1",
202203
"react": "^16.9.0",
@@ -220,9 +221,9 @@
220221
"request": "^2.88.0",
221222
"request-progress": "^3.0.0",
222223
"reselect": "^4.0.0",
224+
"sanitize-html": "^1.27.0",
223225
"touch": "^3.1.0",
224226
"typeface-roboto": "0.0.54",
225-
"yup": "^0.27.0",
226-
"sanitize-html": "^1.27.0"
227+
"yup": "^0.27.0"
227228
}
228229
}

src/main/main.js

Lines changed: 52 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,18 @@ import convert from 'convert-seconds'
2121
import R from 'ramda'
2222
import findInFiles from 'find-in-files'
2323
import readLastLines from 'read-last-lines'
24+
import find from 'find-process'
25+
import ps from 'ps-node'
26+
import util from 'util'
2427

2528
import { createRpcCredentials } from '../renderer/zcash'
2629
import config from './config'
2730
import { spawnZcashNode } from './zcash/bootstrap'
2831
import electronStore from '../shared/electronStore'
2932
import recoveryHandlers from './zcash/recover'
3033

34+
const _killProcess = util.promisify(ps.kill)
35+
3136
const osPathsBlockchainCustom = {
3237
darwin: `${process.env.HOME ||
3338
process.env.USERPROFILE}/Library/Application Support/ZbayData/`,
@@ -443,9 +448,56 @@ const fetchBlockchain = async (win, torUrl) => {
443448

444449
let powerSleepId
445450

451+
const killZcashdProcess = async () => {
452+
const zcashProcess = await find('name', 'zcashd')
453+
if (zcashProcess.length > 0) {
454+
const [ processDetails ] = zcashProcess
455+
const { pid } = processDetails
456+
await _killProcess(pid)
457+
}
458+
}
459+
460+
const checkZcashdStatus = async () => {
461+
const isBlockchainRescanned = electronStore.get('AppStatus.blockchain.isRescanned')
462+
if (mainWindow && isBlockchainRescanned && !isDev) {
463+
const zcashProcess = await find('name', 'zcashd')
464+
if (zcashProcess.length > 0) {
465+
mainWindow.webContents.send('checkNodeStatus', {
466+
status: 'up'
467+
})
468+
} else {
469+
mainWindow.webContents.send('checkNodeStatus', {
470+
status: 'down'
471+
})
472+
}
473+
}
474+
setTimeout(checkZcashdStatus, 1200000)
475+
}
476+
477+
setTimeout(() => {
478+
const isBlockchainRescanned = electronStore.get('AppStatus.blockchain.isRescanned')
479+
if (isBlockchainRescanned && !isDev) {
480+
checkZcashdStatus()
481+
}
482+
}, 1200000)
483+
484+
ipcMain.on('restart-node-proc', async (event, arg) => {
485+
await killZcashdProcess()
486+
spawnZcashNode(process.platform, isTestnet)
487+
})
488+
446489
const createZcashNode = async (win, torUrl) => {
490+
const updateStatus = electronStore.get('updateStatus')
491+
const blockchainConfiguration = electronStore.get('blockchainConfiguration')
492+
if (updateStatus !== config.UPDATE_STATUSES.NO_UPDATE || (blockchainConfiguration === config.BLOCKCHAIN_STATUSES.WAITING_FOR_USER_DECISION && isFetchedFromExternalSource)) {
493+
setTimeout(() => {
494+
createZcashNode(win, torUrl)
495+
}, 5000)
496+
return
497+
}
447498
const isBlockchainRescanned = electronStore.get('AppStatus.blockchain.isRescanned')
448499
if (isBlockchainRescanned && !isDev) {
500+
await killZcashdProcess()
449501
setTimeout(() => {
450502
recoveryHandlers.checkIfProcessIsRunning((status) => {
451503
if (!status) {
@@ -456,14 +508,6 @@ const createZcashNode = async (win, torUrl) => {
456508
})
457509
}, 180000)
458510
}
459-
const updateStatus = electronStore.get('updateStatus')
460-
const blockchainConfiguration = electronStore.get('blockchainConfiguration')
461-
if (updateStatus !== config.UPDATE_STATUSES.NO_UPDATE || (blockchainConfiguration === config.BLOCKCHAIN_STATUSES.WAITING_FOR_USER_DECISION && isFetchedFromExternalSource)) {
462-
setTimeout(() => {
463-
createZcashNode(win, torUrl)
464-
}, 5000)
465-
return
466-
}
467511
let AppStatus = electronStore.get('AppStatus')
468512
const vaultStatus = electronStore.get('vaultStatus')
469513
if (!isDev && (!isFetchedFromExternalSource || blockchainConfiguration === config.BLOCKCHAIN_STATUSES.TO_FETCH)) {

src/renderer/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,10 @@ ipcRenderer.on('load-logs-to-store', (event, { transactions, debug, applicationL
108108
store.dispatch(logsHandlers.actions.setApplicationLogs(applicationLogs))
109109
})
110110

111+
ipcRenderer.on('checkNodeStatus', (event, { status }) => {
112+
store.dispatch(nodeHandlers.epics.checkNodeStatus(status))
113+
})
114+
111115
ipcRenderer.on('newChannel', (event, { channelParams }) => {
112116
if (nodeSelectors.status(store.getState()) === 'healthy') {
113117
store.dispatch(

src/renderer/store/handlers/node.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { createAction, handleActions } from 'redux-actions'
66
import { typeRejected, LoaderState, FetchingState } from './utils'
77
import { getClient } from '../../zcash'
88
import { actionTypes } from '../../../shared/static'
9+
import nodeSelectors from '../selectors/node'
910

1011
const DEFAULT_ADDRESS_TYPE = 'sapling'
1112

@@ -81,6 +82,13 @@ export const disablePowerSaveMode = () => async (dispatch, getState) => {
8182
ipcRenderer.send('disable-sleep-prevention')
8283
}
8384

85+
export const checkNodeStatus = (nodeProcessStatus) => async (dispatch, getState) => {
86+
const nodeResponseStatus = nodeSelectors.status(getState())
87+
if (nodeProcessStatus === 'up' && nodeResponseStatus === 'down') {
88+
ipcRenderer.send('restart-node-proc')
89+
}
90+
}
91+
8492
const getStatus = () => async (dispatch) => {
8593
try {
8694
const info = await getClient({ timeout: 200 }).status.info()
@@ -106,7 +114,8 @@ const epics = {
106114
togglePower,
107115
startRescanningMonitor,
108116
disablePowerSaveMode,
109-
setRescanningInitialized
117+
setRescanningInitialized,
118+
checkNodeStatus
110119
}
111120

112121
export const reducer = handleActions({

0 commit comments

Comments
 (0)