Skip to content

Commit

Permalink
Introduce built-in node troubleshooting (#877)
Browse files Browse the repository at this point in the history
* Add troubleshooting components

* Add troubleshooting logic

* Update vscode linting settings

* Use cjs exports at main process

* Update [email protected]

* Update gh actions node version@14

* Handle troubleshooting cases

* Consider runInternalNode when detecting offline

* Drop null exit codes
  • Loading branch information
aidenaio authored Jan 18, 2023
1 parent c801083 commit df80226
Show file tree
Hide file tree
Showing 12 changed files with 3,024 additions and 1,690 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
- name: Setup Node.js
uses: actions/setup-node@v1
with:
node-version: 12
node-version: 14

- name: Install Linux canvas deps
if: matrix.os == 'ubuntu-latest'
Expand Down
27 changes: 23 additions & 4 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,29 @@
{
// turn it off for JS and JSX, we will do this via eslint
"[javascript]": {
"editor.formatOnSave": true
"editor.formatOnPaste": false,
"editor.formatOnSave": false
},
"[javascriptreact]": {
"editor.formatOnSave": true
"editor.formatOnPaste": false,
"editor.formatOnSave": false
},
"editor.formatOnSave": true
"[typescript]": {
"editor.formatOnPaste": false,
"editor.formatOnSave": false
},
"[typescriptreact]": {
"editor.formatOnPaste": false,
"editor.formatOnSave": false
},
"editor.formatOnSaveMode": "modificationsIfAvailable",
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.fixAll": true
},
"eslint.validate": [
"javascript",
"javascriptreact",
"typescript",
"typescriptreact"
]
}
24 changes: 24 additions & 0 deletions main/idena-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const lineReader = require('reverse-line-reader')
// eslint-disable-next-line import/no-extraneous-dependencies
const appDataPath = require('./app-data-path')
const {sleep} = require('./utils')
const logger = require('./logger')

const idenaBin = 'idena-go'
const idenaNodeReleasesUrl =
Expand All @@ -32,6 +33,8 @@ const getTempNodeFile = () =>
const getNodeChainDbFolder = () =>
path.join(getNodeDataDir(), idenaChainDbFolder)

const getNodeIpfsDir = () => path.join(getNodeDataDir(), 'ipfs')

const getNodeLogsFile = () => path.join(getNodeDataDir(), 'logs', 'output.log')

const getNodeErrorFile = () => path.join(getNodeDataDir(), 'logs', 'error.log')
Expand Down Expand Up @@ -307,6 +310,23 @@ function getLastLogs() {
})
}

async function tryStopNode(node, {onSuccess, onFail}) {
try {
if (node) {
const log = await stopNode(node)
logger.info(log)
if (onSuccess) {
onSuccess()
}
}
} catch (e) {
logger.error('error while stopping node', e.toString())
if (onFail) {
onFail()
}
}
}

module.exports = {
downloadNode,
getCurrentVersion,
Expand All @@ -317,4 +337,8 @@ module.exports = {
nodeExists,
cleanNodeState,
getLastLogs,
getNodeFile,
getNodeChainDbFolder,
getNodeIpfsDir,
tryStopNode,
}
69 changes: 67 additions & 2 deletions main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ const {
getCurrentVersion,
cleanNodeState,
getLastLogs,
getNodeChainDbFolder,
getNodeFile,
getNodeIpfsDir,
tryStopNode,
} = require('./idena-node')

const NodeUpdater = require('./node-updater')
Expand Down Expand Up @@ -384,9 +388,9 @@ ipcMain.on(NODE_COMMAND, async (_event, command, data) => {
switch (command) {
case 'init-local-node': {
if (macosVersion.isMacOS && macosVersion.is('<10.15')) {
sendMainWindowMsg(NODE_EVENT, 'unsupported-macos-version')
return
return sendMainWindowMsg(NODE_EVENT, 'unsupported-macos-version')
}

getCurrentVersion()
.then(version => {
sendMainWindowMsg(NODE_EVENT, 'node-ready', version)
Expand Down Expand Up @@ -497,6 +501,7 @@ ipcMain.on(NODE_COMMAND, async (_event, command, data) => {
sendMainWindowMsg(NODE_EVENT, 'node-failed')
logger.error('error while stopping node', e.toString())
})

break
}
case 'get-last-logs': {
Expand All @@ -509,6 +514,66 @@ ipcMain.on(NODE_COMMAND, async (_event, command, data) => {
})
break
}

case 'troubleshooting-restart-node': {
await tryStopNode(node, {
onSuccess() {
node = null
},
})

return sendMainWindowMsg(NODE_EVENT, 'troubleshooting-restart-node')
}

case 'troubleshooting-update-node': {
if (nodeDownloadPromise) return

await tryStopNode(node, {
onSuccess() {
node = null
},
})

sendMainWindowMsg(NODE_EVENT, 'troubleshooting-update-node')

nodeDownloadPromise = downloadNode(info => {
sendMainWindowMsg(AUTO_UPDATE_EVENT, 'node-download-progress', info)
})
.then(async () => {
await updateNode()
sendMainWindowMsg(NODE_EVENT, 'node-ready')
})
.catch(err => {
sendMainWindowMsg(NODE_EVENT, 'node-failed')
logger.error('error while downloading node', err.toString())
})
.finally(() => {
nodeDownloadPromise = null
})

break
}

case 'troubleshooting-reset-node': {
await tryStopNode(node, {
onSuccess() {
node = null
},
})

try {
await fs.remove(getNodeFile())
await fs.remove(getNodeChainDbFolder())
await fs.remove(getNodeIpfsDir())

sendMainWindowMsg(NODE_EVENT, 'troubleshooting-reset-node')
} catch (e) {
logger.error('error deleting idenachain.db', e.toString())
sendMainWindowMsg(NODE_EVENT, 'node-failed')
}

break
}
default:
}
})
Expand Down
Loading

0 comments on commit df80226

Please sign in to comment.