Skip to content
This repository has been archived by the owner on Sep 5, 2020. It is now read-only.

Fixes the node start IPC connection #841

Merged
merged 6 commits into from
Jun 29, 2016
Merged
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
2 changes: 1 addition & 1 deletion gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ var packager = require('electron-packager');
var spawn = require('child_process').spawn;
var merge = require('merge-stream');
var rename = require("gulp-rename");
var download = require('gulp-download');
var download = require('gulp-download-stream');
var decompress = require('gulp-decompress');
var tap = require("gulp-tap");
// const zip = require('gulp-zip');
Expand Down
4 changes: 3 additions & 1 deletion interface/client/templates/popupWindows/splashScreen.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ <h1>

{{#if TemplateVar.get "showProgressBar"}}
<progress class="{{mode}}" max="100" value="{{TemplateVar.get 'progress'}}"></progress>
<progress class="state {{mode}}" max="100" value="{{TemplateVar.get 'stateProgress'}}"></progress>
{{#if TemplateVar.get "showStateProgressBar"}}
<progress class="state {{mode}}" max="100" value="{{TemplateVar.get 'stateProgress'}}"></progress>
{{/if}}
{{/if}}
</div>
</template>
29 changes: 17 additions & 12 deletions interface/client/templates/popupWindows/splashScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,10 @@ Template['popupWindows_splashScreen'].onCreated(function(){
if(web3.net.peerCount > 0) {
// Check which state we are

if ( lastSyncData.pulledStates != Math.round(lastSyncData._displayState)
|| lastSyncData.knownStates != Math.round(lastSyncData._displayKnownStates)) {
if ( 0 < lastSyncData._displayKnownStates && (
lastSyncData.pulledStates != Math.round(lastSyncData._displayState)
|| lastSyncData.knownStates != Math.round(lastSyncData._displayKnownStates))
) {
// Mostly downloading new states
translationString = 'mist.startScreen.nodeSyncInfoStates';

Expand Down Expand Up @@ -181,16 +183,13 @@ Template['popupWindows_splashScreen'].helpers({
if (!(syncData._displayBlock > -1)) {
// initialize the display numbers
syncData._displayBlock = Number(syncData.currentBlock);
syncData._displayState = Number(syncData.pulledStates);
syncData._displayKnownStates = Number(syncData.knownStates);

syncData._displayState = Number(syncData.pulledStates || 0);
syncData._displayKnownStates = Number(syncData.knownStates || 0);
} else {
// Increment each them slowly to match target number
syncData._displayBlock = syncData._displayBlock + (Number(syncData.currentBlock) - syncData._displayBlock) / 10;

syncData._displayState = syncData._displayState + (Number(syncData.pulledStates) - syncData._displayState) / 10;

syncData._displayKnownStates = syncData._displayKnownStates + (Number(syncData.knownStates) - syncData._displayKnownStates) / 10;
syncData._displayBlock += (Number(syncData.currentBlock) - syncData._displayBlock) / 10;
syncData._displayState += (Number(syncData.pulledStates || 0) - syncData._displayState) / 10;
syncData._displayKnownStates += (Number(syncData.knownStates || 0) - syncData._displayKnownStates) / 10;
};

// Create the fancy strings
Expand All @@ -202,7 +201,10 @@ Template['popupWindows_splashScreen'].helpers({
var translatedMessage = TAPi18n.__(translationString, syncData);

// Calculates both progress bars
var stateProgress = (lastSyncData._displayState / lastSyncData._displayKnownStates) * 100;
var stateProgress = null;
if (0 < lastSyncData._displayKnownStates) {
stateProgress = (lastSyncData._displayState / lastSyncData._displayKnownStates) * 100;
}

var progress = ((lastSyncData._displayBlock - Number(lastSyncData.startingBlock)) / (Number(lastSyncData._highestBlock) - Number(lastSyncData.startingBlock))) * 100 ;

Expand All @@ -214,7 +216,10 @@ Template['popupWindows_splashScreen'].helpers({
if(_.isFinite(progress)) {
TemplateVar.set(template, 'showProgressBar', true);
TemplateVar.set(template, 'progress', progress);
TemplateVar.set(template, 'stateProgress', stateProgress);
if (null !== stateProgress) {
TemplateVar.set(template, 'showStateProgressBar', true);
TemplateVar.set(template, 'stateProgress', stateProgress);
}
}

}, 100);
Expand Down
8 changes: 1 addition & 7 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,20 +144,14 @@ app.on('before-quit', function(event){

// delay quit, so the sockets can close
setTimeout(function(){
killedSockets = true;

ethereumNode.stop().then(function() {
killedSockets = true;
app.quit();
});
}, 500);
});




const NODE_TYPE = 'geth';


var mainWindow;
var splashWindow;

Expand Down
101 changes: 15 additions & 86 deletions modules/ethereumNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const DEFAULT_NETWORK = 'main';
const UNABLE_TO_BIND_PORT_ERROR = 'unableToBindPort';
const UNABLE_TO_SPAWN_ERROR = 'unableToSpan';
const PASSWORD_WRONG_ERROR = 'badPassword';

const NODE_START_WAIT_MS = 3000;


/**
Expand Down Expand Up @@ -143,7 +143,7 @@ class EthereumNode extends EventEmitter {
return this._start(this.defaultNodeType, this.defaultNetwork)
.catch((err) => {
log.error('Failed to start node', err);

throw err;
});
});
Expand Down Expand Up @@ -289,8 +289,8 @@ class EthereumNode extends EventEmitter {
this._saveUserData('network', this._network);

return this._socket.connect({ path: ipcPath }, {
timeout: 30000 /* 30s */
})
timeout: 30000 /* 30s */
})
.then(() => {
this.state = STATES.CONNECTED;
})
Expand Down Expand Up @@ -336,68 +336,16 @@ class EthereumNode extends EventEmitter {
log.debug(`Start node using ${binPath}`);

return new Q((resolve, reject) => {
if ('eth' === nodeType) {
let modalWindow = Windows.createPopup('unlockMasterPassword', {
electronOptions: {
width: 400,
height: 220,
},
useWeb3: false,
});

let called = false;

modalWindow.on('closed', () => {
if (!called) {
app.quit();
}
});

let popupCallback = function(err) {
if (err && _.get(modalWindow,'webContents')) {
log.error('unlockMasterPassword error', err);

if(UNABLE_TO_SPAWN_ERROR === err) {
modalWindow.close();
modalWindow = null;
} else {
modalWindow.webContents.send('data', {
masterPasswordWrong: true
});
}
} else {
called = true;
modalWindow.close();
modalWindow = null;
ipc.removeAllListeners('backendAction_unlockedMasterPassword');
}
};

ipc.on('backendAction_unlockedMasterPassword', (ev, err, pw) => {
if (_.get(modalWindow, 'webContents') && ev.sender.getId() === modalWindow.webContents.getId()) {
if (!err) {
this.__startProcess(nodeType, network, binPath, pw, popupCallback)
.then(resolve, reject);
} else {
app.quit();
}

return;
}
});
} else {
this.__startProcess(nodeType, network, binPath)
.then(resolve, reject);
}

this.__startProcess(nodeType, network, binPath)
.then(resolve, reject);
});
}


/**
* @return {Promise}
*/
__startProcess (nodeType, network, binPath, pw, popupCallback) {
__startProcess (nodeType, network, binPath) {
return new Q((resolve, reject) => {
log.trace('Rotate log file');

Expand All @@ -421,8 +369,7 @@ class EthereumNode extends EventEmitter {
else {
args = (nodeType === 'geth')
? ['--fast', '--cache', '512']
: ['--unsafe-transactions', '--master', pw];
pw = null;
: ['--unsafe-transactions'];
}

let nodeOptions = Settings.nodeOptions;
Expand All @@ -442,10 +389,6 @@ class EthereumNode extends EventEmitter {
if (STATES.STARTING === this.state) {
this.state = STATES.ERROR;

if (popupCallback) {
popupCallback(UNABLE_TO_SPAWN_ERROR);
}

log.info('Node startup error');

// TODO: detect this properly
Expand All @@ -455,17 +398,6 @@ class EthereumNode extends EventEmitter {
}
});

// node quit, e.g. master pw wrong
proc.once('exit', () => {
if ('eth' === nodeType) {
log.warn('Password wrong!');

if (popupCallback) {
popupCallback(PASSWORD_WRONG_ERROR);
}
}
});

// we need to read the buff to prevent node from not working
proc.stderr.pipe(
fs.createWriteStream(this._buildFilePath('node.log'), { flags: 'a' })
Expand Down Expand Up @@ -510,20 +442,17 @@ class EthereumNode extends EventEmitter {
// when data is first received
this.once('data', () => {
/*
Assume startup succeeded after 5 seconds. At this point
IPC connections are usually possible.
We wait a short while before marking startup as successful
because we may want to parse the initial node output for
errors, etc (see geth port-binding error above)
*/
setTimeout(() => {
if (STATES.STARTING === this.state) {
log.info('4s elapsed, assuming node started up successfully');

if (popupCallback) {
popupCallback();
}
log.info(`${NODE_START_WAIT_MS}ms elapsed, assuming node started up successfully`);

resolve(proc);
}
}, 4000);
}, NODE_START_WAIT_MS);
})
});
});
Expand Down Expand Up @@ -571,8 +500,8 @@ class EthereumNode extends EventEmitter {
_loadDefaults () {
log.trace('Load defaults');

this.defaultNodeType = this._loadUserData('node') || DEFAULT_NODE_TYPE;
this.defaultNetwork = this._loadUserData('network') || DEFAULT_NETWORK;
this.defaultNodeType = Settings.nodeType || this._loadUserData('node') || DEFAULT_NODE_TYPE;
this.defaultNetwork = Settings.network || this._loadUserData('network') || DEFAULT_NETWORK;
}


Expand Down
26 changes: 26 additions & 0 deletions modules/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,24 @@ const argv = require('yargs')
type: 'string',
group: 'Mist options:',
},
node: {
demand: false,
default: null,
describe: 'Node to use: geth, eth',
requiresArg: true,
nargs: 1,
type: 'string',
group: 'Mist options:',
},
network: {
demand: false,
default: null,
describe: 'Network to connect to: main, test',
requiresArg: true,
nargs: 1,
type: 'string',
group: 'Mist options:',
},
ipcpath: {
demand: false,
describe: 'Path to node IPC socket file (this will automatically get passed as an option to Geth).',
Expand Down Expand Up @@ -162,6 +180,14 @@ class Settings {
return argv.ipcpath;
}

get nodeType () {
return argv.node;
}

get network () {
return argv.network;
}

get nodeOptions () {
return argv.nodeOptions;
}
Expand Down
Loading