Moving share validation into remoteShare before it ever gets to our internal processing DB loop.

This commit is contained in:
Alexander Blair
2017-05-19 16:54:20 -07:00
parent cdf17d4e70
commit 063b206d46
2 changed files with 10 additions and 2 deletions
+3 -1
View File
@@ -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;
}
+7 -1
View File
@@ -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 {