From 063b206d46b32ba9a58a3cc73d54b548b49a8068 Mon Sep 17 00:00:00 2001 From: Alexander Blair Date: Fri, 19 May 2017 16:54:20 -0700 Subject: [PATCH] Moving share validation into remoteShare before it ever gets to our internal processing DB loop. --- lib/local_comms.js | 4 +++- lib/remoteShare.js | 8 +++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/local_comms.js b/lib/local_comms.js index 3ca0829..19829e8 100644 --- a/lib/local_comms.js +++ b/lib/local_comms.js @@ -188,14 +188,15 @@ function Database(){ }; let shares = {}; // Shares keyed by blockID let shareCount = 0; + debug(shareObject.length + ' shares to process'); shareObject.forEach(function(data){ //Data is the share object at this point. let share = global.protos.Share.decode(data); + shareCount += 1; if (!shares.hasOwnProperty(share.blockHeight)){ shares[share.blockHeight] = []; } shares[share.blockHeight].push(data); - shareCount += 1; let minerID = share.paymentAddress; if (typeof(share.paymentID) !== 'undefined' && share.paymentID.length > 10) { minerID = minerID + '.' + share.paymentID; @@ -276,6 +277,7 @@ function Database(){ sharesSeen += 1; txn.putBinary(global.database.shareDB, key, share); if (Object.keys(shares).length === blocksSeen && sharesSeen === shares[key].length){ + debug('Made it to where I can do the insert'); txn.commit(); return true; } diff --git a/lib/remoteShare.js b/lib/remoteShare.js index ed02ae8..4d9a905 100644 --- a/lib/remoteShare.js +++ b/lib/remoteShare.js @@ -37,7 +37,11 @@ app.post('/leafApi', function (req, res) { } switch (msgData.msgType) { case global.protos.MESSAGETYPE.SHARE: - process.send({block: msgData.exInt, data: msgData.msg}); + try { + global.protos.Share.decode(msgData.msg); + process.send({block: msgData.exInt, data: msgData.msg}); + } catch (e){ + } return res.json({'success': true}); case global.protos.MESSAGETYPE.BLOCK: global.database.storeBlock(msgData.exInt, msgData.msg, function(data){ @@ -80,6 +84,7 @@ if (cluster.isMaster) { for (let i = 0; i < numWorkers; i++) { let worker = cluster.fork(); + worker.on('message', messageHandler); workerList.push(worker); } @@ -91,6 +96,7 @@ if (cluster.isMaster) { console.log('Worker ' + worker.process.pid + ' died with code: ' + code + ', and signal: ' + signal); console.log('Starting a new worker'); worker = cluster.fork(); + worker.on('message', messageHandler); workerList.push(worker); }); } else {