Skip to content

Commit

Permalink
perf(lnd): run lnd integration in web workers
Browse files Browse the repository at this point in the history
  • Loading branch information
mrfelton committed Apr 17, 2019
1 parent b369993 commit 91dbaec
Show file tree
Hide file tree
Showing 77 changed files with 2,204 additions and 2,889 deletions.
433 changes: 41 additions & 392 deletions electron/controller.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions electron/main.js
Expand Up @@ -244,6 +244,7 @@ app.on('ready', async () => {
backgroundColor: get(theme, 'colors.primaryColor', '#242633'),
webPreferences: {
nodeIntegration: false,
nodeIntegrationInWorker: true,
preload: isDev
? path.resolve(__dirname, '..', 'dist', 'preload.js')
: path.resolve(__dirname, 'preload.js'),
Expand Down
31 changes: 30 additions & 1 deletion electron/preload.js
Expand Up @@ -14,8 +14,11 @@ import config from 'config'
import { getDb } from '@zap/renderer/store/db'
import isSubDir from '@zap/utils/isSubDir'
import { getAllLocalWallets } from '@zap/utils/localWallets'
import lndBinaryPath from '@zap/utils/lndBinaryPath'
import lndGrpcProtoPath from '@zap/utils/lndGrpcProtoPath'
import validateHost from '@zap/utils/validateHost'
import { getDbName } from '@zap/utils/db'
import LndConfig from '@zap/utils/lndConfig'

const fsReadFile = promisify(fs.readFile)
const fsRimraf = promisify(rimraf)
Expand Down Expand Up @@ -68,10 +71,35 @@ function openTestnetFaucet() {
function killLnd() {
return new Promise(resolve => {
ipcRenderer.once('killLndSuccess', resolve)
ipcRenderer.send('killLnd', { signal: 'SIGKILL', timeout: 2500 })
ipcRenderer.send('killLnd')
})
}

/**
* Generates an lnd config object from a wallet config.
* @param {Object} wallet Wallet config
* @return {Object} Lnd config
*/
async function generateLndConfigFromWallet(wallet) {
// Convert wallet config to lnd config.
wallet.decoder = wallet.decoder || 'lnd.lndconnect.v1'
let lndConfig = new LndConfig({
...wallet,
userDataDir: getUserDataDir(),
binaryPath: lndBinaryPath(),
protoPath: lndGrpcProtoPath(),
})

// Wait for the config to become fully initialized.
await lndConfig.isReady

// Flatten the config into a plan object so we can pass it between services.
// We can not pass a Promise to the Web Worker, so replace with true value.
lndConfig = Object.assign({}, lndConfig, { isReady: true })

return lndConfig
}

/**
* Returns specified wallet files location
* @param {*} chain
Expand Down Expand Up @@ -158,6 +186,7 @@ window.Zap = {
openExternal,
openHelpPage,
openTestnetFaucet,
generateLndConfigFromWallet,
getWalletDir,
getAllLocalWallets,
deleteLocalWallet,
Expand Down
274 changes: 0 additions & 274 deletions lnd/config.js

This file was deleted.

0 comments on commit 91dbaec

Please sign in to comment.