This repository has been archived by the owner on Sep 5, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Light client #1547
Closed
Closed
Light client #1547
Changes from 4 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
3c9ac3a
redo changes to menu items`
alexvansande c4ad73b
reapply changes to ethereumNode
alexvansande a86e4ee
reapply changes to i18n strings
alexvansande 4a72779
add mode do log
alexvansande a76b4d3
fixes network variable
alexvansande b63b270
Merge branch 'develop' into light-client-2
alexvansande 3f7b52f
fix restart functions
alexvansande 257d856
[ESLint] minor fixes
evertonfraga 8b12854
Merge branch 'develop' into light-client-2
alexvansande File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,7 @@ const ClientBinaryManager = require('./clientBinaryManager'); | |
|
||
const DEFAULT_NODE_TYPE = 'geth'; | ||
const DEFAULT_NETWORK = 'main'; | ||
|
||
const DEFAULT_MODE = 'full'; | ||
|
||
const UNABLE_TO_BIND_PORT_ERROR = 'unableToBindPort'; | ||
const UNABLE_TO_SPAWN_ERROR = 'unableToSpan'; | ||
|
@@ -22,7 +22,7 @@ const NODE_START_WAIT_MS = 3000; | |
|
||
|
||
/** | ||
* Etheruem nodes manager. | ||
* Ethereum nodes manager. | ||
*/ | ||
class EthereumNode extends EventEmitter { | ||
constructor() { | ||
|
@@ -35,6 +35,7 @@ class EthereumNode extends EventEmitter { | |
this._node = null; | ||
this._type = null; | ||
this._network = null; | ||
this._mode = null; | ||
|
||
this._socket = Sockets.get('node-ipc', Settings.rpcMode); | ||
|
||
|
@@ -61,6 +62,10 @@ class EthereumNode extends EventEmitter { | |
return this.isOwnNode ? this._network : null; | ||
} | ||
|
||
get mode() { | ||
return this.isOwnNode ? this._mode : null; | ||
} | ||
|
||
get isEth() { | ||
return this._type === 'eth'; | ||
} | ||
|
@@ -77,6 +82,10 @@ class EthereumNode extends EventEmitter { | |
return this.network === 'test'; | ||
} | ||
|
||
get isLightClient() { | ||
return this.mode === 'light'; | ||
} | ||
|
||
get state() { | ||
return this._state; | ||
} | ||
|
@@ -130,7 +139,7 @@ class EthereumNode extends EventEmitter { | |
log.info(`Network: ${this.defaultNetwork}`); | ||
|
||
// if not, start node yourself | ||
return this._start(this.defaultNodeType, this.defaultNetwork) | ||
return this._start(this.defaultNodeType, this.defaultNetwork, this.defaultMode) | ||
.catch((err) => { | ||
log.error('Failed to start node', err); | ||
|
||
|
@@ -140,20 +149,20 @@ class EthereumNode extends EventEmitter { | |
} | ||
|
||
|
||
restart(newType, newNetwork) { | ||
restart(newType, newNetwork, newMode) { | ||
return Q.try(() => { | ||
if (!this.isOwnNode) { | ||
throw new Error('Cannot restart node since it was started externally'); | ||
} | ||
|
||
log.info('Restart node', newType, newNetwork); | ||
log.info('Restart node..', newType, newNetwork, newMode); | ||
|
||
return this.stop() | ||
.then(() => { | ||
Windows.loading.show(); | ||
}) | ||
.then(() => { | ||
return this._start(newType || this.type, newNetwork || this.network); | ||
return this._start(newType || this.type, newNetwork || this.network, newMode || this.nodeMode); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Whats this |
||
}) | ||
.then(() => { | ||
Windows.loading.hide(); | ||
|
@@ -181,7 +190,7 @@ class EthereumNode extends EventEmitter { | |
|
||
this.state = STATES.STOPPING; | ||
|
||
log.info(`Stopping existing node: ${this._type} ${this._network}`); | ||
log.info(`Stopping existing node: ${this._type} ${this._network} ${this._mode}`); | ||
|
||
this._node.stderr.removeAllListeners('data'); | ||
this._node.stdout.removeAllListeners('data'); | ||
|
@@ -243,8 +252,8 @@ class EthereumNode extends EventEmitter { | |
* @param {String} network network id | ||
* @return {Promise} | ||
*/ | ||
_start(nodeType, network) { | ||
log.info(`Start node: ${nodeType} ${network}`); | ||
_start(nodeType, network, mode) { | ||
log.info(`Starting ${nodeType} node on ${network}-network with ${mode} node`); | ||
|
||
const isTestNet = (network === 'test'); | ||
|
||
|
@@ -254,7 +263,7 @@ class EthereumNode extends EventEmitter { | |
|
||
return this.stop() | ||
.then(() => { | ||
return this.__startNode(nodeType, network) | ||
return this.__startNode(nodeType, network, mode) | ||
.catch((err) => { | ||
log.error('Failed to start node', err); | ||
|
||
|
@@ -264,13 +273,14 @@ class EthereumNode extends EventEmitter { | |
}); | ||
}) | ||
.then((proc) => { | ||
log.info(`Started node successfully: ${nodeType} ${network}`); | ||
log.info(`Started node successfully: ${nodeType} ${network} ${mode}`); | ||
|
||
this._node = proc; | ||
this.state = STATES.STARTED; | ||
|
||
Settings.saveUserData('node', this._type); | ||
Settings.saveUserData('network', this._network); | ||
Settings.saveUserData('mode', this._mode); | ||
|
||
return this._socket.connect(Settings.rpcConnectConfig, { | ||
timeout: 30000, /* 30s */ | ||
|
@@ -309,11 +319,12 @@ class EthereumNode extends EventEmitter { | |
/** | ||
* @return {Promise} | ||
*/ | ||
__startNode(nodeType, network) { | ||
__startNode(nodeType, network, mode) { | ||
this.state = STATES.STARTING; | ||
|
||
this._network = network; | ||
this._type = nodeType; | ||
this._mode = mode; | ||
|
||
const client = ClientBinaryManager.getClient(nodeType); | ||
let binPath; | ||
|
@@ -327,7 +338,7 @@ class EthereumNode extends EventEmitter { | |
log.info(`Start node using ${binPath}`); | ||
|
||
return new Q((resolve, reject) => { | ||
this.__startProcess(nodeType, network, binPath) | ||
this.__startProcess(nodeType, network, binPath, mode) | ||
.then(resolve, reject); | ||
}); | ||
} | ||
|
@@ -336,7 +347,7 @@ class EthereumNode extends EventEmitter { | |
/** | ||
* @return {Promise} | ||
*/ | ||
__startProcess(nodeType, network, binPath) { | ||
__startProcess(nodeType, network, binPath, mode) { | ||
return new Q((resolve, reject) => { | ||
log.trace('Rotate log file'); | ||
|
||
|
@@ -350,16 +361,23 @@ class EthereumNode extends EventEmitter { | |
|
||
let args; | ||
|
||
// START TESTNET | ||
if (network == 'test') { | ||
args = (nodeType === 'geth') | ||
? ['--testnet', '--fast', '--ipcpath', Settings.rpcIpcPath] | ||
: ['--morden', '--unsafe-transactions']; | ||
} | ||
// START MAINNET | ||
else { | ||
args = (nodeType === 'geth') | ||
? ['--fast', '--cache', '1024'] | ||
if (nodeType === 'geth') { | ||
if (network === 'test') { | ||
// START GETH TESTNET | ||
args = (mode === 'full') | ||
? ['--testnet', '--fast', '--ipcpath', Settings.rpcIpcPath] | ||
: ['--testnet', '--light', '--ipcpath', Settings.rpcIpcPath]; | ||
} else { | ||
// START GETH MAINNET | ||
args = (mode === 'full') | ||
? ['--fast', '--cache', '1024' ] | ||
: ['--light']; | ||
} | ||
} else { | ||
// START ETH | ||
args = (network === 'test') | ||
? ['--ropsten', '--unsafe-transactions'] | ||
|
||
: ['--unsafe-transactions']; | ||
} | ||
|
||
|
@@ -492,6 +510,7 @@ class EthereumNode extends EventEmitter { | |
|
||
this.defaultNodeType = Settings.nodeType || Settings.loadUserData('node') || DEFAULT_NODE_TYPE; | ||
this.defaultNetwork = Settings.network || Settings.loadUserData('network') || DEFAULT_NETWORK; | ||
this.defaultMode = Settings.mode || Settings.loadUserData('mode') || DEFAULT_MODE; | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be good to add:
log.info(
Mode: ${this.defaultMode});