optimization

This commit is contained in:
cubedro 2015-05-05 01:31:19 +03:00
parent 019507a44f
commit c2f8a103bd

View File

@ -177,9 +177,10 @@ Node.prototype.setupSockets = function()
.on('ready', function() .on('ready', function()
{ {
self._socket = true; self._socket = true;
self.sendUpdate(true);
console.info('==> The connection has been established.'); console.info('==> The connection has been established.');
self.updateBlock();
self.update(true);
}) })
.on('data', function incoming(data) .on('data', function incoming(data)
{ {
@ -216,7 +217,7 @@ Node.prototype.setupSockets = function()
}) })
.on('reconnecting', function reconnecting(opts) .on('reconnecting', function reconnecting(opts)
{ {
console.warn('We are scheduling a reconnect operation', opts); console.warn('!!!', 'We are scheduling a reconnect operation', opts);
}); });
} }
@ -249,6 +250,10 @@ Node.prototype.setInactive = function()
Node.prototype.getInfo = function() Node.prototype.getInfo = function()
{ {
var start = _.now();
console.info('==>', 'Getting info');
try { try {
this.info.coinbase = web3.eth.coinbase; this.info.coinbase = web3.eth.coinbase;
this.info.node = web3.version.client; this.info.node = web3.version.client;
@ -256,7 +261,8 @@ Node.prototype.getInfo = function()
this.info.protocol = web3.toDecimal(web3.version.ethereum); this.info.protocol = web3.toDecimal(web3.version.ethereum);
this.info.api = web3.version.api; this.info.api = web3.version.api;
console.info(this.info); console.info('==>', 'Got info in', _.now() - start, 'ms');
console.info(' i ', this.info);
return true; return true;
} }
@ -273,7 +279,8 @@ Node.prototype.getBlock = function(number)
number: 0, number: 0,
hash: '?', hash: '?',
difficulty: 0, difficulty: 0,
timestamp: 0 timestamp: 0,
miner: ''
}; };
if( _.isUndefined(number) ) if( _.isUndefined(number) )
@ -617,8 +624,9 @@ Node.prototype.setWatches = function()
{ {
var now = _.now(); var now = _.now();
var time = now - self._lastPendingLog; var time = now - self._lastPendingLog;
self._lastPendingLog = now;
console.log('>>> Pending Filter triggered: ', now); console.log('>>> Pending Filter triggered: ', now, '- last trigger:', time);
if(time > 50) if(time > 50)
{ {
@ -630,8 +638,6 @@ Node.prototype.setWatches = function()
self.update(true); self.update(true);
}, 50); }, 50);
} }
self._lastPendingLog = now;
}); });
} }
catch (err) catch (err)
@ -651,13 +657,17 @@ Node.prototype.setWatches = function()
Node.prototype.installContract = function() Node.prototype.installContract = function()
{ {
var start = _.now();
try { try {
Contract = web3.eth.contract( registrar.desc ); Contract = web3.eth.contract( registrar.desc );
this._Registrar = new Contract( registrar.address ); this._Registrar = new Contract( registrar.address );
console.log('==>', 'Installed Registrar contract in', _.now() - start, 'ms');
} }
catch (err) catch (err)
{ {
console.error("Couldn't set up registrar contract"); console.error("!!!", "Couldn't set up registrar contract");
console.error(err); console.error(err);
} }
} }
@ -667,20 +677,14 @@ Node.prototype.init = function()
// Fetch node info // Fetch node info
this.getInfo(); this.getInfo();
// Start socket connection
this.startSocketConnection();
// Install Registrar contract // Install Registrar contract
this.installContract(); this.installContract();
// Start socket connection
this.startSocketConnection();
// Set filters // Set filters
this.setWatches(); this.setWatches();
// Update block and send info
this.updateBlock();
// Update stats and send info
this.update();
} }
Node.prototype.stop = function() Node.prototype.stop = function()