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

Light client #1547

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from 4 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
7 changes: 6 additions & 1 deletion interface/i18n/mist.en.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@
"ethereumNode": "Ethereum Node",
"network": "Network",
"mainNetwork": "Main Network",
"nodeMode": "Chain download",
"fullNode": "Store full blockchain",
"lightNode": "Use light Node (experimental!)",
"mainNetwork": "Main Network",
"startMining": "⛏ Start Mining (Testnet only)",
"stopMining": "⛏ Stop Mining"
},
Expand Down Expand Up @@ -226,7 +230,7 @@
"lookupDataExplainer": "Look this up on the internet"
},
"onboarding": {
"description" : "Ethereum is a public blockchain that features a turing complete programming for building solid, decentralized applications.",
"description" : "Ethereum is a platform for decentralized blockchain apps with a fully featured programming language",
"goToTestnet" : "Use the test network",
"goToTestnetDescription" : "Test the technology freely in a sandboxed testnet, without using real ether.",
"gotoMainnet" : "Use the main network",
Expand All @@ -253,6 +257,7 @@
"downloadingBlocks": "Downloading blocks",
"syncMessage": "Block __displayBlock__ of __highestBlockString__",
"syncMessageWithStates": "Block __displayBlock__ of __highestBlockString__ (Chain structure __statesPercent__%)",
"startingSync": "Getting ready to sync..",
"tutorial1Description" : "<p> Now the only thing left to do is wait for the download to finish. Here's some reading suggestions: </p> <h4>Make your own money </h4> <p> Make a cryptocurrency with a fixed market supply, tokens representing real world assets, etc </p>",
"tutorial2Description" : "<h4> Create a crowdsale </h4> <p> Raise funds for a common goal, fully trustable without a third party. Sidestep the hurdle of traditional funding system and go directly to the source by funding an organization via the blockchain.</p>",
"tutorial3Description" : "<h4> Create a blockchain organization </h4> <p> Create an autonomous organization with rules on spending money and making decisions for you and your investors.</p>",
Expand Down
67 changes: 43 additions & 24 deletions modules/ethereumNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -22,7 +22,7 @@ const NODE_START_WAIT_MS = 3000;


/**
* Etheruem nodes manager.
* Ethereum nodes manager.
*/
class EthereumNode extends EventEmitter {
constructor() {
Expand All @@ -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);

Expand All @@ -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';
}
Expand All @@ -77,6 +82,10 @@ class EthereumNode extends EventEmitter {
return this.network === 'test';
}

get isLightClient() {
return this.mode === 'light';
}

get state() {
return this._state;
}
Expand Down Expand Up @@ -130,7 +139,7 @@ class EthereumNode extends EventEmitter {
log.info(`Network: ${this.defaultNetwork}`);
Copy link
Contributor

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});


// 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);

Expand All @@ -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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whats this this.nodeMode ? i never see this variable created,shouldnt it be this.mode or something?

})
.then(() => {
Windows.loading.hide();
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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');

Expand All @@ -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);

Expand All @@ -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 */
Expand Down Expand Up @@ -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;
Expand All @@ -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);
});
}
Expand All @@ -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');

Expand All @@ -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'];
}

Expand Down Expand Up @@ -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;
}
}

Expand Down
35 changes: 30 additions & 5 deletions modules/menuItems.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,13 @@ const createMenu = function (webviews) {
};


const restartNode = function (newType, newNetwork) {
const restartNode = function (newType, newNetwork, newMode) {
newNetwork = newNetwork || ethereumNode.network;
newMode = newMode || ethereumNode.mode;

log.info('Switch node', newType, newNetwork);
log.info('Switch node type, network and mode', newType, newNetwork, newMode);

return ethereumNode.restart(newType, newNetwork)
return ethereumNode.restart(newType, newNetwork, newMode)
.then(() => {
Windows.getByType('main').load(global.interfaceAppUrl);

Expand Down Expand Up @@ -418,7 +419,7 @@ let menuTempl = function (webviews) {
enabled: ethereumNode.isOwnNode && !ethereumNode.isMainNetwork,
type: 'checkbox',
click() {
restartNode(ethereumNode.type, 'main');
restartNode(ethereumNode.type, 'main', ethereumNode.mode);
},
},
{
Expand All @@ -428,10 +429,34 @@ let menuTempl = function (webviews) {
enabled: ethereumNode.isOwnNode && !ethereumNode.isTestNetwork,
type: 'checkbox',
click() {
restartNode(ethereumNode.type, 'test');
restartNode(ethereumNode.type, 'test', ethereumNode.mode);
},
},
] });

// add light mode switch
devToolsMenu.push({
label: i18n.t('mist.applicationMenu.develop.nodeMode'),
submenu: [
{
label: i18n.t('mist.applicationMenu.develop.fullNode'),
checked: ethereumNode.isOwnNode && !ethereumNode.isLightClient,
enabled: ethereumNode.isOwnNode && ethereumNode.isLightClient,
type: 'checkbox',
click() {
restartNode(ethereumNode.type, ethereumNode.network, 'full');
},
},
{
label: i18n.t('mist.applicationMenu.develop.lightNode'),
checked: ethereumNode.isOwnNode && ethereumNode.isLightClient,
enabled: ethereumNode.isOwnNode && !ethereumNode.isLightClient,
type: 'checkbox',
click() {
restartNode(ethereumNode.type, ethereumNode.network, 'light');
},
},
] });


devToolsMenu.push({
Expand Down